diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-12-17 14:35:11 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-12-17 14:35:11 +0000 |
commit | 0d56a8120699812f385798918322a235ef70dbf8 (patch) | |
tree | adbd1e4ae6dd5f479270b0b4029fda8e449f1952 /app/src/main/java/ml | |
parent | e69c26db19b4940acdd25573a0b92c67eef0e076 (diff) | |
download | infinity-for-reddit-0d56a8120699812f385798918322a235ef70dbf8.tar infinity-for-reddit-0d56a8120699812f385798918322a235ef70dbf8.tar.gz infinity-for-reddit-0d56a8120699812f385798918322a235ef70dbf8.tar.bz2 infinity-for-reddit-0d56a8120699812f385798918322a235ef70dbf8.tar.lz infinity-for-reddit-0d56a8120699812f385798918322a235ef70dbf8.tar.xz infinity-for-reddit-0d56a8120699812f385798918322a235ef70dbf8.tar.zst infinity-for-reddit-0d56a8120699812f385798918322a235ef70dbf8.zip |
Fix sorting and changing post layout for multireddits.
Diffstat (limited to 'app/src/main/java/ml')
4 files changed, 33 insertions, 21 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java index 37bc8cdb..99bd19fc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java @@ -166,6 +166,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment(); Bundle bottomSheetBundle = new Bundle(); bottomSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true); + bottomSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_RANDOM_TYPE, true); sortTypeBottomSheetFragment.setArguments(bottomSheetBundle); sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment(); @@ -173,13 +174,6 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams(); - - //Get status bar height - int statusBarHeight = 0; - int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); - if (resourceId > 0) { - statusBarHeight = getResources().getDimensionPixelSize(resourceId); - } } private void getCurrentAccountAndInitializeFragment() { @@ -285,9 +279,11 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT @Override public void sortTypeSelected(SortType sortType) { - mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST, sortType.getType().name()).apply(); + mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiPath, + sortType.getType().name()).apply(); if(sortType.getTime() != null) { - mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST, sortType.getTime().name()).apply(); + mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE+ multiPath, + sortType.getTime().name()).apply(); } ((PostFragment) mFragment).changeSortType(sortType); @@ -304,7 +300,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT @Override public void postLayoutSelected(int postLayout) { if (mFragment != null) { - //mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + multiPath, postLayout).apply(); + mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiPath, postLayout).apply(); ((FragmentCommunicator) mFragment).changePostLayout(postLayout); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index f2c9f494..37d48957 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -420,16 +420,19 @@ public class PostFragment extends Fragment implements FragmentCommunicator { filter, nsfw); } } else if(postType == PostDataSource.TYPE_MULTI_REDDIT) { - String multiRedditName = getArguments().getString(EXTRA_NAME); + String multiRedditPath = getArguments().getString(EXTRA_NAME); String sort; String sortTime = null; SortType sortType; - sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_ALL_POST, SortType.Type.HOT.name()); + sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath, + SortType.Type.HOT.name()); if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) { - sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_ALL_POST, SortType.Time.ALL.name()); + sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath, + SortType.Time.ALL.name()); } - postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, SharedPreferencesUtils.POST_LAYOUT_CARD); + postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath, + SharedPreferencesUtils.POST_LAYOUT_CARD); if(sortTime != null) { sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime)); @@ -448,7 +451,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void typeChipClicked(int filter) { Intent intent = new Intent(activity, FilteredThingActivity.class); - intent.putExtra(FilteredThingActivity.EXTRA_NAME, multiRedditName); + intent.putExtra(FilteredThingActivity.EXTRA_NAME, multiRedditPath); intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType); intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter); startActivity(intent); @@ -457,11 +460,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { if (accessToken == null) { factory = new PostViewModel.Factory(mRetrofit, accessToken, - getResources().getConfiguration().locale, multiRedditName, postType, sortType, + getResources().getConfiguration().locale, multiRedditPath, postType, sortType, filter, nsfw); } else { factory = new PostViewModel.Factory(mOauthRetrofit, accessToken, - getResources().getConfiguration().locale, multiRedditName, postType, sortType, + getResources().getConfiguration().locale, multiRedditPath, postType, sortType, filter, nsfw); } } else if (postType == PostDataSource.TYPE_USER) { @@ -587,6 +590,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mFetchPostInfoLinearLayout.setVisibility(View.GONE); mGlide.clear(mFetchPostInfoImageView); } + mAdapter.removeFooter(); + hasPost = false; + if (isInLazyMode) { + stopLazyMode(); + } mPostViewModel.changeSortType(sortType); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTypeBottomSheetFragment.java index 4f9d67b7..f5ee3696 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTypeBottomSheetFragment.java @@ -29,6 +29,7 @@ import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; public class SortTypeBottomSheetFragment extends RoundedBottomSheetDialogFragment { public static final String EXTRA_NO_BEST_TYPE = "ENBT"; + public static final String EXTRA_NO_RANDOM_TYPE = "ENRT"; @BindView(R.id.best_type_text_view_sort_type_bottom_sheet_fragment) TextView bestTypeTextView; @BindView(R.id.hot_type_text_view_sort_type_bottom_sheet_fragment) @@ -78,10 +79,14 @@ public class SortTypeBottomSheetFragment extends RoundedBottomSheetDialogFragmen dismiss(); }); - randomTypeTextView.setOnClickListener(view -> { - ((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.RANDOM)); - dismiss(); - }); + if (getArguments() == null || (getArguments().containsKey(EXTRA_NO_RANDOM_TYPE) && getArguments().getBoolean(EXTRA_NO_RANDOM_TYPE))) { + randomTypeTextView.setVisibility(View.GONE); + } else { + randomTypeTextView.setOnClickListener(view -> { + ((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.RANDOM)); + dismiss(); + }); + } risingTypeTextView.setOnClickListener(view -> { ((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.RISING)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java index 9e04530f..f4cc86fc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -40,6 +40,8 @@ public class SharedPreferencesUtils { public static final String SORT_TIME_SEARCH_POST = "sort_time_search_post"; public static final String SORT_TYPE_SUBREDDIT_POST = "sort_type_subreddit_post"; public static final String SORT_TIME_SUBREDDIT_POST = "sort_time_subreddit_post"; + public static final String SORT_TYPE_MULTI_REDDIT_POST_BASE = "sort_type_multi_reddit_post_"; + public static final String SORT_TIME_MULTI_REDDIT_POST_BASE = "sort_time_multi_reddit_post_"; public static final String SORT_TYPE_USER_POST = "sort_type_user_post"; public static final String SORT_TIME_USER_POST = "sort_time_user_post"; public static final String SORT_TYPE_USER_COMMENT = "sort_type_user_comment"; @@ -51,6 +53,7 @@ public class SharedPreferencesUtils { public static final String POST_LAYOUT_POPULAR_POST = "post_layout_popular_post"; public static final String POST_LAYOUT_ALL_POST = "post_layout_all_post"; public static final String POST_LAYOUT_SUBREDDIT_POST_BASE = "post_layout_subreddit_post_"; + public static final String POST_LAYOUT_MULTI_REDDIT_POST_BASE = "post_layout_multi_reddit_post_"; public static final String POST_LAYOUT_USER_POST_BASE = "post_layout_user_post_"; public static final String POST_LAYOUT_SEARCH_POST = "post_layout_search_post"; public static final int POST_LAYOUT_CARD = 0; |