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 mLockFab;
private boolean mSwipeUpToHideFab; private boolean mSwipeUpToHideFab;
private boolean mExpandChildren; private boolean mExpandChildren;
private boolean mShowCommentDivider;
private LinearLayoutManager mLinearLayoutManager; private LinearLayoutManager mLinearLayoutManager;
private CommentAndPostRecyclerViewAdapter mAdapter; private CommentAndPostRecyclerViewAdapter mAdapter;
private RecyclerView.SmoothScroller mSmoothScroller; 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); 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); 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); mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false);
mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
mGlide = Glide.with(this); mGlide = Glide.with(this);
mLocale = getResources().getConfiguration().locale; mLocale = getResources().getConfiguration().locale;
@ -508,7 +510,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit, mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost, mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost,
mLocale, mSingleCommentId, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler, mLocale, mSingleCommentId, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler,
mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, mShowCommentDivider,
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override @Override
public void updatePost(Post post) { public void updatePost(Post post) {
@ -631,7 +633,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide,
mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId,
isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler,
mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, mShowCommentDivider,
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override @Override
public void updatePost(Post post) { public void updatePost(Post post) {

View File

@ -123,6 +123,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private boolean mVoteButtonsOnTheRight; private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime; private boolean mShowElapsedTime;
private boolean mExpandChildren; private boolean mExpandChildren;
private boolean mShowCommentDivider;
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback; private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
private boolean isInitiallyLoading; private boolean isInitiallyLoading;
private boolean isInitiallyLoadingFailed; private boolean isInitiallyLoadingFailed;
@ -138,7 +139,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
String accessToken, String accountName, Post post, Locale locale, String accessToken, String accountName, Post post, Locale locale,
String singleCommentId, boolean isSingleCommentThreadMode, String singleCommentId, boolean isSingleCommentThreadMode,
boolean needBlurNSFW, boolean needBlurSpoiler, boolean voteButtonsOnTheRight, boolean needBlurNSFW, boolean needBlurSpoiler, boolean voteButtonsOnTheRight,
boolean showElapsedTime, boolean expandChildren, boolean showElapsedTime, boolean expandChildren, boolean showCommentDivider,
CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) { CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
mActivity = activity; mActivity = activity;
mRetrofit = retrofit; mRetrofit = retrofit;
@ -229,6 +230,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mVoteButtonsOnTheRight = voteButtonsOnTheRight; mVoteButtonsOnTheRight = voteButtonsOnTheRight;
mShowElapsedTime = showElapsedTime; mShowElapsedTime = showElapsedTime;
mExpandChildren = expandChildren; mExpandChildren = expandChildren;
mShowCommentDivider = showCommentDivider;
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback; mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
isInitiallyLoading = true; isInitiallyLoading = true;
isInitiallyLoadingFailed = false; isInitiallyLoadingFailed = false;
@ -1940,6 +1942,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
ImageView replyButton; ImageView replyButton;
@BindView(R.id.vertical_block_item_post_comment) @BindView(R.id.vertical_block_item_post_comment)
View verticalBlock; View verticalBlock;
@BindView(R.id.divider_item_comment)
View commentDivider;
CommentViewHolder(View itemView) { CommentViewHolder(View itemView) {
super(itemView); super(itemView);
@ -1964,6 +1968,10 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
constraintSet.setHorizontalBias(moreButton.getId(), 0); constraintSet.setHorizontalBias(moreButton.getId(), 0);
constraintSet.applyTo(bottomConstraintLayout); constraintSet.applyTo(bottomConstraintLayout);
} }
if (mShowCommentDivider) {
commentDivider.setVisibility(View.VISIBLE);
}
} }
} }
@ -1972,10 +1980,16 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
View verticalBlock; View verticalBlock;
@BindView(R.id.placeholder_text_view_item_load_more_comments) @BindView(R.id.placeholder_text_view_item_load_more_comments)
TextView placeholderTextView; TextView placeholderTextView;
@BindView(R.id.divider_item_load_more_comments_placeholder)
View commentDivider;
LoadMoreChildCommentsViewHolder(View itemView) { LoadMoreChildCommentsViewHolder(View itemView) {
super(itemView); super(itemView);
ButterKnife.bind(this, 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 int mColorAccent;
private boolean mVoteButtonsOnTheRight; private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime; private boolean mShowElapsedTime;
private boolean mShowCommentDivider;
private NetworkState networkState; private NetworkState networkState;
private RetryLoadingMoreCallback mRetryLoadingMoreCallback; private RetryLoadingMoreCallback mRetryLoadingMoreCallback;
public CommentsListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, public CommentsListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit,
String accessToken, String accountName, String accessToken, String accountName,
boolean voteButtonsOnTheRight, boolean voteButtonsOnTheRight, boolean showElapsedTime,
boolean showElapsedTime, RetryLoadingMoreCallback retryLoadingMoreCallback) { boolean showCommentDivider,
RetryLoadingMoreCallback retryLoadingMoreCallback) {
super(DIFF_CALLBACK); super(DIFF_CALLBACK);
mContext = context; mContext = context;
mOauthRetrofit = oauthRetrofit; mOauthRetrofit = oauthRetrofit;
@ -109,6 +111,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
mAccountName = accountName; mAccountName = accountName;
mVoteButtonsOnTheRight = voteButtonsOnTheRight; mVoteButtonsOnTheRight = voteButtonsOnTheRight;
mShowElapsedTime = showElapsedTime; mShowElapsedTime = showElapsedTime;
mShowCommentDivider = showCommentDivider;
mRetryLoadingMoreCallback = retryLoadingMoreCallback; mRetryLoadingMoreCallback = retryLoadingMoreCallback;
mTextColorPrimaryDark = mContext.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme); mTextColorPrimaryDark = mContext.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme);
mColorAccent = mContext.getResources().getColor(R.color.colorAccent); mColorAccent = mContext.getResources().getColor(R.color.colorAccent);
@ -429,6 +432,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
ImageView expandButton; ImageView expandButton;
@BindView(R.id.reply_button_item_post_comment) @BindView(R.id.reply_button_item_post_comment)
ImageView replyButton; ImageView replyButton;
@BindView(R.id.divider_item_comment)
View commentDivider;
DataViewHolder(View itemView) { DataViewHolder(View itemView) {
super(itemView); super(itemView);
@ -452,6 +457,10 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
constraintSet.setHorizontalBias(moreButton.getId(), 0); constraintSet.setHorizontalBias(moreButton.getId(), 0);
constraintSet.applyTo(bottomConstraintLayout); 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 Activity mActivity;
private CommentsListingRecyclerViewAdapter mAdapter; private CommentsListingRecyclerViewAdapter mAdapter;
private boolean mShowElapsedTime; private boolean mShowElapsedTime;
private boolean mShowCommentDivider;
public CommentsListingFragment() { public CommentsListingFragment() {
// Required empty public constructor // Required empty public constructor
@ -116,6 +117,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
} }
mShowElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false); mShowElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
if (savedInstanceState == null) { if (savedInstanceState == null) {
getCurrentAccountAndBindView(resources); 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); boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mOauthRetrofit, mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mOauthRetrofit,
getArguments().getString(EXTRA_ACCESS_TOKEN), getArguments().getString(EXTRA_ACCOUNT_NAME), 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 username = getArguments().getString(EXTRA_USERNAME);
String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.value); String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.value);

View File

@ -1,9 +1,14 @@
package ml.docilealligator.infinityforreddit.Settings; 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.Build;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
@ -19,15 +24,24 @@ import ml.docilealligator.infinityforreddit.Event.ShowDividerInCompactLayoutPref
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; 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. * A simple {@link Fragment} subclass.
*/ */
public class InterfacePreferenceFragment extends PreferenceFragmentCompat { public class InterfacePreferenceFragment extends PreferenceFragmentCompat {
private Activity activity;
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.interface_preference, 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 immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY);
SwitchPreference bottomAppBarSwitch = findPreference(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY); SwitchPreference bottomAppBarSwitch = findPreference(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY);
SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_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); ListPreference defaultPostLayoutSwitch = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY);
SwitchPreference showDividerInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT); 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 (immersiveInterfaceSwitch != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
immersiveInterfaceSwitch.setVisible(true); 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.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.ListPreference;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference; import androidx.preference.SwitchPreference;
@ -27,11 +23,6 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; 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. * A simple {@link PreferenceFragmentCompat} subclass.
*/ */
@ -46,22 +37,10 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat {
setPreferencesFromResource(R.xml.main_preferences, rootKey); setPreferencesFromResource(R.xml.main_preferences, rootKey);
((Infinity) activity.getApplication()).getAppComponent().inject(this); ((Infinity) activity.getApplication()).getAppComponent().inject(this);
SwitchPreference amoledDarkSwitch = findPreference(SharedPreferencesUtils.AMOLED_DARK_KEY);
SwitchPreference confirmToExitSwitch = findPreference(SharedPreferencesUtils.CONFIRM_TO_EXIT); SwitchPreference confirmToExitSwitch = findPreference(SharedPreferencesUtils.CONFIRM_TO_EXIT);
SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY); SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY);
SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY); SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY);
SwitchPreference blurSpoilerSwitch = findPreference(SharedPreferencesUtils.BLUR_SPOILER_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) { if (confirmToExitSwitch != null) {
confirmToExitSwitch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { confirmToExitSwitch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@ -104,35 +83,6 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat {
return true; 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 @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 SHOW_TOP_LEVEL_COMMENTS_FIRST = "show_top_level_comments_first";
public static final String CONFIRM_TO_EXIT = "confirm_to_exit"; 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 LOCK_BOTTOM_APP_BAR = "lock_bottom_app_bar";
public static final String SHOW_COMMENT_DIVIDER = "show_comment_divider";
} }

View File

@ -4,219 +4,219 @@
android:id="@+id/linear_layout_item_comment" android:id="@+id/linear_layout_item_comment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"
android:background="?attr/cardViewBackgroundColor"> android:background="?attr/cardViewBackgroundColor">
<View
android:id="@+id/vertical_block_item_post_comment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDarkDayNightTheme"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout <View
android:id="@+id/vertical_block_item_post_comment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDarkDayNightTheme"/>
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="16dp" android:layout_marginTop="12dp"
android:paddingEnd="16dp"> android:layout_marginBottom="12dp"
android:orientation="vertical">
<ImageView <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/author_type_image_view_item_comment" android:layout_width="match_parent"
android:layout_width="?attr/font_default" android:layout_height="wrap_content"
android:layout_height="?attr/font_default" android:paddingStart="16dp"
android:layout_marginEnd="4dp" android:paddingEnd="16dp">
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/author_flair_text_view_item_post_comment" <ImageView
app:layout_constraintEnd_toStartOf="@id/author_text_view_item_post_comment" android:id="@+id/author_type_image_view_item_comment"
app:layout_constraintStart_toStartOf="parent" android:layout_width="?attr/font_default"
app:layout_constraintTop_toTopOf="parent" /> android:layout_height="?attr/font_default"
android:layout_marginEnd="4dp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/author_flair_text_view_item_post_comment"
app:layout_constraintEnd_toStartOf="@id/author_text_view_item_post_comment"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/author_text_view_item_post_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/colorPrimaryDarkDayNightTheme"
android:textSize="?attr/font_default"
app:layout_constraintBottom_toTopOf="@id/author_flair_text_view_item_post_comment"
app:layout_constraintEnd_toStartOf="@+id/barrier"
app:layout_constraintStart_toEndOf="@id/author_type_image_view_item_comment"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/author_flair_text_view_item_post_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/authorFlairTextColor"
android:textSize="?attr/font_12"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/barrier"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/author_text_view_item_post_comment" />
<TextView
android:id="@+id/comment_time_text_view_item_post_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="end"
android:textSize="?attr/font_default"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="start"
app:constraint_referenced_ids="comment_time_text_view_item_post_comment" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView <TextView
android:id="@+id/author_text_view_item_post_comment" android:id="@+id/comment_markdown_view_item_post_comment"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="8dp" android:layout_marginTop="8dp"
android:ellipsize="end" android:layout_marginStart="16dp"
android:maxLines="2" android:layout_marginEnd="16dp"
android:textColor="@color/colorPrimaryDarkDayNightTheme" android:layout_marginBottom="8dp"
android:textSize="?attr/font_default" android:textColor="@color/primaryTextColor"
app:layout_constraintBottom_toTopOf="@id/author_flair_text_view_item_post_comment" android:textSize="?attr/content_font_default" />
app:layout_constraintEnd_toStartOf="@+id/barrier"
app:layout_constraintStart_toEndOf="@id/author_type_image_view_item_comment"
app:layout_constraintTop_toTopOf="parent" />
<TextView <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/author_flair_text_view_item_post_comment" android:id="@+id/bottom_constraint_layout_item_post_comment"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="8dp" android:paddingStart="4dp"
android:ellipsize="end" android:paddingEnd="4dp">
android:maxLines="2"
android:textColor="@color/authorFlairTextColor"
android:textSize="?attr/font_12"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/barrier"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/author_text_view_item_post_comment" />
<TextView <ImageView
android:id="@+id/comment_time_text_view_item_post_comment" android:id="@+id/up_vote_button_item_post_comment"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="end" android:paddingStart="8dp"
android:textSize="?attr/font_default" android:paddingEnd="8dp"
app:layout_constraintBottom_toBottomOf="parent" android:background="?actionBarItemBackground"
app:layout_constraintEnd_toEndOf="parent" android:clickable="true"
app:layout_constraintTop_toTopOf="parent" /> android:focusable="true"
android:src="@drawable/ic_arrow_upward_grey_24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<androidx.constraintlayout.widget.Barrier <TextView
android:id="@+id/barrier" android:id="@+id/score_text_view_item_post_comment"
android:layout_width="wrap_content" android:layout_width="64dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:barrierDirection="start" android:gravity="center"
app:constraint_referenced_ids="comment_time_text_view_item_post_comment" /> android:textSize="?attr/font_12"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="@+id/up_vote_button_item_post_comment"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout> <ImageView
android:id="@+id/down_vote_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_arrow_downward_grey_24dp"
android:tint="@android:color/tab_indicator_text"
app:layout_constraintStart_toEndOf="@+id/score_text_view_item_post_comment"
app:layout_constraintEnd_toStartOf="@id/more_button_item_post_comment"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0" />
<TextView <ImageView
android:id="@+id/comment_markdown_view_item_post_comment" android:id="@+id/more_button_item_post_comment"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:paddingStart="8dp"
android:layout_marginStart="16dp" android:paddingEnd="8dp"
android:layout_marginEnd="16dp" android:background="?actionBarItemBackground"
android:layout_marginBottom="8dp" android:clickable="true"
android:textColor="@color/primaryTextColor" android:focusable="true"
android:textSize="?attr/content_font_default" /> android:src="@drawable/ic_more_vert_grey_24dp"
app:layout_constraintEnd_toStartOf="@+id/expand_button_item_post_comment"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<androidx.constraintlayout.widget.ConstraintLayout <ImageView
android:id="@+id/bottom_constraint_layout_item_post_comment" android:id="@+id/expand_button_item_post_comment"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="4dp" android:paddingStart="8dp"
android:paddingEnd="4dp"> android:paddingEnd="8dp"
android:background="?actionBarItemBackground"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_expand_less_grey_24dp"
android:tint="@android:color/tab_indicator_text"
android:visibility="gone"
app:layout_constraintEnd_toStartOf="@+id/save_button_item_post_comment"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<ImageView <ImageView
android:id="@+id/up_vote_button_item_post_comment" android:id="@+id/save_button_item_post_comment"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="8dp" android:paddingStart="8dp"
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:background="?actionBarItemBackground" android:background="?actionBarItemBackground"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:src="@drawable/ic_arrow_upward_grey_24dp" app:layout_constraintEnd_toStartOf="@+id/reply_button_item_post_comment"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent"/>
app:layout_constraintBottom_toBottomOf="parent" />
<TextView <ImageView
android:id="@+id/score_text_view_item_post_comment" android:id="@+id/reply_button_item_post_comment"
android:layout_width="64dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:paddingStart="8dp"
android:textSize="?attr/font_12" android:paddingEnd="8dp"
android:textStyle="bold" android:background="?actionBarItemBackground"
app:layout_constraintStart_toEndOf="@+id/up_vote_button_item_post_comment" android:clickable="true"
app:layout_constraintTop_toTopOf="parent" android:focusable="true"
app:layout_constraintBottom_toBottomOf="parent"/> android:src="@drawable/ic_reply_grey_24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<ImageView </androidx.constraintlayout.widget.ConstraintLayout>
android:id="@+id/down_vote_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_arrow_downward_grey_24dp"
android:tint="@android:color/tab_indicator_text"
app:layout_constraintStart_toEndOf="@+id/score_text_view_item_post_comment"
app:layout_constraintEnd_toStartOf="@id/more_button_item_post_comment"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0" />
<ImageView </LinearLayout>
android:id="@+id/more_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_more_vert_grey_24dp"
app:layout_constraintEnd_toStartOf="@+id/expand_button_item_post_comment"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<ImageView
android:id="@+id/expand_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_expand_less_grey_24dp"
android:tint="@android:color/tab_indicator_text"
android:visibility="gone"
app:layout_constraintEnd_toStartOf="@+id/save_button_item_post_comment"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<ImageView
android:id="@+id/save_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"
app:layout_constraintEnd_toStartOf="@+id/reply_button_item_post_comment"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<ImageView
android:id="@+id/reply_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_reply_grey_24dp"
app:layout_constraintEnd_toEndOf="parent"
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> </LinearLayout>

View File

@ -2,22 +2,35 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"
android:background="?attr/cardViewBackgroundColor"> android:background="?attr/cardViewBackgroundColor">
<View <LinearLayout
android:id="@+id/vertical_block_item_load_more_comments"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDarkDayNightTheme" />
<TextView
android:id="@+id/placeholder_text_view_item_load_more_comments"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:gravity="center"
android:padding="8dp" <View
android:text="@string/comment_load_more_comments" android:id="@+id/vertical_block_item_load_more_comments"
android:textColor="@color/primaryTextColor" android:layout_width="wrap_content"
android:textSize="?attr/font_default" /> android:layout_height="match_parent"
android:background="@color/colorPrimaryDarkDayNightTheme" />
<TextView
android:id="@+id/placeholder_text_view_item_load_more_comments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="8dp"
android:text="@string/comment_load_more_comments"
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> </LinearLayout>

View File

@ -308,6 +308,7 @@
<string name="settings_mute_video_title">Mute Video</string> <string name="settings_mute_video_title">Mute Video</string>
<string name="settings_confirm_to_exit">Confirm to Exit</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_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_show_elapsed_time">Show Elapsed Time in Posts and Comments</string>
<string name="settings_default_post_layout">Default Post Layout</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> <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" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> 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 <Preference
app:title="@string/settings_font_size_title" app:title="@string/settings_font_size_title"
app:icon="@drawable/ic_font_size_24dp" app:icon="@drawable/ic_font_size_24dp"
@ -46,4 +59,9 @@
app:key="show_top_level_comments_first" app:key="show_top_level_comments_first"
app:title="@string/settings_show_top_level_comments_first_title" /> 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> </PreferenceScreen>

View File

@ -7,19 +7,6 @@
app:title="@string/settings_notification_master_title" app:title="@string/settings_notification_master_title"
app:fragment="ml.docilealligator.infinityforreddit.Settings.NotificationPreferenceFragment" /> 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 <Preference
app:icon="@drawable/ic_interface_24dp" app:icon="@drawable/ic_interface_24dp"
app:title="@string/settings_interface_title" app:title="@string/settings_interface_title"