From 0c3a6a5822e8af94bb168fc5423bd6be7589764d Mon Sep 17 00:00:00 2001 From: cyberta Date: Tue, 6 Dec 2022 12:51:59 +0100 Subject: fix: show message of thew day only once a day --- app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java | 3 ++- .../java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java index 6e557236..58b057b7 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java @@ -276,7 +276,8 @@ public class StartActivity extends Activity{ String hash = message.hash(); lastSeenHashes.add(hash); p.setMotdLastSeenHashes(lastSeenHashes); - PreferenceHelper.persistProvider(this, p); + p.setLastMotdSeen(System.currentTimeMillis()); + PreferenceHelper.persistProviderAsync(this, p); ProviderObservable.getInstance().updateProvider(p); } showMotdFragment(message); diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java index 76e54794..ff3b5ab1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java @@ -95,7 +95,7 @@ public class PreferenceHelper { return preferences.getStringSet(toFetch + "." + providerDomain, new HashSet<>()); } - public static void persistProvider(Context context, Provider provider) { + public static void persistProviderAsync(Context context, Provider provider) { SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); storeProviderInPreferences(preferences, provider, true); } @@ -106,7 +106,7 @@ public class PreferenceHelper { // TODO: replace commit with apply after refactoring EIP //FIXME: don't save private keys in shared preferences! use the keystore - public static void storeProviderInPreferences(SharedPreferences preferences, Provider provider, boolean apply) { + public static void storeProviderInPreferences(SharedPreferences preferences, Provider provider, boolean async) { SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean(PROVIDER_CONFIGURED, true). putString(Provider.PROVIDER_IP, provider.getProviderIp()). @@ -123,7 +123,7 @@ public class PreferenceHelper { putStringSet(PROVIDER_MOTD_HASHES, provider.getMotdLastSeenHashes()). putLong(PROVIDER_MOTD_LAST_SEEN, provider.getLastMotdSeen()). putLong(PROVIDER_MOTD_LAST_UPDATED, provider.getLastMotdUpdate()); - if (apply) { + if (async) { editor.apply(); } else { editor.commit(); -- cgit v1.2.3