This repository has been archived on 2023-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
ha_client/lib/managers/startup_user_messages_manager.class.dart

58 lines
2.1 KiB
Dart
Raw Normal View History

2019-08-31 23:55:32 +03:00
part of '../main.dart';
class StartupUserMessagesManager {
static final StartupUserMessagesManager _instance = StartupUserMessagesManager
._internal();
factory StartupUserMessagesManager() {
return _instance;
}
StartupUserMessagesManager._internal() {}
bool _supportAppDevelopmentMessageShown;
2019-09-09 14:24:54 +03:00
bool _whatsNewMessageShown;
2019-09-01 23:19:26 +03:00
static final _supportAppDevelopmentMessageKey = "user-message-shown-support-development_3";
2019-09-15 20:55:28 +03:00
static final _whatsNewMessageKey = "user-message-shown-whats-new-673";
2019-08-31 23:55:32 +03:00
void checkMessagesToShow() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.reload();
_supportAppDevelopmentMessageShown = prefs.getBool(_supportAppDevelopmentMessageKey) ?? false;
2019-09-09 14:24:54 +03:00
_whatsNewMessageShown = prefs.getBool(_whatsNewMessageKey) ?? false;
if (!_whatsNewMessageShown) {
_showWhatsNewMessage();
} else if (!_supportAppDevelopmentMessageShown) {
2019-08-31 23:55:32 +03:00
_showSupportAppDevelopmentMessage();
}
}
void _showSupportAppDevelopmentMessage() {
eventBus.fire(ShowPopupDialogEvent(
title: "Hi!",
2019-09-05 00:09:40 +03:00
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",
negativeText: "Cancel",
2019-08-31 23:55:32 +03:00
onPositive: () {
SharedPreferences.getInstance().then((prefs) {
prefs.setBool(_supportAppDevelopmentMessageKey, true);
2019-09-01 23:19:26 +03:00
eventBus.fire(ShowPageEvent(path: "/putchase"));
2019-08-31 23:55:32 +03:00
});
},
onNegative: () {
SharedPreferences.getInstance().then((prefs) {
prefs.setBool(_supportAppDevelopmentMessageKey, true);
});
}
));
}
2019-09-09 14:24:54 +03:00
void _showWhatsNewMessage() {
2019-09-15 20:23:03 +03:00
SharedPreferences.getInstance().then((prefs) {
prefs.setBool(_whatsNewMessageKey, true);
eventBus.fire(ShowPageEvent(path: "/whats-new"));
});
2019-09-09 14:24:54 +03:00
}
2019-08-31 23:55:32 +03:00
}