aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchRules.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java24
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java48
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java22
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java59
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java26
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java30
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java26
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java34
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java71
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertSubscribedThings.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSource.java24
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSourceFactory.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentViewModel.java15
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchComment.java27
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java49
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchPost.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/HistoryPostPagingSource.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java52
-rw-r--r--app/src/main/res/values-es/strings.xml2
-rw-r--r--app/src/main/res/values-vi/strings.xml8
46 files changed, 323 insertions, 456 deletions
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<String> rulesCall = accessToken == null ? api.getRules(subredditName) : api.getRulesOauth(APIUtils.getOAuthHeader(accessToken), subredditName);
- rulesCall.enqueue(new Callback<String>() {
+ Call<String> rulesCall = api.getRulesOauth(APIUtils.getOAuthHeader(accessToken), subredditName);
+ rulesCall.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> 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<ReportReason> 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<Rule> 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<Rule> 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<Rule> 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<Rule> 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<TrendingSearch> 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<String> trendingCall;
- if (mAccessToken == null) {
- trendingCall = mRetrofit.create(RedditAPI.class).getTrendingSearches();
- } else {
- trendingCall = mOauthRetrofit.create(RedditAPI.class).getTrendingSearchesOauth(APIUtils.getOAuthHeader(mAccessToken));
- }
+ Call<String> trendingCall = mOauthRetrofit.create(RedditAPI.class)
+ .getTrendingSearchesOauth(APIUtils.getOAuthHeader(mAccessToken));
trendingCall.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> 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<String> 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<String> 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<String> historyPosts = mOauthRetrofit.create(RedditAPI.class).getInfoOauth(ids.toString(),
+ APIUtils.getOAuthHeader(mAccessToken));
try {
Response<String> 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<Comment
commentMarkdownView.setAdapter(markwonAdapter);
upvoteButton.setOnClickListener(view -> {
- 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<Comment
});
downvoteButton.setOnClickListener(view -> {
- 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<RecyclerVi
private BaseActivity mActivity;
private ViewPostDetailFragment mFragment;
private Executor mExecutor;
- private Retrofit mRetrofit;
private Retrofit mOauthRetrofit;
private EmoteCloseBracketInlineProcessor mEmoteCloseBracketInlineProcessor;
private EmotePlugin mEmotePlugin;
@@ -164,7 +164,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
public CommentsRecyclerViewAdapter(BaseActivity activity, ViewPostDetailFragment fragment,
CustomThemeWrapper customThemeWrapper,
- Executor executor, Retrofit retrofit, Retrofit oauthRetrofit,
+ Executor executor, Retrofit oauthRetrofit,
String accessToken, String accountName,
Post post, Locale locale, String singleCommentId,
boolean isSingleCommentThreadMode,
@@ -174,7 +174,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mActivity = activity;
mFragment = fragment;
mExecutor = executor;
- mRetrofit = retrofit;
mOauthRetrofit = oauthRetrofit;
mGlide = Glide.with(activity);
mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
@@ -667,10 +666,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mVisibleComments.get(commentPosition).setLoadMoreChildrenFailed(false);
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.loading);
- Retrofit retrofit = mAccessToken == null ? mRetrofit : mOauthRetrofit;
SortType.Type sortType = mCommentRecyclerViewAdapterCallback.getSortType();
- FetchComment.fetchMoreComment(mExecutor, new Handler(), retrofit, mAccessToken,
- parentComment.getMoreChildrenIds(),
+ FetchComment.fetchMoreComment(mExecutor, new Handler(), mOauthRetrofit, mAccessToken,
+ mAccountName, parentComment.getMoreChildrenIds(),
mExpandChildren, mPost.getFullName(), sortType, new FetchComment.FetchMoreCommentListener() {
@Override
public void onFetchMoreCommentSuccess(ArrayList<Comment> topLevelComments,
@@ -1412,7 +1410,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
});
replyButton.setOnClickListener(view -> {
- 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<RecyclerVi
return;
}
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -1540,7 +1538,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
return;
}
- 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/FollowedUsersRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java
index 33be9ea3..143a9596 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java
@@ -46,6 +46,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
private Retrofit mOauthRetrofit;
private RedditDataRoomDatabase mRedditDataRoomDatabase;
private String mAccessToken;
+ private String mAccountName;
private RequestManager glide;
private int mPrimaryTextColor;
private int mSecondaryTextColor;
@@ -53,12 +54,13 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
public FollowedUsersRecyclerViewAdapter(BaseActivity activity, Executor executor, Retrofit oauthRetrofit,
RedditDataRoomDatabase redditDataRoomDatabase,
CustomThemeWrapper customThemeWrapper,
- String accessToken) {
+ String accessToken, String accountName) {
mActivity = activity;
mExecutor = executor;
mOauthRetrofit = oauthRetrofit;
mRedditDataRoomDatabase = redditDataRoomDatabase;
mAccessToken = accessToken;
+ mAccountName = accountName;
glide = Glide.with(activity);
mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor();
mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
@@ -223,7 +225,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
mFavoriteSubscribedUserData.get(position).setFavorite(false);
FavoriteThing.unfavoriteUser(mExecutor, new Handler(), mOauthRetrofit,
- mRedditDataRoomDatabase, mAccessToken,
+ mRedditDataRoomDatabase, mAccessToken, mAccountName,
mFavoriteSubscribedUserData.get(position),
new FavoriteThing.FavoriteThingListener() {
@Override
@@ -249,7 +251,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
mFavoriteSubscribedUserData.get(position).setFavorite(true);
FavoriteThing.favoriteUser(mExecutor, new Handler(), mOauthRetrofit,
- mRedditDataRoomDatabase, mAccessToken,
+ mRedditDataRoomDatabase, mAccessToken, mAccountName,
mFavoriteSubscribedUserData.get(position),
new FavoriteThing.FavoriteThingListener() {
@Override
@@ -314,7 +316,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
mSubscribedUserData.get(position).setFavorite(false);
FavoriteThing.unfavoriteUser(mExecutor, new Handler(), mOauthRetrofit,
- mRedditDataRoomDatabase, mAccessToken,
+ mRedditDataRoomDatabase, mAccessToken, mAccountName,
mSubscribedUserData.get(position),
new FavoriteThing.FavoriteThingListener() {
@Override
@@ -340,7 +342,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
mSubscribedUserData.get(position).setFavorite(true);
FavoriteThing.favoriteUser(mExecutor, new Handler(), mOauthRetrofit,
- mRedditDataRoomDatabase, mAccessToken,
+ mRedditDataRoomDatabase, mAccessToken, mAccountName,
mSubscribedUserData.get(position),
new FavoriteThing.FavoriteThingListener() {
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java
index d306c151..5701960a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java
@@ -5,7 +5,6 @@ import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
-import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
@@ -73,6 +72,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;
@@ -165,6 +165,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
private Retrofit mRedgifsRetrofit;
private Provider<StreamableAPI> 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<Post, Recy
mRedgifsRetrofit = redgifsRetrofit;
mStreamableApiProvider = streambleApiProvider;
mAccessToken = accessToken;
+ mAccountName = accountName;
mPostType = postType;
mDisplaySubredditName = displaySubredditName;
- mNeedBlurNsfw = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true);
- mNeedBlurSpoiler = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, false);
+ mNeedBlurNsfw = nsfwAndSpoilerSharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true);
+ mNeedBlurSpoiler = nsfwAndSpoilerSharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, false);
mVoteButtonsOnTheRight = sharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
mTimeFormatPattern = sharedPreferences.getString(SharedPreferencesUtils.TIME_FORMAT_KEY, SharedPreferencesUtils.TIME_FORMAT_DEFAULT_VALUE);
@@ -2798,7 +2800,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
}
Post post = getItem(position);
if (post != null) {
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -2903,7 +2905,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
}
Post post = getItem(position);
if (post != null) {
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -3004,7 +3006,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
}
Post post = getItem(position);
if (post != null) {
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -4106,7 +4108,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
}
Post post = getItem(position);
if (post != null) {
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -4207,7 +4209,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
}
Post post = getItem(position);
if (post != null) {
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -4302,7 +4304,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
});
saveButton.setOnClickListener(view -> {
- 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<Post, Recy
}
Post post = getItem(position);
if (post != null) {
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -5567,7 +5569,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
}
Post post = getItem(position);
if (post != null) {
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -5666,7 +5668,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
}
Post post = getItem(position);
if (post != null) {
- 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/MultiRedditListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java
index 3f75f967..bef5f998 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java
@@ -24,6 +24,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import me.zhanghai.android.fastscroll.PopupTextProvider;
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.asynctasks.InsertMultireddit;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
@@ -46,6 +47,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
private RequestManager mGlide;
private String mAccessToken;
+ private String mAccountName;
private List<MultiReddit> mMultiReddits;
private List<MultiReddit> 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<Recycler
return;
}
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -1339,7 +1340,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
return;
}
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -1435,7 +1436,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
return;
}
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -1455,7 +1456,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
}
this.saveButton.setOnClickListener(view -> {
- 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<Post, RecyclerVie
private Retrofit mRedgifsRetrofit;
private Provider<StreamableAPI> 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<Post, RecyclerVie
mRedgifsRetrofit = redgifsRetrofit;
mStreamableApiProvider = streamableApiProvider;
mAccessToken = accessToken;
+ mAccountName = accountName;
mPostType = postType;
mDisplaySubredditName = displaySubredditName;
- mNeedBlurNsfw = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true);
- mDoNotBlurNsfwInNsfwSubreddits = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.DO_NOT_BLUR_NSFW_IN_NSFW_SUBREDDITS, false);
- mNeedBlurSpoiler = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, false);
+ mNeedBlurNsfw = nsfwAndSpoilerSharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true);
+ mDoNotBlurNsfwInNsfwSubreddits = nsfwAndSpoilerSharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.DO_NOT_BLUR_NSFW_IN_NSFW_SUBREDDITS, false);
+ mNeedBlurSpoiler = nsfwAndSpoilerSharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, false);
mVoteButtonsOnTheRight = sharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
mTimeFormatPattern = sharedPreferences.getString(SharedPreferencesUtils.TIME_FORMAT_KEY, SharedPreferencesUtils.TIME_FORMAT_DEFAULT_VALUE);
@@ -315,9 +317,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
mDisableImagePreview = sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false);
mOnlyDisablePreviewInVideoAndGifPosts = sharedPreferences.getBoolean(SharedPreferencesUtils.ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS, false);
- mMarkPostsAsRead = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false);
- mMarkPostsAsReadAfterVoting = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, false);
- mMarkPostsAsReadOnScroll = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_ON_SCROLL_BASE, false);
+ mMarkPostsAsRead = postHistorySharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false);
+ mMarkPostsAsReadAfterVoting = postHistorySharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, false);
+ mMarkPostsAsReadOnScroll = postHistorySharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_ON_SCROLL_BASE, false);
mHidePostType = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_TYPE, false);
mHidePostFlair = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_FLAIR, false);
@@ -2926,7 +2928,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
Post post = getItem(position);
if (post != null) {
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -3035,7 +3037,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
Post post = getItem(position);
if (post != null) {
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -3142,7 +3144,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
Post post = getItem(position);
if (post != null) {
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -4273,7 +4275,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
Post post = getItem(position);
if (post != null) {
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -4378,7 +4380,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
Post post = getItem(position);
if (post != null) {
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -4479,7 +4481,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
commentsCountButton.setOnClickListener(view -> 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<Post, RecyclerVie
}
Post post = getItem(position);
if (post != null) {
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -5801,7 +5803,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
Post post = getItem(position);
if (post != null) {
- if (mAccessToken == null) {
+ if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
}
@@ -5909,7 +5911,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
Post post = getItem(position);
if (post != null) {
- 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/SubscribedSubredditsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java
index ef8e1d36..f6f3d597 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java
@@ -49,6 +49,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
private ItemClickListener itemClickListener;
private String accessToken;
+ private String accountName;
private String username;
private String userIconUrl;
private boolean hasClearSelectionRow;
@@ -59,13 +60,14 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
public SubscribedSubredditsRecyclerViewAdapter(BaseActivity activity, Executor executor, Retrofit oauthRetrofit,
RedditDataRoomDatabase redditDataRoomDatabase,
CustomThemeWrapper customThemeWrapper,
- String accessToken) {
+ String accessToken, String accountName) {
mActivity = activity;
mExecutor = executor;
glide = Glide.with(activity);
mOauthRetrofit = oauthRetrofit;
mRedditDataRoomDatabase = redditDataRoomDatabase;
this.accessToken = accessToken;
+ this.accountName = accountName;
primaryTextColor = customThemeWrapper.getPrimaryTextColor();
secondaryTextColor = customThemeWrapper.getSecondaryTextColor();
}
@@ -73,9 +75,9 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
public SubscribedSubredditsRecyclerViewAdapter(BaseActivity activity, Executor executor, Retrofit oauthRetrofit,
RedditDataRoomDatabase redditDataRoomDatabase,
CustomThemeWrapper customThemeWrapper,
- String accessToken, boolean hasClearSelectionRow,
+ String accessToken, String accountName, boolean hasClearSelectionRow,
ItemClickListener itemClickListener) {
- this(activity, executor, oauthRetrofit, redditDataRoomDatabase, customThemeWrapper, accessToken);
+ this(activity, executor, oauthRetrofit, redditDataRoomDatabase, customThemeWrapper, accessToken, accountName);
this.hasClearSelectionRow = hasClearSelectionRow;
this.itemClickListener = itemClickListener;
}
@@ -195,7 +197,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).setFavorite(false);
FavoriteThing.unfavoriteSubreddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, accessToken,
- mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset),
+ accountName, mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset),
new FavoriteThing.FavoriteThingListener() {
@Override
public void success() {
@@ -220,7 +222,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).setFavorite(true);
FavoriteThing.favoriteSubreddit(mExecutor, new Handler(), mOauthRetrofit,
- mRedditDataRoomDatabase, accessToken,
+ mRedditDataRoomDatabase, accessToken, accountName,
mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset),
new FavoriteThing.FavoriteThingListener() {
@Override
@@ -294,7 +296,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).setFavorite(false);
FavoriteThing.unfavoriteSubreddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, accessToken,
- mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset),
+ accountName, mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset),
new FavoriteThing.FavoriteThingListener() {
@Override
public void success() {
@@ -319,7 +321,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).setFavorite(true);
FavoriteThing.favoriteSubreddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, accessToken,
- mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset),
+ accountName, mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset),
new FavoriteThing.FavoriteThingListener() {
@Override
public void success() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
index a85d5078..37eb42f3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
@@ -48,9 +48,6 @@ public interface RedditAPI {
@GET("comments/{id}.json?raw_json=1")
Call<String> getPostOauth(@Path("id") String id, @HeaderMap Map<String, String> headers);
- @GET("comments/{id}.json?raw_json=1")
- Call<String> getPost(@Path("id") String id);
-
@GET("user/{username}/about.json?raw_json=1")
Call<String> getUserData(@Path("username") String username);
@@ -58,10 +55,6 @@ public interface RedditAPI {
Call<String> getUserDataOauth(@HeaderMap Map<String, String> headers, @Path("username") String username);
@GET("user/{username}/comments.json?raw_json=1&limit=100")
- Call<String> 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<String> getUserCommentsOauth(@HeaderMap Map<String, String> headers, @Path("username") String username,
@Query("after") String after, @Query("sort") SortType.Type sortType,
@Query("t") SortType.Time sortTime);
@@ -76,9 +69,6 @@ public interface RedditAPI {
Call<String> subredditSubscription(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
@GET("/api/info.json?raw_json=1")
- Call<String> getInfo(@Query("id") String id);
-
- @GET("/api/info.json?raw_json=1")
Call<String> getInfoOauth(@Query("id") String id, @HeaderMap Map<String, String> headers);
@GET("subreddits/search.json?raw_json=1")
@@ -110,9 +100,6 @@ public interface RedditAPI {
Call<String> getFlairs(@HeaderMap Map<String, String> headers, @Path("subredditName") String subredditName);
@GET("/r/{subredditName}/about/rules.json?raw_json=1")
- Call<String> getRules(@Path("subredditName") String subredditName);
-
- @GET("/r/{subredditName}/about/rules.json?raw_json=1")
Call<String> getRulesOauth(@HeaderMap Map<String, String> headers, @Path("subredditName") String subredditName);
@GET("/comments/{id}/placeholder/{singleCommentId}.json?raw_json=1")
@@ -124,13 +111,6 @@ public interface RedditAPI {
Call<String> getPostAndCommentsByIdOauth(@Path("id") String id, @Query("sort") SortType.Type sortType,
@HeaderMap Map<String, String> headers);
- @GET("/comments/{id}/placeholder/{singleCommentId}.json?raw_json=1")
- Call<String> 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<String> getPostAndCommentsById(@Path("id") String id, @Query("sort") SortType.Type sortType);
-
@Multipart
@POST(".")
Call<String> uploadMediaToAWS(@PartMap() Map<String, RequestBody> params, @Part() MultipartBody.Part file);
@@ -261,9 +241,6 @@ public interface RedditAPI {
Call<String> submitPollPost(@HeaderMap Map<String, String> headers, @Body String body);
@GET("/api/trending_searches_v1.json?withAds=0&raw_json=1&gilding_detail=1")
- Call<String> getTrendingSearches();
-
- @GET("/api/trending_searches_v1.json?withAds=0&raw_json=1&gilding_detail=1")
Call<String> getTrendingSearchesOauth(@HeaderMap Map<String, String> headers);
default Call<String> getWiki(@Path("subredditName") String subredditName) {
@@ -282,45 +259,23 @@ public interface RedditAPI {
@Query("t") SortType.Time sortTime, @Query("after") String lastItem,
@HeaderMap Map<String, String> headers);
- @GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=100&always_show_media=1")
- ListenableFuture<Response<String>> 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<Response<String>> 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<String, String> headers);
- @GET("user/{username}/submitted.json?raw_json=1&limit=100")
- ListenableFuture<Response<String>> 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<Response<String>> 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<String, String> headers);
- @GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link")
- ListenableFuture<Response<String>> 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<Response<String>> 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<String, String> headers);
- @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true")
- ListenableFuture<Response<String>> 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<Response<String>> 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<Response<String>> 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<String, String> headers);
- @GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=100&always_show_media=1")
- Call<String> 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<String> 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<String, String> headers);
- @GET("user/{username}/submitted.json?raw_json=1&limit=100")
- Call<String> 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<String> 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<String, String> headers);
- @GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link")
- Call<String> 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<String> 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<String, String> headers);
- @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true")
- Call<String> 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<String> 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<String> getMultiRedditPostsOauth(@Path(value = "multipath", encoded = true) String multiPath,
@Query("after") String after, @Query("t") SortType.Time sortTime,
@@ -401,9 +334,5 @@ public interface RedditAPI {
@FormUrlEncoded
@POST("/api/morechildren.json?raw_json=1&api_type=json")
- Call<String> 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<String> moreChildrenOauth(@Field("link_id") String linkId, @Field("children") String children, @Field("sort") SortType.Type sort, @HeaderMap Map<String, String> 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<String, Comment> {
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<String, Comment> {
private LoadParams<String> params;
private LoadCallback<String, Comment> 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<String, Comment> {
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<String>() {
@Override
@@ -146,13 +145,8 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
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<String>() {
@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<CommentDataSource> 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<PagedList<Comment>> comments;
private MutableLiveData<SortType> 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 extends ViewModel> T create(@NonNull Class<T> 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<String> 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<String> allChildren,
boolean expandChildren, String postFullName,
SortType.Type sortType,
@@ -89,13 +81,8 @@ public class FetchComment {
}
RedditAPI api = retrofit.create(RedditAPI.class);
- Call<String> moreComments;
- if (accessToken == null) {
- moreComments = api.moreChildren(postFullName, childrenIds, sortType);
- } else {
- moreComments = api.moreChildrenOauth(postFullName, childrenIds,
- sortType, APIUtils.getOAuthHeader(accessToken));
- }
+ Call<String> 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<String> 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<Comment> 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<Comment> topLevelComments,
ArrayList<Comment> 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<String> postCall;
- if (accessToken == null) {
- postCall = retrofit.create(RedditAPI.class).getPost(id);
- } else {
- postCall = retrofit.create(RedditAPI.class).getPostOauth(id, APIUtils.getOAuthHeader(accessToken));
- }
+ Call<String> postCall = retrofit.create(RedditAPI.class).getPostOauth(id, APIUtils.getOAuthHeader(accessToken));
postCall.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> 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<String
ids.deleteCharAt(ids.length() - 1);
}
- Call<String> 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<String> historyPosts = retrofit.create(RedditAPI.class).getInfoOauth(ids.toString(), APIUtils.getOAuthHeader(accessToken));
try {
Response<String> 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<String, Post>
}
private ListenableFuture<LoadResult<String, Post>> loadSubredditPosts(@NonNull LoadParams<String> loadParams, RedditAPI api) {
- ListenableFuture<Response<String>> 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<Response<String>> subredditPost = api.getSubredditBestPostsOauthListenableFuture(subredditOrUserName, sortType.getType(),
+ sortType.getTime(), loadParams.getKey(), APIUtils.getOAuthHeader(accessToken));
ListenableFuture<LoadResult<String, Post>> pageFuture = Futures.transform(subredditPost, this::transformData, executor);
@@ -253,12 +249,12 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
private ListenableFuture<LoadResult<String, Post>> loadUserPosts(@NonNull LoadParams<String> loadParams, RedditAPI api) {
ListenableFuture<Response<String>> 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<LoadResult<String, Post>> pageFuture = Futures.transform(userPosts, this::transformData, executor);
@@ -274,22 +270,12 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
private ListenableFuture<LoadResult<String, Post>> loadSearchPosts(@NonNull LoadParams<String> loadParams, RedditAPI api) {
ListenableFuture<Response<String>> 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<LoadResult<String, Post>> pageFuture = Futures.transform(searchPosts, this::transformData, executor);
@@ -303,13 +289,8 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
}
private ListenableFuture<LoadResult<String, Post>> loadMultiRedditPosts(@NonNull LoadParams<String> loadParams, RedditAPI api) {
- ListenableFuture<Response<String>> 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<Response<String>> multiRedditPosts = api.getMultiRedditPostsOauthListenableFuture(multiRedditPath, loadParams.getKey(),
+ sortType.getTime(), APIUtils.getOAuthHeader(accessToken));
ListenableFuture<LoadResult<String, Post>> pageFuture = Futures.transform(multiRedditPosts, this::transformData, executor);
@@ -323,7 +304,8 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
private ListenableFuture<LoadResult<String, Post>> loadAnonymousHomePosts(@NonNull LoadParams<String> loadParams, RedditAPI api) {
ListenableFuture<Response<String>> 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<LoadResult<String, Post>> 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."</string>
<string name="message_change_banner_success">"Banner cambiado correctamente"</string>
<string name="message_change_banner_failed">"Error al cambiar banner %s"</string>
<string name="message_save_profile_success">"Perfil guardado correctamente"</string>
- <string name="message_save_profile_failed">"Error al guardar perfil"</string>
+ <string name="message_save_profile_failed">Error al guardar perfil %s</string>
<string name="post_poll_activity_label">"Publicación de encuesta"</string>
<string name="action_open_external_browser">"Abrir en el navegador"</string>
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."</string>
<string name="message_remove_avatar_success">"Xoá ảnh đại diện thành công"</string>
<string name="message_remove_avatar_failed">"Xoá ảnh đại diện %s thất bại"</string>
<string name="message_remove_banner_success">"Xoá banner thành công"</string>
- <string name="message_remove_banner_failed">"Gỡ bỏ banner thất bại"</string>
+ <string name="message_remove_banner_failed">Gỡ bỏ banner thất bại %s</string>
<string name="message_change_avatar_success">"Thay đổi ảnh đại diện thành công"</string>
- <string name="message_change_avatar_failed">"Thay đổi ảnh đại diện thất bại"</string>
+ <string name="message_change_avatar_failed">Thay đổi ảnh đại diện thất bại %s</string>
<string name="message_change_banner_success">"Thay đổi banner thành công"</string>
- <string name="message_change_banner_failed">"Thay đổi banner thất bại"</string>
+ <string name="message_change_banner_failed">Thay đổi banner thất bại %s</string>
<string name="message_save_profile_success">"Lưu Hồ sơ thành công"</string>
- <string name="message_save_profile_failed">"Lưu hồ sơ %s thất bại"</string>
+ <string name="message_save_profile_failed">Lưu hồ sơ %s thất bại</string>
</resources> \ No newline at end of file