From 1ecb839042a2b2d7f1e5ec3d94ccfc8377f14feb Mon Sep 17 00:00:00 2001 From: estevez-dev Date: Sat, 31 Aug 2019 23:55:32 +0300 Subject: [PATCH] Add user messages --- flutter_02.log | 41 +++++++++++ lib/main.dart | 19 +++++ lib/managers/location_manager.class.dart | 4 +- .../startup_user_messages_manager.class.dart | 73 +++++++++++++++++++ lib/pages/entity.page.dart | 1 + lib/panels/config_panel_widget.dart | 2 +- lib/utils.class.dart | 6 ++ 7 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 flutter_02.log create mode 100644 lib/managers/startup_user_messages_manager.class.dart diff --git a/flutter_02.log b/flutter_02.log new file mode 100644 index 0000000..063a37a --- /dev/null +++ b/flutter_02.log @@ -0,0 +1,41 @@ +Flutter crash report; please file at https://github.com/flutter/flutter/issues. + +## command + +flutter --no-color run --machine --track-widget-creation --device-id=89AY052S4 lib/main.dart + +## exception + +_InternalLinkedHashMap: {code: 105, message: Isolate must be runnable, data: {request: {method: _reloadSources, params: {pause: true, rootLibUri: file:///data/user/0/com.keyboardcrumbs.haclient/code_cache/ha_clientWYMXDL/ha_client/lib/main.dart.incremental.dill, packagesUri: file:///data/user/0/com.keyboardcrumbs.haclient/code_cache/ha_clientWYMXDL/ha_client/.packages, isolateId: isolates/289688365}}, details: Isolate must be runnable before this request is made.}} + +``` +null``` + +## flutter doctor + +``` +[✓] Flutter (Channel stable, v1.7.8+hotfix.4, on Linux, locale en_US.UTF-8) + • Flutter version 1.7.8+hotfix.4 at /home/estevez/sdk/flutter + • Framework revision 20e59316b8 (6 weeks ago), 2019-07-18 20:04:33 -0700 + • Engine revision fee001c93f + • Dart version 2.4.0 + +[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2) + • Android SDK at /home/estevez/Android/Sdk + • Android NDK location not configured (optional; useful for native profiling support) + • Platform android-29, build-tools 29.0.2 + • Java binary at: /home/estevez/bin/android-studio/jre/bin/java + • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405) + • All Android licenses accepted. + +[✓] Android Studio (version 3.5) + • Android Studio at /home/estevez/bin/android-studio + • Flutter plugin version 38.2.3 + • Dart plugin version 191.8423 + • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405) + +[✓] Connected device (1 available) + • Pixel 3 XL • 89AY052S4 • android-arm64 • Android 9 (API 28) + +• No issues found! +``` diff --git a/lib/main.dart b/lib/main.dart index 8bb6eb9..ea7050b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -106,6 +106,7 @@ part 'managers/location_manager.class.dart'; part 'managers/mobile_app_integration_manager.class.dart'; part 'managers/connection_manager.class.dart'; part 'managers/device_info_manager.class.dart'; +part 'managers/startup_user_messages_manager.class.dart'; part 'ui_class/ui.dart'; part 'ui_class/view.class.dart'; part 'ui_class/card.class.dart'; @@ -211,6 +212,7 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker StreamSubscription _showPopupDialogSubscription; StreamSubscription _showPopupMessageSubscription; StreamSubscription _reloadUISubscription; + StreamSubscription _showPageSubscription; int _previousViewCount; bool _showLoginButton = false; @@ -290,6 +292,7 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker ConnectionManager().init(loadSettings: true, forceReconnect: true).then((__){ LocationManager(); _fetchData(); + StartupUserMessagesManager().checkMessagesToShow(); }, onError: (e) { _setErrorState(e); }); @@ -302,6 +305,7 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker ConnectionManager().init(loadSettings: false, forceReconnect: false).then((_){ LocationManager().updateDeviceLocation(); _fetchData(); + StartupUserMessagesManager().checkMessagesToShow(); }, onError: (e) { _setErrorState(e); }); @@ -405,6 +409,13 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker }); } + if (_showPageSubscription == null) { + _showPageSubscription = + eventBus.on().listen((event) { + _showPage(event.path); + }); + } + if (_showErrorSubscription == null) { _showErrorSubscription = eventBus.on().listen((event){ _showErrorBottomBar(event.error); @@ -499,6 +510,13 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker ); } + void _showPage(String path) { + Navigator.pushNamed( + context, + path + ); + } + List buildUIViewTabs() { List result = []; @@ -938,6 +956,7 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker _showErrorSubscription?.cancel(); _startAuthSubscription?.cancel(); _subscription?.cancel(); + _showPageSubscription?.cancel(); _reloadUISubscription?.cancel(); //TODO disconnect //widget.homeAssistant?.disconnect(); diff --git a/lib/managers/location_manager.class.dart b/lib/managers/location_manager.class.dart index dabde95..7922086 100644 --- a/lib/managers/location_manager.class.dart +++ b/lib/managers/location_manager.class.dart @@ -78,13 +78,13 @@ class LocationManager { } LocationManager._internal() { - _startLocationService(); + startLocationService(); } final int defaultUpdateIntervalMinutes = 15; final int alarmId = 34901199; - void _startLocationService() async { + void startLocationService() async { SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.reload(); bool enabled = prefs.getBool("location-enabled") ?? false; diff --git a/lib/managers/startup_user_messages_manager.class.dart b/lib/managers/startup_user_messages_manager.class.dart new file mode 100644 index 0000000..13756ed --- /dev/null +++ b/lib/managers/startup_user_messages_manager.class.dart @@ -0,0 +1,73 @@ +part of '../main.dart'; + +class StartupUserMessagesManager { + + static final StartupUserMessagesManager _instance = StartupUserMessagesManager + ._internal(); + + factory StartupUserMessagesManager() { + return _instance; + } + + StartupUserMessagesManager._internal() {} + + bool _locationTrackingMessageShown; + bool _supportAppDevelopmentMessageShown; + static final _locationTrackingMessageKey = "user-message-shown-location_1"; + static final _supportAppDevelopmentMessageKey = "user-message-shown-support-development_1"; + + void checkMessagesToShow() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + await prefs.reload(); + _locationTrackingMessageShown = prefs.getBool(_locationTrackingMessageKey) ?? false; + _supportAppDevelopmentMessageShown = prefs.getBool(_supportAppDevelopmentMessageKey) ?? false; + if (!_locationTrackingMessageShown) { + _showLocationTrackingMessage(); + } else if (!_supportAppDevelopmentMessageShown) { + _showSupportAppDevelopmentMessage(); + } + } + + void _showLocationTrackingMessage() { + eventBus.fire(ShowPopupDialogEvent( + title: "Device location tracking is here!", + body: "HA Client now support sending your device gps data to device_tracker instance created for current app integration. You can control location tracking in Configuration.", + positiveText: "Enable now", + negativeText: "Cancel", + onPositive: () { + SharedPreferences.getInstance().then((prefs) { + prefs.setBool("location-enabled", true); + prefs.setBool(_locationTrackingMessageKey, true); + LocationManager().startLocationService(); + LocationManager().updateDeviceLocation(); + }); + }, + onNegative: () { + SharedPreferences.getInstance().then((prefs) { + prefs.setBool(_locationTrackingMessageKey, true); + }); + } + )); + } + + void _showSupportAppDevelopmentMessage() { + eventBus.fire(ShowPopupDialogEvent( + title: "Hi!", + body: "As you may have noticed this app contains no ads. Also all app features are available for you for free. Following the principles of free and open source softwere this will not be changed in nearest future. But still you can support this application development materially. There is several options available, please check them in main menu -> Support app development. Thanks.", + positiveText: "Take me there", + negativeText: "Nope", + onPositive: () { + SharedPreferences.getInstance().then((prefs) { + prefs.setBool(_supportAppDevelopmentMessageKey, true); + eventBus.fire(ShowPageEvent("/configuration")); + }); + }, + onNegative: () { + SharedPreferences.getInstance().then((prefs) { + prefs.setBool(_supportAppDevelopmentMessageKey, true); + }); + } + )); + } + +} \ No newline at end of file diff --git a/lib/pages/entity.page.dart b/lib/pages/entity.page.dart index 7379ee4..ec02bd6 100644 --- a/lib/pages/entity.page.dart +++ b/lib/pages/entity.page.dart @@ -4,6 +4,7 @@ class EntityViewPage extends StatefulWidget { EntityViewPage({Key key, @required this.entityId, @required this.homeAssistant }) : super(key: key); final String entityId; + //TODO remove it! final HomeAssistant homeAssistant; @override diff --git a/lib/panels/config_panel_widget.dart b/lib/panels/config_panel_widget.dart index fe166e2..0e9dc89 100644 --- a/lib/panels/config_panel_widget.dart +++ b/lib/panels/config_panel_widget.dart @@ -193,7 +193,7 @@ class _ConfigPanelWidgetState extends State { void dispose() { if (_needToRestartLocationTracking) { Logger.d("Location tracking settings was changed. Restarting location service..."); - LocationManager()._startLocationService(); + LocationManager().startLocationService(); if (_locationTrackingEnabled) { LocationManager().updateDeviceLocation(); } diff --git a/lib/utils.class.dart b/lib/utils.class.dart index a0fc37c..5e3ffcb 100644 --- a/lib/utils.class.dart +++ b/lib/utils.class.dart @@ -199,6 +199,12 @@ class ShowEntityPageEvent { ShowEntityPageEvent(this.entity); } +class ShowPageEvent { + String path; + + ShowPageEvent(this.path); +} + class ShowErrorEvent { final HAError error;