diff options
Diffstat (limited to 'app/src/main/java')
5 files changed, 45 insertions, 11 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index cec20a29..82ccc212 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -206,6 +206,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie private boolean mHideTheNumberOfVotes; private boolean mHideTheNumberOfComments; private boolean mLegacyAutoplayVideoControllerUI; + private boolean mFixedHeightPreviewInCard; private Drawable mCommentIcon; private ExoCreator mExoCreator; private Callback mCallback; @@ -282,6 +283,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie mHideTheNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES, false); mHideTheNumberOfComments = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_COMMENTS, false); mLegacyAutoplayVideoControllerUI = sharedPreferences.getBoolean(SharedPreferencesUtils.LEGACY_AUTOPLAY_VIDEO_CONTROLLER_UI, false); + mFixedHeightPreviewInCard = sharedPreferences.getBoolean(SharedPreferencesUtils.FIXED_HEIGHT_PREVIEW_IN_CARD, false); mPostLayout = postLayout; mDefaultLinkPostLayout = Integer.parseInt(sharedPreferences.getString(SharedPreferencesUtils.DEFAULT_LINK_POST_LAYOUT_KEY, "-1")); @@ -681,7 +683,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie if (holder instanceof PostVideoAutoplayViewHolder) { ((PostVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.VISIBLE); Post.Preview preview = getSuitablePreview(post.getPreviews()); - if (preview != null) { + if (!mFixedHeightPreviewInCard && preview != null) { ((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewWidth() / preview.getPreviewHeight()); mGlide.load(preview.getPreviewUrl()).centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostVideoAutoplayViewHolder) holder).previewImageView); } else { @@ -798,7 +800,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostWithPreviewTypeViewHolder) holder).preview = preview; if (preview != null) { ((PostWithPreviewTypeViewHolder) holder).imageWrapperRelativeLayout.setVisibility(View.VISIBLE); - if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { int height = (int) (400 * mScale); ((PostWithPreviewTypeViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); ((PostWithPreviewTypeViewHolder) holder).imageView.getLayoutParams().height = height; @@ -833,7 +835,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } else if (holder instanceof PostCard2VideoAutoplayViewHolder) { ((PostCard2VideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.VISIBLE); Post.Preview preview = getSuitablePreview(post.getPreviews()); - if (preview != null) { + if (!mFixedHeightPreviewInCard && preview != null) { ((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewWidth() / preview.getPreviewHeight()); mGlide.load(preview.getPreviewUrl()).centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostCard2VideoAutoplayViewHolder) holder).previewImageView); } else { @@ -952,7 +954,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostCard2WithPreviewViewHolder) holder).preview = preview; if (preview != null) { ((PostCard2WithPreviewViewHolder) holder).imageView.setVisibility(View.VISIBLE); - if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { int height = (int) (400 * mScale); ((PostCard2WithPreviewViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); ((PostCard2WithPreviewViewHolder) holder).imageView.getLayoutParams().height = height; @@ -1261,7 +1263,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostCompactBaseViewHolder) holder).noPreviewPostImageView.setImageResource(R.drawable.ic_image_24dp); } else { ((PostCompactBaseViewHolder) holder).playButtonImageView.setVisibility(View.VISIBLE); - ((PostCompactBaseViewHolder) holder).playButtonImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp)); + ((PostCompactBaseViewHolder) holder).playButtonImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_24dp)); } break; case Post.VIDEO_TYPE: @@ -1271,7 +1273,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostCompactBaseViewHolder) holder).noPreviewPostImageView.setImageResource(R.drawable.ic_outline_video_24dp); } else { ((PostCompactBaseViewHolder) holder).playButtonImageView.setVisibility(View.VISIBLE); - ((PostCompactBaseViewHolder) holder).playButtonImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp)); + ((PostCompactBaseViewHolder) holder).playButtonImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_24dp)); } break; case Post.NO_PREVIEW_LINK_TYPE: @@ -1332,7 +1334,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie Post.Preview preview = getSuitablePreview(post.getPreviews()); ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { - if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { int height = (int) (400 * mScale); ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; @@ -1366,7 +1368,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie Post.Preview preview = getSuitablePreview(post.getPreviews()); ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { - if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { int height = (int) (400 * mScale); ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; @@ -1390,7 +1392,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie Post.Preview preview = getSuitablePreview(post.getPreviews()); ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { - if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { int height = (int) (400 * mScale); ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; @@ -1414,7 +1416,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie Post.Preview preview = getSuitablePreview(post.getPreviews()); ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { - if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { int height = (int) (400 * mScale); ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; @@ -1448,7 +1450,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie Post.Preview preview = getSuitablePreview(post.getPreviews()); ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { - if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { int height = (int) (400 * mScale); ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; @@ -1731,6 +1733,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie mDefaultLinkPostLayout = defaultLinkPostLayout; } + public void setFixedHeightPreviewInCard(boolean fixedHeightPreviewInCard) { + mFixedHeightPreviewInCard = fixedHeightPreviewInCard; + } + @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { super.onViewRecycled(holder); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeFixedHeightPreviewInCardEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeFixedHeightPreviewInCardEvent.java new file mode 100644 index 00000000..fff0c816 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeFixedHeightPreviewInCardEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.events; + +public class ChangeFixedHeightPreviewInCardEvent { + public boolean fixedHeightPreviewInCard; + + public ChangeFixedHeightPreviewInCardEvent(boolean fixedHeightPreviewInCard) { + this.fixedHeightPreviewInCard = fixedHeightPreviewInCard; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index 6d63b6c7..3638190c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -95,6 +95,7 @@ import ml.docilealligator.infinityforreddit.events.ChangeDefaultLinkPostLayoutEv import ml.docilealligator.infinityforreddit.events.ChangeDefaultPostLayoutEvent; import ml.docilealligator.infinityforreddit.events.ChangeDisableImagePreviewEvent; import ml.docilealligator.infinityforreddit.events.ChangeEnableSwipeActionSwitchEvent; +import ml.docilealligator.infinityforreddit.events.ChangeFixedHeightPreviewInCardEvent; import ml.docilealligator.infinityforreddit.events.ChangeHidePostFlairEvent; import ml.docilealligator.infinityforreddit.events.ChangeHidePostTypeEvent; import ml.docilealligator.infinityforreddit.events.ChangeHideSubredditAndUserPrefixEvent; @@ -2065,6 +2066,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } } + @Subscribe + public void onChangeFixedHeightPreviewCardEvent(ChangeFixedHeightPreviewInCardEvent event) { + if (mAdapter != null) { + mAdapter.setFixedHeightPreviewInCard(event.fixedHeightPreviewInCard); + refreshAdapter(); + } + } + private void refreshAdapter() { int previousPosition = -1; if (mLinearLayoutManager != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java index a93bc592..d4785cc7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java @@ -13,6 +13,7 @@ import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFrag import ml.docilealligator.infinityforreddit.events.ChangeCompactLayoutToolbarHiddenByDefaultEvent; import ml.docilealligator.infinityforreddit.events.ChangeDefaultLinkPostLayoutEvent; import ml.docilealligator.infinityforreddit.events.ChangeDefaultPostLayoutEvent; +import ml.docilealligator.infinityforreddit.events.ChangeFixedHeightPreviewInCardEvent; import ml.docilealligator.infinityforreddit.events.ChangeHidePostFlairEvent; import ml.docilealligator.infinityforreddit.events.ChangeHidePostTypeEvent; import ml.docilealligator.infinityforreddit.events.ChangeHideSubredditAndUserPrefixEvent; @@ -48,6 +49,7 @@ public class PostPreferenceFragment extends CustomFontPreferenceFragmentCompat { SwitchPreference hideSubredditAndUserPrefixSwitch = findPreference(SharedPreferencesUtils.HIDE_SUBREDDIT_AND_USER_PREFIX); SwitchPreference hideTheNumberOfVotesSwitch = findPreference(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES); SwitchPreference hideTheNumberOfCommentsSwitch = findPreference(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_COMMENTS); + SwitchPreference fixedHeightPreviewInCardSwitch = findPreference(SharedPreferencesUtils.FIXED_HEIGHT_PREVIEW_IN_CARD); if (defaultPostLayoutList != null) { defaultPostLayoutList.setOnPreferenceChangeListener((preference, newValue) -> { @@ -142,5 +144,12 @@ public class PostPreferenceFragment extends CustomFontPreferenceFragmentCompat { } }); } + + if (fixedHeightPreviewInCardSwitch != null) { + fixedHeightPreviewInCardSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeFixedHeightPreviewInCardEvent((Boolean) newValue)); + return true; + }); + } } }
\ No newline at end of file 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 fad3a640..e5713e4f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -200,6 +200,7 @@ public class SharedPreferencesUtils { public static final String DEFAULT_PLAYBACK_SPEED = "default_playback_speed"; public static final String LEGACY_AUTOPLAY_VIDEO_CONTROLLER_UI = "legacy_autoplay_video_controller_ui"; public static final String PINCH_TO_ZOOM_VIDEO = "pinch_to_zoom_video"; + public static final String FIXED_HEIGHT_PREVIEW_IN_CARD = "fixed_height_preview_in_card"; 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"; |