diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-09-27 12:01:55 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-09-27 12:01:55 +0000 |
commit | 10cccb5b935202122516a50c7740688d940eb466 (patch) | |
tree | 1a9743567af72ea87edd2548d9affc1b3aec15ba /app/src/main/java | |
parent | 191023301da6b1e5bd3b9c577977b2b96bf815d4 (diff) | |
download | infinity-for-reddit-10cccb5b935202122516a50c7740688d940eb466.tar infinity-for-reddit-10cccb5b935202122516a50c7740688d940eb466.tar.gz infinity-for-reddit-10cccb5b935202122516a50c7740688d940eb466.tar.bz2 infinity-for-reddit-10cccb5b935202122516a50c7740688d940eb466.tar.lz infinity-for-reddit-10cccb5b935202122516a50c7740688d940eb466.tar.xz infinity-for-reddit-10cccb5b935202122516a50c7740688d940eb466.tar.zst infinity-for-reddit-10cccb5b935202122516a50c7740688d940eb466.zip |
Disable refreshing in SubscribedThingListingActivity in anonymous mode.
Diffstat (limited to 'app/src/main/java')
5 files changed, 57 insertions, 35 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java index a0b9acbb..344f00dd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java @@ -131,7 +131,7 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act mSwipeRefreshLayout.setEnabled(false); mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "-"); - + bindView(); } 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 22b1a469..850ada27 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java @@ -44,6 +44,7 @@ import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.asynctasks.DeleteMultiredditInDatabase; import ml.docilealligator.infinityforreddit.asynctasks.InsertMultireddit; import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThings; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; @@ -153,7 +154,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti setToolbarGoToTop(toolbar); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "-"); if (savedInstanceState != null) { mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE); @@ -242,7 +243,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti } public void loadSubscriptions(boolean forceLoad) { - if (!(!forceLoad && mInsertSuccess)) { + if (mAccessToken != null && !(!forceLoad && mInsertSuccess)) { FetchSubscribedThing.fetchSubscribedThing(mOauthRetrofit, mAccessToken, mAccountName, null, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), @@ -293,22 +294,24 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti } private void loadMultiReddits() { - FetchMyMultiReddits.fetchMyMultiReddits(mOauthRetrofit, mAccessToken, new FetchMyMultiReddits.FetchMyMultiRedditsListener() { - @Override - public void success(ArrayList<MultiReddit> multiReddits) { - InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddits, mAccountName, () -> { - mInsertMultiredditSuccess = true; - sectionsPagerAdapter.stopMultiRedditRefreshProgressbar(); - }); - } + if (mAccessToken != null) { + FetchMyMultiReddits.fetchMyMultiReddits(mOauthRetrofit, mAccessToken, new FetchMyMultiReddits.FetchMyMultiRedditsListener() { + @Override + public void success(ArrayList<MultiReddit> multiReddits) { + InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddits, mAccountName, () -> { + mInsertMultiredditSuccess = true; + sectionsPagerAdapter.stopMultiRedditRefreshProgressbar(); + }); + } - @Override - public void failed() { - mInsertMultiredditSuccess = false; - sectionsPagerAdapter.stopMultiRedditRefreshProgressbar(); - Toast.makeText(SubscribedThingListingActivity.this, R.string.error_loading_multi_reddit_list, Toast.LENGTH_SHORT).show(); - } - }); + @Override + public void failed() { + mInsertMultiredditSuccess = false; + sectionsPagerAdapter.stopMultiRedditRefreshProgressbar(); + Toast.makeText(SubscribedThingListingActivity.this, R.string.error_loading_multi_reddit_list, Toast.LENGTH_SHORT).show(); + } + }); + } } public void deleteMultiReddit(MultiReddit multiReddit) { @@ -316,21 +319,29 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti .setTitle(R.string.delete) .setMessage(R.string.delete_multi_reddit_dialog_message) .setPositiveButton(R.string.delete, (dialogInterface, i) - -> DeleteMultiReddit.deleteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, - mAccessToken, mAccountName, multiReddit.getPath(), new DeleteMultiReddit.DeleteMultiRedditListener() { - @Override - public void success() { - Toast.makeText(SubscribedThingListingActivity.this, - R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show(); - loadMultiReddits(); - } - - @Override - public void failed() { - Toast.makeText(SubscribedThingListingActivity.this, - R.string.delete_multi_reddit_failed, Toast.LENGTH_SHORT).show(); - } - })) + -> { + if (mAccessToken == null) { + DeleteMultiredditInDatabase.deleteMultiredditInDatabase(mExecutor, new Handler(), mRedditDataRoomDatabase, mAccountName, multiReddit.getPath(), + () -> Toast.makeText(SubscribedThingListingActivity.this, + R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show()); + } else { + DeleteMultiReddit.deleteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, + mAccessToken, mAccountName, multiReddit.getPath(), new DeleteMultiReddit.DeleteMultiRedditListener() { + @Override + public void success() { + Toast.makeText(SubscribedThingListingActivity.this, + R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show(); + loadMultiReddits(); + } + + @Override + public void failed() { + Toast.makeText(SubscribedThingListingActivity.this, + R.string.delete_multi_reddit_failed, Toast.LENGTH_SHORT).show(); + } + }); + } + }) .setNegativeButton(R.string.cancel, null) .show(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java index 1fda28d4..b3413209 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java @@ -109,11 +109,14 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo mGlide = Glide.with(this); + String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); + if (accessToken == null) { + mSwipeRefreshLayout.setEnabled(false); + } mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity); mRecyclerView.setLayoutManager(mLinearLayoutManager); FollowedUsersRecyclerViewAdapter adapter = new FollowedUsersRecyclerViewAdapter(mActivity, - mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, - getArguments().getString(EXTRA_ACCESS_TOKEN)); + mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, accessToken); mRecyclerView.setAdapter(adapter); new FastScrollerBuilder(mRecyclerView).build(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java index 0f80d47a..c6ff0b85 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java @@ -112,6 +112,10 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); boolean isGettingMultiredditInfo = getArguments().getBoolean(EXTRA_IS_GETTING_MULTIREDDIT_INFO, false); + if (accessToken == null) { + mSwipeRefreshLayout.setEnabled(false); + } + mGlide = Glide.with(this); mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java index 61333955..26425941 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java @@ -113,6 +113,10 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); + if (accessToken == null) { + mSwipeRefreshLayout.setEnabled(false); + } + mGlide = Glide.with(this); mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity); |