Add an option to show comment dividers. Put theme option to InterfacePreferenceFragment.

This commit is contained in:
Alex Ning 2020-02-20 15:10:50 +08:00
parent 59465390a9
commit d9b9a7c3c1
12 changed files with 329 additions and 273 deletions

View File

@ -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) {

View File

@ -123,6 +123,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime;
private boolean mExpandChildren;
private boolean mShowCommentDivider;
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
private boolean isInitiallyLoading;
private boolean isInitiallyLoadingFailed;
@ -138,7 +139,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
String accessToken, String accountName, Post post, Locale locale,
String singleCommentId, boolean isSingleCommentThreadMode,
boolean needBlurNSFW, boolean needBlurSpoiler, boolean voteButtonsOnTheRight,
boolean showElapsedTime, boolean expandChildren,
boolean showElapsedTime, boolean expandChildren, boolean showCommentDivider,
CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
mActivity = activity;
mRetrofit = retrofit;
@ -229,6 +230,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mVoteButtonsOnTheRight = voteButtonsOnTheRight;
mShowElapsedTime = showElapsedTime;
mExpandChildren = expandChildren;
mShowCommentDivider = showCommentDivider;
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
isInitiallyLoading = true;
isInitiallyLoadingFailed = false;
@ -1940,6 +1942,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
ImageView replyButton;
@BindView(R.id.vertical_block_item_post_comment)
View verticalBlock;
@BindView(R.id.divider_item_comment)
View commentDivider;
CommentViewHolder(View itemView) {
super(itemView);
@ -1964,6 +1968,10 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
constraintSet.setHorizontalBias(moreButton.getId(), 0);
constraintSet.applyTo(bottomConstraintLayout);
}
if (mShowCommentDivider) {
commentDivider.setVisibility(View.VISIBLE);
}
}
}
@ -1972,10 +1980,16 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
View verticalBlock;
@BindView(R.id.placeholder_text_view_item_load_more_comments)
TextView placeholderTextView;
@BindView(R.id.divider_item_load_more_comments_placeholder)
View commentDivider;
LoadMoreChildCommentsViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
if (mShowCommentDivider) {
commentDivider.setVisibility(View.VISIBLE);
}
}
}

View File

@ -70,13 +70,15 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
private int mColorAccent;
private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime;
private boolean mShowCommentDivider;
private NetworkState networkState;
private RetryLoadingMoreCallback mRetryLoadingMoreCallback;
public CommentsListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit,
String accessToken, String accountName,
boolean voteButtonsOnTheRight,
boolean showElapsedTime, RetryLoadingMoreCallback retryLoadingMoreCallback) {
boolean voteButtonsOnTheRight, boolean showElapsedTime,
boolean showCommentDivider,
RetryLoadingMoreCallback retryLoadingMoreCallback) {
super(DIFF_CALLBACK);
mContext = context;
mOauthRetrofit = oauthRetrofit;
@ -109,6 +111,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
mAccountName = accountName;
mVoteButtonsOnTheRight = voteButtonsOnTheRight;
mShowElapsedTime = showElapsedTime;
mShowCommentDivider = showCommentDivider;
mRetryLoadingMoreCallback = retryLoadingMoreCallback;
mTextColorPrimaryDark = mContext.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme);
mColorAccent = mContext.getResources().getColor(R.color.colorAccent);
@ -429,6 +432,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
ImageView expandButton;
@BindView(R.id.reply_button_item_post_comment)
ImageView replyButton;
@BindView(R.id.divider_item_comment)
View commentDivider;
DataViewHolder(View itemView) {
super(itemView);
@ -452,6 +457,10 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
constraintSet.setHorizontalBias(moreButton.getId(), 0);
constraintSet.applyTo(bottomConstraintLayout);
}
if (mShowCommentDivider) {
commentDivider.setVisibility(View.VISIBLE);
}
}
}

View File

@ -87,6 +87,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
private Activity mActivity;
private CommentsListingRecyclerViewAdapter mAdapter;
private boolean mShowElapsedTime;
private boolean mShowCommentDivider;
public CommentsListingFragment() {
// Required empty public constructor
@ -116,6 +117,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
}
mShowElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
if (savedInstanceState == null) {
getCurrentAccountAndBindView(resources);
@ -150,7 +152,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mOauthRetrofit,
getArguments().getString(EXTRA_ACCESS_TOKEN), getArguments().getString(EXTRA_ACCOUNT_NAME),
voteButtonsOnTheRight, mShowElapsedTime, () -> 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);

View File

@ -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;
}
}

View File

@ -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

View File

@ -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";
}

View File

@ -4,8 +4,13 @@
android:id="@+id/linear_layout_item_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="?attr/cardViewBackgroundColor">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="@+id/vertical_block_item_post_comment"
android:layout_width="0dp"
@ -201,22 +206,17 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<!--<ImageView
android:id="@+id/share_button_item_post_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:background="?actionBarItemBackground"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_share_grey_24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>-->
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</LinearLayout>
<View
android:id="@+id/divider_item_comment"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/dividerColor"
android:visibility="gone" />
</LinearLayout>

View File

@ -2,8 +2,13 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="?attr/cardViewBackgroundColor">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="@+id/vertical_block_item_load_more_comments"
android:layout_width="wrap_content"
@ -20,4 +25,12 @@
android:textColor="@color/primaryTextColor"
android:textSize="?attr/font_default" />
</LinearLayout>
<View
android:id="@+id/divider_item_load_more_comments_placeholder"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/dividerColor" />
</LinearLayout>

View File

@ -308,6 +308,7 @@
<string name="settings_mute_video_title">Mute Video</string>
<string name="settings_confirm_to_exit">Confirm to Exit</string>
<string name="settings_show_top_level_comments_first_title">Show Top-level Comments First</string>
<string name="settings_show_comment_divider_title">Show comment divider</string>
<string name="settings_show_elapsed_time">Show Elapsed Time in Posts and Comments</string>
<string name="settings_default_post_layout">Default Post Layout</string>
<string name="settings_show_divider_in_compact_layout">Show Divider in Compact Layout</string>

View File

@ -2,6 +2,19 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ListPreference
app:defaultValue="2"
app:entryValues="@array/settings_theme_values"
app:key="theme"
app:icon="@drawable/ic_outline_color_lens_24px"
app:title="@string/settings_theme_title"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
app:defaultValue="false"
app:key="amoled_dark"
app:title="@string/settings_amoled_dark_title" />
<Preference
app:title="@string/settings_font_size_title"
app:icon="@drawable/ic_font_size_24dp"
@ -46,4 +59,9 @@
app:key="show_top_level_comments_first"
app:title="@string/settings_show_top_level_comments_first_title" />
<SwitchPreference
app:defaultValue="false"
app:key="show_comment_divider"
app:title="@string/settings_show_comment_divider_title" />
</PreferenceScreen>

View File

@ -7,19 +7,6 @@
app:title="@string/settings_notification_master_title"
app:fragment="ml.docilealligator.infinityforreddit.Settings.NotificationPreferenceFragment" />
<ListPreference
app:defaultValue="2"
app:entryValues="@array/settings_theme_values"
app:key="theme"
app:icon="@drawable/ic_outline_color_lens_24px"
app:title="@string/settings_theme_title"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
app:defaultValue="false"
app:key="amoled_dark"
app:title="@string/settings_amoled_dark_title" />
<Preference
app:icon="@drawable/ic_interface_24dp"
app:title="@string/settings_interface_title"