Fix token login popup show

This commit is contained in:
Yegor Vialov 2020-05-03 15:26:44 +00:00
parent 8aa0e03187
commit cc60dc2b21
5 changed files with 18 additions and 45 deletions

View File

@ -238,7 +238,7 @@ class _HAClientAppState extends State<HAClientApp> {
if (purchase is List<PurchaseDetails>) { if (purchase is List<PurchaseDetails>) {
if (purchase[0].status == PurchaseStatus.purchased) { if (purchase[0].status == PurchaseStatus.purchased) {
eventBus.fire(ShowPopupEvent( eventBus.fire(ShowPopupEvent(
Popup( popup: Popup(
title: "Thanks a lot!", title: "Thanks a lot!",
body: "Thank you for supporting HA Client development!", body: "Thank you for supporting HA Client development!",
positiveText: "Ok" positiveText: "Ok"
@ -298,7 +298,10 @@ class _HAClientAppState extends State<HAClientApp> {
decoration: TextDecoration.underline decoration: TextDecoration.underline
)), )),
onPressed: () { onPressed: () {
eventBus.fire(ShowTokenLoginPopupEvent(goBackFirst: true)); eventBus.fire(ShowPopupEvent(
goBackFirst: true,
popup: TokenLoginPopup()
));
}, },
) )
], ],

View File

@ -23,7 +23,7 @@ class MobileAppIntegrationManager {
return '${HomeAssistant().userName}\'s ${DeviceInfoManager().model}'; return '${HomeAssistant().userName}\'s ${DeviceInfoManager().model}';
} }
static Future checkAppRegistration({bool showOkDialog: false}) { static Future checkAppRegistration() {
Completer completer = Completer(); Completer completer = Completer();
_appRegistrationData["device_name"] = ConnectionManager().mobileAppDeviceName ?? getDefaultDeviceName(); _appRegistrationData["device_name"] = ConnectionManager().mobileAppDeviceName ?? getDefaultDeviceName();
(_appRegistrationData["app_data"] as Map)["push_token"] = "${HomeAssistant().fcmToken}"; (_appRegistrationData["app_data"] as Map)["push_token"] = "${HomeAssistant().fcmToken}";
@ -52,7 +52,7 @@ class MobileAppIntegrationManager {
completer.complete(); completer.complete();
eventBus.fire(ShowPopupEvent( eventBus.fire(ShowPopupEvent(
Popup( popup: Popup(
title: "Mobile app Integration was created", 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", 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", positiveText: "Restart now",
@ -94,15 +94,6 @@ class MobileAppIntegrationManager {
_askToRemoveAndRegisterApp(); _askToRemoveAndRegisterApp();
} else { } else {
Logger.d('App registration works fine'); 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(); completer.complete();
@ -122,7 +113,7 @@ class MobileAppIntegrationManager {
static void _showError() { static void _showError() {
eventBus.fire(ShowPopupEvent( eventBus.fire(ShowPopupEvent(
Popup( popup: Popup(
title: "App integration is not working properly", 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.", 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", positiveText: "Report to GitHub",
@ -139,7 +130,7 @@ class MobileAppIntegrationManager {
static void _askToRemoveAndRegisterApp() { static void _askToRemoveAndRegisterApp() {
eventBus.fire(ShowPopupEvent( eventBus.fire(ShowPopupEvent(
Popup( popup: Popup(
title: "Mobile app integration needs to be updated", 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.", 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", positiveText: "Ok",
@ -153,7 +144,7 @@ class MobileAppIntegrationManager {
static void _askToRegisterApp() { static void _askToRegisterApp() {
eventBus.fire(ShowPopupEvent( eventBus.fire(ShowPopupEvent(
RegisterAppPopup( popup: RegisterAppPopup(
title: "Mobile App integration is missing", title: "Mobile App integration is missing",
body: "Looks like mobile app integration was removed from your Home Assistant or it needs to be updated.", body: "Looks like mobile app integration was removed from your Home Assistant or it needs to be updated.",
) )

View File

@ -30,7 +30,7 @@ class StartupUserMessagesManager {
void _showSupportAppDevelopmentMessage() { void _showSupportAppDevelopmentMessage() {
eventBus.fire(ShowPopupEvent( eventBus.fire(ShowPopupEvent(
Popup( popup: Popup(
title: "Hi!", 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.", 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", positiveText: "Show options",

View File

@ -186,6 +186,9 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
_showPopupSubscription = eventBus.on<ShowPopupEvent>().listen((event){ _showPopupSubscription = eventBus.on<ShowPopupEvent>().listen((event){
if (!_popupShown) { if (!_popupShown) {
_popupShown = true; _popupShown = true;
if (event.goBackFirst) {
Navigator.of(context).pop();
}
event.popup.show(context).then((_){ event.popup.show(context).then((_){
_popupShown = false; _popupShown = false;
}); });
@ -539,7 +542,9 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
FlatButton( FlatButton(
child: Text("Login with long-lived token", style: Theme.of(context).textTheme.button), child: Text("Login with long-lived token", style: Theme.of(context).textTheme.button),
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
onPressed: () => eventBus.fire(ShowTokenLoginPopupEvent(goBackFirst: false)) onPressed: () => eventBus.fire(ShowPopupEvent(
popup: TokenLoginPopup()
))
), ),
Container(height: 20,), Container(height: 20,),
FlatButton( FlatButton(

View File

@ -58,35 +58,9 @@ class NotifyServiceCallEvent {
class ShowPopupEvent { class ShowPopupEvent {
final Popup popup; 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; final bool goBackFirst;
ShowTokenLoginPopupEvent({this.goBackFirst: false}); ShowPopupEvent({this.popup, this.goBackFirst: false});
} }
class ShowEntityPageEvent { class ShowEntityPageEvent {