diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-01-11 02:39:49 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-01-11 02:39:49 +0000 |
commit | cb9154369070fe3773c16da0d4e7b3c33b716a1f (patch) | |
tree | c6619bb95f66f605c4d7d84da0cc0fb9329de723 /app/src/main/java | |
parent | b04ad8956dac3d5d07a389b56e1e22e70bf9ff51 (diff) | |
download | infinity-for-reddit-cb9154369070fe3773c16da0d4e7b3c33b716a1f.tar infinity-for-reddit-cb9154369070fe3773c16da0d4e7b3c33b716a1f.tar.gz infinity-for-reddit-cb9154369070fe3773c16da0d4e7b3c33b716a1f.tar.bz2 infinity-for-reddit-cb9154369070fe3773c16da0d4e7b3c33b716a1f.tar.lz infinity-for-reddit-cb9154369070fe3773c16da0d4e7b3c33b716a1f.tar.xz infinity-for-reddit-cb9154369070fe3773c16da0d4e7b3c33b716a1f.tar.zst infinity-for-reddit-cb9154369070fe3773c16da0d4e7b3c33b716a1f.zip |
Setting default post layout is now available. Add an option to hide the divider in post compact layout.
Diffstat (limited to '')
7 files changed, 80 insertions, 18 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index c5eb9ac2..70b38606 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -3,10 +3,8 @@ package ml.docilealligator.infinityforreddit.Activity; import android.app.Activity; import android.content.Intent; 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.os.Build; import android.os.Bundle; import android.util.TypedValue; @@ -27,7 +25,6 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.core.content.ContextCompat; import androidx.core.view.GravityCompat; import androidx.core.widget.NestedScrollView; import androidx.drawerlayout.widget.DrawerLayout; @@ -464,8 +461,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb lp.setAnchorId(View.NO_ID); lp.gravity = Gravity.END | Gravity.BOTTOM; fab.setLayoutParams(lp); - fab.setImageTintList(ColorStateList.valueOf(Color.WHITE)); - fab.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(this, R.color.backgroundColorPrimary))); } fab.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 2a4e6fe1..ad9c215d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -102,6 +102,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView private boolean mNeedBlurNSFW; private boolean mNeedBlurSpoiler; private boolean mShowElapsedTime; + private boolean mShowDividerInCompactLayout; private NetworkState networkState; private Callback mCallback; private ShareLinkBottomSheetFragment mShareLinkBottomSheetFragment; @@ -110,7 +111,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView RedditDataRoomDatabase redditDataRoomDatabase, String accessToken, int postType, int postLayout, boolean displaySubredditName, boolean needBlurNSFW, boolean needBlurSpoiler, boolean voteButtonsOnTheRight, - boolean showElapsedTime, Callback callback) { + boolean showElapsedTime, boolean showDividerInCompactLayout, Callback callback) { super(DIFF_CALLBACK); if (activity != null) { mActivity = activity; @@ -123,6 +124,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mNeedBlurSpoiler = needBlurSpoiler; mVoteButtonsOnTheRight = voteButtonsOnTheRight; mShowElapsedTime = showElapsedTime; + mShowDividerInCompactLayout = showDividerInCompactLayout; mPostLayout = postLayout; mGlide = Glide.with(mActivity.getApplicationContext()); mRedditDataRoomDatabase = redditDataRoomDatabase; @@ -891,6 +893,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView ((PostCompactViewHolder) holder).postTimeTextView.setText(postTime); } + if (mShowDividerInCompactLayout) { + ((PostCompactViewHolder) holder).divider.setVisibility(View.VISIBLE); + } else { + ((PostCompactViewHolder) holder).divider.setVisibility(View.GONE); + } + ((PostCompactViewHolder) holder).titleTextView.setText(title); ((PostCompactViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType())); @@ -1377,6 +1385,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mShowElapsedTime = showElapsedTime; } + public void setShowDividerInCompactLayout(boolean showDividerInCompactLayout) { + mShowDividerInCompactLayout = showDividerInCompactLayout; + } + private boolean hasExtraRow() { return networkState != null && networkState.getStatus() != NetworkState.Status.SUCCESS; } @@ -1601,6 +1613,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView ImageView saveButton; @BindView(R.id.share_button_item_post_compact) ImageView shareButton; + @BindView(R.id.divider_item_post_compact) + View divider; PostCompactViewHolder(View itemView) { super(itemView); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangePostLayoutEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangePostLayoutEvent.java new file mode 100644 index 00000000..a02b1373 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangePostLayoutEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.Event; + +public class ChangePostLayoutEvent { + public int postLayout; + + public ChangePostLayoutEvent(int postLayout) { + this.postLayout = postLayout; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ShowDividerInCompactLayoutPreferenceEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ShowDividerInCompactLayoutPreferenceEvent.java new file mode 100644 index 00000000..eb53c58e --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ShowDividerInCompactLayoutPreferenceEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.Event; + +public class ShowDividerInCompactLayoutPreferenceEvent { + public boolean showDividerInCompactLayout; + + public ShowDividerInCompactLayoutPreferenceEvent(boolean showDividerInCompactLayout) { + this.showDividerInCompactLayout = showDividerInCompactLayout; + } +} 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 785c460a..7ebd735a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -53,10 +53,12 @@ import ml.docilealligator.infinityforreddit.Activity.MainActivity; import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity; import ml.docilealligator.infinityforreddit.Adapter.PostRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; +import ml.docilealligator.infinityforreddit.Event.ChangePostLayoutEvent; import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent; import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList; +import ml.docilealligator.infinityforreddit.Event.ShowDividerInCompactLayoutPreferenceEvent; import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.NetworkState; @@ -318,6 +320,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { boolean needBlurSpoiler = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_SPOILER_KEY, false); boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false); boolean showElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false); + boolean showDividerInCompactLayout = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT, true); + int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0")); if (postType == PostDataSource.TYPE_SEARCH) { String subredditName = getArguments().getString(EXTRA_NAME); @@ -326,11 +330,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, SortType.Type.RELEVANCE.name()); String sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, SortType.Time.ALL.name()); SortType sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime)); - postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, SharedPreferencesUtils.POST_LAYOUT_CARD); + postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout); mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler, - voteButtonsOnTheRight, showElapsedTime, new PostRecyclerViewAdapter.Callback() { + voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); @@ -369,20 +373,20 @@ public class PostFragment extends Fragment implements FragmentCommunicator { if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) { sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_POPULAR_POST, SortType.Time.ALL.name()); } - postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, SharedPreferencesUtils.POST_LAYOUT_CARD); + postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, defaultPostLayout); } else { sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_ALL_POST, 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()); } - postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, SharedPreferencesUtils.POST_LAYOUT_CARD); + postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, defaultPostLayout); } } else { sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST, SortType.Type.HOT.name()); if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) { sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST, SortType.Time.ALL.name()); } - postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, SharedPreferencesUtils.POST_LAYOUT_CARD); + postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, defaultPostLayout); } if(sortTime != null) { @@ -393,7 +397,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, accessToken, postType, postLayout, displaySubredditName, needBlurNsfw, needBlurSpoiler, - voteButtonsOnTheRight, showElapsedTime, new PostRecyclerViewAdapter.Callback() { + voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); @@ -431,7 +435,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { SortType.Time.ALL.name()); } postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath, - SharedPreferencesUtils.POST_LAYOUT_CARD); + defaultPostLayout); if(sortTime != null) { sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime)); @@ -441,7 +445,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler, - voteButtonsOnTheRight, showElapsedTime, new PostRecyclerViewAdapter.Callback() { + voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); @@ -483,11 +487,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } else { sortType = new SortType(SortType.Type.valueOf(sort)); } - postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, SharedPreferencesUtils.POST_LAYOUT_CARD); + postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout); mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler, - voteButtonsOnTheRight, showElapsedTime, new PostRecyclerViewAdapter.Callback() { + voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); @@ -522,11 +526,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } else { sortType = new SortType(SortType.Type.valueOf(sort)); } - postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, SharedPreferencesUtils.POST_LAYOUT_CARD); + postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout); mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler, - voteButtonsOnTheRight, showElapsedTime, new PostRecyclerViewAdapter.Callback() { + voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); @@ -754,6 +758,17 @@ public class PostFragment extends Fragment implements FragmentCommunicator { refreshAdapter(); } + @Subscribe + public void onChangePostLayoutEvent(ChangePostLayoutEvent event) { + changePostLayout(event.postLayout); + } + + @Subscribe + public void onShowDividerInCompactLayoutPreferenceEvent(ShowDividerInCompactLayoutPreferenceEvent event) { + mAdapter.setShowDividerInCompactLayout(event.showDividerInCompactLayout); + refreshAdapter(); + } + private void refreshAdapter() { int previousPosition = -1; if (mLinearLayoutManager != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java index 8228333e..e6b9f04b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java @@ -18,10 +18,12 @@ import javax.inject.Inject; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; +import ml.docilealligator.infinityforreddit.Event.ChangePostLayoutEvent; import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent; import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; +import ml.docilealligator.infinityforreddit.Event.ShowDividerInCompactLayoutPreferenceEvent; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; @@ -52,6 +54,8 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { SwitchPreference bottomAppBarSwitch = findPreference(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY); SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY); SwitchPreference showElapsedTimeSwitch = findPreference(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY); + ListPreference defaultPostLayoutSwitch = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY); + SwitchPreference showDividerInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT); SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY); SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY); SwitchPreference blurSpoilerSwitch = findPreference(SharedPreferencesUtils.BLUR_SPOILER_KEY); @@ -100,6 +104,20 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { }); } + if (defaultPostLayoutSwitch != null) { + defaultPostLayoutSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangePostLayoutEvent(Integer.parseInt((String) newValue))); + return true; + }); + } + + if (showDividerInCompactLayout != null) { + showDividerInCompactLayout.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ShowDividerInCompactLayoutPreferenceEvent((Boolean) newValue)); + return true; + }); + } + if (nsfwSwitch != null) { nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeNSFWEvent((Boolean) newValue)); 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 b0434d82..7154f06e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -62,6 +62,8 @@ public class SharedPreferencesUtils { public static final int POST_LAYOUT_COMPACT = 1; public static final String PULL_NOTIFICATION_TIME = "pull_notification_time"; public static final String SHOW_ELAPSED_TIME_KEY = "show_elapsed_time"; + public static final String DEFAULT_POST_LAYOUT_KEY = "default_post_layout"; + public static final String SHOW_DIVIDER_IN_COMPACT_LAYOUT = "show_divider_in_compact_layout"; public static final String SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL = "swipe_to_go_back_from_post_detail"; public static final String VOLUME_KEYS_NAVIGATE_COMMENTS = "volume_keys_navigate_comments"; public static final String VOLUME_KEYS_NAVIGATE_POSTS = "volume_keys_navigate_posts"; |