From 168456f57ccd80a52c7d95761b1df6827d0b90c8 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 29 Oct 2019 11:20:16 +0800 Subject: Make Placing vote buttons on the right an option. --- .../Activity/ViewPostDetailActivity.java | 38 ++++++------ .../Adapter/CommentAndPostRecyclerViewAdapter.java | 67 +++++++++++++++------- .../CommentsListingRecyclerViewAdapter.java | 12 ++-- .../Adapter/PostRecyclerViewAdapter.java | 47 ++++++++++++--- .../Event/ChangeVoteButtonsPositionEvent.java | 9 +++ .../infinityforreddit/Fragment/PostFragment.java | 16 ++++-- .../Settings/MainPreferenceFragment.java | 13 ++++- .../infinityforreddit/SharedPreferencesUtils.java | 1 + 8 files changed, 143 insertions(+), 60 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeVoteButtonsPositionEvent.java (limited to 'app/src/main/java/ml') 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 4bb8711e..6bafbebe 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -159,6 +159,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS private String mSingleCommentId; private boolean mNeedBlurNsfw; private boolean mNeedBlurSpoiler; + private boolean mVoteButtonsOnTheRight; private boolean showToast = false; private boolean isSortingComments = false; private LinearLayoutManager mLinearLayoutManager; @@ -232,6 +233,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mNeedBlurNsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_NSFW_KEY, true); mNeedBlurSpoiler = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_SPOILER_KEY, false); + mVoteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false); mGlide = Glide.with(this); mLocale = getResources().getConfiguration().locale; @@ -239,7 +241,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mLinearLayoutManager = new LinearLayoutManager(this); mRecyclerView.setLayoutManager(mLinearLayoutManager); - mSingleCommentId = getIntent().hasExtra(EXTRA_SINGLE_COMMENT_ID) ? getIntent().getExtras().getString(EXTRA_SINGLE_COMMENT_ID) : null; + mSingleCommentId = getIntent().getStringExtra(EXTRA_SINGLE_COMMENT_ID); if (savedInstanceState == null) { if (mSingleCommentId != null) { isSingleCommentThreadMode = true; @@ -336,10 +338,10 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS if (mAccessToken != null) { if (mPost.isSaved()) { saveItem.setVisible(true); - saveItem.setIcon(R.drawable.ic_baseline_bookmark_24px); + saveItem.setIcon(R.drawable.ic_bookmark_black_24dp); } else { saveItem.setVisible(true); - saveItem.setIcon(R.drawable.ic_baseline_bookmark_border_24px); + saveItem.setIcon(R.drawable.ic_bookmark_border_black_24dp); } if (mPost.isHidden()) { @@ -385,6 +387,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, new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { @Override public void updatePost(Post post) { @@ -473,10 +476,10 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS if (mAccessToken != null) { if (post.isSaved()) { saveItem.setVisible(true); - saveItem.setIcon(R.drawable.ic_baseline_bookmark_24px); + saveItem.setIcon(R.drawable.ic_bookmark_black_24dp); } else { saveItem.setVisible(true); - saveItem.setIcon(R.drawable.ic_baseline_bookmark_border_24px); + saveItem.setIcon(R.drawable.ic_bookmark_border_black_24dp); } if (post.isHidden()) { @@ -505,6 +508,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler, + mVoteButtonsOnTheRight, new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { @Override public void updatePost(Post post) { @@ -727,10 +731,10 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS if (mAccessToken != null) { if (post.isSaved()) { saveItem.setVisible(true); - saveItem.setIcon(R.drawable.ic_baseline_bookmark_24px); + saveItem.setIcon(R.drawable.ic_bookmark_black_24dp); } else { saveItem.setVisible(true); - saveItem.setIcon(R.drawable.ic_baseline_bookmark_border_24px); + saveItem.setIcon(R.drawable.ic_bookmark_border_black_24dp); } if (post.isHidden()) { @@ -962,10 +966,10 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS if (mMenu != null) { if (event.post.isSaved()) { mMenu.findItem(R.id.action_save_view_post_detail_activity).setIcon(getResources() - .getDrawable(R.drawable.ic_baseline_bookmark_24px)); + .getDrawable(R.drawable.ic_bookmark_black_24dp)); } else { mMenu.findItem(R.id.action_save_view_post_detail_activity).setIcon(getResources() - .getDrawable(R.drawable.ic_baseline_bookmark_border_24px)); + .getDrawable(R.drawable.ic_bookmark_border_black_24dp)); } } mAdapter.updatePost(mPost); @@ -1022,10 +1026,10 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS if (mAccessToken != null) { if (mPost.isSaved()) { saveItem.setVisible(true); - saveItem.setIcon(R.drawable.ic_baseline_bookmark_24px); + saveItem.setIcon(R.drawable.ic_bookmark_black_24dp); } else { saveItem.setVisible(true); - saveItem.setIcon(R.drawable.ic_baseline_bookmark_border_24px); + saveItem.setIcon(R.drawable.ic_bookmark_border_black_24dp); } if (mPost.isHidden()) { @@ -1104,13 +1108,13 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS case R.id.action_save_view_post_detail_activity: if (mPost != null && mAccessToken != null) { if (mPost.isSaved()) { - item.setIcon(R.drawable.ic_baseline_bookmark_border_24px); + item.setIcon(R.drawable.ic_bookmark_border_black_24dp); SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(), new SaveThing.SaveThingListener() { @Override public void success() { mPost.setSaved(false); - item.setIcon(R.drawable.ic_baseline_bookmark_border_24px); + item.setIcon(R.drawable.ic_bookmark_border_black_24dp); showMessage(R.string.post_unsaved_success); EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } @@ -1118,19 +1122,19 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS @Override public void failed() { mPost.setSaved(true); - item.setIcon(R.drawable.ic_baseline_bookmark_24px); + item.setIcon(R.drawable.ic_bookmark_black_24dp); showMessage(R.string.post_unsaved_failed); EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } }); } else { - item.setIcon(R.drawable.ic_baseline_bookmark_24px); + item.setIcon(R.drawable.ic_bookmark_black_24dp); SaveThing.saveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(), new SaveThing.SaveThingListener() { @Override public void success() { mPost.setSaved(true); - item.setIcon(R.drawable.ic_baseline_bookmark_24px); + item.setIcon(R.drawable.ic_bookmark_black_24dp); showMessage(R.string.post_saved_success); EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } @@ -1138,7 +1142,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS @Override public void failed() { mPost.setSaved(false); - item.setIcon(R.drawable.ic_baseline_bookmark_border_24px); + item.setIcon(R.drawable.ic_bookmark_border_black_24dp); showMessage(R.string.post_saved_failed); EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } 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 84585046..169a5cee 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -23,6 +23,8 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.constraintlayout.widget.ConstraintSet; import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; @@ -102,6 +104,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + ((PostDetailViewHolder) holder).commentsCountTextView.setOnClickListener(view -> { if (mAccessToken == null) { Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); return; @@ -509,9 +513,9 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { @@ -521,13 +525,13 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { @@ -851,14 +855,14 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { @@ -307,14 +307,14 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { @@ -627,13 +631,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { //Do nothing in order to prevent clicking this to start ViewPostDetailActivity }); + + if (mVoteButtonsOnTheRight) { + ConstraintSet constraintSet = new ConstraintSet(); + constraintSet.clone(bottomConstraintLayout); + constraintSet.clear(upvoteButton.getId(), ConstraintSet.START); + constraintSet.clear(scoreTextView.getId(), ConstraintSet.START); + constraintSet.clear(downvoteButton.getId(), ConstraintSet.START); + constraintSet.clear(saveButton.getId(), ConstraintSet.END); + constraintSet.clear(shareButton.getId(), ConstraintSet.END); + constraintSet.connect(upvoteButton.getId(), ConstraintSet.END, scoreTextView.getId(), ConstraintSet.START); + constraintSet.connect(scoreTextView.getId(), ConstraintSet.END, downvoteButton.getId(), ConstraintSet.START); + constraintSet.connect(downvoteButton.getId(), ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END); + constraintSet.connect(commentsCountTextView.getId(), ConstraintSet.START, saveButton.getId(), ConstraintSet.END); + constraintSet.connect(commentsCountTextView.getId(), ConstraintSet.END, upvoteButton.getId(), ConstraintSet.START); + constraintSet.connect(saveButton.getId(), ConstraintSet.START, shareButton.getId(), ConstraintSet.END); + constraintSet.connect(shareButton.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START); + constraintSet.setHorizontalBias(commentsCountTextView.getId(), 0); + constraintSet.applyTo(bottomConstraintLayout); + } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeVoteButtonsPositionEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeVoteButtonsPositionEvent.java new file mode 100644 index 00000000..00f506ab --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeVoteButtonsPositionEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.Event; + +public class ChangeVoteButtonsPositionEvent { + public boolean voteButtonsOnTheRight; + + public ChangeVoteButtonsPositionEvent(boolean voteButtonsOnTheRight) { + this.voteButtonsOnTheRight = voteButtonsOnTheRight; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index e5f8c2f3..921763c6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -51,6 +51,7 @@ import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity import ml.docilealligator.infinityforreddit.Adapter.PostRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent; import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList; import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; @@ -275,6 +276,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { boolean nsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_KEY, false); boolean needBlurNsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_NSFW_KEY, true); boolean needBlurSpoiler = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_SPOILER_KEY, false); + boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false); PostViewModel.Factory factory; @@ -288,7 +290,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, accessToken, postType, true, needBlurNsfw, needBlurSpoiler, - new PostRecyclerViewAdapter.Callback() { + voteButtonsOnTheRight, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); @@ -348,7 +350,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, accessToken, postType, displaySubredditName, needBlurNsfw, needBlurSpoiler, - new PostRecyclerViewAdapter.Callback() { + voteButtonsOnTheRight, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); @@ -393,7 +395,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, accessToken, postType, true, needBlurNsfw, needBlurSpoiler, - new PostRecyclerViewAdapter.Callback() { + voteButtonsOnTheRight, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); @@ -431,7 +433,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, accessToken, postType, true, needBlurNsfw, needBlurSpoiler, - new PostRecyclerViewAdapter.Callback() { + voteButtonsOnTheRight, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); @@ -625,6 +627,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } } + @Subscribe + public void onChangeVoteButtonsPositionEvent(ChangeVoteButtonsPositionEvent event) { + mAdapter.setVoteButtonsPosition(event.voteButtonsOnTheRight); + refreshAdapter(); + } + @Subscribe public void onChangeNSFWBlurEvent(ChangeNSFWBlurEvent event) { mAdapter.setBlurNSFW(event.needBlurNSFW); 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 9e366424..dcc1c201 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java @@ -19,6 +19,7 @@ import javax.inject.Inject; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent; import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; @@ -47,12 +48,13 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { SwitchPreference amoledDarkSwitch = findPreference(SharedPreferencesUtils.AMOLED_DARK_KEY); SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY); + SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY); 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) { + 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()); @@ -62,7 +64,7 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { }); } - if(immersiveInterfaceSwitch != null) { + if (immersiveInterfaceSwitch != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { immersiveInterfaceSwitch.setVisible(true); immersiveInterfaceSwitch.setOnPreferenceChangeListener((preference, newValue) -> { @@ -74,6 +76,13 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { } } + if (voteButtonsOnTheRightSwitch != null) { + voteButtonsOnTheRightSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeVoteButtonsPositionEvent((Boolean) newValue)); + return true; + }); + } + if (nsfwSwitch != null) { nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeNSFWEvent((Boolean) newValue)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java index 334aff47..b11f4c32 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java @@ -29,6 +29,7 @@ public class SharedPreferencesUtils { public static final String CONTENT_FONT_SIZE_KEY = "content_font_size"; public static final String AMOLED_DARK_KEY = "amoled_dark"; public static final String IMMERSIVE_INTERFACE_KEY = "immersive_interface"; + public static final String VOTE_BUTTONS_ON_THE_RIGHT_KEY = "vote_buttons_on_the_right"; public static final String SORT_TYPE_BEST_POST = "sort_type_best_post"; public static final String SORT_TIME_BEST_POST = "sort_time_best_post"; public static final String SORT_TYPE_ALL_POST = "sort_type_all_post"; -- cgit v1.2.3