From ed7dc47c5080ce1ad134d61e9f8cdfc6e7d1e6f2 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Mon, 1 Jan 2024 02:39:54 -0500 Subject: Use !accountName.equals(Account.ANONYMOUS_ACCOUNT) instead of accessToken != null. --- .../FetchPostFilterReadPostsAndConcatenatedSubredditNames.java | 4 +++- .../activities/CreateMultiRedditActivity.java | 2 +- .../infinityforreddit/activities/FilteredPostsActivity.java | 2 +- .../infinityforreddit/activities/InboxActivity.java | 2 +- .../infinityforreddit/activities/MainActivity.java | 4 ++-- .../activities/MultiredditSelectionActivity.java | 3 ++- .../activities/SubscribedThingListingActivity.java | 4 ++-- .../adapters/CommentsListingRecyclerViewAdapter.java | 1 + .../adapters/CommentsRecyclerViewAdapter.java | 1 + .../infinityforreddit/adapters/PostRecyclerViewAdapter.java | 10 +++++----- .../adapters/SubredditListingRecyclerViewAdapter.java | 3 ++- .../bottomsheetfragments/CommentMoreBottomSheetFragment.java | 5 ++++- .../infinityforreddit/fragments/HistoryPostFragment.java | 2 +- .../infinityforreddit/fragments/PostFragment.java | 8 ++++---- .../fragments/SubscribedSubredditsListingFragment.java | 2 +- .../infinityforreddit/fragments/ViewPostDetailFragment.java | 8 ++++---- .../infinityforreddit/subreddit/FetchSubredditData.java | 5 +---- 17 files changed, 36 insertions(+), 30 deletions(-) (limited to 'app') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchPostFilterReadPostsAndConcatenatedSubredditNames.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchPostFilterReadPostsAndConcatenatedSubredditNames.java index 1837d6e5..2971a150 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchPostFilterReadPostsAndConcatenatedSubredditNames.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchPostFilterReadPostsAndConcatenatedSubredditNames.java @@ -2,6 +2,8 @@ package ml.docilealligator.infinityforreddit; import android.os.Handler; +import androidx.annotation.NonNull; + import java.util.ArrayList; import java.util.List; import java.util.concurrent.Executor; @@ -22,7 +24,7 @@ public class FetchPostFilterReadPostsAndConcatenatedSubredditNames { } public static void fetchPostFilterAndReadPosts(RedditDataRoomDatabase redditDataRoomDatabase, Executor executor, - Handler handler, String accountName, int postFilterUsage, + Handler handler, @NonNull String accountName, int postFilterUsage, String nameOfUsage, FetchPostFilterAndReadPostsListener fetchPostFilterAndReadPostsListener) { executor.execute(() -> { List postFilters = redditDataRoomDatabase.postFilterDao().getValidPostFilters(postFilterUsage, nameOfUsage); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java index c14d930c..50e4d725 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java @@ -160,7 +160,7 @@ public class CreateMultiRedditActivity extends BaseActivity { return true; } - if (mAccessToken != null) { + if (!mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { String jsonModel = new MultiRedditJSONModel(nameEditText.getText().toString(), descriptionEditText.getText().toString(), visibilitySwitch.isChecked(), mSubreddits).createJSONModel(); CreateMultiReddit.createMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java index 257ad00a..a7656c8f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java @@ -339,7 +339,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec startActivityForResult(intent, CUSTOMIZE_POST_FILTER_ACTIVITY_REQUEST_CODE); }); - if (mAccessToken != null) { + if (!mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { fab.setOnLongClickListener(view -> { FilteredThingFABMoreOptionsBottomSheetFragment filteredThingFABMoreOptionsBottomSheetFragment = new FilteredThingFABMoreOptionsBottomSheetFragment(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java index 3e019455..9c916fe1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java @@ -300,7 +300,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf } return true; } else if (item.getItemId() == R.id.action_read_all_messages_inbox_activity) { - if (mAccessToken != null) { + if (!mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { Toast.makeText(this, R.string.please_wait, Toast.LENGTH_SHORT).show(); mOauthRetrofit.create(RedditAPI.class).readAllMessages(APIUtils.getOAuthHeader(mAccessToken)) .enqueue(new Callback<>() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index 4cf166f6..45492485 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -988,7 +988,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb loadUserData(); - if (mAccessToken != null) { + if (!mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { if (mMessageFullname != null) { ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() { @Override @@ -1006,7 +1006,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } private void loadSubscriptions() { - if (mAccessToken != null && !mFetchSubscriptionsSuccess) { + if (!mAccountName.equals(Account.ANONYMOUS_ACCOUNT) && !mFetchSubscriptionsSuccess) { FetchSubscribedThing.fetchSubscribedThing(mOauthRetrofit, mAccessToken, mAccountName, null, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java index 25108607..09d36b79 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java @@ -34,6 +34,7 @@ import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.asynctasks.InsertMultireddit; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr; @@ -150,7 +151,7 @@ public class MultiredditSelectionActivity extends BaseActivity implements Activi return; } - if (mAccessToken != null) { + if (!mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { loadMultiReddits(); } 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 bc22542b..f79d4667 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java @@ -324,7 +324,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti return; } - if (mAccessToken != null && !(!forceLoad && mInsertSuccess)) { + if (!mAccountName.equals(Account.ANONYMOUS_ACCOUNT) && !(!forceLoad && mInsertSuccess)) { FetchSubscribedThing.fetchSubscribedThing(mOauthRetrofit, mAccessToken, mAccountName, null, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), @@ -376,7 +376,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti } private void loadMultiReddits() { - if (mAccessToken != null) { + if (!mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { FetchMyMultiReddits.fetchMyMultiReddits(mOauthRetrofit, mAccessToken, new FetchMyMultiReddits.FetchMyMultiRedditsListener() { @Override public void success(ArrayList multiReddits) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java index 3ded569d..64539461 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -528,6 +528,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { - if (accessToken != null) { + if (!accountName.equals(Account.ANONYMOUS_ACCOUNT)) { SubredditSubscription.subscribeToSubreddit(executor, new Handler(), oauthRetrofit, retrofit, accessToken, subredditData.getName(), accountName, redditDataRoomDatabase, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java index f8ad6cb2..59345840 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java @@ -17,6 +17,7 @@ import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CommentActivity; import ml.docilealligator.infinityforreddit.activities.CommentFilterPreferenceActivity; @@ -37,6 +38,7 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott public static final String EXTRA_COMMENT = "ECF"; public static final String EXTRA_ACCESS_TOKEN = "EAT"; + public static final String EXTRA_ACCOUNT_NAME = "EAN"; public static final String EXTRA_EDIT_AND_DELETE_AVAILABLE = "EEADA"; public static final String EXTRA_POSITION = "EP"; public static final String EXTRA_SHOW_REPLY_AND_SAVE_OPTION = "ESSARO"; @@ -70,10 +72,11 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott return binding.getRoot(); } String accessToken = bundle.getString(EXTRA_ACCESS_TOKEN); + String accountName = bundle.getString(EXTRA_ACCOUNT_NAME); boolean editAndDeleteAvailable = bundle.getBoolean(EXTRA_EDIT_AND_DELETE_AVAILABLE, false); boolean showReplyAndSaveOption = bundle.getBoolean(EXTRA_SHOW_REPLY_AND_SAVE_OPTION, false); - if (accessToken != null && !accessToken.equals("")) { + if (!accountName.equals(Account.ANONYMOUS_ACCOUNT) && !accessToken.equals("")) { if (editAndDeleteAvailable) { binding.editTextViewCommentMoreBottomSheetFragment.setVisibility(View.VISIBLE); binding.deleteTextViewCommentMoreBottomSheetFragment.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java index 10244d4a..bced3f57 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java @@ -446,7 +446,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato if (postFilter == null) { FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor, - new Handler(), null, PostFilterUsage.HISTORY_TYPE, PostFilterUsage.HISTORY_TYPE_USAGE_READ_POSTS, (postFilter, readPostList) -> { + new Handler(), accountName, PostFilterUsage.HISTORY_TYPE, PostFilterUsage.HISTORY_TYPE_USAGE_READ_POSTS, (postFilter, readPostList) -> { if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) { this.postFilter = postFilter; postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.NSFW_BASE, false); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index 712eeb0a..624c4848 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -917,12 +917,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator { ((ActivityToolbarInterface) activity).displaySortType(); } - if (accessToken != null && !accessToken.equals("")) { + if (!accountName.equals(Account.ANONYMOUS_ACCOUNT)) { if (mPostHistorySharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false) && readPosts == null) { if (getArguments().getBoolean(EXTRA_DISABLE_READ_POSTS, false)) { if (postFilter == null) { FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor, - new Handler(), null, usage, nameOfUsage, (postFilter, readPostList) -> { + new Handler(), accountName, usage, nameOfUsage, (postFilter, readPostList) -> { if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) { this.postFilter = postFilter; postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.NSFW_BASE, false); @@ -948,7 +948,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } else { if (postFilter == null) { FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor, - new Handler(), null, usage, nameOfUsage, (postFilter, readPostList) -> { + new Handler(), accountName, usage, nameOfUsage, (postFilter, readPostList) -> { if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) { this.postFilter = postFilter; postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.NSFW_BASE, false); @@ -999,7 +999,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } } else { FetchPostFilterReadPostsAndConcatenatedSubredditNames.fetchPostFilterAndReadPosts(mRedditDataRoomDatabase, mExecutor, - new Handler(), null, usage, nameOfUsage, (postFilter, readPostList) -> { + new Handler(), accountName, usage, nameOfUsage, (postFilter, readPostList) -> { if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) { this.postFilter = postFilter; postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false); 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 d0177aaf..cda55e3b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java @@ -150,7 +150,7 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra mGlide.clear(mImageView); } - if (accessToken != null) { + if (!accountName.equals(Account.ANONYMOUS_ACCOUNT)) { adapter.addUser(accountName, getArguments().getString(EXTRA_ACCOUNT_PROFILE_IMAGE_URL)); } adapter.setSubscribedSubreddits(subscribedSubredditData); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java index 1d30084b..1ee0d0d0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -576,7 +576,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic } private void bindView() { - if (mAccessToken != null && mMessageFullname != null) { + if (!mAccountName.equals(Account.ANONYMOUS_ACCOUNT) && mMessageFullname != null) { ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() { @Override public void readSuccess() { @@ -682,7 +682,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic mMenu.findItem(R.id.action_comment_view_post_detail_fragment).setVisible(true); mMenu.findItem(R.id.action_sort_view_post_detail_fragment).setVisible(true); - if (mAccessToken != null) { + if (!mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { if (mPost.isSaved()) { saveItem.setVisible(true); saveItem.setIcon(mSavedIcon); @@ -976,7 +976,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic } return true; } else if (itemId == R.id.action_save_view_post_detail_fragment) { - if (mPost != null && mAccessToken != null) { + if (mPost != null && !mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { if (mPost.isSaved()) { item.setIcon(mUnsavedIcon); SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(), @@ -1040,7 +1040,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic startActivity(crosspostIntent); return true; } else if (itemId == R.id.action_hide_view_post_detail_fragment) { - if (mPost != null && mAccessToken != null) { + if (mPost != null && !mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { if (mPost.isHidden()) { Utils.setTitleWithCustomFontToMenuItem(activity.typeface, item, getString(R.string.action_hide_post)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java index 3201cc6d..e19e5492 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java @@ -5,8 +5,6 @@ import android.text.TextUtils; import androidx.annotation.NonNull; import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; import ml.docilealligator.infinityforreddit.SortType; @@ -59,8 +57,7 @@ public class FetchSubredditData { boolean nsfw, final FetchSubredditListingDataListener fetchSubredditListingDataListener) { RedditAPI api = retrofit.create(RedditAPI.class); - Map map = new HashMap<>(); - Map headers = accessToken != null ? APIUtils.getOAuthHeader(accessToken) : Collections.unmodifiableMap(map); + Map headers = APIUtils.getOAuthHeader(accessToken); Call subredditDataCall = api.searchSubreddits(query, after, sortType, nsfw ? 1 : 0, headers); subredditDataCall.enqueue(new Callback() { @Override -- cgit v1.2.3