diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-06-13 14:11:57 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-06-13 14:11:57 +0000 |
commit | 8ed7f54d46307177e4ef05721b3c6f15aa4fa9c4 (patch) | |
tree | 811631764f74d23eac7f936113249bd300e99790 /app/src/main/java/ml/docilealligator/infinityforreddit | |
parent | ee048b25dd0d2a412271a17e954619702dcfae53 (diff) | |
download | infinity-for-reddit-8ed7f54d46307177e4ef05721b3c6f15aa4fa9c4.tar infinity-for-reddit-8ed7f54d46307177e4ef05721b3c6f15aa4fa9c4.tar.gz infinity-for-reddit-8ed7f54d46307177e4ef05721b3c6f15aa4fa9c4.tar.bz2 infinity-for-reddit-8ed7f54d46307177e4ef05721b3c6f15aa4fa9c4.tar.lz infinity-for-reddit-8ed7f54d46307177e4ef05721b3c6f15aa4fa9c4.tar.xz infinity-for-reddit-8ed7f54d46307177e4ef05721b3c6f15aa4fa9c4.tar.zst infinity-for-reddit-8ed7f54d46307177e4ef05721b3c6f15aa4fa9c4.zip |
Add an option to move thumbnail in compact layout to the left.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
7 files changed, 134 insertions, 37 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 7aaaa391..98355c69 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -22,6 +22,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.constraintlayout.widget.Barrier; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintSet; import androidx.core.graphics.drawable.DrawableCompat; @@ -72,10 +73,10 @@ import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.Activity.ViewVideoActivity; import ml.docilealligator.infinityforreddit.AsyncTask.LoadSubredditIconAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.LoadUserDataAsyncTask; +import ml.docilealligator.infinityforreddit.BottomSheetFragment.ShareLinkBottomSheetFragment; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.CustomView.AspectRatioGifImageView; import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToDetailActivity; -import ml.docilealligator.infinityforreddit.BottomSheetFragment.ShareLinkBottomSheetFragment; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.Post.Post; import ml.docilealligator.infinityforreddit.Post.PostDataSource; @@ -153,6 +154,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView private int mVoteAndReplyUnavailableVoteButtonColor; private int mButtonTextColor; private int mPostIconAndInfoColor; + private int mDividerColor; private float mScale; private boolean mDisplaySubredditName; private boolean mVoteButtonsOnTheRight; @@ -163,6 +165,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView private boolean mShowAbsoluteNumberOfVotes; private boolean mAutoplay = false; private boolean mAutoplayNsfwVideos; + private boolean mShowThumbnailOnTheRightInCompactLayout; private Drawable mCommentIcon; private NetworkState networkState; private ExoCreator mExoCreator; @@ -196,6 +199,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mAutoplay = Utils.isConnectedToWifi(activity); } mAutoplayNsfwVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS, true); + mShowThumbnailOnTheRightInCompactLayout = sharedPreferences.getBoolean( + SharedPreferencesUtils.SHOW_THUMBNAIL_ON_THE_RIGHT_IN_COMPACT_LAYOUT, false); mPostLayout = postLayout; mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme(); @@ -227,6 +232,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mVoteAndReplyUnavailableVoteButtonColor = customThemeWrapper.getVoteAndReplyUnavailableButtonColor(); mButtonTextColor = customThemeWrapper.getButtonTextColor(); mPostIconAndInfoColor = customThemeWrapper.getPostIconAndInfoColor(); + mDividerColor = customThemeWrapper.getDividerColor(); mCommentIcon = activity.getDrawable(R.drawable.ic_comment_grey_24dp); if (mCommentIcon != null) { @@ -1322,6 +1328,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mAutoplayNsfwVideos = autoplayNsfwVideos; } + public void setShowThumbnailOnTheRightInCompactLayout(boolean showThumbnailOnTheRightInCompactLayout) { + mShowThumbnailOnTheRightInCompactLayout = showThumbnailOnTheRightInCompactLayout; + } + @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { super.onViewRecycled(holder); @@ -2536,6 +2546,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView ImageView stickiedPostImageView; @BindView(R.id.post_time_text_view_item_post_compact) TextView postTimeTextView; + @BindView(R.id.title_and_image_constraint_layout) + ConstraintLayout titleAndImageConstraintLayout; @BindView(R.id.title_text_view_item_post_compact) TextView titleTextView; @BindView(R.id.type_text_view_item_post_compact) @@ -2566,6 +2578,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView ImageView playButtonImageView; @BindView(R.id.image_view_no_preview_link_item_post_compact) ImageView noPreviewLinkImageView; + @BindView(R.id.barrier2) + Barrier imageBarrier; @BindView(R.id.bottom_constraint_layout_item_post_compact) ConstraintLayout bottomConstraintLayout; @BindView(R.id.plus_button_item_post_compact) @@ -2609,6 +2623,38 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView constraintSet.applyTo(bottomConstraintLayout); } + if (mShowThumbnailOnTheRightInCompactLayout) { + ConstraintSet constraintSet = new ConstraintSet(); + constraintSet.clone(titleAndImageConstraintLayout); + constraintSet.clear(titleTextView.getId(), ConstraintSet.START); + constraintSet.clear(titleTextView.getId(), ConstraintSet.END); + constraintSet.clear(R.id.flow_layout_item_post_compact, ConstraintSet.START); + constraintSet.clear(R.id.flow_layout_item_post_compact, ConstraintSet.END); + constraintSet.clear(linkTextView.getId(), ConstraintSet.START); + constraintSet.clear(linkTextView.getId(), ConstraintSet.END); + constraintSet.clear(relativeLayout.getId(), ConstraintSet.START); + constraintSet.clear(relativeLayout.getId(), ConstraintSet.END); + constraintSet.clear(noPreviewLinkImageView.getId(), ConstraintSet.START); + constraintSet.clear(noPreviewLinkImageView.getId(), ConstraintSet.END); + int barrierId = 1234; + constraintSet.createBarrier(barrierId, Barrier.END, R.id.image_view_wrapper_item_post_compact, + R.id.image_view_no_preview_link_item_post_compact); + constraintSet.connect(titleTextView.getId(), ConstraintSet.START, barrierId, ConstraintSet.END); + constraintSet.connect(titleTextView.getId(), ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END); + constraintSet.connect(R.id.flow_layout_item_post_compact, ConstraintSet.START, barrierId, ConstraintSet.END); + constraintSet.connect(R.id.flow_layout_item_post_compact, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END); + constraintSet.connect(R.id.flow_layout_item_post_compact, ConstraintSet.BOTTOM, linkTextView.getId(), ConstraintSet.TOP); + constraintSet.connect(linkTextView.getId(), ConstraintSet.START, barrierId, ConstraintSet.END); + constraintSet.connect(linkTextView.getId(), ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END); + constraintSet.connect(relativeLayout.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START); + constraintSet.connect(relativeLayout.getId(), ConstraintSet.END, barrierId, ConstraintSet.START); + constraintSet.connect(noPreviewLinkImageView.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START); + constraintSet.connect(noPreviewLinkImageView.getId(), ConstraintSet.END, barrierId, ConstraintSet.START); + constraintSet.applyTo(titleAndImageConstraintLayout); + + ((ConstraintLayout.LayoutParams) relativeLayout.getLayoutParams()).leftMargin = (int) Utils.convertDpToPixel(16, mActivity); + } + itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor)); postTimeTextView.setTextColor(mSecondaryTextColor); titleTextView.setTextColor(mPostTitleColor); @@ -2641,6 +2687,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView commentsCountTextView.setCompoundDrawablesWithIntrinsicBounds(mCommentIcon, null, null, null); saveButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); shareButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); + divider.setBackgroundColor(mDividerColor); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ShowThumbnailOnTheRightInCompactLayoutEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ShowThumbnailOnTheRightInCompactLayoutEvent.java new file mode 100644 index 00000000..f1010773 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ShowThumbnailOnTheRightInCompactLayoutEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.Event; + +public class ShowThumbnailOnTheRightInCompactLayoutEvent { + public boolean showThumbnailOnTheRightInCompactLayout; + + public ShowThumbnailOnTheRightInCompactLayoutEvent(boolean showThumbnailOnTheRightInCompactLayout) { + this.showThumbnailOnTheRightInCompactLayout = showThumbnailOnTheRightInCompactLayout; + } +} 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 37888f9a..48972914 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -69,6 +69,7 @@ import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent import ml.docilealligator.infinityforreddit.Event.ChangeWifiStatusEvent; import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList; import ml.docilealligator.infinityforreddit.Event.ShowDividerInCompactLayoutPreferenceEvent; +import ml.docilealligator.infinityforreddit.Event.ShowThumbnailOnTheRightInCompactLayoutEvent; import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.NetworkState; @@ -905,6 +906,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } } + @Subscribe + public void onShowThumbnailOnTheRightInCompactLayoutEvent(ShowThumbnailOnTheRightInCompactLayoutEvent showThumbnailOnTheRightInCompactLayoutEvent) { + if (mAdapter != null) { + mAdapter.setShowThumbnailOnTheRightInCompactLayout(showThumbnailOnTheRightInCompactLayoutEvent.showThumbnailOnTheRightInCompactLayout); + refreshAdapter(); + } + } + private void refreshAdapter() { int previousPosition = -1; if (mLinearLayoutManager != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ImmersiveInterfacePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ImmersiveInterfacePreferenceFragment.java new file mode 100644 index 00000000..c9f95e98 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ImmersiveInterfacePreferenceFragment.java @@ -0,0 +1,53 @@ +package ml.docilealligator.infinityforreddit.Settings; + +import android.os.Build; +import android.os.Bundle; + +import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.SwitchPreference; + +import org.greenrobot.eventbus.EventBus; + +import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; + +public class ImmersiveInterfacePreferenceFragment extends PreferenceFragmentCompat { + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + setPreferencesFromResource(R.xml.immersive_interface_preferences, rootKey); + + SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY); + SwitchPreference immersiveInterfaceIgnoreNavBarSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY); + + if (immersiveInterfaceSwitch != null && immersiveInterfaceIgnoreNavBarSwitch != null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + immersiveInterfaceSwitch.setVisible(true); + immersiveInterfaceSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + if ((Boolean) newValue) { + immersiveInterfaceIgnoreNavBarSwitch.setVisible(true); + } else { + immersiveInterfaceIgnoreNavBarSwitch.setVisible(false); + } + EventBus.getDefault().post(new RecreateActivityEvent()); + return true; + }); + + if (immersiveInterfaceSwitch.isChecked()) { + immersiveInterfaceIgnoreNavBarSwitch.setVisible(true); + } else { + immersiveInterfaceIgnoreNavBarSwitch.setVisible(false); + } + + immersiveInterfaceIgnoreNavBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new RecreateActivityEvent()); + return true; + }); + } else { + immersiveInterfaceSwitch.setVisible(false); + immersiveInterfaceIgnoreNavBarSwitch.setVisible(false); + } + } + } +}
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java index c3c21c1c..85ba2a5e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java @@ -1,10 +1,8 @@ package ml.docilealligator.infinityforreddit.Settings; -import android.os.Build; import android.os.Bundle; -import androidx.fragment.app.Fragment; import androidx.preference.ListPreference; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; @@ -17,56 +15,24 @@ import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent; import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Event.ShowDividerInCompactLayoutPreferenceEvent; +import ml.docilealligator.infinityforreddit.Event.ShowThumbnailOnTheRightInCompactLayoutEvent; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; -/** - * A simple {@link Fragment} subclass. - */ public class InterfacePreferenceFragment extends PreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.interface_preference, rootKey); - SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY); - SwitchPreference immersiveInterfaceIgnoreNavBarSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY); SwitchPreference bottomAppBarSwitch = findPreference(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY); SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY); SwitchPreference showElapsedTimeSwitch = findPreference(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY); ListPreference defaultPostLayoutSwitch = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY); SwitchPreference showDividerInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT); + SwitchPreference showThumbnailOnTheRightInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_THUMBNAIL_ON_THE_RIGHT_IN_COMPACT_LAYOUT); SwitchPreference showAbsoluteNumberOfVotes = findPreference(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES); - if (immersiveInterfaceSwitch != null && immersiveInterfaceIgnoreNavBarSwitch != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - immersiveInterfaceSwitch.setVisible(true); - immersiveInterfaceSwitch.setOnPreferenceChangeListener((preference, newValue) -> { - if ((Boolean) newValue) { - immersiveInterfaceIgnoreNavBarSwitch.setVisible(true); - } else { - immersiveInterfaceIgnoreNavBarSwitch.setVisible(false); - } - EventBus.getDefault().post(new RecreateActivityEvent()); - return true; - }); - - if (immersiveInterfaceSwitch.isChecked()) { - immersiveInterfaceIgnoreNavBarSwitch.setVisible(true); - } else { - immersiveInterfaceIgnoreNavBarSwitch.setVisible(false); - } - - immersiveInterfaceIgnoreNavBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> { - EventBus.getDefault().post(new RecreateActivityEvent()); - return true; - }); - } else { - immersiveInterfaceSwitch.setVisible(false); - immersiveInterfaceIgnoreNavBarSwitch.setVisible(false); - } - } - if (bottomAppBarSwitch != null) { bottomAppBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new RecreateActivityEvent()); @@ -102,6 +68,13 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat { }); } + if (showThumbnailOnTheRightInCompactLayout != null) { + showThumbnailOnTheRightInCompactLayout.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ShowThumbnailOnTheRightInCompactLayoutEvent((Boolean) newValue)); + return true; + }); + } + if (showAbsoluteNumberOfVotes != null) { showAbsoluteNumberOfVotes.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeShowAbsoluteNumberOfVotesEvent((Boolean) newValue)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java index b29ff3ed..a26571a9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -74,6 +74,7 @@ public class SharedPreferencesUtils { public static final String SHOW_ELAPSED_TIME_KEY = "show_elapsed_time"; public static final String DEFAULT_POST_LAYOUT_KEY = "default_post_layout"; public static final String SHOW_DIVIDER_IN_COMPACT_LAYOUT = "show_divider_in_compact_layout"; + public static final String SHOW_THUMBNAIL_ON_THE_RIGHT_IN_COMPACT_LAYOUT = "show_thumbnail_on_the_right_in_compact_layout"; public static final String SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL = "swipe_to_go_back_from_post_detail"; public static final String VOLUME_KEYS_NAVIGATE_COMMENTS = "volume_keys_navigate_comments"; public static final String VOLUME_KEYS_NAVIGATE_POSTS = "volume_keys_navigate_posts"; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java index 329371dc..52a1972a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java @@ -7,6 +7,7 @@ import android.net.Network; import android.net.NetworkInfo; import android.text.Html; import android.text.Spannable; +import android.util.DisplayMetrics; import android.view.inputmethod.InputMethodManager; import android.widget.TextView; @@ -126,4 +127,8 @@ public class Utils { inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); } } + + public static float convertDpToPixel(float dp, Context context){ + return dp * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT); + } } |