From d9b9a7c3c13303e2f61b2cb557ab96ec1a23a7ac Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 20 Feb 2020 15:10:50 +0800 Subject: Add an option to show comment dividers. Put theme option to InterfacePreferenceFragment. --- .../Activity/ViewPostDetailActivity.java | 6 ++- .../Adapter/CommentAndPostRecyclerViewAdapter.java | 16 +++++- .../CommentsListingRecyclerViewAdapter.java | 13 ++++- .../Fragment/CommentsListingFragment.java | 4 +- .../Settings/InterfacePreferenceFragment.java | 59 ++++++++++++++++++++++ .../Settings/MainPreferenceFragment.java | 50 ------------------ .../Utils/SharedPreferencesUtils.java | 1 + 7 files changed, 93 insertions(+), 56 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java index a3123182..65711954 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -176,6 +176,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS private boolean mLockFab; private boolean mSwipeUpToHideFab; private boolean mExpandChildren; + private boolean mShowCommentDivider; private LinearLayoutManager mLinearLayoutManager; private CommentAndPostRecyclerViewAdapter mAdapter; private RecyclerView.SmoothScroller mSmoothScroller; @@ -263,6 +264,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mLockFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false); mSwipeUpToHideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false); mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false); + mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false); mGlide = Glide.with(this); mLocale = getResources().getConfiguration().locale; @@ -508,7 +510,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler, - mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, + mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, mShowCommentDivider, new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { @Override public void updatePost(Post post) { @@ -631,7 +633,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler, - mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, + mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, mShowCommentDivider, new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { @Override public void updatePost(Post post) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index 80887700..82270285 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -123,6 +123,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter mCommentViewModel.retryLoadingMore()); + voteButtonsOnTheRight, mShowElapsedTime, mShowCommentDivider, () -> mCommentViewModel.retryLoadingMore()); String username = getArguments().getString(EXTRA_USERNAME); String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.value); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java index 3ce67392..4123f276 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java @@ -1,9 +1,14 @@ package ml.docilealligator.infinityforreddit.Settings; +import android.app.Activity; +import android.content.Context; +import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatDelegate; import androidx.fragment.app.Fragment; import androidx.preference.ListPreference; import androidx.preference.PreferenceFragmentCompat; @@ -19,15 +24,24 @@ import ml.docilealligator.infinityforreddit.Event.ShowDividerInCompactLayoutPref import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + /** * A simple {@link Fragment} subclass. */ public class InterfacePreferenceFragment extends PreferenceFragmentCompat { + private Activity activity; + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.interface_preference, rootKey); + ListPreference themePreference = findPreference(SharedPreferencesUtils.THEME_KEY); + SwitchPreference amoledDarkSwitch = findPreference(SharedPreferencesUtils.AMOLED_DARK_KEY); SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY); SwitchPreference bottomAppBarSwitch = findPreference(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY); SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY); @@ -35,6 +49,45 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat { ListPreference defaultPostLayoutSwitch = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY); SwitchPreference showDividerInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT); + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + + if (themePreference != null) { + if (systemDefault) { + themePreference.setEntries(R.array.settings_theme_q); + } else { + themePreference.setEntries(R.array.settings_theme); + } + + themePreference.setOnPreferenceChangeListener((preference, newValue) -> { + int option = Integer.parseInt((String) newValue); + switch (option) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if (systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + } + return true; + }); + } + + if (amoledDarkSwitch != null) { + amoledDarkSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_NO) { + EventBus.getDefault().post(new RecreateActivityEvent()); + activity.recreate(); + } + return true; + }); + } + if (immersiveInterfaceSwitch != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { immersiveInterfaceSwitch.setVisible(true); @@ -82,4 +135,10 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat { }); } } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + activity = (Activity) context; + } } 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 58bd8cf1..5733c32e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java @@ -4,13 +4,9 @@ package ml.docilealligator.infinityforreddit.Settings; import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.os.Build; import android.os.Bundle; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatDelegate; -import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; @@ -27,11 +23,6 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - /** * A simple {@link PreferenceFragmentCompat} subclass. */ @@ -46,22 +37,10 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { setPreferencesFromResource(R.xml.main_preferences, rootKey); ((Infinity) activity.getApplication()).getAppComponent().inject(this); - SwitchPreference amoledDarkSwitch = findPreference(SharedPreferencesUtils.AMOLED_DARK_KEY); SwitchPreference confirmToExitSwitch = findPreference(SharedPreferencesUtils.CONFIRM_TO_EXIT); SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY); SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY); SwitchPreference blurSpoilerSwitch = findPreference(SharedPreferencesUtils.BLUR_SPOILER_KEY); - ListPreference themePreference = findPreference(SharedPreferencesUtils.THEME_KEY); - - if (amoledDarkSwitch != null) { - amoledDarkSwitch.setOnPreferenceChangeListener((preference, newValue) -> { - if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_NO) { - EventBus.getDefault().post(new RecreateActivityEvent()); - activity.recreate(); - } - return true; - }); - } if (confirmToExitSwitch != null) { confirmToExitSwitch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @@ -104,35 +83,6 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { return true; }); } - - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - - if (themePreference != null) { - if (systemDefault) { - themePreference.setEntries(R.array.settings_theme_q); - } else { - themePreference.setEntries(R.array.settings_theme); - } - - themePreference.setOnPreferenceChangeListener((preference, newValue) -> { - int option = Integer.parseInt((String) newValue); - switch (option) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - } - return true; - }); - } } @Override 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 3717a6cd..357ee2a5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -74,4 +74,5 @@ public class SharedPreferencesUtils { public static final String SHOW_TOP_LEVEL_COMMENTS_FIRST = "show_top_level_comments_first"; public static final String CONFIRM_TO_EXIT = "confirm_to_exit"; public static final String LOCK_BOTTOM_APP_BAR = "lock_bottom_app_bar"; + public static final String SHOW_COMMENT_DIVIDER = "show_comment_divider"; } -- cgit v1.2.3