Compare commits
	
		
			4 Commits
		
	
	
		
			v0.0.10-al
			...
			v0.0.11-al
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 0d690e7630 | ||
|  | 4b0d857e9c | ||
|  | d2d1398f89 | ||
|  | de5321565d | 
| @@ -37,10 +37,10 @@ android { | ||||
|  | ||||
|     defaultConfig { | ||||
|         applicationId "com.keyboardcrumbs.haclient" | ||||
|         minSdkVersion 16 | ||||
|         minSdkVersion 21 | ||||
|         targetSdkVersion 27 | ||||
|         versionCode 15 | ||||
|         versionName "0.0.10-alpha1" | ||||
|         versionCode 16 | ||||
|         versionName "0.0.11-alpha" | ||||
|         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -31,6 +31,7 @@ class HassioDataModel { | ||||
|   Completer _servicesCompleter; | ||||
|   Completer _configCompleter; | ||||
|   Timer _fetchingTimer; | ||||
|   List _topBadgeDomains = ["alarm_control_panel", "binary_sensor", "device_tracker", "updater", "sun", "timer", "sensor"]; | ||||
|  | ||||
|   Map get entities => _entitiesData; | ||||
|   Map get services => _servicesData; | ||||
| @@ -277,18 +278,38 @@ class HassioDataModel { | ||||
|  | ||||
|     //Gethering information for UI | ||||
|     debugPrint("Gethering views"); | ||||
|     uiGroups.forEach((viewId) { | ||||
|     int viewCounter = 0; | ||||
|     uiGroups.forEach((viewId) { //Each view | ||||
|       viewCounter +=1; | ||||
|       var viewGroup = _entitiesData[viewId]; | ||||
|       Map viewGroupStructure = {}; | ||||
|       if (viewGroup != null) { | ||||
|         viewGroupStructure["standalone"] = []; | ||||
|         viewGroupStructure["groups"] = []; | ||||
|         viewGroupStructure["standalone"] = {}; | ||||
|         viewGroupStructure["groups"] = {}; | ||||
|         viewGroupStructure["groups"]["haclientui.badges"] = {"children": [], "friendly_name": "Badges"}; | ||||
|         viewGroupStructure["iconCode"] = viewGroup["iconCode"]; | ||||
|         viewGroup["attributes"]["entity_id"].forEach((entityId) { | ||||
|           if (_entitiesData[entityId]["domain"] != "group") { | ||||
|             viewGroupStructure["standalone"].add(entityId); | ||||
|  | ||||
|  | ||||
|         viewGroup["attributes"]["entity_id"].forEach((entityId) { //Each entity or group in view | ||||
|           Map newGroup = {}; | ||||
|           String domain = _entitiesData[entityId]["domain"]; | ||||
|           if (domain != "group") { | ||||
|             String autoGroupID; | ||||
|             if (_topBadgeDomains.contains(domain)) { | ||||
|               autoGroupID = "haclientui.badges"; | ||||
|             } else { | ||||
|               autoGroupID = "$domain.$domain$viewCounter"; | ||||
|             } | ||||
|             if (viewGroupStructure["groups"]["$autoGroupID"] == null) { | ||||
|               newGroup["entity_id"] = "$domain.$domain$viewCounter"; | ||||
|               newGroup["friendly_name"] = "$domain"; | ||||
|               newGroup["children"] = []; | ||||
|               newGroup["children"].add(entityId); | ||||
|               viewGroupStructure["groups"]["$autoGroupID"] = Map.from(newGroup); | ||||
|             } else { | ||||
|               viewGroupStructure["groups"]["$autoGroupID"]["children"].add(entityId); | ||||
|             } | ||||
|           } else { | ||||
|             Map newGroup = {}; | ||||
|             newGroup["entity_id"] = entityId; | ||||
|             newGroup["friendly_name"] = | ||||
|             (_entitiesData[entityId]['attributes'] != null) | ||||
| @@ -299,7 +320,7 @@ class HassioDataModel { | ||||
|                 groupedEntityId) { | ||||
|               newGroup["children"].add(groupedEntityId); | ||||
|             }); | ||||
|             viewGroupStructure["groups"].add(Map.from(newGroup)); | ||||
|             viewGroupStructure["groups"]["$entityId"] = Map.from(newGroup); | ||||
|           } | ||||
|         }); | ||||
|       _uiStructure[viewId.split(".")[1]] = viewGroupStructure; | ||||
|   | ||||
							
								
								
									
										170
									
								
								lib/main.dart
									
									
									
									
									
								
							
							
						
						
									
										170
									
								
								lib/main.dart
									
									
									
									
									
								
							| @@ -13,7 +13,7 @@ part 'data_model.dart'; | ||||
|  | ||||
| EventBus eventBus = new EventBus(); | ||||
| const String appName = "HA Client"; | ||||
| const appVersion = "0.0.10-alpha1"; | ||||
| const appVersion = "0.0.11-alpha"; | ||||
|  | ||||
| void main() => runApp(new HassClientApp()); | ||||
|  | ||||
| @@ -156,6 +156,91 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|     }).catchError((e) => _setErrorState(e)); | ||||
|   } | ||||
|  | ||||
|   List<Widget> _buildViews() { | ||||
|     List<Widget> result = []; | ||||
|     if ((_entitiesData != null) && (_uiStructure != null)) { | ||||
|       _uiStructure.forEach((viewId, structure) { | ||||
|         result.add( | ||||
|             RefreshIndicator( | ||||
|               color: Colors.amber, | ||||
|               child: ListView( | ||||
|                 physics: const AlwaysScrollableScrollPhysics(), | ||||
|                 children: _buildSingleView(structure), | ||||
|               ), | ||||
|               onRefresh: () => _refreshData(), | ||||
|             ) | ||||
|         ); | ||||
|       }); | ||||
|     } | ||||
|     return result; | ||||
|   } | ||||
|  | ||||
|   List<Widget> _buildSingleView(structure) { | ||||
|     List<Widget> result = []; | ||||
|     /*structure["standalone"].forEach((entityId) { | ||||
|         result.add(_buildCard([entityId], "")); | ||||
|       });*/ | ||||
|     structure["groups"].forEach((id, group) { | ||||
|       if (group["children"].length > 0) { | ||||
|         result.add(_buildCard( | ||||
|             group["children"], group["friendly_name"].toString())); | ||||
|       } | ||||
|     }); | ||||
|  | ||||
|     return result; | ||||
|   } | ||||
|  | ||||
|   Card _buildCard(List ids, String name) { | ||||
|     List<Widget> body = []; | ||||
|     body.add(_buildCardHeader(name)); | ||||
|     body.addAll(_buildCardBody(ids)); | ||||
|     Card result = | ||||
|     Card(child: new Column(mainAxisSize: MainAxisSize.min, children: body)); | ||||
|     return result; | ||||
|   } | ||||
|  | ||||
|   Widget _buildCardHeader(String name) { | ||||
|     var result; | ||||
|     if (name.length > 0) { | ||||
|       result = new ListTile( | ||||
|         //leading: const Icon(Icons.device_hub), | ||||
|         //subtitle: Text(".."), | ||||
|         //trailing: Text("${data["state"]}"), | ||||
|         title: Text("$name", | ||||
|             textAlign: TextAlign.left, | ||||
|             overflow: TextOverflow.ellipsis, | ||||
|             style: new TextStyle(fontWeight: FontWeight.bold, fontSize: 25.0)), | ||||
|       ); | ||||
|     } else { | ||||
|       result = new Container(width: 0.0, height: 0.0); | ||||
|     } | ||||
|     return result; | ||||
|   } | ||||
|  | ||||
|   List<Widget> _buildCardBody(List ids) { | ||||
|     List<Widget> entities = []; | ||||
|     ids.forEach((id) { | ||||
|       var data = _entitiesData[id]; | ||||
|       if (data == null) { | ||||
|         debugPrint("Hiding unknown entity from card: $id"); | ||||
|       } else { | ||||
|         entities.add(new ListTile( | ||||
|           leading: Icon( | ||||
|             _createMDIfromCode(data["iconCode"]), | ||||
|             color: _stateIconColors[data["state"]] ?? Colors.blueGrey, | ||||
|           ), | ||||
|           //subtitle: Text("${data['entity_id']}"), | ||||
|           trailing: _buildEntityAction(id), | ||||
|           title: Text( | ||||
|             "${data["display_name"]}", | ||||
|             overflow: TextOverflow.ellipsis, | ||||
|           ), | ||||
|         )); | ||||
|       } | ||||
|     }); | ||||
|     return entities; | ||||
|   } | ||||
|  | ||||
|   Widget _buildEntityAction(String entityId) { | ||||
|     var entity = _entitiesData[entityId]; | ||||
|     Widget result; | ||||
| @@ -201,82 +286,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|     return result; | ||||
|   } | ||||
|  | ||||
|   Card _buildCard(List<String> ids, String name) { | ||||
|     List<Widget> body = []; | ||||
|     body.add(_buildCardHeader(name)); | ||||
|     body.addAll(_buildCardBody(ids)); | ||||
|     Card result = | ||||
|         Card(child: new Column(mainAxisSize: MainAxisSize.min, children: body)); | ||||
|     return result; | ||||
|   } | ||||
|  | ||||
|   Widget _buildCardHeader(String name) { | ||||
|     var result; | ||||
|     if (name.length > 0) { | ||||
|       result = new ListTile( | ||||
|         //leading: const Icon(Icons.device_hub), | ||||
|         //subtitle: Text(".."), | ||||
|         //trailing: Text("${data["state"]}"), | ||||
|         title: Text("$name", | ||||
|             textAlign: TextAlign.left, | ||||
|             overflow: TextOverflow.ellipsis, | ||||
|             style: new TextStyle(fontWeight: FontWeight.bold, fontSize: 25.0)), | ||||
|       ); | ||||
|     } else { | ||||
|       result = new Container(width: 0.0, height: 0.0); | ||||
|     } | ||||
|     return result; | ||||
|   } | ||||
|  | ||||
|   List<Widget> _buildCardBody(List<String> ids) { | ||||
|     List<Widget> entities = []; | ||||
|     ids.forEach((id) { | ||||
|       var data = _entitiesData[id]; | ||||
|       if (data == null) { | ||||
|         debugPrint("Hiding unknown entity from card: $id"); | ||||
|       } else { | ||||
|         entities.add(new ListTile( | ||||
|           leading: Icon( | ||||
|             _createMDIfromCode(data["iconCode"]), | ||||
|             color: _stateIconColors[data["state"]] ?? Colors.blueGrey, | ||||
|           ), | ||||
|           //subtitle: Text("${data['entity_id']}"), | ||||
|           trailing: _buildEntityAction(id), | ||||
|           title: Text( | ||||
|             "${data["display_name"]}", | ||||
|             overflow: TextOverflow.ellipsis, | ||||
|           ), | ||||
|         )); | ||||
|       } | ||||
|     }); | ||||
|     return entities; | ||||
|   } | ||||
|  | ||||
|   List<Widget> buildSingleView(structure) { | ||||
|       List<Widget> result = []; | ||||
|       structure["standalone"].forEach((entityId) { | ||||
|         result.add(_buildCard([entityId], "")); | ||||
|       }); | ||||
|       structure["groups"].forEach((group) { | ||||
|         result.add(_buildCard( | ||||
|             group["children"], group["friendly_name"].toString())); | ||||
|       }); | ||||
|  | ||||
|       return result; | ||||
|   } | ||||
|  | ||||
|   List<ListView> buildUIViews() { | ||||
|     List<ListView> result = []; | ||||
|     if ((_entitiesData != null) && (_uiStructure != null)) { | ||||
|       _uiStructure.forEach((viewId, structure) { | ||||
|         result.add(ListView( | ||||
|           children: buildSingleView(structure), | ||||
|         )); | ||||
|       }); | ||||
|     } | ||||
|     return result; | ||||
|   } | ||||
|  | ||||
|   IconData _createMDIfromCode(int code) { | ||||
|     return IconData(code, fontFamily: 'Material Design Icons'); | ||||
|   } | ||||
| @@ -468,12 +477,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|             ), | ||||
|             drawer: _buildAppDrawer(), | ||||
|             body: TabBarView( | ||||
|                 children: buildUIViews() | ||||
|             ), | ||||
|             floatingActionButton: new FloatingActionButton( | ||||
|               onPressed: _refreshData, | ||||
|               tooltip: 'Increment', | ||||
|               child: new Icon(Icons.refresh), | ||||
|                 children: _buildViews() | ||||
|             ), | ||||
|           ) | ||||
|       ); | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| name: hass_client | ||||
| description: Home Assistant Android Client | ||||
|  | ||||
| version: 0.0.10-alpha1 | ||||
| version: 0.0.11-alpha | ||||
|  | ||||
| environment: | ||||
|   sdk: ">=2.0.0-dev.68.0 <3.0.0" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user