1002
This commit is contained in:
@ -152,6 +152,7 @@ part 'entities/media_player/widgets/media_player_seek_bar.widget.dart';
|
|||||||
part 'entities/media_player/widgets/media_player_progress_bar.widget.dart';
|
part 'entities/media_player/widgets/media_player_progress_bar.widget.dart';
|
||||||
part 'pages/whats_new.page.dart';
|
part 'pages/whats_new.page.dart';
|
||||||
part 'pages/fullscreen.page.dart';
|
part 'pages/fullscreen.page.dart';
|
||||||
|
part 'popups.dart';
|
||||||
|
|
||||||
EventBus eventBus = new EventBus();
|
EventBus eventBus = new EventBus();
|
||||||
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
|
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
|
||||||
@ -236,10 +237,12 @@ class _HAClientAppState extends State<HAClientApp> {
|
|||||||
void _handlePurchaseUpdates(purchase) {
|
void _handlePurchaseUpdates(purchase) {
|
||||||
if (purchase is List<PurchaseDetails>) {
|
if (purchase is List<PurchaseDetails>) {
|
||||||
if (purchase[0].status == PurchaseStatus.purchased) {
|
if (purchase[0].status == PurchaseStatus.purchased) {
|
||||||
eventBus.fire(ShowPopupMessageEvent(
|
eventBus.fire(ShowPopupEvent(
|
||||||
|
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!",
|
||||||
buttonText: "Ok"
|
positiveText: "Ok"
|
||||||
|
)
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
Logger.d("Purchase change handler: ${purchase[0].status}");
|
Logger.d("Purchase change handler: ${purchase[0].status}");
|
||||||
|
@ -51,7 +51,8 @@ class MobileAppIntegrationManager {
|
|||||||
prefs.setInt('app-integration-version', INTEGRATION_VERSION);
|
prefs.setInt('app-integration-version', INTEGRATION_VERSION);
|
||||||
|
|
||||||
completer.complete();
|
completer.complete();
|
||||||
eventBus.fire(ShowPopupDialogEvent(
|
eventBus.fire(ShowPopupEvent(
|
||||||
|
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",
|
||||||
@ -59,6 +60,7 @@ class MobileAppIntegrationManager {
|
|||||||
onPositive: () {
|
onPositive: () {
|
||||||
ConnectionManager().callService(domain: "homeassistant", service: "restart");
|
ConnectionManager().callService(domain: "homeassistant", service: "restart");
|
||||||
},
|
},
|
||||||
|
)
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}).catchError((e) {
|
}).catchError((e) {
|
||||||
@ -93,11 +95,12 @@ class MobileAppIntegrationManager {
|
|||||||
} else {
|
} else {
|
||||||
Logger.d('App registration works fine');
|
Logger.d('App registration works fine');
|
||||||
if (showOkDialog) {
|
if (showOkDialog) {
|
||||||
eventBus.fire(ShowPopupDialogEvent(
|
eventBus.fire(ShowPopupEvent(
|
||||||
|
Popup(
|
||||||
title: "All good",
|
title: "All good",
|
||||||
body: "HA Client integration with your Home Assistant server works fine",
|
body: "HA Client integration with your Home Assistant server works fine",
|
||||||
positiveText: "Nice!",
|
positiveText: "Ok"
|
||||||
negativeText: "Ok"
|
)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,7 +112,8 @@ class MobileAppIntegrationManager {
|
|||||||
_askToRegisterApp();
|
_askToRegisterApp();
|
||||||
} else {
|
} else {
|
||||||
Logger.e("Error updating app registration: $e");
|
Logger.e("Error updating app registration: $e");
|
||||||
eventBus.fire(ShowPopupDialogEvent(
|
eventBus.fire(ShowPopupEvent(
|
||||||
|
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.",
|
body: "Something wrong with HA Client integration on your Home Assistant server. Please report this issue.",
|
||||||
positiveText: "Report to GitHub",
|
positiveText: "Report to GitHub",
|
||||||
@ -120,6 +124,7 @@ class MobileAppIntegrationManager {
|
|||||||
onNegative: () {
|
onNegative: () {
|
||||||
Launcher.launchURLInBrowser("https://discord.gg/AUzEvwn");
|
Launcher.launchURLInBrowser("https://discord.gg/AUzEvwn");
|
||||||
},
|
},
|
||||||
|
)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
completer.complete();
|
completer.complete();
|
||||||
@ -129,7 +134,8 @@ class MobileAppIntegrationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void _askToRemoveAndRegisterApp() {
|
static void _askToRemoveAndRegisterApp() {
|
||||||
eventBus.fire(ShowPopupDialogEvent(
|
eventBus.fire(ShowPopupEvent(
|
||||||
|
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",
|
||||||
@ -137,11 +143,13 @@ class MobileAppIntegrationManager {
|
|||||||
onNegative: () {
|
onNegative: () {
|
||||||
Launcher.launchURLInBrowser("https://github.com/estevez-dev/ha_client/issues/new");
|
Launcher.launchURLInBrowser("https://github.com/estevez-dev/ha_client/issues/new");
|
||||||
},
|
},
|
||||||
|
)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _askToRegisterApp() {
|
static void _askToRegisterApp() {
|
||||||
eventBus.fire(ShowPopupDialogEvent(
|
eventBus.fire(ShowPopupEvent(
|
||||||
|
Popup(
|
||||||
title: "App integration is broken",
|
title: "App integration is broken",
|
||||||
body: "Looks like app integration was removed from your Home Assistant or it needs to be updated. HA Client needs to be registered on your Home Assistant server to make it possible to use notifications and location tracking. Please remove 'Mobile App' integration for this device from your Home Assistant before registering and restart Home Assistant. Then go back here.",
|
body: "Looks like app integration was removed from your Home Assistant or it needs to be updated. HA Client needs to be registered on your Home Assistant server to make it possible to use notifications and location tracking. Please remove 'Mobile App' integration for this device from your Home Assistant before registering and restart Home Assistant. Then go back here.",
|
||||||
positiveText: "Register now",
|
positiveText: "Register now",
|
||||||
@ -153,6 +161,7 @@ class MobileAppIntegrationManager {
|
|||||||
checkAppRegistration();
|
checkAppRegistration();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,8 @@ class StartupUserMessagesManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _showSupportAppDevelopmentMessage() {
|
void _showSupportAppDevelopmentMessage() {
|
||||||
eventBus.fire(ShowPopupDialogEvent(
|
eventBus.fire(ShowPopupEvent(
|
||||||
|
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",
|
||||||
@ -45,6 +46,7 @@ class StartupUserMessagesManager {
|
|||||||
prefs.setBool(_supportAppDevelopmentMessageKey, true);
|
prefs.setBool(_supportAppDevelopmentMessageKey, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
|||||||
StreamSubscription _showEntityPageSubscription;
|
StreamSubscription _showEntityPageSubscription;
|
||||||
StreamSubscription _showErrorSubscription;
|
StreamSubscription _showErrorSubscription;
|
||||||
StreamSubscription _startAuthSubscription;
|
StreamSubscription _startAuthSubscription;
|
||||||
StreamSubscription _showPopupDialogSubscription;
|
StreamSubscription _showPopupSubscription;
|
||||||
StreamSubscription _showPopupMessageSubscription;
|
|
||||||
StreamSubscription _showTokenLoginPopupSubscription;
|
StreamSubscription _showTokenLoginPopupSubscription;
|
||||||
StreamSubscription _reloadUISubscription;
|
StreamSubscription _reloadUISubscription;
|
||||||
StreamSubscription _fullReloadSubscription;
|
StreamSubscription _fullReloadSubscription;
|
||||||
@ -183,27 +182,9 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
|||||||
_fullLoad();
|
_fullLoad();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (_showPopupDialogSubscription == null) {
|
if (_showPopupSubscription == null) {
|
||||||
_showPopupDialogSubscription = eventBus.on<ShowPopupDialogEvent>().listen((event){
|
_showPopupSubscription = eventBus.on<ShowPopupEvent>().listen((event){
|
||||||
_showPopupDialog(
|
event.popup.show(context);
|
||||||
title: event.title,
|
|
||||||
body: event.body,
|
|
||||||
onPositive: event.onPositive,
|
|
||||||
onNegative: event.onNegative,
|
|
||||||
positiveText: event.positiveText,
|
|
||||||
negativeText: event.negativeText
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (_showPopupMessageSubscription == null) {
|
|
||||||
_showPopupMessageSubscription = eventBus.on<ShowPopupMessageEvent>().listen((event){
|
|
||||||
_showPopupDialog(
|
|
||||||
title: event.title,
|
|
||||||
body: event.body,
|
|
||||||
onPositive: event.onButtonClick,
|
|
||||||
positiveText: event.buttonText,
|
|
||||||
negativeText: null
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (_showTokenLoginPopupSubscription == null) {
|
if (_showTokenLoginPopupSubscription == null) {
|
||||||
@ -278,43 +259,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showPopupDialog({String title, String body, var onPositive, var onNegative, String positiveText, String negativeText}) {
|
|
||||||
List<Widget> buttons = [];
|
|
||||||
buttons.add(FlatButton(
|
|
||||||
child: new Text("$positiveText"),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
if (onPositive != null) {
|
|
||||||
onPositive();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
));
|
|
||||||
if (negativeText != null) {
|
|
||||||
buttons.add(FlatButton(
|
|
||||||
child: new Text("$negativeText"),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
if (onNegative != null) {
|
|
||||||
onNegative();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
));
|
|
||||||
}
|
|
||||||
// flutter defined function
|
|
||||||
showDialog(
|
|
||||||
barrierDismissible: false,
|
|
||||||
context: context,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
// return object of type Dialog
|
|
||||||
return AlertDialog(
|
|
||||||
title: new Text("$title"),
|
|
||||||
content: new Text("$body"),
|
|
||||||
actions: buttons,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final _tokenLoginFormKey = GlobalKey<FormState>();
|
final _tokenLoginFormKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
void _showTokenLoginDialog() {
|
void _showTokenLoginDialog() {
|
||||||
@ -360,9 +304,8 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
|||||||
Row(
|
Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
RaisedButton(
|
FlatButton(
|
||||||
child: Text('Login', style: Theme.of(context).textTheme.button.copyWith(fontSize: 20)),
|
child: Text('Login'),
|
||||||
color: Theme.of(context).primaryColor,
|
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (_tokenLoginFormKey.currentState.validate()) {
|
if (_tokenLoginFormKey.currentState.validate()) {
|
||||||
_tokenLoginFormKey.currentState.save();
|
_tokenLoginFormKey.currentState.save();
|
||||||
@ -370,8 +313,8 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
Container(width: 10),
|
Container(width: 10),
|
||||||
RaisedButton(
|
FlatButton(
|
||||||
child: Text('Cancel', style: Theme.of(context).textTheme.button.copyWith(fontSize: 20)),
|
child: Text('Cancel'),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
@ -793,8 +736,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
|||||||
_lovelaceSubscription?.cancel();
|
_lovelaceSubscription?.cancel();
|
||||||
_settingsSubscription?.cancel();
|
_settingsSubscription?.cancel();
|
||||||
_serviceCallSubscription?.cancel();
|
_serviceCallSubscription?.cancel();
|
||||||
_showPopupDialogSubscription?.cancel();
|
_showPopupSubscription?.cancel();
|
||||||
_showPopupMessageSubscription?.cancel();
|
|
||||||
_showEntityPageSubscription?.cancel();
|
_showEntityPageSubscription?.cancel();
|
||||||
_showErrorSubscription?.cancel();
|
_showErrorSubscription?.cancel();
|
||||||
_startAuthSubscription?.cancel();
|
_startAuthSubscription?.cancel();
|
||||||
|
@ -57,19 +57,22 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
restart() {
|
restart() {
|
||||||
eventBus.fire(ShowPopupDialogEvent(
|
eventBus.fire(ShowPopupEvent(
|
||||||
|
Popup(
|
||||||
title: "Are you sure you want to restart Home Assistant?",
|
title: "Are you sure you want to restart Home Assistant?",
|
||||||
body: "This will restart your Home Assistant server.",
|
body: "This will restart your Home Assistant server.",
|
||||||
positiveText: "Sure. Make it so",
|
positiveText: "Sure. Make it so",
|
||||||
negativeText: "What?? No!",
|
negativeText: "What?? No!",
|
||||||
onPositive: () {
|
onPositive: () {
|
||||||
ConnectionManager().callService(domain: "homeassistant", service: "restart");
|
ConnectionManager().callService(domain: "homeassistant", service: "restart");
|
||||||
},
|
}
|
||||||
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
eventBus.fire(ShowPopupDialogEvent(
|
eventBus.fire(ShowPopupEvent(
|
||||||
|
Popup(
|
||||||
title: "Are you sure you want to STOP Home Assistant?",
|
title: "Are you sure you want to STOP Home Assistant?",
|
||||||
body: "This will STOP your Home Assistant server. It means that your web interface as well as HA Client will not work untill you'll find a way to start your server using ssh or something.",
|
body: "This will STOP your Home Assistant server. It means that your web interface as well as HA Client will not work untill you'll find a way to start your server using ssh or something.",
|
||||||
positiveText: "Sure. Make it so",
|
positiveText: "Sure. Make it so",
|
||||||
@ -77,6 +80,7 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
|
|||||||
onPositive: () {
|
onPositive: () {
|
||||||
ConnectionManager().callService(domain: "homeassistant", service: "stop");
|
ConnectionManager().callService(domain: "homeassistant", service: "stop");
|
||||||
},
|
},
|
||||||
|
)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +89,8 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resetRegistration() {
|
resetRegistration() {
|
||||||
eventBus.fire(ShowPopupDialogEvent(
|
eventBus.fire(ShowPopupEvent(
|
||||||
|
Popup(
|
||||||
title: "Waaaait",
|
title: "Waaaait",
|
||||||
body: "If you don't whant to have duplicate integrations and entities in your HA for your current device, first you need to remove MobileApp integration from Integration settings in HA and restart server.",
|
body: "If you don't whant to have duplicate integrations and entities in your HA for your current device, first you need to remove MobileApp integration from Integration settings in HA and restart server.",
|
||||||
positiveText: "Done it already",
|
positiveText: "Done it already",
|
||||||
@ -93,6 +98,7 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
|
|||||||
onPositive: () {
|
onPositive: () {
|
||||||
MobileAppIntegrationManager.checkAppRegistration(showOkDialog: true, forceRegister: true);
|
MobileAppIntegrationManager.checkAppRegistration(showOkDialog: true, forceRegister: true);
|
||||||
},
|
},
|
||||||
|
)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
49
lib/popups.dart
Normal file
49
lib/popups.dart
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
part of 'main.dart';
|
||||||
|
|
||||||
|
class Popup {
|
||||||
|
final String title;
|
||||||
|
final String body;
|
||||||
|
final String positiveText;
|
||||||
|
final String negativeText;
|
||||||
|
final onPositive;
|
||||||
|
final onNegative;
|
||||||
|
|
||||||
|
Popup({@required this.title, @required this.body, this.positiveText, this.negativeText, this.onPositive, this.onNegative});
|
||||||
|
|
||||||
|
void show(BuildContext context) {
|
||||||
|
List<Widget> buttons = [];
|
||||||
|
buttons.add(FlatButton(
|
||||||
|
child: new Text("$positiveText"),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
if (onPositive != null) {
|
||||||
|
onPositive();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
));
|
||||||
|
if (negativeText != null) {
|
||||||
|
buttons.add(FlatButton(
|
||||||
|
child: new Text("$negativeText"),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
if (onNegative != null) {
|
||||||
|
onNegative();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
// flutter defined function
|
||||||
|
showDialog(
|
||||||
|
barrierDismissible: false,
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
// return object of type Dialog
|
||||||
|
return AlertDialog(
|
||||||
|
title: new Text("$title"),
|
||||||
|
content: new Text("$body"),
|
||||||
|
actions: buttons,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -56,6 +56,12 @@ class NotifyServiceCallEvent {
|
|||||||
NotifyServiceCallEvent(this.domain, this.service, this.entityId);
|
NotifyServiceCallEvent(this.domain, this.service, this.entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ShowPopupEvent {
|
||||||
|
final Popup popup;
|
||||||
|
|
||||||
|
ShowPopupEvent(this.popup);
|
||||||
|
}
|
||||||
|
/*
|
||||||
class ShowPopupDialogEvent {
|
class ShowPopupDialogEvent {
|
||||||
final String title;
|
final String title;
|
||||||
final String body;
|
final String body;
|
||||||
@ -75,6 +81,7 @@ class ShowPopupMessageEvent {
|
|||||||
|
|
||||||
ShowPopupMessageEvent({this.title, this.body, this.buttonText: "Ok", this.onButtonClick});
|
ShowPopupMessageEvent({this.title, this.body, this.buttonText: "Ok", this.onButtonClick});
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
class ShowTokenLoginPopupEvent {
|
class ShowTokenLoginPopupEvent {
|
||||||
final bool goBackFirst;
|
final bool goBackFirst;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
name: hass_client
|
name: hass_client
|
||||||
description: Home Assistant Android Client
|
description: Home Assistant Android Client
|
||||||
|
|
||||||
version: 1.0.0+1001
|
version: 1.0.0+1002
|
||||||
|
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
Reference in New Issue
Block a user