diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-12-31 04:38:50 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-12-31 04:38:50 +0000 |
commit | cfd4813bf94ef3db75e0151e1e9a636600ea140d (patch) | |
tree | f09cc084885a928880938f44cc59c066ca203a11 /app/src/main | |
parent | f64dc1b9ddb244440465dbe7722ef5613745c85e (diff) | |
download | infinity-for-reddit-cfd4813bf94ef3db75e0151e1e9a636600ea140d.tar infinity-for-reddit-cfd4813bf94ef3db75e0151e1e9a636600ea140d.tar.gz infinity-for-reddit-cfd4813bf94ef3db75e0151e1e9a636600ea140d.tar.bz2 infinity-for-reddit-cfd4813bf94ef3db75e0151e1e9a636600ea140d.tar.lz infinity-for-reddit-cfd4813bf94ef3db75e0151e1e9a636600ea140d.tar.xz infinity-for-reddit-cfd4813bf94ef3db75e0151e1e9a636600ea140d.tar.zst infinity-for-reddit-cfd4813bf94ef3db75e0151e1e9a636600ea140d.zip |
Account.ANONYMOUS_ACCOUNT
Diffstat (limited to 'app/src/main')
27 files changed, 163 insertions, 89 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java index 588d4041..6fd2522f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java @@ -48,18 +48,30 @@ class AccessTokenAuthenticator implements Authenticator { synchronized (this) { Account account = mRedditDataRoomDatabase.accountDao().getCurrentAccount(); if (account == null) { - return null; - } - String accessTokenFromDatabase = account.getAccessToken(); - if (accessToken.equals(accessTokenFromDatabase)) { - String newAccessToken = refreshAccessToken(account); - if (!newAccessToken.equals("")) { - return response.request().newBuilder().headers(Headers.of(APIUtils.getOAuthHeader(newAccessToken))).build(); + //Anonymous mode + String accessTokenFromSharedPreference = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, ""); + if (accessToken.equals(accessTokenFromSharedPreference)) { + String newAccessToken = getApplicationOnlyAccessToken(); + if (!newAccessToken.equals("")) { + return response.request().newBuilder().headers(Headers.of(APIUtils.getOAuthHeader(newAccessToken))).build(); + } else { + return null; + } } else { - return null; + return response.request().newBuilder().headers(Headers.of(APIUtils.getOAuthHeader(accessTokenFromSharedPreference))).build(); } } else { - return response.request().newBuilder().headers(Headers.of(APIUtils.getOAuthHeader(accessTokenFromDatabase))).build(); + String accessTokenFromDatabase = account.getAccessToken(); + if (accessToken.equals(accessTokenFromDatabase)) { + String newAccessToken = refreshAccessToken(account); + if (!newAccessToken.equals("")) { + return response.request().newBuilder().headers(Headers.of(APIUtils.getOAuthHeader(newAccessToken))).build(); + } else { + return null; + } + } else { + return response.request().newBuilder().headers(Headers.of(APIUtils.getOAuthHeader(accessTokenFromDatabase))).build(); + } } } } @@ -100,4 +112,32 @@ class AccessTokenAuthenticator implements Authenticator { return ""; } + + //For anonymous mode + private String getApplicationOnlyAccessToken() { + RedditAPI api = mRetrofit.create(RedditAPI.class); + + Map<String, String> params = new HashMap<>(); + params.put(APIUtils.GRANT_TYPE_KEY, APIUtils.GRANT_TYPE_INSTALLED_CLIENT); + params.put(APIUtils.DEVICE_ID_KEY, APIUtils.DEVICE_ID); + + Call<String> accessTokenCall = api.getAccessToken(APIUtils.getApplicationOnlyBasicAuthHeader(), params); + try { + retrofit2.Response<String> response = accessTokenCall.execute(); + if (response.isSuccessful() && response.body() != null) { + JSONObject jsonObject = new JSONObject(response.body()); + String newAccessToken = jsonObject.getString(APIUtils.ACCESS_TOKEN_KEY); + if (mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "").equals(Account.ANONYMOUS_ACCOUNT)) { + mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.ACCESS_TOKEN, newAccessToken).apply(); + } + + return newAccessToken; + } + return ""; + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + + return ""; + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchPostFilterReadPostsAndConcatenatedSubredditNames.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchPostFilterReadPostsAndConcatenatedSubredditNames.java index 76d5457a..127328d1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchPostFilterReadPostsAndConcatenatedSubredditNames.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchPostFilterReadPostsAndConcatenatedSubredditNames.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.Executor; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.multireddit.AnonymousMultiredditSubreddit; import ml.docilealligator.infinityforreddit.postfilter.PostFilter; import ml.docilealligator.infinityforreddit.readpost.ReadPost; @@ -45,7 +46,7 @@ public class FetchPostFilterReadPostsAndConcatenatedSubredditNames { executor.execute(() -> { List<PostFilter> postFilters = redditDataRoomDatabase.postFilterDao().getValidPostFilters(postFilterUsage, nameOfUsage); PostFilter mergedPostFilter = PostFilter.mergePostFilter(postFilters); - List<SubscribedSubredditData> anonymousSubscribedSubreddits = redditDataRoomDatabase.subscribedSubredditDao().getAllSubscribedSubredditsList("-"); + List<SubscribedSubredditData> anonymousSubscribedSubreddits = redditDataRoomDatabase.subscribedSubredditDao().getAllSubscribedSubredditsList(Account.ANONYMOUS_ACCOUNT); if (anonymousSubscribedSubreddits != null && !anonymousSubscribedSubreddits.isEmpty()) { StringBuilder stringBuilder = new StringBuilder(); for (SubscribedSubredditData s : anonymousSubscribedSubreddits) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/account/Account.java b/app/src/main/java/ml/docilealligator/infinityforreddit/account/Account.java index a40d36ca..7c83c75a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/account/Account.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/account/Account.java @@ -11,6 +11,7 @@ import androidx.room.PrimaryKey; @Entity(tableName = "accounts") public class Account implements Parcelable { + public static final String ANONYMOUS_ACCOUNT = "-"; @PrimaryKey @NonNull @ColumnInfo(name = "username") @@ -56,7 +57,7 @@ public class Account implements Parcelable { @Ignore public static Account getAnonymousAccount() { - return new Account("-", null, null, null, null, null, 0, false); + return new Account(Account.ANONYMOUS_ACCOUNT, null, null, null, null, null, 0, false); } public Account(@NonNull String accountName, String accessToken, String refreshToken, String code, 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 9f07ddc3..6679152b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java @@ -34,6 +34,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.customviews.slidr.Slidr; import ml.docilealligator.infinityforreddit.multireddit.CreateMultiReddit; @@ -114,7 +115,7 @@ public class CreateMultiRedditActivity extends BaseActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "-"); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); if (mAccessToken == null) { visibilityLinearLayout.setVisibility(View.GONE); 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 11322efc..b2af5138 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java @@ -35,6 +35,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.customviews.slidr.Slidr; import ml.docilealligator.infinityforreddit.multireddit.EditMultiReddit; @@ -123,7 +124,7 @@ public class EditMultiRedditActivity extends BaseActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "-"); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); if (mAccessToken == null) { visibilityLinearLayout.setVisibility(View.GONE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java index b5a00239..f7c984f1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java @@ -39,6 +39,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.bottomsheetfragments.FilteredThingFABMoreOptionsBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SearchPostSortTypeBottomSheetFragment; @@ -163,7 +164,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec int filter = getIntent().getIntExtra(EXTRA_FILTER, -1000); PostFilter postFilter = new PostFilter(); - postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null || mAccountName.equals("-") ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false); + postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null || mAccountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false); switch (filter) { case Post.NSFW_TYPE: postFilter.onlyNSFW = true; 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 12a1dfce..cc974d2e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -81,6 +81,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.account.AccountViewModel; import ml.docilealligator.infinityforreddit.adapters.SubredditAutocompleteRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.adapters.navigationdrawer.NavigationDrawerRecyclerViewMergedAdapter; @@ -583,9 +584,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } if (showBottomAppBar) { - int optionCount = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_COUNT, 4); - int option1 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS); - int option2 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_MULTIREDDITS); + 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); if (optionCount == 2) { navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2)); @@ -612,8 +613,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb }); } } else { - int option3 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + 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 ? "-" : "") + 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((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); navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2), getBottomAppBarOptionDrawableResource(option3), @@ -662,7 +663,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb navigationWrapper.floatingActionButton.setLayoutParams(lp); } - fabOption = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB, + fabOption = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? 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: @@ -943,7 +944,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb loadSubscriptions(); multiRedditViewModel = new ViewModelProvider(this, new MultiRedditViewModel.Factory(getApplication(), - mRedditDataRoomDatabase, mAccountName == null ? "-" : mAccountName)) + mRedditDataRoomDatabase, mAccountName == null ? Account.ANONYMOUS_ACCOUNT : mAccountName)) .get(MultiRedditViewModel.class); multiRedditViewModel.getAllFavoriteMultiReddits().observe(this, multiReddits -> { @@ -959,7 +960,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb }); subscribedSubredditViewModel = new ViewModelProvider(this, - new SubscribedSubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName == null ? "-" : mAccountName)) + new SubscribedSubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName == null ? Account.ANONYMOUS_ACCOUNT : mAccountName)) .get(SubscribedSubredditViewModel.class); subscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this, subscribedSubredditData -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java index 4c3fe53a..6826f4c7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java @@ -37,6 +37,7 @@ import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.SubredditMultiselectionRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; @@ -131,7 +132,7 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act mSwipeRefreshLayout.setEnabled(false); - mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "-"); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); bindView(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java index 979e0731..c5e2e638 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java @@ -50,6 +50,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.asynctasks.DeleteMultiredditInDatabase; import ml.docilealligator.infinityforreddit.asynctasks.InsertMultireddit; import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThings; @@ -169,7 +170,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti setToolbarGoToTop(toolbar); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "-"); + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); if (savedInstanceState != null) { mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE); @@ -489,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 ? "-" : mAccountName); + bundle.putString(FollowedUsersListingFragment.EXTRA_ACCOUNT_NAME, mAccountName == null ? Account.ANONYMOUS_ACCOUNT : mAccountName); bundle.putString(FollowedUsersListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken); fragment.setArguments(bundle); return fragment; @@ -498,7 +499,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti MultiRedditListingFragment fragment = new MultiRedditListingFragment(); Bundle bundle = new Bundle(); bundle.putString(MultiRedditListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken); - bundle.putString(MultiRedditListingFragment.EXTRA_ACCOUNT_NAME, mAccountName == null ? "-" : mAccountName); + bundle.putString(MultiRedditListingFragment.EXTRA_ACCOUNT_NAME, mAccountName == null ? Account.ANONYMOUS_ACCOUNT : mAccountName); fragment.setArguments(bundle); return fragment; } 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 e51058b3..caa4d4d8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java @@ -48,6 +48,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.asynctasks.DeleteMultiredditInDatabase; @@ -232,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 ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, 4); - int option1 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME); - int option2 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS); + 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); if (optionCount == 2) { navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2)); @@ -261,8 +262,8 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT }); } } else { - int option3 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + 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 ? "-" : "") + 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((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); navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2), getBottomAppBarOptionDrawableResource(option3), 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 80c0b8b5..cd4502e4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -80,6 +80,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.asynctasks.AddSubredditOrUserToMultiReddit; @@ -764,9 +765,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp } if (showBottomAppBar) { - int optionCount = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, 4); - int option1 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME); - int option2 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS); + 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); if (optionCount == 2) { navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2)); @@ -793,8 +794,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp }); } } else { - int option3 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + 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 ? "-" : "") + 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((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); navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2), getBottomAppBarOptionDrawableResource(option3), @@ -843,7 +844,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp navigationWrapper.floatingActionButton.setLayoutParams(lp); } - fabOption = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS); + fabOption = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? 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); 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 659d0a4b..d0d7a1c0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -77,6 +77,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.asynctasks.AddSubredditOrUserToMultiReddit; @@ -715,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 ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, 4); - int option1 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_HOME); - int option2 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS); + 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); if (optionCount == 2) { navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2)); @@ -744,8 +745,8 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele }); } } else { - int option3 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + 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 ? "-" : "") + 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((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); navigationWrapper.bindOptionDrawableResource(getBottomAppBarOptionDrawableResource(option1), getBottomAppBarOptionDrawableResource(option2), getBottomAppBarOptionDrawableResource(option3), @@ -794,7 +795,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele navigationWrapper.floatingActionButton.setLayoutParams(lp); } - fabOption = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS); + fabOption = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? 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); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/BackupSettings.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/BackupSettings.java index 1b79fe3c..2e353b06 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/BackupSettings.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/BackupSettings.java @@ -31,6 +31,7 @@ import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.BuildConfig; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; import ml.docilealligator.infinityforreddit.multireddit.AnonymousMultiredditSubreddit; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; @@ -95,15 +96,15 @@ public class BackupSettings { boolean res10 = saveSharedPreferencesToFile(postHistorySharedPreferences, backupDir, SharedPreferencesUtils.POST_HISTORY_SHARED_PREFERENCES_FILE); - List<SubscribedSubredditData> anonymousSubscribedSubredditsData = redditDataRoomDatabase.subscribedSubredditDao().getAllSubscribedSubredditsList("-"); + List<SubscribedSubredditData> anonymousSubscribedSubredditsData = redditDataRoomDatabase.subscribedSubredditDao().getAllSubscribedSubredditsList(Account.ANONYMOUS_ACCOUNT); String anonymousSubscribedSubredditsDataJson = new Gson().toJson(anonymousSubscribedSubredditsData); boolean res11 = saveDatabaseTableToFile(anonymousSubscribedSubredditsDataJson, databaseDirFile.getAbsolutePath(), "/anonymous_subscribed_subreddits.json"); - List<SubscribedUserData> anonymousSubscribedUsersData = redditDataRoomDatabase.subscribedUserDao().getAllSubscribedUsersList("-"); + List<SubscribedUserData> anonymousSubscribedUsersData = redditDataRoomDatabase.subscribedUserDao().getAllSubscribedUsersList(Account.ANONYMOUS_ACCOUNT); String anonymousSubscribedUsersDataJson = new Gson().toJson(anonymousSubscribedUsersData); boolean res12 = saveDatabaseTableToFile(anonymousSubscribedUsersDataJson, databaseDirFile.getAbsolutePath(), "/anonymous_subscribed_users.json"); - List<MultiReddit> anonymousMultireddits = redditDataRoomDatabase.multiRedditDao().getAllMultiRedditsList("-"); + List<MultiReddit> anonymousMultireddits = redditDataRoomDatabase.multiRedditDao().getAllMultiRedditsList(Account.ANONYMOUS_ACCOUNT); String anonymousMultiredditsJson = new Gson().toJson(anonymousMultireddits); boolean res13 = saveDatabaseTableToFile(anonymousMultiredditsJson, databaseDirFile.getAbsolutePath(), "/anonymous_multireddits.json"); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsFollowingUser.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsFollowingUser.java index 0e174697..12bedc46 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsFollowingUser.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsFollowingUser.java @@ -5,6 +5,7 @@ import android.os.Handler; import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData; public class CheckIsFollowingUser { @@ -12,7 +13,7 @@ public class CheckIsFollowingUser { RedditDataRoomDatabase redditDataRoomDatabase, String username, String accountName, CheckIsFollowingUserListener checkIsFollowingUserListener) { executor.execute(() -> { - SubscribedUserData subscribedUserData = redditDataRoomDatabase.subscribedUserDao().getSubscribedUser(username, accountName == null ? "-" : accountName); + SubscribedUserData subscribedUserData = redditDataRoomDatabase.subscribedUserDao().getSubscribedUser(username, accountName == null ? Account.ANONYMOUS_ACCOUNT : accountName); handler.post(() -> { if (subscribedUserData != null) { checkIsFollowingUserListener.isSubscribed(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsSubscribedToSubreddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsSubscribedToSubreddit.java index 572baf17..60700edc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsSubscribedToSubreddit.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/CheckIsSubscribedToSubreddit.java @@ -19,7 +19,7 @@ public class CheckIsSubscribedToSubreddit { redditDataRoomDatabase.accountDao().insert(Account.getAnonymousAccount()); } } - SubscribedSubredditData subscribedSubredditData = redditDataRoomDatabase.subscribedSubredditDao().getSubscribedSubreddit(subredditName, accountName == null ? "-" : accountName); + SubscribedSubredditData subscribedSubredditData = redditDataRoomDatabase.subscribedSubredditDao().getSubscribedSubreddit(subredditName, accountName == null ? Account.ANONYMOUS_ACCOUNT : accountName); handler.post(() -> { if (subscribedSubredditData != null) { checkIsSubscribedToSubredditListener.isSubscribed(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteMultiredditInDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteMultiredditInDatabase.java index 0279498f..bc871fe0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteMultiredditInDatabase.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/DeleteMultiredditInDatabase.java @@ -5,6 +5,7 @@ import android.os.Handler; import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.account.Account; public class DeleteMultiredditInDatabase { @@ -13,7 +14,7 @@ public class DeleteMultiredditInDatabase { String accountName, String multipath, DeleteMultiredditInDatabaseListener deleteMultiredditInDatabaseListener) { executor.execute(() -> { - if (accountName.equals("-")) { + if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { redditDataRoomDatabase.multiRedditDao().anonymousDeleteMultiReddit(multipath); } else { redditDataRoomDatabase.multiRedditDao().deleteMultiReddit(multipath, accountName); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertMultireddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertMultireddit.java index 80fbb74e..ff3b2712 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertMultireddit.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/InsertMultireddit.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.multireddit.AnonymousMultiredditSubreddit; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; import ml.docilealligator.infinityforreddit.multireddit.MultiRedditDao; @@ -40,7 +41,7 @@ public class InsertMultireddit { MultiReddit multiReddit, InsertMultiRedditListener insertMultiRedditListener) { executor.execute(() -> { - if (multiReddit.getOwner().equals("-")) { + if (multiReddit.getOwner().equals(Account.ANONYMOUS_ACCOUNT)) { ArrayList<AnonymousMultiredditSubreddit> allAnonymousMultiRedditSubreddits = (ArrayList<AnonymousMultiredditSubreddit>) redditDataRoomDatabase.anonymousMultiredditSubredditDao().getAllAnonymousMultiRedditSubreddits(multiReddit.getPath()); redditDataRoomDatabase.multiRedditDao().insert(multiReddit); 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 962fadc4..f2301187 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.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.MultiredditSelectionActivity; import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity; @@ -107,7 +108,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm } } - String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME, "-"); + String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); boolean isGettingMultiredditInfo = getArguments().getBoolean(EXTRA_IS_GETTING_MULTIREDDIT_INFO, false); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index 322c5088..7f63b9e0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -76,6 +76,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.AccountPostsActivity; import ml.docilealligator.infinityforreddit.activities.AccountSavedThingActivity; import ml.docilealligator.infinityforreddit.activities.BaseActivity; @@ -726,9 +727,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator { usage = PostFilterUsage.HOME_TYPE; nameOfUsage = PostFilterUsage.NO_USAGE; - String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + "-", SortType.Type.HOT.name()); + String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + Account.ANONYMOUS_ACCOUNT, SortType.Type.HOT.name()); if (sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) { - String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + "-", SortType.Time.ALL.name()); + String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + Account.ANONYMOUS_ACCOUNT, SortType.Time.ALL.name()); sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime)); } else { sortType = new SortType(SortType.Type.valueOf(sort)); @@ -1395,9 +1396,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } break; case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE: - mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + "-", sortType.getType().name()).apply(); + mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + Account.ANONYMOUS_ACCOUNT, sortType.getType().name()).apply(); if (sortType.getTime() != null) { - mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + "-", sortType.getTime().name()).apply(); + mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + Account.ANONYMOUS_ACCOUNT, sortType.getTime().name()).apply(); } break; } 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 3a18b05e..b35b2ffb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.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.SubredditSelectionActivity; import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity; @@ -109,7 +110,7 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra } } - String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME, "-"); + String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT); String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); if (accessToken == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/AnonymousMultiredditSubreddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/AnonymousMultiredditSubreddit.java index 1a8e2bf3..036a1ab0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/AnonymousMultiredditSubreddit.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/AnonymousMultiredditSubreddit.java @@ -5,6 +5,8 @@ import androidx.room.ColumnInfo; import androidx.room.Entity; import androidx.room.ForeignKey; +import ml.docilealligator.infinityforreddit.account.Account; + @Entity(tableName = "anonymous_multireddit_subreddits", primaryKeys = {"path", "username", "subreddit_name"}, foreignKeys = @ForeignKey(entity = MultiReddit.class, parentColumns = {"path", "username"}, childColumns = {"path", "username"}, onDelete = ForeignKey.CASCADE, onUpdate = ForeignKey.CASCADE)) @@ -14,7 +16,7 @@ public class AnonymousMultiredditSubreddit { private String path; @NonNull @ColumnInfo(name = "username") - public String username = "-"; + public String username = Account.ANONYMOUS_ACCOUNT; @NonNull @ColumnInfo(name = "subreddit_name") private String subredditName; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/CreateMultiReddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/CreateMultiReddit.java index 1c3113ea..1bef9993 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/CreateMultiReddit.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/CreateMultiReddit.java @@ -70,7 +70,7 @@ public class CreateMultiReddit { redditDataRoomDatabase.accountDao().insert(Account.getAnonymousAccount()); } redditDataRoomDatabase.multiRedditDao().insert(new MultiReddit(multipath, name, name, description, - null, null, "private", "-", 0, System.currentTimeMillis(), true, false, false)); + null, null, "private", Account.ANONYMOUS_ACCOUNT, 0, System.currentTimeMillis(), true, false, false)); List<AnonymousMultiredditSubreddit> anonymousMultiredditSubreddits = new ArrayList<>(); for (String s : subreddits) { anonymousMultiredditSubreddits.add(new AnonymousMultiredditSubreddit(multipath, s)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FetchMultiRedditInfo.java b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FetchMultiRedditInfo.java index f867d530..b13225a5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FetchMultiRedditInfo.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FetchMultiRedditInfo.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.utils.JSONUtils; import ml.docilealligator.infinityforreddit.utils.APIUtils; @@ -52,7 +53,7 @@ public class FetchMultiRedditInfo { String multipath, FetchMultiRedditInfoListener fetchMultiRedditInfoListener) { executor.execute(() -> { - MultiReddit multiReddit = redditDataRoomDatabase.multiRedditDao().getMultiReddit(multipath, "-"); + MultiReddit multiReddit = redditDataRoomDatabase.multiRedditDao().getMultiReddit(multipath, Account.ANONYMOUS_ACCOUNT); ArrayList<AnonymousMultiredditSubreddit> anonymousMultiredditSubreddits = (ArrayList<AnonymousMultiredditSubreddit>) redditDataRoomDatabase.anonymousMultiredditSubredditDao().getAllAnonymousMultiRedditSubreddits(multipath); ArrayList<String> subredditNames = new ArrayList<>(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeBottomAppBarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeBottomAppBarFragment.java index f4641ac6..0348f3c1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeBottomAppBarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeBottomAppBarFragment.java @@ -26,6 +26,7 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.SettingsActivity; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -161,12 +162,12 @@ public class CustomizeBottomAppBarFragment extends Fragment { String[] mainActivityOptionAnonymous = resources.getStringArray(R.array.settings_main_activity_bottom_app_bar_options_anonymous); String[] mainActivityOptionAnonymousValues = resources.getStringArray(R.array.settings_main_activity_bottom_app_bar_options_anonymous_values); String[] fabOptions; - mainActivityOptionCount = sharedPreferences.getInt((accountName == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_COUNT, 4); - mainActivityOption1 = sharedPreferences.getInt((accountName == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_1, 0); - mainActivityOption2 = sharedPreferences.getInt((accountName == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_2, 1); - mainActivityOption3 = sharedPreferences.getInt((accountName == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_3, 2); - mainActivityOption4 = sharedPreferences.getInt((accountName == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_4, 3); - mainActivityFAB = sharedPreferences.getInt((accountName == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB, accountName == null ? 7: 0); + mainActivityOptionCount = sharedPreferences.getInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_COUNT, 4); + mainActivityOption1 = sharedPreferences.getInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_1, 0); + mainActivityOption2 = sharedPreferences.getInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_2, 1); + mainActivityOption3 = sharedPreferences.getInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_3, 2); + mainActivityOption4 = sharedPreferences.getInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_4, 3); + mainActivityFAB = sharedPreferences.getInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB, accountName == null ? 7: 0); mainActivityOption1 = Utils.fixIndexOutOfBounds(mainActivityOptions, mainActivityOption1); mainActivityOption2 = Utils.fixIndexOutOfBounds(mainActivityOptions, mainActivityOption2); @@ -199,7 +200,7 @@ public class CustomizeBottomAppBarFragment extends Fragment { .setTitle(R.string.settings_tab_count) .setSingleChoiceItems(R.array.settings_bottom_app_bar_option_count_options, mainActivityOptionCount / 2 - 1, (dialogInterface, i) -> { mainActivityOptionCount = (i + 1) * 2; - sharedPreferences.edit().putInt((accountName == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_COUNT, mainActivityOptionCount).apply(); + sharedPreferences.edit().putInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_COUNT, mainActivityOptionCount).apply(); mainActivityOptionCountTextView.setText(Integer.toString(mainActivityOptionCount)); dialogInterface.dismiss(); }) @@ -212,7 +213,7 @@ public class CustomizeBottomAppBarFragment extends Fragment { .setSingleChoiceItems(accountName == null ? mainActivityOptionAnonymous : mainActivityOptions, mainActivityOption1, (dialogInterface, i) -> { mainActivityOption1 = i; int optionToSaveToPreference = accountName == null ? Integer.parseInt(mainActivityOptionAnonymousValues[i]) : mainActivityOption1; - sharedPreferences.edit().putInt((accountName == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_1, optionToSaveToPreference).apply(); + sharedPreferences.edit().putInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_1, optionToSaveToPreference).apply(); mainActivityOption1TextView.setText(mainActivityOptions[optionToSaveToPreference]); dialogInterface.dismiss(); }) @@ -225,7 +226,7 @@ public class CustomizeBottomAppBarFragment extends Fragment { .setSingleChoiceItems(accountName == null ? mainActivityOptionAnonymous : mainActivityOptions, mainActivityOption2, (dialogInterface, i) -> { mainActivityOption2 = i; int optionToSaveToPreference = accountName == null ? Integer.parseInt(mainActivityOptionAnonymousValues[i]) : mainActivityOption2; - sharedPreferences.edit().putInt((accountName == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_2, optionToSaveToPreference).apply(); + sharedPreferences.edit().putInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_2, optionToSaveToPreference).apply(); mainActivityOption2TextView.setText(mainActivityOptions[optionToSaveToPreference]); dialogInterface.dismiss(); }) @@ -238,7 +239,7 @@ public class CustomizeBottomAppBarFragment extends Fragment { .setSingleChoiceItems(accountName == null ? mainActivityOptionAnonymous : mainActivityOptions, mainActivityOption3, (dialogInterface, i) -> { mainActivityOption3 = i; int optionToSaveToPreference = accountName == null ? Integer.parseInt(mainActivityOptionAnonymousValues[i]) : mainActivityOption3; - sharedPreferences.edit().putInt((accountName == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_3, optionToSaveToPreference).apply(); + sharedPreferences.edit().putInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_3, optionToSaveToPreference).apply(); mainActivityOption3TextView.setText(mainActivityOptions[optionToSaveToPreference]); dialogInterface.dismiss(); }) @@ -251,7 +252,7 @@ public class CustomizeBottomAppBarFragment extends Fragment { .setSingleChoiceItems(accountName == null ? mainActivityOptionAnonymous : mainActivityOptions, mainActivityOption4, (dialogInterface, i) -> { mainActivityOption4 = i; int optionToSaveToPreference = accountName == null ? Integer.parseInt(mainActivityOptionAnonymousValues[i]) : mainActivityOption4; - sharedPreferences.edit().putInt((accountName == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_4, optionToSaveToPreference).apply(); + sharedPreferences.edit().putInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_4, optionToSaveToPreference).apply(); mainActivityOption4TextView.setText(mainActivityOptions[optionToSaveToPreference]); dialogInterface.dismiss(); }) @@ -273,7 +274,7 @@ public class CustomizeBottomAppBarFragment extends Fragment { } else { optionToSaveToPreference = i; } - sharedPreferences.edit().putInt((accountName == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB, optionToSaveToPreference).apply(); + sharedPreferences.edit().putInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB, optionToSaveToPreference).apply(); mainActivityFABTextView.setText(fabOptions[mainActivityFAB]); dialogInterface.dismiss(); }) @@ -283,12 +284,12 @@ public class CustomizeBottomAppBarFragment extends Fragment { String[] otherActivitiesOptions = resources.getStringArray(R.array.settings_other_activities_bottom_app_bar_options); String[] otherActivitiesOptionAnonymous = resources.getStringArray(R.array.settings_other_activities_bottom_app_bar_options_anonymous); String[] otherActivitiesOptionAnonymousValues = resources.getStringArray(R.array.settings_other_activities_bottom_app_bar_options_anonymous_values); - otherActivitiesOptionCount = sharedPreferences.getInt((accountName == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, 4); - otherActivitiesOption1 = sharedPreferences.getInt((accountName == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, 0); - otherActivitiesOption2 = sharedPreferences.getInt((accountName == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, 1); - otherActivitiesOption3 = sharedPreferences.getInt((accountName == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_3, 2); - otherActivitiesOption4 = sharedPreferences.getInt((accountName == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_4, 3); - otherActivitiesFAB = sharedPreferences.getInt((accountName == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, accountName == null ? 7: 0); + otherActivitiesOptionCount = sharedPreferences.getInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, 4); + otherActivitiesOption1 = sharedPreferences.getInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, 0); + otherActivitiesOption2 = sharedPreferences.getInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, 1); + otherActivitiesOption3 = sharedPreferences.getInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_3, 2); + otherActivitiesOption4 = sharedPreferences.getInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_4, 3); + otherActivitiesFAB = sharedPreferences.getInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, accountName == null ? 7: 0); otherActivitiesOption1 = Utils.fixIndexOutOfBounds(otherActivitiesOptions, otherActivitiesOption1); otherActivitiesOption2 = Utils.fixIndexOutOfBounds(otherActivitiesOptions, otherActivitiesOption2); @@ -317,7 +318,7 @@ public class CustomizeBottomAppBarFragment extends Fragment { .setTitle(R.string.settings_tab_count) .setSingleChoiceItems(R.array.settings_bottom_app_bar_option_count_options, otherActivitiesOptionCount / 2 - 1, (dialogInterface, i) -> { otherActivitiesOptionCount = (i + 1) * 2; - sharedPreferences.edit().putInt((accountName == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, otherActivitiesOptionCount).apply(); + sharedPreferences.edit().putInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_COUNT, otherActivitiesOptionCount).apply(); otherActivitiesOptionCountTextView.setText(Integer.toString(otherActivitiesOptionCount)); dialogInterface.dismiss(); }) @@ -330,7 +331,7 @@ public class CustomizeBottomAppBarFragment extends Fragment { .setSingleChoiceItems(accountName == null ? otherActivitiesOptionAnonymous : otherActivitiesOptions, otherActivitiesOption1, (dialogInterface, i) -> { otherActivitiesOption1 = i; int optionToSaveToPreference = accountName == null ? Integer.parseInt(otherActivitiesOptionAnonymousValues[i]) : otherActivitiesOption1; - sharedPreferences.edit().putInt((accountName == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, optionToSaveToPreference).apply(); + sharedPreferences.edit().putInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_1, optionToSaveToPreference).apply(); otherActivitiesOption1TextView.setText(otherActivitiesOptions[optionToSaveToPreference]); dialogInterface.dismiss(); }) @@ -343,7 +344,7 @@ public class CustomizeBottomAppBarFragment extends Fragment { .setSingleChoiceItems(accountName == null ? otherActivitiesOptionAnonymous : otherActivitiesOptions, otherActivitiesOption2, (dialogInterface, i) -> { otherActivitiesOption2 = i; int optionToSaveToPreference = accountName == null ? Integer.parseInt(otherActivitiesOptionAnonymousValues[i]) : otherActivitiesOption2; - sharedPreferences.edit().putInt((accountName == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, optionToSaveToPreference).apply(); + sharedPreferences.edit().putInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_2, optionToSaveToPreference).apply(); otherActivitiesOption2TextView.setText(otherActivitiesOptions[optionToSaveToPreference]); dialogInterface.dismiss(); }) @@ -356,7 +357,7 @@ public class CustomizeBottomAppBarFragment extends Fragment { .setSingleChoiceItems(accountName == null ? otherActivitiesOptionAnonymous : otherActivitiesOptions, otherActivitiesOption3, (dialogInterface, i) -> { otherActivitiesOption3 = i; int optionToSaveToPreference = accountName == null ? Integer.parseInt(otherActivitiesOptionAnonymousValues[i]) : otherActivitiesOption3; - sharedPreferences.edit().putInt((accountName == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_3, optionToSaveToPreference).apply(); + sharedPreferences.edit().putInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_3, optionToSaveToPreference).apply(); otherActivitiesOption3TextView.setText(otherActivitiesOptions[optionToSaveToPreference]); dialogInterface.dismiss(); }) @@ -369,7 +370,7 @@ public class CustomizeBottomAppBarFragment extends Fragment { .setSingleChoiceItems(accountName == null ? otherActivitiesOptionAnonymous : otherActivitiesOptions, otherActivitiesOption4, (dialogInterface, i) -> { otherActivitiesOption4 = i; int optionToSaveToPreference = accountName == null ? Integer.parseInt(otherActivitiesOptionAnonymousValues[i]) : otherActivitiesOption4; - sharedPreferences.edit().putInt((accountName == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_4, optionToSaveToPreference).apply(); + sharedPreferences.edit().putInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_4, optionToSaveToPreference).apply(); otherActivitiesOption4TextView.setText(otherActivitiesOptions[optionToSaveToPreference]); dialogInterface.dismiss(); }) @@ -391,7 +392,7 @@ public class CustomizeBottomAppBarFragment extends Fragment { } else { optionToSaveToPreference = i; } - sharedPreferences.edit().putInt((accountName == null ? "-" : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, optionToSaveToPreference).apply(); + sharedPreferences.edit().putInt((accountName == null ? Account.ANONYMOUS_ACCOUNT : "") + SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, optionToSaveToPreference).apply(); otherActivitiesFABTextView.setText(fabOptions[otherActivitiesFAB]); dialogInterface.dismiss(); }) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java index ab79f618..e8073caf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditSubscription.java @@ -34,7 +34,7 @@ public class SubredditSubscription { @Override public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { insertSubscription(executor, handler, redditDataRoomDatabase, - subredditData, "-", subredditSubscriptionListener); + subredditData, Account.ANONYMOUS_ACCOUNT, subredditSubscriptionListener); } @Override @@ -56,7 +56,7 @@ public class SubredditSubscription { RedditDataRoomDatabase redditDataRoomDatabase, String subredditName, SubredditSubscriptionListener subredditSubscriptionListener) { - removeSubscription(executor, handler, redditDataRoomDatabase, subredditName, "-", subredditSubscriptionListener); + removeSubscription(executor, handler, redditDataRoomDatabase, subredditName, Account.ANONYMOUS_ACCOUNT, subredditSubscriptionListener); } private static void subredditSubscription(Executor executor, Handler handler, Retrofit oauthRetrofit, @@ -117,7 +117,7 @@ public class SubredditSubscription { executor.execute(() -> { SubscribedSubredditData subscribedSubredditData = new SubscribedSubredditData(subredditData.getId(), subredditData.getName(), subredditData.getIconUrl(), accountName, false); - if (accountName.equals("-")) { + if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { if (!redditDataRoomDatabase.accountDao().isAnonymousAccountInserted()) { redditDataRoomDatabase.accountDao().insert(Account.getAnonymousAccount()); } @@ -132,7 +132,7 @@ public class SubredditSubscription { String subredditName, String accountName, SubredditSubscriptionListener subredditSubscriptionListener) { executor.execute(() -> { - if (accountName.equals("-")) { + if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { if (!redditDataRoomDatabase.accountDao().isAnonymousAccountInserted()) { redditDataRoomDatabase.accountDao().insert(Account.getAnonymousAccount()); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserFollowing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserFollowing.java index 1bde2aa3..b2748f78 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserFollowing.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserFollowing.java @@ -39,7 +39,7 @@ public class UserFollowing { redditDataRoomDatabase.accountDao().insert(Account.getAnonymousAccount()); } redditDataRoomDatabase.subscribedUserDao().insert(new SubscribedUserData(userData.getName(), userData.getIconUrl(), - "-", false)); + Account.ANONYMOUS_ACCOUNT, false)); handler.post(userFollowingListener::onUserFollowingSuccess); }); @@ -64,7 +64,7 @@ public class UserFollowing { RedditDataRoomDatabase redditDataRoomDatabase, UserFollowingListener userFollowingListener) { executor.execute(() -> { - redditDataRoomDatabase.subscribedUserDao().deleteSubscribedUser(username, "-"); + redditDataRoomDatabase.subscribedUserDao().deleteSubscribedUser(username, Account.ANONYMOUS_ACCOUNT); handler.post(userFollowingListener::onUserFollowingSuccess); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java index 3d463845..10104f5a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java @@ -28,6 +28,7 @@ public class APIUtils { public static final String CLIENT_ID_KEY = "client_id"; public static final String CLIENT_SECRET_KEY = "client_secret"; public static final String CLIENT_ID = "NOe2iKrPPzwscA"; + public static final String APPLICATION_ONLY_CLIENT_ID = "PLEASE_USE_YOUR_CLIENT_ID"; public static final String IMGUR_CLIENT_ID = "Client-ID cc671794e0ab397"; public static final String REDGIFS_CLIENT_ID = "1828d0bcc93-15ac-bde6-0005-d2ecbe8daab3"; public static final String REDGIFS_CLIENT_SECRET = "TJBlw7jRXW65NAGgFBtgZHu97WlzRXHYybK81sZ9dLM="; @@ -51,7 +52,10 @@ public class APIUtils { public static final String GRANT_TYPE_KEY = "grant_type"; public static final String GRANT_TYPE_REFRESH_TOKEN = "refresh_token"; public static final String GRANT_TYPE_CLIENT_CREDENTIALS = "client_credentials"; + public static final String GRANT_TYPE_INSTALLED_CLIENT = "https://oauth.reddit.com/grants/installed_client"; public static final String REFRESH_TOKEN_KEY = "refresh_token"; + public static final String DEVICE_ID_KEY = "device_id"; + public static final String DEVICE_ID = "DO_NOT_TRACK_THIS_DEVICE"; public static final String DIR_KEY = "dir"; public static final String ID_KEY = "id"; @@ -122,6 +126,14 @@ public class APIUtils { return params; } + public static Map<String, String> getApplicationOnlyBasicAuthHeader() { + Map<String, String> params = new HashMap<>(); + String credentials = String.format("%s:%s", APIUtils.APPLICATION_ONLY_CLIENT_ID, ""); + String auth = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP); + params.put(APIUtils.AUTHORIZATION_KEY, auth); + return params; + } + public static Map<String, String> getOAuthHeader(String accessToken) { Map<String, String> params = new HashMap<>(); params.put(APIUtils.AUTHORIZATION_KEY, APIUtils.AUTHORIZATION_BASE + accessToken); |