Reverting views refactoring
This commit is contained in:
@ -4,13 +4,11 @@ class HACard extends StatelessWidget {
|
||||
|
||||
final List<Entity> entities;
|
||||
final String friendlyName;
|
||||
final bool hidden;
|
||||
|
||||
const HACard({
|
||||
Key key,
|
||||
this.entities,
|
||||
this.friendlyName,
|
||||
this.hidden
|
||||
this.friendlyName
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -18,14 +16,10 @@ class HACard extends StatelessWidget {
|
||||
List<Widget> body = [];
|
||||
body.add(_buildCardHeader());
|
||||
body.addAll(_buildCardBody(context));
|
||||
if (hidden) {
|
||||
return Container(height: 0.0,);
|
||||
} else {
|
||||
return Card(
|
||||
child: new Column(mainAxisSize: MainAxisSize.min, children: body)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildCardHeader() {
|
||||
var result;
|
||||
|
@ -62,7 +62,6 @@ class Entity {
|
||||
String get unitOfMeasurement => attributes["unit_of_measurement"] ?? "";
|
||||
List get childEntityIds => attributes["entity_id"] ?? [];
|
||||
String get lastUpdated => _getLastUpdatedFormatted();
|
||||
bool get isHidden => attributes["hidden"] ?? false;
|
||||
|
||||
Entity(Map rawData) {
|
||||
update(rawData);
|
||||
|
@ -781,12 +781,14 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
|
||||
Color _tmpColor;
|
||||
bool _changedHere = false;
|
||||
String _tmpEffect;
|
||||
String _tmpFlash;
|
||||
|
||||
void _resetState(LightEntity entity) {
|
||||
_tmpBrightness = entity.brightness;
|
||||
_tmpColorTemp = entity.colorTemp;
|
||||
_tmpColor = entity.color;
|
||||
_tmpEffect = null;
|
||||
_tmpFlash = null;
|
||||
}
|
||||
|
||||
void _setBrightness(LightEntity entity, double value) {
|
||||
@ -844,6 +846,18 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
|
||||
});
|
||||
}
|
||||
|
||||
void _setFlash(LightEntity entity, String value) {
|
||||
setState(() {
|
||||
_tmpFlash = value;
|
||||
_changedHere = true;
|
||||
if (_tmpFlash != null) {
|
||||
eventBus.fire(new ServiceCallEvent(
|
||||
entity.domain, "turn_on", entity.entityId,
|
||||
{"flash": "$value"}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final entityModel = EntityModel.of(context);
|
||||
|
@ -13,8 +13,8 @@ class ViewBuilder{
|
||||
}
|
||||
|
||||
Widget buildWidget(BuildContext context) {
|
||||
return TabBarView(
|
||||
children: _views
|
||||
return ViewBuilderWidget(
|
||||
entities: _views
|
||||
);
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ class ViewBuilder{
|
||||
entitiesForView.add(entityCollection.get(entityId));
|
||||
});
|
||||
return View(
|
||||
childEntities: entitiesForView,
|
||||
entities: entitiesForView,
|
||||
count: 0
|
||||
);
|
||||
}
|
||||
@ -68,7 +68,7 @@ class ViewBuilder{
|
||||
});
|
||||
result.add(View(
|
||||
count: counter,
|
||||
childEntities: entitiesForView
|
||||
entities: entitiesForView
|
||||
));
|
||||
/*} catch (error) {
|
||||
TheLogger.log("Error","Error parsing view: $viewId");
|
||||
@ -77,3 +77,29 @@ class ViewBuilder{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
class ViewBuilderWidget extends StatelessWidget {
|
||||
|
||||
final List<View> entities;
|
||||
|
||||
const ViewBuilderWidget({
|
||||
Key key,
|
||||
this.entities
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TabBarView(
|
||||
children: _buildChildren(context)
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildChildren(BuildContext context) {
|
||||
List<Widget> result = [];
|
||||
entities.forEach((View view){
|
||||
result.add(view.buildWidget(context));
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +1,77 @@
|
||||
part of 'main.dart';
|
||||
|
||||
class View extends StatefulWidget {
|
||||
final String displayName;
|
||||
final List<Entity> childEntities;
|
||||
final int count;
|
||||
class View {
|
||||
List<Entity> childEntitiesAsBadges;
|
||||
Map<String, CardSkeleton> childEntitiesAsCards;
|
||||
|
||||
int count;
|
||||
List<Entity> entities;
|
||||
|
||||
View({
|
||||
Key key,
|
||||
@required this.childEntities,
|
||||
@required this.count,
|
||||
this.count,
|
||||
this.entities
|
||||
}) {
|
||||
childEntitiesAsBadges = [];
|
||||
childEntitiesAsCards = {};
|
||||
_composeEntities();
|
||||
}
|
||||
|
||||
Widget buildWidget(BuildContext context) {
|
||||
return ViewWidget(
|
||||
badges: childEntitiesAsBadges,
|
||||
cards: childEntitiesAsCards,
|
||||
);
|
||||
}
|
||||
|
||||
void _composeEntities() {
|
||||
entities.forEach((Entity entity){
|
||||
if (!entity.isGroup) {
|
||||
if (entity.isBadge) {
|
||||
childEntitiesAsBadges.add(entity);
|
||||
} else {
|
||||
String groupIdToAdd = "${entity.domain}.${entity.domain}$count";
|
||||
if (childEntitiesAsCards[groupIdToAdd] == null) {
|
||||
childEntitiesAsCards[groupIdToAdd] = CardSkeleton(
|
||||
displayName: entity.domain,
|
||||
);
|
||||
}
|
||||
childEntitiesAsCards[groupIdToAdd].childEntities.add(entity);
|
||||
}
|
||||
} else {
|
||||
childEntitiesAsCards[entity.entityId] = CardSkeleton(
|
||||
displayName: entity.displayName,
|
||||
);
|
||||
childEntitiesAsCards[entity.entityId].childEntities = entity.childEntities;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ViewWidget extends StatefulWidget {
|
||||
final List<Entity> badges;
|
||||
final Map<String, CardSkeleton> cards;
|
||||
final String displayName;
|
||||
|
||||
const ViewWidget({
|
||||
Key key,
|
||||
this.badges,
|
||||
this.cards,
|
||||
this.displayName
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return ViewState();
|
||||
return ViewWidgetState();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ViewState extends State<View> {
|
||||
class ViewWidgetState extends State<ViewWidget> {
|
||||
|
||||
StreamSubscription _refreshDataSubscription;
|
||||
Completer _refreshCompleter;
|
||||
List<Entity> _childEntitiesAsBadges;
|
||||
Map<String, Entity> _childEntitiesAsCards;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -34,28 +81,6 @@ class ViewState extends State<View> {
|
||||
_refreshCompleter.complete();
|
||||
}
|
||||
});
|
||||
_childEntitiesAsCards = {};
|
||||
_childEntitiesAsBadges = [];
|
||||
_composeEntities();
|
||||
}
|
||||
|
||||
void _composeEntities() {
|
||||
widget.childEntities.forEach((Entity entity){
|
||||
if (!entity.isGroup) {
|
||||
if (entity.isBadge) {
|
||||
_childEntitiesAsBadges.add(entity);
|
||||
} else {
|
||||
String groupIdToAdd = "${entity.domain}.${entity.domain}${widget.count}";
|
||||
if (_childEntitiesAsCards[groupIdToAdd] == null) {
|
||||
_childEntitiesAsCards[groupIdToAdd] = entity;
|
||||
}
|
||||
_childEntitiesAsCards[groupIdToAdd].childEntities.add(entity);
|
||||
}
|
||||
} else {
|
||||
_childEntitiesAsCards[entity.entityId] = entity;
|
||||
_childEntitiesAsCards[entity.entityId].childEntities = entity.childEntities;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@ -73,23 +98,22 @@ class ViewState extends State<View> {
|
||||
List<Widget> _buildChildren(BuildContext context) {
|
||||
List<Widget> result = [];
|
||||
|
||||
if (_childEntitiesAsBadges.isNotEmpty) {
|
||||
if (widget.badges.isNotEmpty) {
|
||||
result.insert(0,
|
||||
Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
spacing: 10.0,
|
||||
runSpacing: 1.0,
|
||||
children: _buildBadges(context),
|
||||
children: _buildBadges(context, widget.badges),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
_childEntitiesAsCards.forEach((String id, Entity groupEntity){
|
||||
widget.cards.forEach((String id, CardSkeleton skeleton){
|
||||
result.add(
|
||||
HACard(
|
||||
entities: groupEntity.childEntities,
|
||||
friendlyName: groupEntity.displayName,
|
||||
hidden: groupEntity.isHidden
|
||||
entities: skeleton.childEntities,
|
||||
friendlyName: skeleton.displayName,
|
||||
)
|
||||
);
|
||||
});
|
||||
@ -97,9 +121,9 @@ class ViewState extends State<View> {
|
||||
return result;
|
||||
}
|
||||
|
||||
List<Widget> _buildBadges(BuildContext context) {
|
||||
List<Widget> _buildBadges(BuildContext context, List<Entity> badges) {
|
||||
List<Widget> result = [];
|
||||
_childEntitiesAsBadges.forEach((Entity entity) {
|
||||
badges.forEach((Entity entity) {
|
||||
result.add(entity.buildBadgeWidget(context));
|
||||
});
|
||||
return result;
|
||||
@ -120,4 +144,15 @@ class ViewState extends State<View> {
|
||||
_refreshDataSubscription.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class CardSkeleton {
|
||||
String displayName;
|
||||
List<Entity> childEntities;
|
||||
|
||||
CardSkeleton({Key key, this.displayName, this.childEntities}) {
|
||||
childEntities = [];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user