Revert all rash decisions
This commit is contained in:
@ -1,175 +0,0 @@
|
||||
part of '../../main.dart';
|
||||
|
||||
class AppDrawer extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<Widget> menuItems = [];
|
||||
menuItems.add(
|
||||
UserAccountsDrawerHeader(
|
||||
accountName: Text(HomeAssistant().userName),
|
||||
accountEmail: Text(ConnectionManager().displayHostname ?? "Not configured"),
|
||||
onDetailsPressed: () {
|
||||
final flutterWebViewPlugin = new FlutterWebviewPlugin();
|
||||
flutterWebViewPlugin.onStateChanged.listen((viewState) async {
|
||||
if (viewState.type == WebViewState.startLoad) {
|
||||
Logger.d("[WebView] Injecting external auth JS");
|
||||
rootBundle.loadString('assets/js/externalAuth.js').then((js){
|
||||
flutterWebViewPlugin.evalJavascript(js.replaceFirst("[token]", ConnectionManager()._token));
|
||||
});
|
||||
}
|
||||
});
|
||||
Navigator.of(context).pushNamed(
|
||||
"/webview",
|
||||
arguments: {
|
||||
"url": "${ConnectionManager().httpWebHost}/profile?external_auth=1",
|
||||
"title": "Profile"
|
||||
}
|
||||
);
|
||||
},
|
||||
currentAccountPicture: CircleAvatar(
|
||||
child: Text(
|
||||
HomeAssistant().userAvatarText,
|
||||
style: TextStyle(
|
||||
fontSize: 32.0
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
if (HomeAssistant().panels.isNotEmpty) {
|
||||
HomeAssistant().panels.forEach((Panel panel) {
|
||||
if (!panel.isHidden) {
|
||||
menuItems.add(
|
||||
new ListTile(
|
||||
leading: Icon(MaterialDesignIcons.getIconDataFromIconName(panel.icon)),
|
||||
title: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text("${panel.title}"),
|
||||
Container(width: 4.0,),
|
||||
panel.isWebView ? Text("webview", style: TextStyle(fontSize: 8.0, color: Colors.black45),) : Container(width: 1.0,)
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
panel.handleOpen(context);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
menuItems.addAll([
|
||||
Divider(),
|
||||
ListTile(
|
||||
leading: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:login-variant")),
|
||||
title: Text("Connection settings"),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pushNamed('/connection-settings');
|
||||
},
|
||||
)
|
||||
]);
|
||||
menuItems.addAll([
|
||||
Divider(),
|
||||
new ListTile(
|
||||
leading: Icon(Icons.insert_drive_file),
|
||||
title: Text("Log"),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pushNamed('/log-view');
|
||||
},
|
||||
),
|
||||
new ListTile(
|
||||
leading: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:github-circle")),
|
||||
title: Text("Report an issue"),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
Launcher.launchURL("https://github.com/estevez-dev/ha_client/issues/new");
|
||||
},
|
||||
),
|
||||
Divider(),
|
||||
new ListTile(
|
||||
leading: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:food")),
|
||||
title: Text("Support app development"),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pushNamed('/putchase');
|
||||
},
|
||||
),
|
||||
Divider(),
|
||||
new ListTile(
|
||||
leading: Icon(Icons.help),
|
||||
title: Text("Help"),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
Launcher.launchURL("http://ha-client.homemade.systems/docs");
|
||||
},
|
||||
),
|
||||
new ListTile(
|
||||
leading: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:discord")),
|
||||
title: Text("Join Discord channel"),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
Launcher.launchURL("https://discord.gg/AUzEvwn");
|
||||
},
|
||||
),
|
||||
new AboutListTile(
|
||||
aboutBoxChildren: <Widget>[
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
Launcher.launchURL("http://ha-client.homemade.systems/");
|
||||
},
|
||||
child: Text(
|
||||
"ha-client.homemade.systems",
|
||||
style: TextStyle(
|
||||
color: Colors.blue,
|
||||
decoration: TextDecoration.underline
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
height: 10.0,
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
Launcher.launchURLInCustomTab(context: context, url: "http://ha-client.homemade.systems/terms_and_conditions");
|
||||
},
|
||||
child: Text(
|
||||
"Terms and Conditions",
|
||||
style: TextStyle(
|
||||
color: Colors.blue,
|
||||
decoration: TextDecoration.underline
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
height: 10.0,
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
Launcher.launchURLInCustomTab(context: context, url: "http://ha-client.homemade.systems/privacy_policy");
|
||||
},
|
||||
child: Text(
|
||||
"Privacy Policy",
|
||||
style: TextStyle(
|
||||
color: Colors.blue,
|
||||
decoration: TextDecoration.underline
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
applicationName: appName,
|
||||
applicationVersion: appVersion
|
||||
)
|
||||
]);
|
||||
return new Drawer(
|
||||
child: ListView(
|
||||
children: menuItems,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
part of '../../main.dart';
|
||||
|
||||
class MainPageBody extends StatelessWidget {
|
||||
|
||||
final bool empty;
|
||||
final onReload;
|
||||
final onMenu;
|
||||
final TabController tabController;
|
||||
|
||||
const MainPageBody({Key key, this.empty, this.onReload, this.tabController, this.onMenu}) : super(key: key);
|
||||
|
||||
List<Tab> buildUIViewTabs() {
|
||||
List<Tab> result = [];
|
||||
|
||||
if (HomeAssistant().ui.views.isNotEmpty) {
|
||||
HomeAssistant().ui.views.forEach((HAView view) {
|
||||
//TODO Create a widget for that and pass view to it. An opposit way as it is implemented now
|
||||
result.add(view.buildTab());
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<PopupMenuItem<String>> popupMenuItems = [];
|
||||
|
||||
popupMenuItems.add(PopupMenuItem<String>(
|
||||
child: new Text("Reload"),
|
||||
value: "reload",
|
||||
));
|
||||
/*List<Widget> emptyBody = [
|
||||
Text("."),
|
||||
];*/
|
||||
if (ConnectionManager().isAuthenticated) {
|
||||
//_showLoginButton = false;
|
||||
popupMenuItems.add(
|
||||
PopupMenuItem<String>(
|
||||
child: new Text("Logout"),
|
||||
value: "logout",
|
||||
));
|
||||
}
|
||||
Widget bodyWidget;
|
||||
if (empty) {
|
||||
bodyWidget = Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
CircularProgressIndicator()
|
||||
],
|
||||
);
|
||||
} else {
|
||||
bodyWidget = HomeAssistant().buildViews(context, tabController);
|
||||
}
|
||||
/*if (_showLoginButton) {
|
||||
emptyBody = [
|
||||
FlatButton(
|
||||
child: Text("Login with Home Assistant", style: TextStyle(fontSize: 16.0, color: Colors.white)),
|
||||
color: Colors.blue,
|
||||
onPressed: () => _fullLoad(),
|
||||
)
|
||||
];
|
||||
}*/
|
||||
return NestedScrollView(
|
||||
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
|
||||
return <Widget>[
|
||||
SliverAppBar(
|
||||
floating: true,
|
||||
pinned: true,
|
||||
primary: true,
|
||||
title: Text(HomeAssistant().locationName ?? ""),
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(MaterialDesignIcons.getIconDataFromIconName(
|
||||
"mdi:dots-vertical"), color: Colors.white,),
|
||||
onPressed: () {
|
||||
showMenu(
|
||||
position: RelativeRect.fromLTRB(MediaQuery.of(context).size.width, 70.0, 0.0, 0.0),
|
||||
context: context,
|
||||
items: popupMenuItems
|
||||
).then((String val) {
|
||||
if (val == "reload") {
|
||||
onReload();
|
||||
} else if (val == "logout") {
|
||||
HomeAssistant().logout().then((_) {
|
||||
onReload();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
)
|
||||
],
|
||||
leading: IconButton(
|
||||
icon: Icon(Icons.menu),
|
||||
onPressed: () => onMenu(),
|
||||
),
|
||||
bottom: empty ? null : TabBar(
|
||||
controller: tabController,
|
||||
tabs: buildUIViewTabs(),
|
||||
isScrollable: true,
|
||||
),
|
||||
),
|
||||
|
||||
];
|
||||
},
|
||||
body: bodyWidget,
|
||||
);
|
||||
}
|
||||
}
|
@ -1,242 +0,0 @@
|
||||
part of '../../main.dart';
|
||||
|
||||
class UserErrorActionButton extends StatelessWidget {
|
||||
|
||||
final onPressed;
|
||||
final String text;
|
||||
|
||||
const UserErrorActionButton({Key key, this.onPressed, this.text}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RaisedButton(
|
||||
onPressed: () => this.onPressed(),
|
||||
color: Colors.blue,
|
||||
child: Text(
|
||||
"${this.text}",
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class UserErrorPanel extends StatelessWidget {
|
||||
|
||||
final UserError error;
|
||||
|
||||
const UserErrorPanel({Key key, this.error}) : super(key: key);
|
||||
|
||||
void _goToAppSettings(BuildContext context) {
|
||||
Navigator.pushNamed(context, '/connection-settings');
|
||||
}
|
||||
|
||||
void _reload() {
|
||||
eventBus.fire(ReloadUIEvent(true));
|
||||
}
|
||||
|
||||
void _disableLovelace() {
|
||||
SharedPreferences.getInstance().then((prefs){
|
||||
prefs.setBool("use-lovelace", false);
|
||||
eventBus.fire(ReloadUIEvent(true));
|
||||
});
|
||||
}
|
||||
|
||||
void _reLogin() {
|
||||
ConnectionManager().logout().then((_) => eventBus.fire(ReloadUIEvent(true)));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String errorText;
|
||||
List<Widget> buttons = [];
|
||||
switch (this.error.code) {
|
||||
case ErrorCode.AUTH_ERROR: {
|
||||
errorText = "There was an error logging in to Home Assistant";
|
||||
buttons.add(UserErrorActionButton(
|
||||
onPressed: () => _reload(),
|
||||
text: "Retry",
|
||||
));
|
||||
buttons.add(UserErrorActionButton(
|
||||
onPressed: () => _reLogin(),
|
||||
text: "Login again",
|
||||
));
|
||||
break;
|
||||
}
|
||||
case ErrorCode.UNABLE_TO_CONNECT: {
|
||||
errorText = "Unable to connect to Home Assistant";
|
||||
buttons.addAll(<Widget>[
|
||||
UserErrorActionButton(
|
||||
onPressed: () => _reload(),
|
||||
text: "Retry"
|
||||
),
|
||||
UserErrorActionButton(
|
||||
onPressed: () => _goToAppSettings(context),
|
||||
text: "Check application settings",
|
||||
)
|
||||
]
|
||||
);
|
||||
break;
|
||||
}
|
||||
case ErrorCode.AUTH_INVALID: {
|
||||
errorText = "${error.message ?? "Can't login to Home Assistant"}";
|
||||
buttons.addAll(<Widget>[
|
||||
UserErrorActionButton(
|
||||
onPressed: () => _reload(),
|
||||
text: "Retry"
|
||||
),
|
||||
UserErrorActionButton(
|
||||
onPressed: () => _reLogin(),
|
||||
text: "Login again",
|
||||
)
|
||||
]
|
||||
);
|
||||
break;
|
||||
}
|
||||
case ErrorCode.GENERAL_AUTH_ERROR: {
|
||||
errorText = "There was some error logging in. ${this.error.message ?? ""}";
|
||||
buttons.addAll(<Widget>[
|
||||
UserErrorActionButton(
|
||||
onPressed: () => _reload(),
|
||||
text: "Retry"
|
||||
),
|
||||
UserErrorActionButton(
|
||||
onPressed: () => _reLogin(),
|
||||
text: "Login again",
|
||||
)
|
||||
]
|
||||
);
|
||||
break;
|
||||
}
|
||||
case ErrorCode.SECURE_STORAGE_READ_ERROR: {
|
||||
errorText = "There was an error reading secure storage. You can try again or clear saved auth data and login again.";
|
||||
buttons.addAll(<Widget>[
|
||||
UserErrorActionButton(
|
||||
onPressed: () => _reload(),
|
||||
text: "Retry"
|
||||
),
|
||||
UserErrorActionButton(
|
||||
onPressed: () => _reLogin(),
|
||||
text: "Clear and login again",
|
||||
)
|
||||
]
|
||||
);
|
||||
break;
|
||||
}
|
||||
case ErrorCode.DISCONNECTED: {
|
||||
errorText = "Disconnected";
|
||||
buttons.addAll(<Widget>[
|
||||
UserErrorActionButton(
|
||||
onPressed: () => _reload(),
|
||||
text: "Reconnect"
|
||||
),
|
||||
UserErrorActionButton(
|
||||
onPressed: () => _goToAppSettings(context),
|
||||
text: "Check application settings",
|
||||
)
|
||||
]
|
||||
);
|
||||
break;
|
||||
}
|
||||
case ErrorCode.CONNECTION_TIMEOUT: {
|
||||
errorText = "Connection timeout";
|
||||
buttons.addAll(<Widget>[
|
||||
UserErrorActionButton(
|
||||
onPressed: () => _reload(),
|
||||
text: "Reconnect"
|
||||
),
|
||||
UserErrorActionButton(
|
||||
onPressed: () => _goToAppSettings(context),
|
||||
text: "Check application settings",
|
||||
)
|
||||
]
|
||||
);
|
||||
break;
|
||||
}
|
||||
case ErrorCode.NOT_CONFIGURED: {
|
||||
errorText = "Looks like HA Client is not configured yet.";
|
||||
buttons.add(UserErrorActionButton(
|
||||
onPressed: () => _goToAppSettings(context),
|
||||
text: "Open application settings",
|
||||
));
|
||||
break;
|
||||
}
|
||||
case ErrorCode.ERROR_GETTING_PANELS:
|
||||
case ErrorCode.ERROR_GETTING_CONFIG:
|
||||
case ErrorCode.ERROR_GETTING_STATES: {
|
||||
errorText = "Couldn't get data from Home Assistant. ${error.message ?? ""}";
|
||||
buttons.add(UserErrorActionButton(
|
||||
onPressed: () => _reload(),
|
||||
text: "Try again",
|
||||
));
|
||||
break;
|
||||
}
|
||||
case ErrorCode.ERROR_GETTING_LOVELACE_CONFIG: {
|
||||
errorText = "Couldn't get Lovelace UI config. You can try to disable it and use group-based UI istead.";
|
||||
buttons.addAll(<Widget>[
|
||||
UserErrorActionButton(
|
||||
onPressed: () => _reload(),
|
||||
text: "Retry",
|
||||
),
|
||||
UserErrorActionButton(
|
||||
onPressed: () => _disableLovelace(),
|
||||
text: "Disable Lovelace UI",
|
||||
)
|
||||
]);
|
||||
break;
|
||||
}
|
||||
case ErrorCode.NOT_LOGGED_IN: {
|
||||
errorText = "You are not logged in yet. Please login.";
|
||||
buttons.add(UserErrorActionButton(
|
||||
onPressed: () => _reload(),
|
||||
text: "Login",
|
||||
));
|
||||
break;
|
||||
}
|
||||
case ErrorCode.NO_MOBILE_APP_COMPONENT: {
|
||||
errorText = "Looks like mobile_app component is not enabled on your Home Assistant instance. Please add it to your configuration.yaml";
|
||||
buttons.add(UserErrorActionButton(
|
||||
onPressed: () => Launcher.launchURLInCustomTab(context: context, url: "https://www.home-assistant.io/components/mobile_app/"),
|
||||
text: "Help",
|
||||
));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
errorText = "There was an error. Code ${this.error.code}";
|
||||
buttons.add(UserErrorActionButton(
|
||||
onPressed: () => _reload(),
|
||||
text: "Reload",
|
||||
));
|
||||
}
|
||||
}
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
Divider(
|
||||
color: Colors.deepOrange,
|
||||
height: 1.0,
|
||||
indent: 8.0,
|
||||
endIndent: 8.0,
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(8.0, 14.0, 8.0, 0.0),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
errorText,
|
||||
textAlign: TextAlign.start,
|
||||
style: TextStyle(color: Colors.black87, fontSize: 18.0),
|
||||
softWrap: true,
|
||||
maxLines: 3,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
ButtonBar(
|
||||
children: buttons,
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user