Merge pull request #73 from OHermesJunior/master

Add hidden comment toolbar feature.
This commit is contained in:
Docile-Alligator 2020-03-31 22:31:55 +08:00 committed by GitHub
commit 093fccc790
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 81 additions and 9 deletions

View File

@ -180,6 +180,8 @@ 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 mCommentToolbarHidden;
private boolean mCommentToolbarHideOnClick;
private boolean mShowCommentDivider; private boolean mShowCommentDivider;
private boolean mShowAbsoluteNumberOfVotes; private boolean mShowAbsoluteNumberOfVotes;
private LinearLayoutManager mLinearLayoutManager; private LinearLayoutManager mLinearLayoutManager;
@ -246,6 +248,8 @@ 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);
mCommentToolbarHidden = mSharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDDEN, false);
mCommentToolbarHideOnClick= mSharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDE_ON_CLICK, true);
mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false); mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
mShowAbsoluteNumberOfVotes = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true); mShowAbsoluteNumberOfVotes = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
@ -503,8 +507,8 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this,
mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide,
mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, isSingleCommentThreadMode, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, isSingleCommentThreadMode,
mNeedBlurNsfw, mNeedBlurSpoiler, mVoteButtonsOnTheRight, mShowElapsedTime, mNeedBlurNsfw, mNeedBlurSpoiler, mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren,
mExpandChildren, mShowCommentDivider, mShowAbsoluteNumberOfVotes, mCommentToolbarHidden, mCommentToolbarHideOnClick, mShowCommentDivider,mShowAbsoluteNumberOfVotes,
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override @Override
public void updatePost(Post post) { public void updatePost(Post post) {
@ -633,10 +637,9 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this,
mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide,
mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, isSingleCommentThreadMode,
isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler, mNeedBlurNsfw, mNeedBlurSpoiler, mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren,
mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, mShowCommentDivider, mCommentToolbarHidden, mCommentToolbarHideOnClick, mShowCommentDivider, mShowAbsoluteNumberOfVotes,
mShowAbsoluteNumberOfVotes,
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override @Override
public void updatePost(Post post) { public void updatePost(Post post) {

View File

@ -17,6 +17,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
@ -125,6 +126,8 @@ 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 mCommentToolbarHidden;
private boolean mCommentToolbarHideOnClick;
private boolean mShowCommentDivider; private boolean mShowCommentDivider;
private boolean mShowAbsoluteNumberOfVotes; private boolean mShowAbsoluteNumberOfVotes;
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback; private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
@ -185,7 +188,8 @@ 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 showCommentDivider, boolean showElapsedTime, boolean expandChildren, boolean commentToolbarHidden,
boolean commentToolbarHideOnClick, boolean showCommentDivider,
boolean showAbsoluteNumberOfVotes, boolean showAbsoluteNumberOfVotes,
CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) { CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
mActivity = activity; mActivity = activity;
@ -277,6 +281,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mVoteButtonsOnTheRight = voteButtonsOnTheRight; mVoteButtonsOnTheRight = voteButtonsOnTheRight;
mShowElapsedTime = showElapsedTime; mShowElapsedTime = showElapsedTime;
mExpandChildren = expandChildren; mExpandChildren = expandChildren;
mCommentToolbarHidden = commentToolbarHidden;
mCommentToolbarHideOnClick = commentToolbarHideOnClick;
mShowCommentDivider = showCommentDivider; mShowCommentDivider = showCommentDivider;
mShowAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes; mShowAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes;
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback; mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
@ -846,9 +852,19 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((CommentViewHolder) holder).commentTimeTextView.setText(comment.getCommentTime()); ((CommentViewHolder) holder).commentTimeTextView.setText(comment.getCommentTime());
} }
if (mCommentToolbarHidden) {
((CommentViewHolder) holder).bottomConstraintLayout.setVisibility(View.GONE);
((CommentViewHolder) holder).topScoreTextView.setVisibility(View.VISIBLE);
} else {
((CommentViewHolder) holder).bottomConstraintLayout.setVisibility(View.VISIBLE);
((CommentViewHolder) holder).topScoreTextView.setVisibility(View.GONE);
}
mCommentMarkwon.setMarkdown(((CommentViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown()); mCommentMarkwon.setMarkdown(((CommentViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown());
((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())); comment.getScore() + comment.getVoteType()));
((CommentViewHolder) holder).topScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()) + " pts");
((CommentViewHolder) holder).itemView.setPadding(comment.getDepth() * 8, 0, 0, 0); ((CommentViewHolder) holder).itemView.setPadding(comment.getDepth() * 8, 0, 0, 0);
if (comment.getDepth() > 0) { if (comment.getDepth() > 0) {
@ -887,6 +903,21 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((CommentViewHolder) holder).verticalBlock.setLayoutParams(params); ((CommentViewHolder) holder).verticalBlock.setLayoutParams(params);
} }
if (mCommentToolbarHideOnClick) {
View.OnClickListener hideToolbarOnClickListener = view -> {
if (((CommentViewHolder) holder).bottomConstraintLayout.getVisibility() == View.GONE){
((CommentViewHolder) holder).bottomConstraintLayout.setVisibility(View.VISIBLE);
((CommentViewHolder) holder).topScoreTextView.setVisibility(View.GONE);
} else {
((CommentViewHolder) holder).bottomConstraintLayout.setVisibility(View.GONE);
((CommentViewHolder) holder).topScoreTextView.setVisibility(View.VISIBLE);
}
};
((CommentViewHolder) holder).linearLayout.setOnClickListener(hideToolbarOnClickListener);
((CommentViewHolder) holder).commentMarkdownView.setOnClickListener(hideToolbarOnClickListener);
((CommentViewHolder) holder).commentTimeTextView.setOnClickListener(hideToolbarOnClickListener);
}
((CommentViewHolder) holder).moreButton.setOnClickListener(view -> { ((CommentViewHolder) holder).moreButton.setOnClickListener(view -> {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
if (!mPost.isArchived() && !mPost.isLocked() && comment.getAuthor().equals(mAccountName)) { if (!mPost.isArchived() && !mPost.isLocked() && comment.getAuthor().equals(mAccountName)) {
@ -1002,6 +1033,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())); comment.getScore() + comment.getVoteType()));
((CommentViewHolder) holder).topScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()) + " pts");
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
@ -1019,6 +1052,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); ((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())); comment.getScore() + comment.getVoteType()));
((CommentViewHolder) holder).topScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()) + " pts");
} }
@Override @Override
@ -1059,6 +1094,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())); comment.getScore() + comment.getVoteType()));
((CommentViewHolder) holder).topScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()) + " pts");
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
@ -1076,6 +1113,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((CommentViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); ((CommentViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())); comment.getScore() + comment.getVoteType()));
((CommentViewHolder) holder).topScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()) + " pts");
} }
@Override @Override
@ -2059,6 +2098,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
} }
class CommentViewHolder extends RecyclerView.ViewHolder { class CommentViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.linear_layout_item_comment)
LinearLayout linearLayout;
@BindView(R.id.author_text_view_item_post_comment) @BindView(R.id.author_text_view_item_post_comment)
TextView authorTextView; TextView authorTextView;
@BindView(R.id.author_flair_text_view_item_post_comment) @BindView(R.id.author_flair_text_view_item_post_comment)
@ -2067,6 +2108,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
ImageView authorTypeImageView; ImageView authorTypeImageView;
@BindView(R.id.comment_time_text_view_item_post_comment) @BindView(R.id.comment_time_text_view_item_post_comment)
TextView commentTimeTextView; TextView commentTimeTextView;
@BindView(R.id.top_score_text_view_item_post_comment)
TextView topScoreTextView;
@BindView(R.id.comment_markdown_view_item_post_comment) @BindView(R.id.comment_markdown_view_item_post_comment)
TextView commentMarkdownView; TextView commentMarkdownView;
@BindView(R.id.bottom_constraint_layout_item_post_comment) @BindView(R.id.bottom_constraint_layout_item_post_comment)

