From 1499a91ef7b4ef8d6829bbe8813b4ce048f245ec Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Thu, 14 May 2020 11:20:06 +0000 Subject: [PATCH] SHow donate message only after 14 days of use --- .../startup_user_messages_manager.class.dart | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/managers/startup_user_messages_manager.class.dart b/lib/managers/startup_user_messages_manager.class.dart index 19d045c..dd6ec36 100644 --- a/lib/managers/startup_user_messages_manager.class.dart +++ b/lib/managers/startup_user_messages_manager.class.dart @@ -11,19 +11,27 @@ class StartupUserMessagesManager { StartupUserMessagesManager._internal(); - bool _supportAppDevelopmentMessageShown; + bool _needToshowDonateMessage; bool _whatsNewMessageShown; - static final _supportAppDevelopmentMessageKey = "user-message-shown-support-development_3"; + static final _donateMsgTimerKey = "user-msg-donate-timer"; + static final _donateMsgShownKey = "user-msg-donate-shpown"; static final _whatsNewMessageKey = "user-msg-whats-new-url"; void checkMessagesToShow() async { SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.reload(); - _supportAppDevelopmentMessageShown = prefs.getBool(_supportAppDevelopmentMessageKey) ?? false; + var tInt = prefs.getInt(_donateMsgTimerKey); + if (tInt == null) { + prefs.setInt(_donateMsgTimerKey, DateTime.now().millisecondsSinceEpoch); + _needToshowDonateMessage = false; + } else { + bool wasShown = prefs.getBool(_donateMsgShownKey) ?? false; + _needToshowDonateMessage = (DateTime.now().millisecondsSinceEpoch - tInt >= 1209600000) && !wasShown; //14 days + } _whatsNewMessageShown = '${prefs.getString(_whatsNewMessageKey)}' == whatsNewUrl; if (!_whatsNewMessageShown) { _showWhatsNewMessage(); - } else if (!_supportAppDevelopmentMessageShown) { + } else if (_needToshowDonateMessage) { _showSupportAppDevelopmentMessage(); } } @@ -34,16 +42,16 @@ class StartupUserMessagesManager { 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.", positiveText: "Show options", - negativeText: "Cancel", + negativeText: "Later", onPositive: () { SharedPreferences.getInstance().then((prefs) { - prefs.setBool(_supportAppDevelopmentMessageKey, true); + prefs.setBool(_donateMsgShownKey, true); eventBus.fire(ShowPageEvent(path: "/putchase")); }); }, onNegative: () { SharedPreferences.getInstance().then((prefs) { - prefs.setBool(_supportAppDevelopmentMessageKey, true); + prefs.setInt(_donateMsgTimerKey, DateTime.now().millisecondsSinceEpoch); }); } )