From 5ec25cb921503bbbcabc207e7d84a51ff5780b3c Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sun, 31 Dec 2023 22:53:32 -0500 Subject: Use OAuth for anonymous mode. Fix translation issues. --- .../infinityforreddit/FavoriteThing.java | 21 ++++--- .../infinityforreddit/FetchRules.java | 8 ++- .../activities/CommentActivity.java | 2 +- .../activities/CreateMultiRedditActivity.java | 2 +- .../activities/CustomizePostFilterActivity.java | 4 +- .../activities/EditMultiRedditActivity.java | 6 +- .../activities/EditProfileActivity.java | 10 +-- .../infinityforreddit/activities/MainActivity.java | 24 ++++---- .../activities/ReportActivity.java | 8 +-- .../activities/RulesActivity.java | 48 +++++++-------- .../activities/SearchActivity.java | 5 +- .../activities/SearchResultActivity.java | 9 +-- .../activities/SubscribedThingListingActivity.java | 6 +- .../activities/TrendingActivity.java | 11 ++-- .../activities/ViewMultiRedditDetailActivity.java | 22 +++---- .../activities/ViewPostDetailActivity.java | 59 ++++++------------ .../activities/ViewSubredditDetailActivity.java | 26 ++++---- .../activities/ViewUserDetailActivity.java | 30 ++++----- .../activities/ViewVideoActivity.java | 2 + .../CommentsListingRecyclerViewAdapter.java | 5 +- .../adapters/CommentsRecyclerViewAdapter.java | 18 +++--- .../adapters/FollowedUsersRecyclerViewAdapter.java | 12 ++-- .../adapters/HistoryPostRecyclerViewAdapter.java | 26 ++++---- .../MultiRedditListingRecyclerViewAdapter.java | 14 +++-- .../adapters/PostDetailRecyclerViewAdapter.java | 11 ++-- .../adapters/PostRecyclerViewAdapter.java | 34 ++++++----- .../SubscribedSubredditsRecyclerViewAdapter.java | 16 ++--- .../infinityforreddit/apis/RedditAPI.java | 71 ---------------------- .../asynctasks/InsertSubscribedThings.java | 10 +-- .../comment/CommentDataSource.java | 24 +++----- .../comment/CommentDataSourceFactory.java | 8 ++- .../comment/CommentViewModel.java | 15 +++-- .../infinityforreddit/comment/FetchComment.java | 27 +++----- .../fragments/CommentsListingFragment.java | 18 ++---- .../fragments/FollowedUsersListingFragment.java | 8 ++- .../fragments/HistoryPostFragment.java | 4 +- .../fragments/MultiRedditListingFragment.java | 4 +- .../infinityforreddit/fragments/PostFragment.java | 14 ++--- .../fragments/SubredditListingFragment.java | 2 +- .../SubscribedSubredditsListingFragment.java | 6 +- .../fragments/ViewPostDetailFragment.java | 49 +++++---------- .../infinityforreddit/post/FetchPost.java | 11 ++-- .../post/HistoryPostPagingSource.java | 7 +-- .../infinityforreddit/post/PostPagingSource.java | 52 ++++++---------- app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values-vi/strings.xml | 8 +-- 46 files changed, 323 insertions(+), 456 deletions(-) (limited to 'app') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java index 81ae4fa3..4ac78c1b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit; import android.os.Handler; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import java.util.HashMap; import java.util.Map; @@ -21,9 +22,10 @@ import retrofit2.Retrofit; public class FavoriteThing { public static void favoriteSubreddit(Executor executor, Handler handler, Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, - String accessToken, SubscribedSubredditData subscribedSubredditData, + @Nullable String accessToken, @Nullable String accountName, + SubscribedSubredditData subscribedSubredditData, FavoriteThingListener favoriteThingListener) { - if (accessToken == null) { + if (accountName == null) { InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, subscribedSubredditData, favoriteThingListener::success); } else { @@ -51,9 +53,10 @@ public class FavoriteThing { public static void unfavoriteSubreddit(Executor executor, Handler handler, Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, - String accessToken, SubscribedSubredditData subscribedSubredditData, + @Nullable String accessToken, @Nullable String accountName, + SubscribedSubredditData subscribedSubredditData, FavoriteThingListener favoriteThingListener) { - if (accessToken == null) { + if (accountName == null) { InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, subscribedSubredditData, favoriteThingListener::success); } else { @@ -81,9 +84,10 @@ public class FavoriteThing { public static void favoriteUser(Executor executor, Handler handler, Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, - String accessToken, SubscribedUserData subscribedUserData, + @Nullable String accessToken, @Nullable String accountName, + SubscribedUserData subscribedUserData, FavoriteThingListener favoriteThingListener) { - if (accessToken == null) { + if (accountName == null) { InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, subscribedUserData, favoriteThingListener::success); } else { @@ -111,9 +115,10 @@ public class FavoriteThing { public static void unfavoriteUser(Executor executor, Handler handler, Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, - String accessToken, SubscribedUserData subscribedUserData, + @Nullable String accessToken, @Nullable String accountName, + SubscribedUserData subscribedUserData, FavoriteThingListener favoriteThingListener) { - if (accessToken == null) { + if (accountName == null) { InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, subscribedUserData, favoriteThingListener::success); } else { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRules.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRules.java index 1a7736c4..808e393f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRules.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRules.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit; import android.os.Handler; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import org.json.JSONArray; import org.json.JSONException; @@ -26,11 +27,12 @@ public class FetchRules { void failed(); } - public static void fetchRules(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String subredditName, + public static void fetchRules(Executor executor, Handler handler, Retrofit retrofit, @Nullable String accessToken, + String accountName, String subredditName, FetchRulesListener fetchRulesListener) { RedditAPI api = retrofit.create(RedditAPI.class); - Call rulesCall = accessToken == null ? api.getRules(subredditName) : api.getRulesOauth(APIUtils.getOAuthHeader(accessToken), subredditName); - rulesCall.enqueue(new Callback() { + Call rulesCall = api.getRulesOauth(APIUtils.getOAuthHeader(accessToken), subredditName); + rulesCall.enqueue(new Callback<>() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java index 316fe0c4..df492641 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -162,7 +162,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA mGlide = Glide.with(this); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - if (mAccessToken == null) { + if (mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null) == null) { finish(); return; } 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 6679152b..c14d930c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java @@ -117,7 +117,7 @@ public class CreateMultiRedditActivity extends BaseActivity { mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { visibilityLinearLayout.setVisibility(View.GONE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { nameEditText.setImeOptions(nameEditText.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java index f2581883..8568a6d8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java @@ -45,6 +45,7 @@ import butterknife.ButterKnife; 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.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.postfilter.PostFilter; import ml.docilealligator.infinityforreddit.postfilter.SavePostFilter; @@ -259,9 +260,8 @@ public class CustomizePostFilterActivity extends BaseActivity { onlySpoilerSwitch.performClick(); }); - String accessToken = currentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); addSubredditsImageView.setOnClickListener(view -> { - if (accessToken == null) { + if (currentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT).equals(Account.ANONYMOUS_ACCOUNT)) { Intent intent = new Intent(this, SearchActivity.class); intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, true); intent.putExtra(SearchActivity.EXTRA_IS_MULTI_SELECTION, true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java index b2af5138..14c881c5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java @@ -126,7 +126,7 @@ public class EditMultiRedditActivity extends BaseActivity { mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); - if (mAccessToken == null) { + if (mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT).equals(Account.ANONYMOUS_ACCOUNT)) { visibilityLinearLayout.setVisibility(View.GONE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { nameEditText.setImeOptions(nameEditText.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING); @@ -146,7 +146,7 @@ public class EditMultiRedditActivity extends BaseActivity { private void bindView() { if (multiReddit == null) { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { FetchMultiRedditInfo.anonymousFetchMultiRedditInfo(mExecutor, new Handler(), mRedditDataRoomDatabase, multipath, new FetchMultiRedditInfo.FetchMultiRedditInfoListener() { @Override @@ -217,7 +217,7 @@ public class EditMultiRedditActivity extends BaseActivity { return true; } - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { String name = nameEditText.getText().toString(); multiReddit.setDisplayName(name); multiReddit.setName(name); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java index 4d57dd00..786eee71 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java @@ -42,6 +42,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation; 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.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr; import ml.docilealligator.infinityforreddit.events.SubmitChangeAvatarEvent; @@ -159,7 +160,7 @@ public class EditProfileActivity extends BaseActivity { changeBanner.setLayoutParams(cBannerLp); glide.load(userBanner).into(bannerImageView); changeBanner.setOnLongClickListener(view -> { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { return false; } new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) @@ -202,7 +203,7 @@ public class EditProfileActivity extends BaseActivity { } else { changeAvatar.setLongClickable(true); changeAvatar.setOnLongClickListener(view -> { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { return false; } new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) @@ -241,8 +242,9 @@ public class EditProfileActivity extends BaseActivity { @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); - if (resultCode != RESULT_OK || data == null) return; // - if (mAccessToken == null || mAccountName == null) return; // + if (resultCode != RESULT_OK || data == null || mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { + return; + } Intent intent = new Intent(this, EditProfileService.class); intent.setData(data.getData()); intent.putExtra(EditProfileService.EXTRA_ACCOUNT_NAME, mAccountName); 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 cc974d2e..29f08f2d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -325,7 +325,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb fragmentManager = getSupportFragmentManager(); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); if (savedInstanceState != null) { mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE); @@ -584,9 +584,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } if (showBottomAppBar) { - int optionCount = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_COUNT, 4); - int option1 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS); - int option2 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_MULTIREDDITS); + int optionCount = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_COUNT, 4); + int option1 = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS); + int option2 = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_MULTIREDDITS); if (optionCount == 2) { navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2)); @@ -613,8 +613,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb }); } } else { - int option3 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_3, mAccessToken == null ? SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_REFRESH : SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_INBOX); - int option4 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_4, mAccessToken == null ? SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_CHANGE_SORT_TYPE : SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_PROFILE); + int option3 = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_3, mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_REFRESH : SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_INBOX); + int option4 = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_4, mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_CHANGE_SORT_TYPE : SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_PROFILE); navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2), getBottomAppBarOptionDrawableResource(option3), @@ -663,7 +663,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb navigationWrapper.floatingActionButton.setLayoutParams(lp); } - fabOption = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB, + fabOption = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS); switch (fabOption) { case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_REFRESH: @@ -688,7 +688,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_random_24dp); break; case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS: - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp); fabOption = SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS; } else { @@ -702,7 +702,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_keyboard_double_arrow_up_24); break; default: - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp); fabOption = SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS; } else { @@ -765,7 +765,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb navigationWrapper.floatingActionButton.setOnLongClickListener(view -> { FABMoreOptionsBottomSheetFragment fabMoreOptionsBottomSheetFragment= new FABMoreOptionsBottomSheetFragment(); Bundle bundle = new Bundle(); - bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccessToken == null); + bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccountName.equals(Account.ANONYMOUS_ACCOUNT)); fabMoreOptionsBottomSheetFragment.setArguments(bundle); fabMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag()); return true; @@ -1637,7 +1637,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME) { PostFragment fragment = new PostFragment(); Bundle bundle = new Bundle(); - bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccessToken == null ? PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE : PostPagingSource.TYPE_FRONT_PAGE); + bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE : PostPagingSource.TYPE_FRONT_PAGE); bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName); fragment.setArguments(bundle); @@ -1664,7 +1664,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb PostFragment fragment = new PostFragment(); Bundle bundle = new Bundle(); bundle.putString(PostFragment.EXTRA_NAME, name); - bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccessToken == null ? PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT : PostPagingSource.TYPE_MULTI_REDDIT); + bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT : PostPagingSource.TYPE_MULTI_REDDIT); bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName); fragment.setArguments(bundle); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java index 58948363..1907d2d4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java @@ -31,6 +31,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.ReportReason; import ml.docilealligator.infinityforreddit.ReportThing; import ml.docilealligator.infinityforreddit.Rule; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.ReportReasonRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr; @@ -56,9 +57,6 @@ public class ReportActivity extends BaseActivity { @Named("oauth") Retrofit mOauthRetrofit; @Inject - @Named("no_oauth") - Retrofit mRetrofit; - @Inject @Named("default") SharedPreferences mSharedPreferences; @Inject @@ -71,6 +69,7 @@ public class ReportActivity extends BaseActivity { @Inject Executor mExecutor; private String mAccessToken; + private String mAccountName; private String mFullname; private String mSubredditName; private ArrayList generalReasons; @@ -105,6 +104,7 @@ public class ReportActivity extends BaseActivity { mSubredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); if (savedInstanceState != null) { generalReasons = savedInstanceState.getParcelableArrayList(GENERAL_REASONS_STATE); @@ -119,7 +119,7 @@ public class ReportActivity extends BaseActivity { recyclerView.setAdapter(mAdapter); if (rulesReasons == null) { - FetchRules.fetchRules(mExecutor, new Handler(), mAccessToken == null ? mRetrofit : mOauthRetrofit, mAccessToken, mSubredditName, new FetchRules.FetchRulesListener() { + FetchRules.fetchRules(mExecutor, new Handler(), mOauthRetrofit, mAccessToken, mAccountName, mSubredditName, new FetchRules.FetchRulesListener() { @Override public void success(ArrayList rules) { mAdapter.setRules(ReportReason.convertRulesToReasons(rules)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java index aa83aaa5..b0f59535 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java @@ -35,6 +35,7 @@ import ml.docilealligator.infinityforreddit.FetchRules; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Rule; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.RulesRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr; @@ -64,17 +65,11 @@ public class RulesActivity extends BaseActivity { @BindView(R.id.error_text_view_rules_activity) TextView errorTextView; @Inject - @Named("no_oauth") - Retrofit mRetrofit; - @Inject @Named("oauth") Retrofit mOauthRetrofit; - - private String mAccessToken; @Inject @Named("current_account") SharedPreferences mCurrentAccountSharedPreferences; - @Inject @Named("default") SharedPreferences mSharedPreferences; @@ -82,6 +77,8 @@ public class RulesActivity extends BaseActivity { CustomThemeWrapper mCustomThemeWrapper; @Inject Executor mExecutor; + private String mAccessToken; + private String mAccountName; private String mSubredditName; private RulesRecyclerViewAdapter mAdapter; @@ -126,6 +123,7 @@ public class RulesActivity extends BaseActivity { } } mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); appBarLayout.setBackgroundColor(mCustomThemeWrapper.getColorPrimary()); setSupportActionBar(toolbar); @@ -136,25 +134,25 @@ public class RulesActivity extends BaseActivity { mAdapter = new RulesRecyclerViewAdapter(this, mCustomThemeWrapper, sliderPanel, mSubredditName); recyclerView.setAdapter(mAdapter); - FetchRules.fetchRules(mExecutor, new Handler(), mAccessToken == null ? mRetrofit : mOauthRetrofit, mAccessToken, mSubredditName, new FetchRules.FetchRulesListener() { - @Override - public void success(ArrayList rules) { - progressBar.setVisibility(View.GONE); - if (rules == null || rules.size() == 0) { - errorTextView.setVisibility(View.VISIBLE); - errorTextView.setText(R.string.no_rule); - errorTextView.setOnClickListener(view -> { - }); - } - mAdapter.changeDataset(rules); - } - - @Override - public void failed() { - displayError(); - } - }); + FetchRules.fetchRules(mExecutor, new Handler(), mOauthRetrofit, mAccessToken, mAccountName, + mSubredditName, new FetchRules.FetchRulesListener() { + @Override + public void success(ArrayList rules) { + progressBar.setVisibility(View.GONE); + if (rules == null || rules.size() == 0) { + errorTextView.setVisibility(View.VISIBLE); + errorTextView.setText(R.string.no_rule); + errorTextView.setOnClickListener(view -> { + }); + } + mAdapter.changeDataset(rules); + } + @Override + public void failed() { + displayError(); + } + }); } @Override @@ -185,7 +183,7 @@ public class RulesActivity extends BaseActivity { errorTextView.setOnClickListener(view -> { progressBar.setVisibility(View.VISIBLE); errorTextView.setVisibility(View.GONE); - FetchRules.fetchRules(mExecutor, new Handler(), mAccessToken == null ? mRetrofit : mOauthRetrofit, mAccessToken, mSubredditName, new FetchRules.FetchRulesListener() { + FetchRules.fetchRules(mExecutor, new Handler(), mOauthRetrofit, mAccessToken, mAccountName, mSubredditName, new FetchRules.FetchRulesListener() { @Override public void success(ArrayList rules) { progressBar.setVisibility(View.GONE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java index fdedff7d..dc3eee4b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java @@ -45,6 +45,7 @@ import butterknife.ButterKnife; 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.adapters.SearchActivityRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.adapters.SubredditAutocompleteRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.apis.RedditAPI; @@ -174,7 +175,7 @@ public class SearchActivity extends BaseActivity { searchEditText.setHint(getText(R.string.search_only_users_hint)); } - mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); boolean nsfw = mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false); @@ -199,7 +200,7 @@ public class SearchActivity extends BaseActivity { finish(); }); - if (mAccessToken == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { searchEditText.setImeOptions(searchEditText.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java index 06a2567a..e02c9332 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java @@ -53,6 +53,7 @@ import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterfac import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.SubredditAutocompleteRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FABMoreOptionsBottomSheetFragment; @@ -204,7 +205,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect fragmentManager = getSupportFragmentManager(); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); if (savedInstanceState != null) { mInsertSearchQuerySuccess = savedInstanceState.getBoolean(INSERT_SEARCH_QUERY_SUCCESS_STATE); @@ -298,7 +299,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect fab.setImageResource(R.drawable.ic_random_24dp); break; case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS: - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { fab.setImageResource(R.drawable.ic_filter_24dp); fabOption = SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS; } else { @@ -312,7 +313,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect fab.setImageResource(R.drawable.ic_keyboard_double_arrow_up_24); break; default: - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { fab.setImageResource(R.drawable.ic_filter_24dp); fabOption = SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS; } else { @@ -382,7 +383,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect fab.setOnLongClickListener(view -> { FABMoreOptionsBottomSheetFragment fabMoreOptionsBottomSheetFragment = new FABMoreOptionsBottomSheetFragment(); Bundle bundle = new Bundle(); - bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccessToken == null); + bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccountName.equals(Account.ANONYMOUS_ACCOUNT)); fabMoreOptionsBottomSheetFragment.setArguments(bundle); fabMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag()); return true; 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 c5e2e638..c40496c0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java @@ -179,7 +179,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti showMultiReddits = getIntent().getBooleanExtra(EXTRA_SHOW_MULTIREDDITS, false); } - if (mAccessToken == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { searchEditText.setImeOptions(searchEditText.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING); } @@ -402,7 +402,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti .setMessage(R.string.delete_multi_reddit_dialog_message) .setPositiveButton(R.string.delete, (dialogInterface, i) -> { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { DeleteMultiredditInDatabase.deleteMultiredditInDatabase(mExecutor, new Handler(), mRedditDataRoomDatabase, mAccountName, multiReddit.getPath(), () -> Toast.makeText(SubscribedThingListingActivity.this, R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show()); @@ -490,7 +490,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti case 1: { FollowedUsersListingFragment fragment = new FollowedUsersListingFragment(); Bundle bundle = new Bundle(); - bundle.putString(FollowedUsersListingFragment.EXTRA_ACCOUNT_NAME, mAccountName == null ? Account.ANONYMOUS_ACCOUNT : mAccountName); + bundle.putString(FollowedUsersListingFragment.EXTRA_ACCOUNT_NAME, mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : mAccountName); bundle.putString(FollowedUsersListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken); fragment.setArguments(bundle); return fragment; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java index 053f6be9..28e4898d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java @@ -43,6 +43,7 @@ import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.TrendingSearch; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.TrendingSearchRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; @@ -101,6 +102,7 @@ public class TrendingActivity extends BaseActivity { @Inject Executor mExecutor; private String mAccessToken; + private String mAccountName; private boolean isRefreshing = false; private ArrayList trendingSearches; private TrendingSearchRecyclerViewAdapter adapter; @@ -150,6 +152,7 @@ public class TrendingActivity extends BaseActivity { setToolbarGoToTop(toolbar); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); mGlide = Glide.with(this); @@ -205,12 +208,8 @@ public class TrendingActivity extends BaseActivity { trendingSearches = null; adapter.setTrendingSearches(null); Handler handler = new Handler(); - Call trendingCall; - if (mAccessToken == null) { - trendingCall = mRetrofit.create(RedditAPI.class).getTrendingSearches(); - } else { - trendingCall = mOauthRetrofit.create(RedditAPI.class).getTrendingSearchesOauth(APIUtils.getOAuthHeader(mAccessToken)); - } + Call trendingCall = mOauthRetrofit.create(RedditAPI.class) + .getTrendingSearchesOauth(APIUtils.getOAuthHeader(mAccessToken)); trendingCall.enqueue(new Callback<>() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java index caa4d4d8..bfeb6135 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java @@ -220,7 +220,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT setToolbarGoToTop(toolbar); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); lockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false); if (savedInstanceState != null) { @@ -233,9 +233,9 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT navigationWrapper.floatingActionButton.setVisibility(hideFab ? View.GONE : View.VISIBLE); if (showBottomAppBar) { - int optionCount = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, 4); - int option1 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME); - int option2 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS); + int optionCount = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, 4); + int option1 = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME); + int option2 = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS); if (optionCount == 2) { navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2)); @@ -262,8 +262,8 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT }); } } else { - int option3 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_3, mAccessToken == null ? SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_MULTIREDDITS : SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_INBOX); - int option4 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_4, mAccessToken == null ? SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_REFRESH : SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_PROFILE); + int option3 = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_3, mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_MULTIREDDITS : SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_INBOX); + int option4 = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_4, mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_REFRESH : SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_PROFILE); navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2), getBottomAppBarOptionDrawableResource(option3), @@ -336,7 +336,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_random_24dp); break; case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS: - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp); fabOption = SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS; } else { @@ -350,7 +350,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_keyboard_double_arrow_up_24); break; default: - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp); fabOption = SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS; } else { @@ -412,7 +412,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT navigationWrapper.floatingActionButton.setOnLongClickListener(view -> { FABMoreOptionsBottomSheetFragment fabMoreOptionsBottomSheetFragment = new FABMoreOptionsBottomSheetFragment(); Bundle bundle = new Bundle(); - bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccessToken == null); + bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccountName.equals(Account.ANONYMOUS_ACCOUNT)); fabMoreOptionsBottomSheetFragment.setArguments(bundle); fabMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag()); return true; @@ -423,7 +423,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT mFragment = new PostFragment(); Bundle bundle = new Bundle(); bundle.putString(PostFragment.EXTRA_NAME, multiPath); - bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccessToken == null ? PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT : PostPagingSource.TYPE_MULTI_REDDIT); + bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT : PostPagingSource.TYPE_MULTI_REDDIT); bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName); mFragment.setArguments(bundle); @@ -758,7 +758,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT .setMessage(R.string.delete_multi_reddit_dialog_message) .setPositiveButton(R.string.delete, (dialogInterface, i) -> { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { DeleteMultiredditInDatabase.deleteMultiredditInDatabase(mExecutor, new Handler(), mRedditDataRoomDatabase, mAccountName, multiPath, () -> { Toast.makeText(this, R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index bd2d6ed4..3e1d732b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -65,6 +65,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount; import ml.docilealligator.infinityforreddit.comment.Comment; @@ -264,7 +265,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele } mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); mVolumeKeysNavigateComments = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOLUME_KEYS_NAVIGATE_COMMENTS, false); @@ -288,7 +289,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele return false; }); - if (mAccessToken == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { searchTextInputEditText.setImeOptions(searchTextInputEditText.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING); } @@ -518,21 +519,18 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele if (postType != HistoryPostPagingSource.TYPE_READ_POSTS) { mExecutor.execute(() -> { - RedditAPI api = (mAccessToken == null ? mRetrofit : mOauthRetrofit).create(RedditAPI.class); + RedditAPI api = mOauthRetrofit.create(RedditAPI.class); Call call; String afterKey = posts.isEmpty() ? null : posts.get(posts.size() - 1).getFullName(); switch (postType) { case PostPagingSource.TYPE_SUBREDDIT: - if (mAccessToken == null) { - call = api.getSubredditBestPosts(subredditName, sortType, sortTime, afterKey); - } else { - call = api.getSubredditBestPostsOauth(subredditName, sortType, - sortTime, afterKey, APIUtils.getOAuthHeader(mAccessToken)); - } + call = api.getSubredditBestPostsOauth(subredditName, sortType, + sortTime, afterKey, APIUtils.getOAuthHeader(mAccessToken)); break; case PostPagingSource.TYPE_USER: - if (mAccessToken == null) { - call = api.getUserPosts(username, afterKey, sortType, sortTime); + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { + call = api.getUserPostsOauth(username, PostPagingSource.USER_WHERE_SUBMITTED, + afterKey, sortType, sortTime, APIUtils.getOAuthHeader(mAccessToken)); } else { call = api.getUserPostsOauth(username, userWhere, afterKey, sortType, sortTime, APIUtils.getOAuthHeader(mAccessToken)); @@ -540,35 +538,22 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele break; case PostPagingSource.TYPE_SEARCH: if (subredditName == null) { - if (mAccessToken == null) { - call = api.searchPosts(query, afterKey, sortType, sortTime, - trendingSource); - } else { - call = api.searchPostsOauth(query, afterKey, sortType, - sortTime, trendingSource, APIUtils.getOAuthHeader(mAccessToken)); - } + call = api.searchPostsOauth(query, afterKey, sortType, + sortTime, trendingSource, APIUtils.getOAuthHeader(mAccessToken)); } else { - if (mAccessToken == null) { - call = api.searchPostsInSpecificSubreddit(subredditName, query, - sortType, sortTime, afterKey); - } else { - call = api.searchPostsInSpecificSubredditOauth(subredditName, query, - sortType, sortTime, afterKey, - APIUtils.getOAuthHeader(mAccessToken)); - } + call = api.searchPostsInSpecificSubredditOauth(subredditName, query, + sortType, sortTime, afterKey, + APIUtils.getOAuthHeader(mAccessToken)); } break; case PostPagingSource.TYPE_MULTI_REDDIT: - if (mAccessToken == null) { - call = api.getMultiRedditPosts(multiPath, afterKey, sortTime); - } else { - call = api.getMultiRedditPostsOauth(multiPath, afterKey, - sortTime, APIUtils.getOAuthHeader(mAccessToken)); - } + call = api.getMultiRedditPostsOauth(multiPath, afterKey, + sortTime, APIUtils.getOAuthHeader(mAccessToken)); break; case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE: //case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT - call = api.getSubredditBestPosts(subredditName, sortType, sortTime, afterKey); + call = api.getSubredditBestPostsOauth(subredditName, sortType, sortTime, afterKey, + APIUtils.getOAuthHeader(mAccessToken)); break; default: call = api.getBestPosts(sortType, sortTime, afterKey, @@ -650,12 +635,8 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele ids.deleteCharAt(ids.length() - 1); } - Call historyPosts; - if (mAccessToken != null && !mAccessToken.isEmpty()) { - historyPosts = mOauthRetrofit.create(RedditAPI.class).getInfoOauth(ids.toString(), APIUtils.getOAuthHeader(mAccessToken)); - } else { - historyPosts = mRetrofit.create(RedditAPI.class).getInfo(ids.toString()); - } + Call historyPosts = mOauthRetrofit.create(RedditAPI.class).getInfoOauth(ids.toString(), + APIUtils.getOAuthHeader(mAccessToken)); try { Response response = historyPosts.execute(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index cd4502e4..939b2cd8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -344,7 +344,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp fragmentManager = getSupportFragmentManager(); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); if (savedInstanceState == null) { mMessageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME); @@ -765,9 +765,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp } if (showBottomAppBar) { - int optionCount = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, 4); - int option1 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME); - int option2 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS); + int optionCount = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, 4); + int option1 = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME); + int option2 = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS); if (optionCount == 2) { navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2)); @@ -794,8 +794,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp }); } } else { - int option3 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_3, mAccessToken == null ? SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_MULTIREDDITS : SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_INBOX); - int option4 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_4, mAccessToken == null ? SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_REFRESH : SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_PROFILE); + int option3 = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_3, mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_MULTIREDDITS : SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_INBOX); + int option4 = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_4, mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_REFRESH : SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_PROFILE); navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2), getBottomAppBarOptionDrawableResource(option3), @@ -844,7 +844,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp navigationWrapper.floatingActionButton.setLayoutParams(lp); } - fabOption = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS); + fabOption = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS); switch (fabOption) { case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_REFRESH: navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_refresh_24dp); @@ -868,7 +868,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_random_24dp); break; case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS: - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp); fabOption = SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS; } else { @@ -882,7 +882,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_keyboard_double_arrow_up_24); break; default: - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp); fabOption = SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS; } else { @@ -946,7 +946,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp navigationWrapper.floatingActionButton.setOnLongClickListener(view -> { FABMoreOptionsBottomSheetFragment fabMoreOptionsBottomSheetFragment = new FABMoreOptionsBottomSheetFragment(); Bundle bundle = new Bundle(); - bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccessToken == null); + bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccountName.equals(Account.ANONYMOUS_ACCOUNT)); fabMoreOptionsBottomSheetFragment.setArguments(bundle); fabMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag()); return true; @@ -954,7 +954,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp navigationWrapper.floatingActionButton.setVisibility(hideFab ? View.GONE : View.VISIBLE); subscribeSubredditChip.setOnClickListener(view -> { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { if (subscriptionReady) { subscriptionReady = false; if (getResources().getString(R.string.subscribe).contentEquals(subscribeSubredditChip.getText())) { @@ -1135,7 +1135,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); return true; } else if (itemId == R.id.action_select_user_flair_view_subreddit_detail_activity) { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { Toast.makeText(this, R.string.login_first, Toast.LENGTH_SHORT).show(); return true; } @@ -1144,7 +1144,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp startActivity(selectUserFlairIntent); return true; } else if (itemId == R.id.action_add_to_multireddit_view_subreddit_detail_activity) { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { Toast.makeText(this, R.string.login_first, Toast.LENGTH_SHORT).show(); return true; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index d0d7a1c0..3d11bfbe 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -261,7 +261,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele fragmentManager = getSupportFragmentManager(); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); lockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false); if (username.equalsIgnoreCase("me")) { @@ -441,7 +441,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele if (subscriptionReady) { subscriptionReady = false; if (resources.getString(R.string.follow).contentEquals(subscribeUserChip.getText())) { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { UserFollowing.anonymousFollowUser(mExecutor, new Handler(), mRetrofit, username, mRedditDataRoomDatabase, new UserFollowing.UserFollowingListener() { @Override @@ -477,7 +477,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele }); } } else { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { UserFollowing.anonymousUnfollowUser(mExecutor, new Handler(), username, mRedditDataRoomDatabase, new UserFollowing.UserFollowingListener() { @Override @@ -716,9 +716,9 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele navigationWrapper.floatingActionButton.setVisibility(hideFab ? View.GONE : View.VISIBLE); if (showBottomAppBar) { - int optionCount = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, 4); - int option1 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME); - int option2 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS); + int optionCount = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, 4); + int option1 = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME); + int option2 = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS); if (optionCount == 2) { navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2)); @@ -745,8 +745,8 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele }); } } else { - int option3 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_3, mAccessToken == null ? SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_MULTIREDDITS : SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_INBOX); - int option4 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_4, mAccessToken == null ? SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_REFRESH : SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_PROFILE); + int option3 = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_3, mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_MULTIREDDITS : SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_INBOX); + int option4 = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_4, mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_REFRESH : SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_PROFILE); navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2), getBottomAppBarOptionDrawableResource(option3), @@ -795,7 +795,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele navigationWrapper.floatingActionButton.setLayoutParams(lp); } - fabOption = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS); + fabOption = mBottomAppBarSharedPreference.getInt((mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS); switch (fabOption) { case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_REFRESH: navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_refresh_24dp); @@ -819,7 +819,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_random_24dp); break; case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS: - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp); fabOption = SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS; } else { @@ -833,7 +833,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_keyboard_double_arrow_up_24); break; default: - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { navigationWrapper.floatingActionButton.setImageResource(R.drawable.ic_filter_24dp); fabOption = SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS; } else { @@ -896,7 +896,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele navigationWrapper.floatingActionButton.setOnLongClickListener(view -> { FABMoreOptionsBottomSheetFragment fabMoreOptionsBottomSheetFragment = new FABMoreOptionsBottomSheetFragment(); Bundle bundle = new Bundle(); - bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccessToken == null); + bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccountName.equals(Account.ANONYMOUS_ACCOUNT)); fabMoreOptionsBottomSheetFragment.setArguments(bundle); fabMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag()); return true; @@ -1149,7 +1149,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele } return true; } else if (itemId == R.id.action_send_private_message_view_user_detail_activity) { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { Toast.makeText(this, R.string.login_first, Toast.LENGTH_SHORT).show(); return true; } @@ -1159,7 +1159,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele startActivity(pmIntent); return true; } else if (itemId == R.id.action_add_to_multireddit_view_user_detail_activity) { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { Toast.makeText(this, R.string.login_first, Toast.LENGTH_SHORT).show(); return true; } @@ -1176,7 +1176,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele startActivity(reportIntent); return true; } else if (itemId == R.id.action_block_user_view_user_detail_activity) { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { Toast.makeText(this, R.string.login_first, Toast.LENGTH_SHORT).show(); return true; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java index 2b047074..d29d92a8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java @@ -93,6 +93,7 @@ import ml.docilealligator.infinityforreddit.FetchStreamableVideo; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.StreamableVideo; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.apis.StreamableAPI; import ml.docilealligator.infinityforreddit.apis.VReddIt; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PlaybackSpeedBottomSheetFragment; @@ -792,6 +793,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe int commentsIndex = segments.lastIndexOf("comments"); String postId = segments.get(commentsIndex + 1); FetchPost.fetchPost(mExecutor, new Handler(), retrofit, postId, null, + mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT), new FetchPost.FetchPostListener() { @Override public void fetchPostSuccess(Post post) { 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 9fb2b239..3ded569d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -40,6 +40,7 @@ import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.VoteThing; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.ViewImageOrGifActivity; @@ -578,7 +579,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); return; } @@ -658,7 +659,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); return; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index ba0e45c0..2c502882 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -48,6 +48,7 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.VoteThing; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CommentActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; @@ -66,10 +67,10 @@ import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface; import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager; import ml.docilealligator.infinityforreddit.databinding.ItemCommentBinding; import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment; -import ml.docilealligator.infinityforreddit.markdown.EvenBetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.markdown.CustomMarkwonAdapter; import ml.docilealligator.infinityforreddit.markdown.EmoteCloseBracketInlineProcessor; import ml.docilealligator.infinityforreddit.markdown.EmotePlugin; +import ml.docilealligator.infinityforreddit.markdown.EvenBetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.markdown.ImageAndGifEntry; import ml.docilealligator.infinityforreddit.markdown.ImageAndGifPlugin; import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils; @@ -96,7 +97,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter topLevelComments, @@ -1412,7 +1410,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); return; } @@ -1449,7 +1447,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter mStreamableApiProvider; private String mAccessToken; + private String mAccountName; private RequestManager mGlide; private int mMaxResolution; private SaveMemoryCenterInisdeDownsampleStrategy mSaveMemoryCenterInsideDownsampleStrategy; @@ -259,10 +260,11 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); return; } @@ -5462,7 +5464,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter mMultiReddits; private List mFavoriteMultiReddits; private int mPrimaryTextColor; @@ -60,13 +62,15 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< public MultiRedditListingRecyclerViewAdapter(BaseActivity activity, Executor executor, Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, CustomThemeWrapper customThemeWrapper, - String accessToken, OnItemClickListener onItemClickListener) { + String accessToken, String accountName, + OnItemClickListener onItemClickListener) { mActivity = activity; mExecutor = executor; mGlide = Glide.with(activity); mOauthRetrofit = oauthRetrofit; mRedditDataRoomDatabase = redditDataRoomDatabase; mAccessToken = accessToken; + mAccountName = accountName; mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor(); mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor(); mOnItemClickListener = onItemClickListener; @@ -130,7 +134,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< if(multiReddit.isFavorite()) { ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); multiReddit.setFavorite(false); - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit, () -> { //Do nothing @@ -163,7 +167,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< } else { ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); multiReddit.setFavorite(true); - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit, () -> { //Do nothing @@ -230,7 +234,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< if(multiReddit.isFavorite()) { ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); multiReddit.setFavorite(false); - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit, () -> { //Do nothing @@ -263,7 +267,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< } else { ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); multiReddit.setFavorite(true); - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit, () -> { //Do nothing diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index 2afce6a5..6881c46e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -69,6 +69,7 @@ import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStra import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.StreamableVideo; import ml.docilealligator.infinityforreddit.VoteThing; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CommentActivity; import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity; @@ -101,10 +102,10 @@ import ml.docilealligator.infinityforreddit.databinding.ItemPostDetailVideoAndGi import ml.docilealligator.infinityforreddit.databinding.ItemPostDetailVideoAutoplayBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostDetailVideoAutoplayLegacyControllerBinding; import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment; -import ml.docilealligator.infinityforreddit.markdown.EvenBetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.markdown.CustomMarkwonAdapter; import ml.docilealligator.infinityforreddit.markdown.EmoteCloseBracketInlineProcessor; import ml.docilealligator.infinityforreddit.markdown.EmotePlugin; +import ml.docilealligator.infinityforreddit.markdown.EvenBetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.markdown.ImageAndGifEntry; import ml.docilealligator.infinityforreddit.markdown.ImageAndGifPlugin; import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils; @@ -1245,7 +1246,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); return; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index b069c8df..31720785 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -50,7 +50,6 @@ import com.google.android.exoplayer2.ui.DefaultTimeBar; import com.google.android.exoplayer2.ui.PlayerView; import com.google.android.exoplayer2.ui.TimeBar; import com.google.android.material.button.MaterialButton; -import com.google.android.material.button.MaterialButtonToggleGroup; import com.google.common.collect.ImmutableList; import com.libRG.CustomTextView; @@ -74,6 +73,7 @@ import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStra import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.StreamableVideo; import ml.docilealligator.infinityforreddit.VoteThing; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; @@ -170,6 +170,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter mStreamableApiProvider; private String mAccessToken; + private String mAccountName; private RequestManager mGlide; private int mMaxResolution; private SaveMemoryCenterInisdeDownsampleStrategy mSaveMemoryCenterInsideDownsampleStrategy; @@ -273,11 +274,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter itemView.performClick()); saveButton.setOnClickListener(view -> { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); return; } @@ -5696,7 +5698,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter getPostOauth(@Path("id") String id, @HeaderMap Map headers); - @GET("comments/{id}.json?raw_json=1") - Call getPost(@Path("id") String id); - @GET("user/{username}/about.json?raw_json=1") Call getUserData(@Path("username") String username); @GET("user/{username}/about.json?raw_json=1&limit=100") Call getUserDataOauth(@HeaderMap Map headers, @Path("username") String username); - @GET("user/{username}/comments.json?raw_json=1&limit=100") - Call getUserComments(@Path("username") String username, @Query("after") String after, - @Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime); - @GET("user/{username}/comments.json?raw_json=1&limit=100") Call getUserCommentsOauth(@HeaderMap Map headers, @Path("username") String username, @Query("after") String after, @Query("sort") SortType.Type sortType, @@ -75,9 +68,6 @@ public interface RedditAPI { @POST("api/subscribe") Call subredditSubscription(@HeaderMap Map headers, @FieldMap Map params); - @GET("/api/info.json?raw_json=1") - Call getInfo(@Query("id") String id); - @GET("/api/info.json?raw_json=1") Call getInfoOauth(@Query("id") String id, @HeaderMap Map headers); @@ -109,9 +99,6 @@ public interface RedditAPI { @GET("r/{subredditName}/api/link_flair.json?raw_json=1") Call getFlairs(@HeaderMap Map headers, @Path("subredditName") String subredditName); - @GET("/r/{subredditName}/about/rules.json?raw_json=1") - Call getRules(@Path("subredditName") String subredditName); - @GET("/r/{subredditName}/about/rules.json?raw_json=1") Call getRulesOauth(@HeaderMap Map headers, @Path("subredditName") String subredditName); @@ -124,13 +111,6 @@ public interface RedditAPI { Call getPostAndCommentsByIdOauth(@Path("id") String id, @Query("sort") SortType.Type sortType, @HeaderMap Map headers); - @GET("/comments/{id}/placeholder/{singleCommentId}.json?raw_json=1") - Call getPostAndCommentsSingleThreadById(@Path("id") String id, @Path("singleCommentId") String singleCommentId, - @Query("sort") SortType.Type sortType, @Query("context") String contextNumber); - - @GET("/comments/{id}.json?raw_json=1") - Call getPostAndCommentsById(@Path("id") String id, @Query("sort") SortType.Type sortType); - @Multipart @POST(".") Call uploadMediaToAWS(@PartMap() Map params, @Part() MultipartBody.Part file); @@ -260,9 +240,6 @@ public interface RedditAPI { @POST("/api/submit_poll_post.json?resubmit=true&raw_json=1&gilding_detail=1") Call submitPollPost(@HeaderMap Map headers, @Body String body); - @GET("/api/trending_searches_v1.json?withAds=0&raw_json=1&gilding_detail=1") - Call getTrendingSearches(); - @GET("/api/trending_searches_v1.json?withAds=0&raw_json=1&gilding_detail=1") Call getTrendingSearchesOauth(@HeaderMap Map headers); @@ -282,45 +259,23 @@ public interface RedditAPI { @Query("t") SortType.Time sortTime, @Query("after") String lastItem, @HeaderMap Map headers); - @GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=100&always_show_media=1") - ListenableFuture> getSubredditBestPostsListenableFuture(@Path("subredditName") String subredditName, @Path("sortType") SortType.Type sortType, - @Query("t") SortType.Time sortTime, @Query("after") String lastItem); - @GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=100") ListenableFuture> getUserPostsOauthListenableFuture(@Path("username") String username, @Path("where") String where, @Query("after") String lastItem, @Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime, @HeaderMap Map headers); - @GET("user/{username}/submitted.json?raw_json=1&limit=100") - ListenableFuture> getUserPostsListenableFuture(@Path("username") String username, @Query("after") String lastItem, - @Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime); - @GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link") ListenableFuture> searchPostsOauthListenableFuture(@Query("q") String query, @Query("after") String after, @Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime, @Query("source") String source, @HeaderMap Map headers); - @GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link") - ListenableFuture> searchPostsListenableFuture(@Query("q") String query, @Query("after") String after, - @Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime, - @Query("source") String source); - @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true") ListenableFuture> searchPostsInSpecificSubredditOauthListenableFuture(@Path("subredditName") String subredditName, @Query("q") String query, @Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime, @Query("after") String after, @HeaderMap Map headers); - @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true") - ListenableFuture> searchPostsInSpecificSubredditListenableFuture(@Path("subredditName") String subredditName, - @Query("q") String query, @Query("sort") SortType.Type sort, - @Query("t") SortType.Time sortTime, @Query("after") String after); - - @GET("{multipath}?raw_json=1&limit=100") - ListenableFuture> getMultiRedditPostsListenableFuture(@Path(value = "multipath", encoded = true) String multiPath, - @Query("after") String after, @Query("t") SortType.Time sortTime); - @GET("{multipath}.json?raw_json=1&limit=100") ListenableFuture> getMultiRedditPostsOauthListenableFuture(@Path(value = "multipath", encoded = true) String multiPath, @Query("after") String after, @Query("t") SortType.Time sortTime, @@ -335,45 +290,23 @@ public interface RedditAPI { @Query("t") SortType.Time sortTime, @Query("after") String lastItem, @HeaderMap Map headers); - @GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=100&always_show_media=1") - Call getSubredditBestPosts(@Path("subredditName") String subredditName, @Path("sortType") SortType.Type sortType, - @Query("t") SortType.Time sortTime, @Query("after") String lastItem); - @GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=100") Call getUserPostsOauth(@Path("username") String username, @Path("where") String where, @Query("after") String lastItem, @Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime, @HeaderMap Map headers); - @GET("user/{username}/submitted.json?raw_json=1&limit=100") - Call getUserPosts(@Path("username") String username, @Query("after") String lastItem, - @Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime); - @GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link") Call searchPostsOauth(@Query("q") String query, @Query("after") String after, @Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime, @Query("source") String source, @HeaderMap Map headers); - @GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link") - Call searchPosts(@Query("q") String query, @Query("after") String after, - @Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime, - @Query("source") String source); - @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true") Call searchPostsInSpecificSubredditOauth(@Path("subredditName") String subredditName, @Query("q") String query, @Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime, @Query("after") String after, @HeaderMap Map headers); - @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true") - Call searchPostsInSpecificSubreddit(@Path("subredditName") String subredditName, - @Query("q") String query, @Query("sort") SortType.Type sort, - @Query("t") SortType.Time sortTime, @Query("after") String after); - - @GET("{multipath}?raw_json=1&limit=100") - Call getMultiRedditPosts(@Path(value = "multipath", encoded = true) String multiPath, - @Query("after") String after, @Query("t") SortType.Time sortTime); - @GET("{multipath}.json?raw_json=1&limit=100") Call getMultiRedditPostsOauth(@Path(value = "multipath", encoded = true) String multiPath, @Query("after") String after, @Query("t") SortType.Time sortTime, @@ -399,10 +332,6 @@ public interface RedditAPI { @POST("/api/site_admin") Call postSiteAdmin(@HeaderMap Map headers, @FieldMap Map params); - @FormUrlEncoded - @POST("/api/morechildren.json?raw_json=1&api_type=json") - Call moreChildren(@Field("link_id") String linkId, @Field("children") String children, @Field("sort") SortType.Type sort); - @FormUrlEncoded @POST("/api/morechildren.json?raw_json=1&api_type=json") Call moreChildrenOauth(@Field("link_id") String linkId, @Field("children") String children, @Field("sort") SortType.Type sort, @HeaderMap Map headers); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubscribedThings.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubscribedThings.java index 02ad624d..a3b90ebd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubscribedThings.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubscribedThings.java @@ -84,7 +84,7 @@ public class InsertSubscribedThings { InsertSubscribedThingListener insertSubscribedThingListener) { executor.execute(() -> { String accountName = singleSubscribedSubredditData.getUsername(); - if (accountName != null && redditDataRoomDatabase.accountDao().getAccountData(accountName) == null) { + if (redditDataRoomDatabase.accountDao().getAccountData(accountName) == null) { handler.post(insertSubscribedThingListener::insertSuccess); return; } @@ -95,16 +95,16 @@ public class InsertSubscribedThings { } public static void insertSubscribedThings(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase, - SubscribedUserData mSingleSubscribedUserData, + SubscribedUserData singleSubscribedUserData, InsertSubscribedThingListener insertSubscribedThingListener) { executor.execute(() -> { - String accountName = mSingleSubscribedUserData.getUsername(); - if (accountName != null && redditDataRoomDatabase.accountDao().getAccountData(accountName) == null) { + String accountName = singleSubscribedUserData.getUsername(); + if (redditDataRoomDatabase.accountDao().getAccountData(accountName) == null) { handler.post(insertSubscribedThingListener::insertSuccess); return; } - redditDataRoomDatabase.subscribedUserDao().insert(mSingleSubscribedUserData); + redditDataRoomDatabase.subscribedUserDao().insert(singleSubscribedUserData); handler.post(insertSubscribedThingListener::insertSuccess); }); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSource.java index 09758d33..3c648a75 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSource.java @@ -31,6 +31,8 @@ public class CommentDataSource extends PageKeyedDataSource { private Locale locale; @Nullable private String accessToken; + @Nullable + private String accountName; private String username; private SortType sortType; private boolean areSavedComments; @@ -42,11 +44,13 @@ public class CommentDataSource extends PageKeyedDataSource { private LoadParams params; private LoadCallback callback; - CommentDataSource(Retrofit retrofit, Locale locale, @Nullable String accessToken, String username, SortType sortType, + CommentDataSource(Retrofit retrofit, Locale locale, @Nullable String accessToken, @Nullable String accountName, + String username, SortType sortType, boolean areSavedComments) { this.retrofit = retrofit; this.locale = locale; this.accessToken = accessToken; + this.accountName = accountName; this.username = username; this.sortType = sortType; this.areSavedComments = areSavedComments; @@ -82,13 +86,8 @@ public class CommentDataSource extends PageKeyedDataSource { null, sortType.getType(), sortType.getTime(), APIUtils.getOAuthHeader(accessToken)); } else { - if (accessToken == null) { - commentsCall = api.getUserComments(username, null, sortType.getType(), - sortType.getTime()); - } else { - commentsCall = api.getUserCommentsOauth(APIUtils.getOAuthHeader(accessToken), username, - null, sortType.getType(), sortType.getTime()); - } + commentsCall = api.getUserCommentsOauth(APIUtils.getOAuthHeader(accessToken), username, + null, sortType.getType(), sortType.getTime()); } commentsCall.enqueue(new Callback() { @Override @@ -146,13 +145,8 @@ public class CommentDataSource extends PageKeyedDataSource { commentsCall = api.getUserSavedCommentsOauth(username, PostPagingSource.USER_WHERE_SAVED, params.key, sortType.getType(), sortType.getTime(), APIUtils.getOAuthHeader(accessToken)); } else { - if (accessToken == null) { - commentsCall = api.getUserComments(username, params.key, sortType.getType(), - sortType.getTime()); - } else { - commentsCall = api.getUserCommentsOauth(APIUtils.getOAuthHeader(accessToken), - username, params.key, sortType.getType(), sortType.getTime()); - } + commentsCall = api.getUserCommentsOauth(APIUtils.getOAuthHeader(accessToken), + username, params.key, sortType.getType(), sortType.getTime()); } commentsCall.enqueue(new Callback() { @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSourceFactory.java index 6f89215c..b55772b7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSourceFactory.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSourceFactory.java @@ -14,6 +14,7 @@ class CommentDataSourceFactory extends DataSource.Factory { private Retrofit retrofit; private Locale locale; private String accessToken; + private String accountName; private String username; private SortType sortType; private boolean areSavedComments; @@ -21,12 +22,13 @@ class CommentDataSourceFactory extends DataSource.Factory { private CommentDataSource commentDataSource; private MutableLiveData commentDataSourceLiveData; - CommentDataSourceFactory(Retrofit retrofit, Locale locale, @Nullable String accessToken, + CommentDataSourceFactory(Retrofit retrofit, Locale locale, @Nullable String accessToken, String accountName, String username, SortType sortType, boolean areSavedComments) { this.retrofit = retrofit; this.locale = locale; this.accessToken = accessToken; + this.accountName = accountName; this.username = username; this.sortType = sortType; this.areSavedComments = areSavedComments; @@ -36,8 +38,8 @@ class CommentDataSourceFactory extends DataSource.Factory { @NonNull @Override public DataSource create() { - commentDataSource = new CommentDataSource(retrofit, locale, accessToken, username, sortType, - areSavedComments); + commentDataSource = new CommentDataSource(retrofit, locale, accessToken, accountName, username, + sortType, areSavedComments); commentDataSourceLiveData.postValue(commentDataSource); return commentDataSource; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentViewModel.java index e6ccd0ca..eeabfd49 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentViewModel.java @@ -23,10 +23,10 @@ public class CommentViewModel extends ViewModel { private LiveData> comments; private MutableLiveData sortTypeLiveData; - public CommentViewModel(Retrofit retrofit, Locale locale, String accessToken, String username, SortType sortType, - boolean areSavedComments) { - commentDataSourceFactory = new CommentDataSourceFactory(retrofit, locale, accessToken, username, sortType, - areSavedComments); + public CommentViewModel(Retrofit retrofit, Locale locale, String accessToken, String accountName, + String username, SortType sortType, boolean areSavedComments) { + commentDataSourceFactory = new CommentDataSourceFactory(retrofit, locale, accessToken, accountName, + username, sortType, areSavedComments); initialLoadingState = Transformations.switchMap(commentDataSourceFactory.getCommentDataSourceLiveData(), CommentDataSource::getInitialLoadStateLiveData); @@ -83,15 +83,17 @@ public class CommentViewModel extends ViewModel { private Retrofit retrofit; private Locale locale; private String accessToken; + private String accountName; private String username; private SortType sortType; private boolean areSavedComments; - public Factory(Retrofit retrofit, Locale locale, String accessToken, String username, + public Factory(Retrofit retrofit, Locale locale, String accessToken, String accountName, String username, SortType sortType, boolean areSavedComments) { this.retrofit = retrofit; this.locale = locale; this.accessToken = accessToken; + this.accountName = accountName; this.username = username; this.sortType = sortType; this.areSavedComments = areSavedComments; @@ -100,7 +102,8 @@ public class CommentViewModel extends ViewModel { @NonNull @Override public T create(@NonNull Class modelClass) { - return (T) new CommentViewModel(retrofit, locale, accessToken, username, sortType, areSavedComments); + return (T) new CommentViewModel(retrofit, locale, accessToken, accountName, username, + sortType, areSavedComments); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchComment.java index 0c2b3762..558f1b90 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchComment.java @@ -25,19 +25,11 @@ public class FetchComment { FetchCommentListener fetchCommentListener) { RedditAPI api = retrofit.create(RedditAPI.class); Call comments; - if (accessToken == null) { - if (commentId == null) { - comments = api.getPostAndCommentsById(article, sortType); - } else { - comments = api.getPostAndCommentsSingleThreadById(article, commentId, sortType, contextNumber); - } + if (commentId == null) { + comments = api.getPostAndCommentsByIdOauth(article, sortType, APIUtils.getOAuthHeader(accessToken)); } else { - if (commentId == null) { - comments = api.getPostAndCommentsByIdOauth(article, sortType, APIUtils.getOAuthHeader(accessToken)); - } else { - comments = api.getPostAndCommentsSingleThreadByIdOauth(article, commentId, sortType, contextNumber, - APIUtils.getOAuthHeader(accessToken)); - } + comments = api.getPostAndCommentsSingleThreadByIdOauth(article, commentId, sortType, contextNumber, + APIUtils.getOAuthHeader(accessToken)); } comments.enqueue(new Callback<>() { @@ -73,7 +65,7 @@ public class FetchComment { } public static void fetchMoreComment(Executor executor, Handler handler, Retrofit retrofit, - @Nullable String accessToken, + @Nullable String accessToken, String accountName, ArrayList allChildren, boolean expandChildren, String postFullName, SortType.Type sortType, @@ -89,13 +81,8 @@ public class FetchComment { } RedditAPI api = retrofit.create(RedditAPI.class); - Call moreComments; - if (accessToken == null) { - moreComments = api.moreChildren(postFullName, childrenIds, sortType); - } else { - moreComments = api.moreChildrenOauth(postFullName, childrenIds, - sortType, APIUtils.getOAuthHeader(accessToken)); - } + Call moreComments = api.moreChildrenOauth(postFullName, childrenIds, + sortType, APIUtils.getOAuthHeader(accessToken)); moreComments.enqueue(new Callback<>() { @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java index 2c5090c7..e0bfd244 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java @@ -47,6 +47,7 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.adapters.CommentsListingRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.comment.CommentViewModel; @@ -84,9 +85,6 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni TextView mFetchCommentInfoTextView; CommentViewModel mCommentViewModel; @Inject - @Named("no_oauth") - Retrofit mRetrofit; - @Inject @Named("oauth") Retrofit mOauthRetrofit; @Inject @@ -108,6 +106,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni @Inject Executor mExecutor; private String mAccessToken; + private String mAccountName; private RequestManager mGlide; private BaseActivity mActivity; private LinearLayoutManagerBugFixed mLinearLayoutManager; @@ -259,6 +258,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni } mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); new Handler().postDelayed(() -> bindView(resources), 0); @@ -301,15 +301,9 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni CommentViewModel.Factory factory; - if (mAccessToken == null) { - factory = new CommentViewModel.Factory(mRetrofit, - resources.getConfiguration().locale, null, username, sortType, - getArguments().getBoolean(EXTRA_ARE_SAVED_COMMENTS)); - } else { - factory = new CommentViewModel.Factory(mOauthRetrofit, - resources.getConfiguration().locale, mAccessToken, username, sortType, - getArguments().getBoolean(EXTRA_ARE_SAVED_COMMENTS)); - } + factory = new CommentViewModel.Factory(mOauthRetrofit, + resources.getConfiguration().locale, mAccessToken, mAccountName, username, sortType, + getArguments().getBoolean(EXTRA_ARE_SAVED_COMMENTS)); mCommentViewModel = new ViewModelProvider(this, factory).get(CommentViewModel.class); mCommentViewModel.getComments().observe(getViewLifecycleOwner(), comments -> mAdapter.submitList(comments)); 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 7ed43e60..78929e32 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java @@ -34,6 +34,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.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity; import ml.docilealligator.infinityforreddit.adapters.FollowedUsersRecyclerViewAdapter; @@ -109,18 +110,19 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo mGlide = Glide.with(this); String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); - if (accessToken == null) { + String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); + if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { mSwipeRefreshLayout.setEnabled(false); } mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity); mRecyclerView.setLayoutManager(mLinearLayoutManager); FollowedUsersRecyclerViewAdapter adapter = new FollowedUsersRecyclerViewAdapter(mActivity, - mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, accessToken); + mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, accessToken, accountName); mRecyclerView.setAdapter(adapter); new FastScrollerBuilder(mRecyclerView).useMd2Style().build(); mSubscribedUserViewModel = new ViewModelProvider(this, - new SubscribedUserViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, getArguments().getString(EXTRA_ACCOUNT_NAME))) + new SubscribedUserViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, accountName)) .get(SubscribedUserViewModel.class); mSubscribedUserViewModel.getAllSubscribedUsers().observe(getViewLifecycleOwner(), subscribedUserData -> { 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 67c158b6..10244d4a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java @@ -655,11 +655,11 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato private void initializeAndBindPostViewModel(String accessToken) { if (postType == HistoryPostPagingSource.TYPE_READ_POSTS) { mHistoryPostViewModel = new ViewModelProvider(HistoryPostFragment.this, new HistoryPostViewModel.Factory(mExecutor, - accessToken == null ? mRetrofit : mOauthRetrofit, mRedditDataRoomDatabase, accessToken, + mOauthRetrofit, mRedditDataRoomDatabase, accessToken, accountName, mSharedPreferences, HistoryPostPagingSource.TYPE_READ_POSTS, postFilter)).get(HistoryPostViewModel.class); } else { mHistoryPostViewModel = new ViewModelProvider(HistoryPostFragment.this, new HistoryPostViewModel.Factory(mExecutor, - accessToken == null ? mRetrofit : mOauthRetrofit, mRedditDataRoomDatabase, accessToken, + mOauthRetrofit, mRedditDataRoomDatabase, accessToken, accountName, mSharedPreferences, HistoryPostPagingSource.TYPE_READ_POSTS, postFilter)).get(HistoryPostViewModel.class); } 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 f2301187..88457354 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java @@ -112,7 +112,7 @@ 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) { + if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { mSwipeRefreshLayout.setEnabled(false); } @@ -122,7 +122,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm mRecyclerView.setLayoutManager(mLinearLayoutManager); MultiRedditListingRecyclerViewAdapter adapter = new MultiRedditListingRecyclerViewAdapter(mActivity, mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, accessToken, - new MultiRedditListingRecyclerViewAdapter.OnItemClickListener() { + accountName, new MultiRedditListingRecyclerViewAdapter.OnItemClickListener() { @Override public void onClick(MultiReddit multiReddit) { if (mActivity instanceof MultiredditSelectionActivity) { 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 7f63b9e0..eb192207 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -1207,26 +1207,22 @@ public class PostFragment extends Fragment implements FragmentCommunicator { private void initializeAndBindPostViewModel(String accessToken) { if (postType == PostPagingSource.TYPE_SEARCH) { mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor, - accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, - accountName, mSharedPreferences, + mOauthRetrofit, accessToken, accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences, mPostHistorySharedPreferences, subredditName, query, trendingSource, postType, sortType, postFilter, readPosts)).get(PostViewModel.class); } else if (postType == PostPagingSource.TYPE_SUBREDDIT) { mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor, - accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, - accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences, + mOauthRetrofit, accessToken, accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences, mPostHistorySharedPreferences, subredditName, postType, sortType, postFilter, readPosts)) .get(PostViewModel.class); } else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) { mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor, - accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, - accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences, + mOauthRetrofit, accessToken, accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences, mPostHistorySharedPreferences, multiRedditPath, postType, sortType, postFilter, readPosts)) .get(PostViewModel.class); } else if (postType == PostPagingSource.TYPE_USER) { mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor, - accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, - accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences, + mOauthRetrofit, accessToken, accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences, mPostHistorySharedPreferences, username, postType, sortType, postFilter, where, readPosts)) .get(PostViewModel.class); } else { @@ -1340,7 +1336,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } else if (item.getItemId() == R.id.action_more_options_post_fragment) { FABMoreOptionsBottomSheetFragment fabMoreOptionsBottomSheetFragment= new FABMoreOptionsBottomSheetFragment(); Bundle bundle = new Bundle(); - bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, accessToken == null); + bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, accountName.equals(Account.ANONYMOUS_ACCOUNT)); fabMoreOptionsBottomSheetFragment.setArguments(bundle); fabMoreOptionsBottomSheetFragment.show(activity.getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag()); return true; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java index 6babfcb8..8545dcbe 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java @@ -179,7 +179,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun } SubredditListingViewModel.Factory factory = new SubredditListingViewModel.Factory( - accessToken == null ? mRetrofit : mOauthRetrofit, query, sortType, accessToken, nsfw); + mOauthRetrofit, query, sortType, accessToken, nsfw); mSubredditListingViewModel = new ViewModelProvider(this, factory).get(SubredditListingViewModel.class); mSubredditListingViewModel.getSubreddits().observe(getViewLifecycleOwner(), subredditData -> mAdapter.submitList(subredditData)); 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 b35b2ffb..d0177aaf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java @@ -113,7 +113,7 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); - if (accessToken == null) { + if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { mSwipeRefreshLayout.setEnabled(false); } @@ -125,11 +125,11 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra SubscribedSubredditsRecyclerViewAdapter adapter; if (getArguments().getBoolean(EXTRA_IS_SUBREDDIT_SELECTION)) { adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity, mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, - mCustomThemeWrapper, accessToken, getArguments().getBoolean(EXTRA_EXTRA_CLEAR_SELECTION), + mCustomThemeWrapper, accessToken, accountName, getArguments().getBoolean(EXTRA_EXTRA_CLEAR_SELECTION), (name, iconUrl, subredditIsUser) -> ((SubredditSelectionActivity) mActivity).getSelectedSubreddit(name, iconUrl, subredditIsUser)); } else { adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity, mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, - mCustomThemeWrapper, accessToken); + mCustomThemeWrapper, accessToken, accountName); } mRecyclerView.setAdapter(adapter); 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 e9618502..1d30084b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -75,6 +75,7 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.CommentActivity; import ml.docilealligator.infinityforreddit.activities.EditPostActivity; import ml.docilealligator.infinityforreddit.activities.PostFilterPreferenceActivity; @@ -279,7 +280,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic mRecyclerView.addOnWindowFocusChangedListener(this::onWindowFocusChanged); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); mSavedIcon = getMenuItemIcon(R.drawable.ic_bookmark_toolbar_24dp); mUnsavedIcon = getMenuItemIcon(R.drawable.ic_bookmark_border_toolbar_24dp); @@ -605,7 +606,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic mSharedPreferences, mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostDetailsSharedPreferences, mExoCreator, post -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition))); mCommentsAdapter = new CommentsRecyclerViewAdapter(activity, - this, mCustomThemeWrapper, mExecutor, mRetrofit, mOauthRetrofit, + this, mCustomThemeWrapper, mExecutor, mOauthRetrofit, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, isSingleCommentThreadMode, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, new CommentsRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { @@ -958,7 +959,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic return true; } - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { showMessage(R.string.login_first); return true; } @@ -1134,7 +1135,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic flairBottomSheetFragment.show(activity.getSupportFragmentManager(), flairBottomSheetFragment.getTag()); return true; } else if (itemId == R.id.action_report_view_post_detail_fragment) { - if (mAccessToken == null) { + if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { Toast.makeText(activity, R.string.login_first, Toast.LENGTH_SHORT).show(); return true; } @@ -1269,22 +1270,12 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic mGlide.clear(mFetchPostInfoImageView); Call postAndComments; - if (mAccessToken == null) { - if (isSingleCommentThreadMode && mSingleCommentId != null) { - postAndComments = mRetrofit.create(RedditAPI.class).getPostAndCommentsSingleThreadById( - subredditId, mSingleCommentId, sortType, mContextNumber); - } else { - postAndComments = mRetrofit.create(RedditAPI.class).getPostAndCommentsById(subredditId, - sortType); - } + if (isSingleCommentThreadMode && mSingleCommentId != null) { + postAndComments = mOauthRetrofit.create(RedditAPI.class).getPostAndCommentsSingleThreadByIdOauth(subredditId, + mSingleCommentId, sortType, mContextNumber, APIUtils.getOAuthHeader(mAccessToken)); } else { - if (isSingleCommentThreadMode && mSingleCommentId != null) { - postAndComments = mOauthRetrofit.create(RedditAPI.class).getPostAndCommentsSingleThreadByIdOauth(subredditId, - mSingleCommentId, sortType, mContextNumber, APIUtils.getOAuthHeader(mAccessToken)); - } else { - postAndComments = mOauthRetrofit.create(RedditAPI.class).getPostAndCommentsByIdOauth(subredditId, - sortType, APIUtils.getOAuthHeader(mAccessToken)); - } + postAndComments = mOauthRetrofit.create(RedditAPI.class).getPostAndCommentsByIdOauth(subredditId, + sortType, APIUtils.getOAuthHeader(mAccessToken)); } postAndComments.enqueue(new Callback<>() { @Override @@ -1314,7 +1305,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic mCommentsAdapter = new CommentsRecyclerViewAdapter(activity, ViewPostDetailFragment.this, mCustomThemeWrapper, mExecutor, - mRetrofit, mOauthRetrofit, mAccessToken, mAccountName, mPost, mLocale, + mOauthRetrofit, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, isSingleCommentThreadMode, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, new CommentsRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { @@ -1496,8 +1487,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic commentId = mSingleCommentId; } - Retrofit retrofit = mAccessToken == null ? mRetrofit : mOauthRetrofit; - FetchComment.fetchComments(mExecutor, new Handler(), retrofit, mAccessToken, mPost.getId(), commentId, sortType, + FetchComment.fetchComments(mExecutor, new Handler(), mOauthRetrofit, mAccessToken, mPost.getId(), commentId, sortType, mContextNumber, mExpandChildren, mCommentFilter, new FetchComment.FetchCommentListener() { @Override public void onFetchCommentSuccess(ArrayList expandedComments, @@ -1583,9 +1573,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic isLoadingMoreChildren = true; - Retrofit retrofit = mAccessToken == null ? mRetrofit : mOauthRetrofit; - FetchComment.fetchMoreComment(mExecutor, new Handler(), retrofit, mAccessToken, children, - mExpandChildren, mPost.getFullName(), sortType, new FetchComment.FetchMoreCommentListener() { + FetchComment.fetchMoreComment(mExecutor, new Handler(), mOauthRetrofit, mAccessToken, mAccountName, + children, mExpandChildren, mPost.getFullName(), sortType, new FetchComment.FetchMoreCommentListener() { @Override public void onFetchMoreCommentSuccess(ArrayList topLevelComments, ArrayList expandedComments, @@ -1618,14 +1607,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic } if (fetchPost) { - Retrofit retrofit; - if (mAccessToken == null) { - retrofit = mRetrofit; - } else { - retrofit = mOauthRetrofit; - } - FetchPost.fetchPost(mExecutor, new Handler(), retrofit, mPost.getId(), mAccessToken, - new FetchPost.FetchPostListener() { + FetchPost.fetchPost(mExecutor, new Handler(), mOauthRetrofit, mPost.getId(), mAccessToken, + mAccountName, new FetchPost.FetchPostListener() { @Override public void fetchPostSuccess(Post post) { if (isAdded()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchPost.java index a3f72153..0b34612c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchPost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchPost.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.post; import android.os.Handler; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import java.util.concurrent.Executor; @@ -14,14 +15,10 @@ import retrofit2.Response; import retrofit2.Retrofit; public class FetchPost { - public static void fetchPost(Executor executor, Handler handler, Retrofit retrofit, String id, String accessToken, + public static void fetchPost(Executor executor, Handler handler, Retrofit retrofit, String id, + @Nullable String accessToken, String accountName, FetchPostListener fetchPostListener) { - Call postCall; - if (accessToken == null) { - postCall = retrofit.create(RedditAPI.class).getPost(id); - } else { - postCall = retrofit.create(RedditAPI.class).getPostOauth(id, APIUtils.getOAuthHeader(accessToken)); - } + Call postCall = retrofit.create(RedditAPI.class).getPostOauth(id, APIUtils.getOAuthHeader(accessToken)); postCall.enqueue(new Callback<>() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/HistoryPostPagingSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/HistoryPostPagingSource.java index ada5ce11..5ca25ada 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/HistoryPostPagingSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/HistoryPostPagingSource.java @@ -81,12 +81,7 @@ public class HistoryPostPagingSource extends ListenableFuturePagingSource historyPosts; - if (accessToken != null && !accessToken.isEmpty()) { - historyPosts = retrofit.create(RedditAPI.class).getInfoOauth(ids.toString(), APIUtils.getOAuthHeader(accessToken)); - } else { - historyPosts = retrofit.create(RedditAPI.class).getInfo(ids.toString()); - } + Call historyPosts = retrofit.create(RedditAPI.class).getInfoOauth(ids.toString(), APIUtils.getOAuthHeader(accessToken)); try { Response response = historyPosts.execute(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java index 3b40d262..99c12ff7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.postfilter.PostFilter; import ml.docilealligator.infinityforreddit.utils.APIUtils; @@ -233,13 +234,8 @@ public class PostPagingSource extends ListenableFuturePagingSource } private ListenableFuture> loadSubredditPosts(@NonNull LoadParams loadParams, RedditAPI api) { - ListenableFuture> subredditPost; - if (accessToken == null) { - subredditPost = api.getSubredditBestPostsListenableFuture(subredditOrUserName, sortType.getType(), sortType.getTime(), loadParams.getKey()); - } else { - subredditPost = api.getSubredditBestPostsOauthListenableFuture(subredditOrUserName, sortType.getType(), - sortType.getTime(), loadParams.getKey(), APIUtils.getOAuthHeader(accessToken)); - } + ListenableFuture> subredditPost = api.getSubredditBestPostsOauthListenableFuture(subredditOrUserName, sortType.getType(), + sortType.getTime(), loadParams.getKey(), APIUtils.getOAuthHeader(accessToken)); ListenableFuture> pageFuture = Futures.transform(subredditPost, this::transformData, executor); @@ -253,12 +249,12 @@ public class PostPagingSource extends ListenableFuturePagingSource private ListenableFuture> loadUserPosts(@NonNull LoadParams loadParams, RedditAPI api) { ListenableFuture> userPosts; - if (accessToken == null) { - userPosts = api.getUserPostsListenableFuture(subredditOrUserName, loadParams.getKey(), sortType.getType(), - sortType.getTime()); + if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { + userPosts = api.getUserPostsOauthListenableFuture(subredditOrUserName, USER_WHERE_SUBMITTED, + loadParams.getKey(), sortType.getType(), sortType.getTime(), APIUtils.getOAuthHeader(accessToken)); } else { - userPosts = api.getUserPostsOauthListenableFuture(subredditOrUserName, userWhere, loadParams.getKey(), sortType.getType(), - sortType.getTime(), APIUtils.getOAuthHeader(accessToken)); + userPosts = api.getUserPostsOauthListenableFuture(subredditOrUserName, userWhere, loadParams.getKey(), + sortType.getType(), sortType.getTime(), APIUtils.getOAuthHeader(accessToken)); } ListenableFuture> pageFuture = Futures.transform(userPosts, this::transformData, executor); @@ -274,22 +270,12 @@ public class PostPagingSource extends ListenableFuturePagingSource private ListenableFuture> loadSearchPosts(@NonNull LoadParams loadParams, RedditAPI api) { ListenableFuture> searchPosts; if (subredditOrUserName == null) { - if (accessToken == null) { - searchPosts = api.searchPostsListenableFuture(query, loadParams.getKey(), sortType.getType(), sortType.getTime(), - trendingSource); - } else { - searchPosts = api.searchPostsOauthListenableFuture(query, loadParams.getKey(), sortType.getType(), - sortType.getTime(), trendingSource, APIUtils.getOAuthHeader(accessToken)); - } + searchPosts = api.searchPostsOauthListenableFuture(query, loadParams.getKey(), sortType.getType(), + sortType.getTime(), trendingSource, APIUtils.getOAuthHeader(accessToken)); } else { - if (accessToken == null) { - searchPosts = api.searchPostsInSpecificSubredditListenableFuture(subredditOrUserName, query, - sortType.getType(), sortType.getTime(), loadParams.getKey()); - } else { - searchPosts = api.searchPostsInSpecificSubredditOauthListenableFuture(subredditOrUserName, query, - sortType.getType(), sortType.getTime(), loadParams.getKey(), - APIUtils.getOAuthHeader(accessToken)); - } + searchPosts = api.searchPostsInSpecificSubredditOauthListenableFuture(subredditOrUserName, query, + sortType.getType(), sortType.getTime(), loadParams.getKey(), + APIUtils.getOAuthHeader(accessToken)); } ListenableFuture> pageFuture = Futures.transform(searchPosts, this::transformData, executor); @@ -303,13 +289,8 @@ public class PostPagingSource extends ListenableFuturePagingSource } private ListenableFuture> loadMultiRedditPosts(@NonNull LoadParams loadParams, RedditAPI api) { - ListenableFuture> multiRedditPosts; - if (accessToken == null) { - multiRedditPosts = api.getMultiRedditPostsListenableFuture(multiRedditPath, loadParams.getKey(), sortType.getTime()); - } else { - multiRedditPosts = api.getMultiRedditPostsOauthListenableFuture(multiRedditPath, loadParams.getKey(), - sortType.getTime(), APIUtils.getOAuthHeader(accessToken)); - } + ListenableFuture> multiRedditPosts = api.getMultiRedditPostsOauthListenableFuture(multiRedditPath, loadParams.getKey(), + sortType.getTime(), APIUtils.getOAuthHeader(accessToken)); ListenableFuture> pageFuture = Futures.transform(multiRedditPosts, this::transformData, executor); @@ -323,7 +304,8 @@ public class PostPagingSource extends ListenableFuturePagingSource private ListenableFuture> loadAnonymousHomePosts(@NonNull LoadParams loadParams, RedditAPI api) { ListenableFuture> anonymousHomePosts; - anonymousHomePosts = api.getSubredditBestPostsListenableFuture(subredditOrUserName, sortType.getType(), sortType.getTime(), loadParams.getKey()); + anonymousHomePosts = api.getSubredditBestPostsOauthListenableFuture(subredditOrUserName, + sortType.getType(), sortType.getTime(), loadParams.getKey(), APIUtils.getOAuthHeader(accessToken)); ListenableFuture> pageFuture = Futures.transform(anonymousHomePosts, this::transformData, executor); diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 141786fd..5c31bc19 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -1244,7 +1244,7 @@ Toque para volver a intentarlo." "Banner cambiado correctamente" "Error al cambiar banner %s" "Perfil guardado correctamente" - "Error al guardar perfil" + Error al guardar perfil %s "Publicación de encuesta" "Abrir en el navegador" diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index ed162dec..6abc758b 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -1201,11 +1201,11 @@ Nhấn để thử lại." "Xoá ảnh đại diện thành công" "Xoá ảnh đại diện %s thất bại" "Xoá banner thành công" - "Gỡ bỏ banner thất bại" + Gỡ bỏ banner thất bại %s "Thay đổi ảnh đại diện thành công" - "Thay đổi ảnh đại diện thất bại" + Thay đổi ảnh đại diện thất bại %s "Thay đổi banner thành công" - "Thay đổi banner thất bại" + Thay đổi banner thất bại %s "Lưu Hồ sơ thành công" - "Lưu hồ sơ %s thất bại" + Lưu hồ sơ %s thất bại \ No newline at end of file -- cgit v1.2.3