New option: Settings->Interface->Comment->Comment Divider Type.

This commit is contained in:
Docile-Alligator 2022-11-14 22:01:31 +11:00
parent af870c157b
commit 67b6906ead
6 changed files with 66 additions and 6 deletions

View File

@ -74,6 +74,9 @@ import ml.docilealligator.infinityforreddit.utils.Utils;
import retrofit2.Retrofit;
public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public static final int DIVIDER_NORMAL = 0;
public static final int DIVIDER_PARENT = 1;
private static final int VIEW_TYPE_FIRST_LOADING = 9;
private static final int VIEW_TYPE_FIRST_LOADING_FAILED = 10;
private static final int VIEW_TYPE_NO_COMMENT_PLACEHOLDER = 11;
@ -107,6 +110,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
private boolean mCommentToolbarHideOnClick;
private boolean mSwapTapAndLong;
private boolean mShowCommentDivider;
private int mDividerType;
private boolean mShowAbsoluteNumberOfVotes;
private boolean mFullyCollapseComment;
private boolean mShowOnlyOneCommentLevelIndicator;
@ -221,6 +225,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mCommentToolbarHideOnClick = sharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDE_ON_CLICK, true);
mSwapTapAndLong = sharedPreferences.getBoolean(SharedPreferencesUtils.SWAP_TAP_AND_LONG_COMMENTS, false);
mShowCommentDivider = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
mDividerType = Integer.parseInt(sharedPreferences.getString(SharedPreferencesUtils.COMMENT_DIVIDER_TYPE, "0"));
mShowAbsoluteNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
mFullyCollapseComment = sharedPreferences.getBoolean(SharedPreferencesUtils.FULLY_COLLAPSE_COMMENT, false);
mShowOnlyOneCommentLevelIndicator = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ONLY_ONE_COMMENT_LEVEL_INDICATOR, false);
@ -525,6 +530,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (position == mSearchCommentIndex) {
holder.itemView.setBackgroundColor(Color.parseColor("#03A9F4"));
}
if (mShowCommentDivider) {
if (mDividerType == DIVIDER_PARENT && comment.getDepth() == 0) {
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
params.setMargins(0, (int) Utils.convertDpToPixel(16, mActivity), 0, 0);
}
}
}
} else if (holder instanceof CommentFullyCollapsedViewHolder) {
Comment comment = getCurrentComment(position);
@ -574,6 +586,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
((CommentFullyCollapsedViewHolder) holder).commentIndentationView.setShowOnlyOneDivider(mShowOnlyOneCommentLevelIndicator);
((CommentFullyCollapsedViewHolder) holder).commentIndentationView.setLevelAndColors(comment.getDepth(), verticalBlockColors);
if (mShowCommentDivider) {
if (mDividerType == DIVIDER_PARENT && comment.getDepth() == 0) {
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
params.setMargins(0, (int) Utils.convertDpToPixel(16, mActivity), 0, 0);
}
}
}
} else if (holder instanceof LoadMoreChildCommentsViewHolder) {
Comment placeholder;
@ -1128,6 +1147,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).expandButton.setText("");
((CommentViewHolder) holder).replyButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
params.setMargins(0, 0, 0, 0);
}
}
@ -1246,8 +1267,10 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
if (mShowCommentDivider) {
commentDivider.setBackgroundColor(mDividerColor);
commentDivider.setVisibility(View.VISIBLE);
if (mDividerType == DIVIDER_NORMAL) {
commentDivider.setBackgroundColor(mDividerColor);
commentDivider.setVisibility(View.VISIBLE);
}
}
if (mActivity.typeface != null) {
@ -1749,8 +1772,10 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
commentTimeTextView.setTextColor(mSecondaryTextColor);
if (mShowCommentDivider) {
commentDivider.setBackgroundColor(mDividerColor);
commentDivider.setVisibility(View.VISIBLE);
if (mDividerType == DIVIDER_NORMAL) {
commentDivider.setBackgroundColor(mDividerColor);
commentDivider.setVisibility(View.VISIBLE);
}
}
if (mShowAuthorAvatar) {
@ -1801,7 +1826,10 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
ButterKnife.bind(this, itemView);
if (mShowCommentDivider) {
commentDivider.setVisibility(View.VISIBLE);
if (mDividerType == DIVIDER_NORMAL) {
commentDivider.setBackgroundColor(mDividerColor);
commentDivider.setVisibility(View.VISIBLE);
}
}
if (mActivity.typeface != null) {
@ -1809,7 +1837,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
itemView.setBackgroundColor(mCommentBackgroundColor);
placeholderTextView.setTextColor(mPrimaryTextColor);
commentDivider.setBackgroundColor(mDividerColor);
}
}

View File

@ -3,7 +3,9 @@ package ml.docilealligator.infinityforreddit.settings;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.preference.ListPreference;
import androidx.preference.SeekBarPreference;
import androidx.preference.SwitchPreference;
import javax.inject.Inject;
import javax.inject.Named;
@ -25,8 +27,18 @@ public class CommentPreferenceFragment extends CustomFontPreferenceFragmentCompa
((Infinity) activity.getApplication()).getAppComponent().inject(this);
SwitchPreference showCommentDividerSwitchPreference = findPreference(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER);
ListPreference commentDividerTypeListPreference = findPreference(SharedPreferencesUtils.COMMENT_DIVIDER_TYPE);
SeekBarPreference showFewerToolbarOptionsThresholdSeekBarPreference = findPreference(SharedPreferencesUtils.SHOW_FEWER_TOOLBAR_OPTIONS_THRESHOLD);
if (showCommentDividerSwitchPreference != null && commentDividerTypeListPreference != null) {
commentDividerTypeListPreference.setVisible(sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false));
showCommentDividerSwitchPreference.setOnPreferenceChangeListener((preference, newValue) -> {
commentDividerTypeListPreference.setVisible((Boolean) newValue);
return true;
});
}
if (showFewerToolbarOptionsThresholdSeekBarPreference != null) {
showFewerToolbarOptionsThresholdSeekBarPreference.setSummary(getString(R.string.settings_show_fewer_toolbar_options_threshold_summary, sharedPreferences.getInt(SharedPreferencesUtils.SHOW_FEWER_TOOLBAR_OPTIONS_THRESHOLD, 5)));

View File

@ -215,6 +215,7 @@ public class SharedPreferencesUtils {
public static final String REDDIT_VIDEO_DEFAULT_RESOLUTION = "reddit_video_default_resolution";
public static final String EASIER_TO_WATCH_IN_FULL_SCREEN = "easier_to_watch_in_full_screen";
public static final String HIDE_THE_NUMBER_OF_VOTES_IN_COMMENTS = "hide_the_number_of_votes_in_comments";
public static final String COMMENT_DIVIDER_TYPE = "comment_divider_type";
public static final String DEFAULT_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit_preferences";
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";

View File

@ -669,4 +669,14 @@
<item>144</item>
</string-array>
<string-array name="settings_comment_divider_type">
<item>Normal</item>
<item>Only on top-level comments</item>
</string-array>
<string-array name="settings_comment_divider_type_values">
<item>0</item>
<item>1</item>
</string-array>
</resources>

View File

@ -647,6 +647,7 @@
<string name="settings_reddit_video_default_resolution">Reddit Video Default Resolution</string>
<string name="settings_easier_to_watch_in_full_screen_title">Easier to Watch in Full Screen</string>
<string name="settings_hide_fab_in_post_feed">Hide FAB in Post Feed</string>
<string name="settings_comment_divider_type">Comment Divider Type</string>
<string name="no_link_available">Cannot get the link</string>

View File

@ -12,6 +12,15 @@
app:key="show_comment_divider"
app:title="@string/settings_show_comment_divider_title" />
<ml.docilealligator.infinityforreddit.customviews.CustomFontListPreference
app:defaultValue="0"
app:key="comment_divider_type"
android:title="@string/settings_comment_divider_type"
app:entries="@array/settings_comment_divider_type"
app:entryValues="@array/settings_comment_divider_type_values"
app:useSimpleSummaryProvider="true"
app:isPreferenceVisible="false" />
<ml.docilealligator.infinityforreddit.customviews.CustomFontSwitchPreference
app:defaultValue="false"
app:key="show_only_one_comment_level_indicator"