View File

@ -80,6 +80,8 @@ 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 COMMENT_TOOLBAR_HIDDEN = "comment_toolbar_hidden";
public static final String COMMENT_TOOLBAR_HIDE_ON_CLICK = "comment_toolbar_hide_on_click";
public static final String SHOW_COMMENT_DIVIDER = "show_comment_divider"; public static final String SHOW_COMMENT_DIVIDER = "show_comment_divider";
public static final String SHOW_ABSOLUTE_NUMBER_OF_VOTES = "show_absolute_number_of_votes"; public static final String SHOW_ABSOLUTE_NUMBER_OF_VOTES = "show_absolute_number_of_votes";
public static final String CUSTOMIZE_LIGHT_THEME = "customize_light_theme"; public static final String CUSTOMIZE_LIGHT_THEME = "customize_light_theme";

View File

@ -21,7 +21,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:layout_marginBottom="12dp" android:layout_marginBottom="12dp"
android:orientation="vertical"> android:orientation="vertical"
android:animateLayoutChanges="true">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -69,6 +70,17 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/author_text_view_item_post_comment" /> app:layout_constraintTop_toBottomOf="@id/author_text_view_item_post_comment" />
<TextView
android:id="@+id/top_score_text_view_item_post_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:gravity="end"
android:textSize="?attr/font_default"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/comment_time_text_view_item_post_comment"
app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/comment_time_text_view_item_post_comment" android:id="@+id/comment_time_text_view_item_post_comment"
android:layout_width="0dp" android:layout_width="0dp"
@ -84,7 +96,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:barrierDirection="start" app:barrierDirection="start"
app:constraint_referenced_ids="comment_time_text_view_item_post_comment" /> app:constraint_referenced_ids="top_score_text_view_item_post_comment" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -314,6 +314,8 @@
<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_comment_divider_title">Show Comment Divider</string>
<string name="settings_comment_toolbar_hide_on_click">Click to Show/Hide Comment Toolbar</string>
<string name="settings_comment_toolbar_hidden">Comment Toolbar Hidden by Default</string>
<string name="settings_show_absolute_number_of_votes_title">Show Absolute Number of Votes</string> <string name="settings_show_absolute_number_of_votes_title">Show Absolute Number of Votes</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>

View File

@ -51,6 +51,16 @@
app:key="show_comment_divider" app:key="show_comment_divider"
app:title="@string/settings_show_comment_divider_title" /> app:title="@string/settings_show_comment_divider_title" />
<SwitchPreference
app:defaultValue="false"
app:key="comment_toolbar_hidden"
app:title="@string/settings_comment_toolbar_hidden" />
<SwitchPreference
app:defaultValue="true"
app:key="comment_toolbar_hide_on_click"
app:title="@string/settings_comment_toolbar_hide_on_click" />
<SwitchPreference <SwitchPreference
app:defaultValue="true" app:defaultValue="true"
app:key="show_absolute_number_of_votes" app:key="show_absolute_number_of_votes"