Add user messages
This commit is contained in:
@ -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<MainPage> with WidgetsBindingObserver, Ticker
|
||||
StreamSubscription _showPopupDialogSubscription;
|
||||
StreamSubscription _showPopupMessageSubscription;
|
||||
StreamSubscription _reloadUISubscription;
|
||||
StreamSubscription _showPageSubscription;
|
||||
int _previousViewCount;
|
||||
bool _showLoginButton = false;
|
||||
|
||||
@ -290,6 +292,7 @@ class _MainPageState extends State<MainPage> 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<MainPage> 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<MainPage> with WidgetsBindingObserver, Ticker
|
||||
});
|
||||
}
|
||||
|
||||
if (_showPageSubscription == null) {
|
||||
_showPageSubscription =
|
||||
eventBus.on<ShowPageEvent>().listen((event) {
|
||||
_showPage(event.path);
|
||||
});
|
||||
}
|
||||
|
||||
if (_showErrorSubscription == null) {
|
||||
_showErrorSubscription = eventBus.on<ShowErrorEvent>().listen((event){
|
||||
_showErrorBottomBar(event.error);
|
||||
@ -499,6 +510,13 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
||||
);
|
||||
}
|
||||
|
||||
void _showPage(String path) {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
path
|
||||
);
|
||||
}
|
||||
|
||||
List<Tab> buildUIViewTabs() {
|
||||
List<Tab> result = [];
|
||||
|
||||
@ -938,6 +956,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
||||
_showErrorSubscription?.cancel();
|
||||
_startAuthSubscription?.cancel();
|
||||
_subscription?.cancel();
|
||||
_showPageSubscription?.cancel();
|
||||
_reloadUISubscription?.cancel();
|
||||
//TODO disconnect
|
||||
//widget.homeAssistant?.disconnect();
|
||||
|
@ -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;
|
||||
|
73
lib/managers/startup_user_messages_manager.class.dart
Normal file
73
lib/managers/startup_user_messages_manager.class.dart
Normal file
@ -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);
|
||||
});
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
|
@ -193,7 +193,7 @@ class _ConfigPanelWidgetState extends State<ConfigPanelWidget> {
|
||||
void dispose() {
|
||||
if (_needToRestartLocationTracking) {
|
||||
Logger.d("Location tracking settings was changed. Restarting location service...");
|
||||
LocationManager()._startLocationService();
|
||||
LocationManager().startLocationService();
|
||||
if (_locationTrackingEnabled) {
|
||||
LocationManager().updateDeviceLocation();
|
||||
}
|
||||
|
@ -199,6 +199,12 @@ class ShowEntityPageEvent {
|
||||
ShowEntityPageEvent(this.entity);
|
||||
}
|
||||
|
||||
class ShowPageEvent {
|
||||
String path;
|
||||
|
||||
ShowPageEvent(this.path);
|
||||
}
|
||||
|
||||
class ShowErrorEvent {
|
||||
final HAError error;
|
||||
|
||||
|
Reference in New Issue
Block a user