From 19d75267a0278407ac893fcba77490bf6eb5d4a9 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Wed, 4 Oct 2023 12:29:56 -0400 Subject: Sync subscriptions once every 24 hours. --- .../activities/SubscribedThingListingActivity.java | 9 ++++++++- .../infinityforreddit/utils/SharedPreferencesUtils.java | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java index 194304d1..83df55cd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java @@ -56,7 +56,6 @@ import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThings; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr; -import ml.docilealligator.infinityforreddit.customviews.slidr.widget.SliderPanel; import ml.docilealligator.infinityforreddit.events.GoBackToMainPageEvent; import ml.docilealligator.infinityforreddit.events.RefreshMultiRedditsEvent; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; @@ -109,6 +108,9 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti @Named("current_account") SharedPreferences mCurrentAccountSharedPreferences; @Inject + @Named("internal") + SharedPreferences mInternalSharedPreferences; + @Inject CustomThemeWrapper mCustomThemeWrapper; @Inject Executor mExecutor; @@ -317,6 +319,10 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti } public void loadSubscriptions(boolean forceLoad) { + if (!forceLoad && System.currentTimeMillis() - mInternalSharedPreferences.getLong(SharedPreferencesUtils.SUBSCRIBED_THINGS_SYNC_TIME, 0L) < 24 * 60 * 60 * 1000) { + return; + } + if (mAccessToken != null && !(!forceLoad && mInsertSuccess)) { FetchSubscribedThing.fetchSubscribedThing(mOauthRetrofit, mAccessToken, mAccountName, null, new ArrayList<>(), new ArrayList<>(), @@ -326,6 +332,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti public void onFetchSubscribedThingSuccess(ArrayList subscribedSubredditData, ArrayList subscribedUserData, ArrayList subredditData) { + mInternalSharedPreferences.edit().putLong(SharedPreferencesUtils.SUBSCRIBED_THINGS_SYNC_TIME, System.currentTimeMillis()).apply(); InsertSubscribedThings.insertSubscribedThings( mExecutor, new Handler(), diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java index f27253d6..baef18de 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -217,6 +217,7 @@ public class SharedPreferencesUtils { public static final String EASIER_TO_WATCH_IN_FULL_SCREEN = "easier_to_watch_in_full_screen"; public static final String HIDE_THE_NUMBER_OF_VOTES_IN_COMMENTS = "hide_the_number_of_votes_in_comments"; public static final String COMMENT_DIVIDER_TYPE = "comment_divider_type"; + public static final String SUBSCRIBED_THINGS_SYNC_TIME = "subscribed_things_sync_time"; public static final String DEFAULT_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit_preferences"; public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs"; -- cgit v1.2.3