diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-10-04 16:29:56 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-10-04 16:29:56 +0000 |
commit | 19d75267a0278407ac893fcba77490bf6eb5d4a9 (patch) | |
tree | 35f91bfbfee60e539cd089e5fa938efaad3b459c | |
parent | 63028069e63dbfd5c994a14d118bc4e98cb0844f (diff) | |
download | infinity-for-reddit-19d75267a0278407ac893fcba77490bf6eb5d4a9.tar infinity-for-reddit-19d75267a0278407ac893fcba77490bf6eb5d4a9.tar.gz infinity-for-reddit-19d75267a0278407ac893fcba77490bf6eb5d4a9.tar.bz2 infinity-for-reddit-19d75267a0278407ac893fcba77490bf6eb5d4a9.tar.lz infinity-for-reddit-19d75267a0278407ac893fcba77490bf6eb5d4a9.tar.xz infinity-for-reddit-19d75267a0278407ac893fcba77490bf6eb5d4a9.tar.zst infinity-for-reddit-19d75267a0278407ac893fcba77490bf6eb5d4a9.zip |
Sync subscriptions once every 24 hours.
2 files changed, 9 insertions, 1 deletions
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> subscribedSubredditData, ArrayList<SubscribedUserData> subscribedUserData, ArrayList<SubredditData> 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"; |