diff --git a/lib/main.dart b/lib/main.dart index 674a464..6fc26b9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -238,7 +238,7 @@ class _HAClientAppState extends State { if (purchase is List) { if (purchase[0].status == PurchaseStatus.purchased) { eventBus.fire(ShowPopupEvent( - Popup( + popup: Popup( title: "Thanks a lot!", body: "Thank you for supporting HA Client development!", positiveText: "Ok" @@ -298,7 +298,10 @@ class _HAClientAppState extends State { decoration: TextDecoration.underline )), onPressed: () { - eventBus.fire(ShowTokenLoginPopupEvent(goBackFirst: true)); + eventBus.fire(ShowPopupEvent( + goBackFirst: true, + popup: TokenLoginPopup() + )); }, ) ], diff --git a/lib/managers/mobile_app_integration_manager.class.dart b/lib/managers/mobile_app_integration_manager.class.dart index c7abf20..6d893ea 100644 --- a/lib/managers/mobile_app_integration_manager.class.dart +++ b/lib/managers/mobile_app_integration_manager.class.dart @@ -23,7 +23,7 @@ class MobileAppIntegrationManager { return '${HomeAssistant().userName}\'s ${DeviceInfoManager().model}'; } - static Future checkAppRegistration({bool showOkDialog: false}) { + static Future checkAppRegistration() { Completer completer = Completer(); _appRegistrationData["device_name"] = ConnectionManager().mobileAppDeviceName ?? getDefaultDeviceName(); (_appRegistrationData["app_data"] as Map)["push_token"] = "${HomeAssistant().fcmToken}"; @@ -52,7 +52,7 @@ class MobileAppIntegrationManager { completer.complete(); eventBus.fire(ShowPopupEvent( - Popup( + popup: Popup( title: "Mobile app Integration was created", body: "HA Client was registered as MobileApp in your Home Assistant. To start using notifications you need to restart your Home Assistant", positiveText: "Restart now", @@ -94,15 +94,6 @@ class MobileAppIntegrationManager { _askToRemoveAndRegisterApp(); } else { Logger.d('App registration works fine'); - if (showOkDialog) { - eventBus.fire(ShowPopupEvent( - Popup( - title: "All good", - body: "HA Client integration with your Home Assistant server works fine", - positiveText: "Ok" - ) - )); - } } } completer.complete(); @@ -122,7 +113,7 @@ class MobileAppIntegrationManager { static void _showError() { eventBus.fire(ShowPopupEvent( - Popup( + popup: Popup( title: "App integration is not working properly", body: "Something wrong with HA Client integration on your Home Assistant server. Please report this issue. You can try to remove Mobile App integration from Home Assistant and restart server to fix this issue.", positiveText: "Report to GitHub", @@ -139,7 +130,7 @@ class MobileAppIntegrationManager { static void _askToRemoveAndRegisterApp() { eventBus.fire(ShowPopupEvent( - Popup( + popup: Popup( title: "Mobile app integration needs to be updated", body: "You need to update HA Client integration to continue using notifications and location tracking. Please remove 'Mobile App' integration for this device from your Home Assistant and restart Home Assistant. Then go back to HA Client to create app integration again.", positiveText: "Ok", @@ -153,7 +144,7 @@ class MobileAppIntegrationManager { static void _askToRegisterApp() { eventBus.fire(ShowPopupEvent( - RegisterAppPopup( + popup: RegisterAppPopup( title: "Mobile App integration is missing", body: "Looks like mobile app integration was removed from your Home Assistant or it needs to be updated.", ) diff --git a/lib/managers/startup_user_messages_manager.class.dart b/lib/managers/startup_user_messages_manager.class.dart index abc97ee..24bb904 100644 --- a/lib/managers/startup_user_messages_manager.class.dart +++ b/lib/managers/startup_user_messages_manager.class.dart @@ -30,7 +30,7 @@ class StartupUserMessagesManager { void _showSupportAppDevelopmentMessage() { eventBus.fire(ShowPopupEvent( - Popup( + popup: Popup( title: "Hi!", body: "As you may have noticed this app contains no ads. Also all app features are available for you for free. I'm not planning to change this in nearest future, but still you can support this application development materially. There is one-time payment available as well as several subscription options. Thanks.", positiveText: "Show options", diff --git a/lib/pages/main/main.page.dart b/lib/pages/main/main.page.dart index 35c9e02..7b621f5 100644 --- a/lib/pages/main/main.page.dart +++ b/lib/pages/main/main.page.dart @@ -186,6 +186,9 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker _showPopupSubscription = eventBus.on().listen((event){ if (!_popupShown) { _popupShown = true; + if (event.goBackFirst) { + Navigator.of(context).pop(); + } event.popup.show(context).then((_){ _popupShown = false; }); @@ -539,7 +542,9 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker FlatButton( child: Text("Login with long-lived token", style: Theme.of(context).textTheme.button), color: Theme.of(context).primaryColor, - onPressed: () => eventBus.fire(ShowTokenLoginPopupEvent(goBackFirst: false)) + onPressed: () => eventBus.fire(ShowPopupEvent( + popup: TokenLoginPopup() + )) ), Container(height: 20,), FlatButton( diff --git a/lib/types/event_bus_events.dart b/lib/types/event_bus_events.dart index fe368c0..ce70e98 100644 --- a/lib/types/event_bus_events.dart +++ b/lib/types/event_bus_events.dart @@ -58,35 +58,9 @@ class NotifyServiceCallEvent { class ShowPopupEvent { final Popup popup; - - ShowPopupEvent(this.popup); -} -/* -class ShowPopupDialogEvent { - final String title; - final String body; - final String positiveText; - final String negativeText; - final onPositive; - final onNegative; - - ShowPopupDialogEvent({this.title, this.body, this.positiveText: "Ok", this.negativeText: "Cancel", this.onPositive, this.onNegative}); -} - -class ShowPopupMessageEvent { - final String title; - final String body; - final String buttonText; - final onButtonClick; - - ShowPopupMessageEvent({this.title, this.body, this.buttonText: "Ok", this.onButtonClick}); -} -*/ - -class ShowTokenLoginPopupEvent { final bool goBackFirst; - ShowTokenLoginPopupEvent({this.goBackFirst: false}); + ShowPopupEvent({this.popup, this.goBackFirst: false}); } class ShowEntityPageEvent {