WebView UI experiment 001

This commit is contained in:
Yegor Vialov 2020-02-11 14:02:32 +00:00
parent f26f3e87c7
commit 8a80d0c5d1
4 changed files with 61 additions and 22 deletions

View File

@ -140,7 +140,7 @@ EventBus eventBus = new EventBus();
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
const String appName = "HA Client";
const appVersionNumber = "0.7.7";
const appVersionNumber = "0.8.0-alpha";
const appVersionAdd = "";
const appVersion = "$appVersionNumber$appVersionAdd";

View File

@ -20,6 +20,7 @@ class ConnectionManager {
String oauthUrl;
String webhookId;
bool useLovelace = true;
bool useWebView = true;
bool settingsLoaded = false;
bool get isAuthenticated => _token != null;
StreamSubscription _socketSubscription;

View File

@ -118,6 +118,18 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
}
_fetchData() async {
if (ConnectionManager().useWebView) {
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));
});
}
});
}
await HomeAssistant().fetchData().then((_) {
_hideBottomBar();
if (_entityToShow != null) {
@ -143,6 +155,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
Future _subscribe() {
Completer completer = Completer();
if (_stateSubscription == null) {
_stateSubscription = eventBus.on<StateChangedEvent>().listen((event) {
if (event.needToRebuildUI) {
@ -837,33 +850,49 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
);
}
}
// This method is rerun every time setState is called.
if (HomeAssistant().isNoViews) {
if (!ConnectionManager().settingsLoaded) {
return Scaffold(
key: _scaffoldKey,
primary: false,
drawer: _buildAppDrawer(),
bottomNavigationBar: bottomBar,
body: _buildScaffoldBody(true)
);
} else {
return WillPopScope(
child: Scaffold(
key: _scaffoldKey,
drawer: _buildAppDrawer(),
primary: false,
bottomNavigationBar: bottomBar,
body: _buildScaffoldBody(false)
),
onWillPop: () {
if (_entityToShow != null) {
eventBus.fire(ShowEntityPageEvent());
return Future.value(false);
} else {
return Future.value(true);
}
},
} else if (ConnectionManager().settingsLoaded && ConnectionManager().useWebView) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
return WebviewScaffold(
url: ConnectionManager().httpWebHost,
primary: false,
appBar: EmptyAppBar (),
bottomNavigationBar: bottomBar,
);
} else {
if (HomeAssistant().isNoViews) {
return Scaffold(
key: _scaffoldKey,
primary: false,
drawer: _buildAppDrawer(),
bottomNavigationBar: bottomBar,
body: _buildScaffoldBody(true)
);
} else {
return WillPopScope(
child: Scaffold(
key: _scaffoldKey,
drawer: _buildAppDrawer(),
primary: false,
bottomNavigationBar: bottomBar,
body: _buildScaffoldBody(false)
),
onWillPop: () {
if (_entityToShow != null) {
eventBus.fire(ShowEntityPageEvent());
return Future.value(false);
} else {
return Future.value(true);
}
},
);
}
}
}
@ -888,3 +917,12 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
super.dispose();
}
}
class EmptyAppBar extends StatelessWidget implements PreferredSizeWidget {
@override
Widget build(BuildContext context) {
return Container();
}
@override
Size get preferredSize => Size(0.0,0.0);
}

View File

@ -1,7 +1,7 @@
name: hass_client
description: Home Assistant Android Client
version: 0.7.7+770
version: 0.8.0+880
environment: