aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorDocile-Alligator <chineseperson5@gmail.com>2022-03-06 02:41:02 +0000
committerDocile-Alligator <chineseperson5@gmail.com>2022-03-06 02:41:02 +0000
commit141abc654a66c003351091d9df9f94229d9eb9ce (patch)
treea399cbeb6bbc32f739cb49e83671b09ef76e3f5f /app/src/main/java
parentdc9725735baa027ce68a59648cc810e7daf77ce9 (diff)
downloadinfinity-for-reddit-141abc654a66c003351091d9df9f94229d9eb9ce.tar
infinity-for-reddit-141abc654a66c003351091d9df9f94229d9eb9ce.tar.gz
infinity-for-reddit-141abc654a66c003351091d9df9f94229d9eb9ce.tar.bz2
infinity-for-reddit-141abc654a66c003351091d9df9f94229d9eb9ce.tar.lz
infinity-for-reddit-141abc654a66c003351091d9df9f94229d9eb9ce.tar.xz
infinity-for-reddit-141abc654a66c003351091d9df9f94229d9eb9ce.tar.zst
infinity-for-reddit-141abc654a66c003351091d9df9f94229d9eb9ce.zip
New option: Settings->Miscellaneous->Post Feed Preview Max Resolution. Fix low resolution post previews when showing them for the first time. Tweak themed icon.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SaveMemoryCenterInisdeDownsampleStrategy.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java75
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontEditTextPreference.java52
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangePostFeedMaxResolutionEvent.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/MiscellaneousPreferenceFragment.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java1
9 files changed, 174 insertions, 20 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SaveMemoryCenterInisdeDownsampleStrategy.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SaveMemoryCenterInisdeDownsampleStrategy.java
index 8516c53e..acb38267 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SaveMemoryCenterInisdeDownsampleStrategy.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SaveMemoryCenterInisdeDownsampleStrategy.java
@@ -4,16 +4,22 @@ import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy;
public class SaveMemoryCenterInisdeDownsampleStrategy extends DownsampleStrategy {
+ private int threshold;
+
+ public SaveMemoryCenterInisdeDownsampleStrategy(int threshold) {
+ this.threshold = threshold;
+ }
+
@Override
public float getScaleFactor(int sourceWidth, int sourceHeight, int requestedWidth, int requestedHeight) {
int originalSourceWidth = sourceWidth;
int originalSourceHeight = sourceHeight;
- if (sourceWidth * sourceHeight > 5_000_000) {
+ if (sourceWidth * sourceHeight > threshold) {
int divisor = 2;
do {
sourceWidth /= divisor;
sourceHeight /= divisor;
- } while (sourceWidth * sourceHeight > 5_000_000);
+ } while (sourceWidth * sourceHeight > threshold);
}
float widthPercentage = (float) requestedWidth / (float) sourceWidth;
@@ -26,4 +32,8 @@ public class SaveMemoryCenterInisdeDownsampleStrategy extends DownsampleStrategy
public SampleSizeRounding getSampleSizeRounding(int sourceWidth, int sourceHeight, int requestedWidth, int requestedHeight) {
return SampleSizeRounding.MEMORY;
}
+
+ public void setThreshold(int threshold) {
+ this.threshold = threshold;
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
index 529bed8d..983c887a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
@@ -141,6 +141,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private Retrofit mStreamableRetrofit;
private RedditDataRoomDatabase mRedditDataRoomDatabase;
private RequestManager mGlide;
+ private SaveMemoryCenterInisdeDownsampleStrategy mSaveMemoryCenterInsideDownSampleStrategy;
private Markwon mPostDetailMarkwon;
private final MarkwonAdapter mMarkwonAdapter;
private String mAccessToken;
@@ -233,6 +234,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mStreamableRetrofit = streamableRetrofit;
mRedditDataRoomDatabase = redditDataRoomDatabase;
mGlide = glide;
+ mSaveMemoryCenterInsideDownSampleStrategy = new SaveMemoryCenterInisdeDownsampleStrategy(Integer.parseInt(sharedPreferences.getString(SharedPreferencesUtils.POST_FEED_MAX_RESOLUTION, "5000000")));
mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
int markdownColor = customThemeWrapper.getPostContentColor();
int postSpoilerBackgroundColor = markdownColor | 0xFF000000;
@@ -655,7 +657,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
Post.Preview preview = getSuitablePreview(mPost.getPreviews());
if (preview != null) {
((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewWidth() / preview.getPreviewHeight());
- mGlide.load(preview.getPreviewUrl()).centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView);
+ mGlide.load(preview.getPreviewUrl()).centerInside().downsample(mSaveMemoryCenterInsideDownSampleStrategy).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView);
} else {
((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
}
@@ -916,7 +918,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
if (blurImage) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
} else {
- imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
+ imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownSampleStrategy).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
}
} else if (holder instanceof PostDetailVideoAndGifPreviewHolder) {
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl())
@@ -944,7 +946,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
} else {
- imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
+ imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownSampleStrategy).into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
}
} else if (holder instanceof PostDetailLinkViewHolder) {
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl())
@@ -972,7 +974,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostDetailLinkViewHolder) holder).mImageView);
} else {
- imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostDetailLinkViewHolder) holder).mImageView);
+ imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownSampleStrategy).into(((PostDetailLinkViewHolder) holder).mImageView);
}
} else if (holder instanceof PostDetailGalleryViewHolder) {
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl())
@@ -999,7 +1001,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
if ((mPost.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mPost.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || (mPost.isSpoiler() && mNeedBlurSpoiler)) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).into(((PostDetailGalleryViewHolder) holder).mImageView);
} else {
- imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostDetailGalleryViewHolder) holder).mImageView);
+ imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownSampleStrategy).into(((PostDetailGalleryViewHolder) holder).mImageView);
}
}
}
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 6a25642e..15504df8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
@@ -11,9 +11,11 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -135,6 +137,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
private Retrofit mStreamableRetrofit;
private String mAccessToken;
private RequestManager mGlide;
+ private int mMaxResolution;
+ private SaveMemoryCenterInisdeDownsampleStrategy mSaveMemoryCenterInsideDownsampleStrategy;
private Locale mLocale;
private boolean canStartActivity = true;
private int mPostType;
@@ -332,6 +336,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
mScale = resources.getDisplayMetrics().density;
mGlide = Glide.with(mActivity);
+ mMaxResolution = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.POST_FEED_MAX_RESOLUTION, "5000000"));
+ mSaveMemoryCenterInsideDownsampleStrategy = new SaveMemoryCenterInisdeDownsampleStrategy(mMaxResolution);
mLocale = locale;
mExoCreator = exoCreator;
mCallback = callback;
@@ -687,7 +693,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
Post.Preview preview = getSuitablePreview(post.getPreviews());
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);
+ mGlide.load(preview.getPreviewUrl()).centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostVideoAutoplayViewHolder) holder).previewImageView);
} else {
((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
}
@@ -810,7 +816,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostWithPreviewTypeViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
}
- loadImage(holder);
+ ((PostWithPreviewTypeViewHolder) holder).imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ ((PostWithPreviewTypeViewHolder) holder).imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ loadImage(holder);
+ }
+ });
} else {
((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE);
if (post.getPostType() == Post.VIDEO_TYPE) {
@@ -839,7 +851,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
Post.Preview preview = getSuitablePreview(post.getPreviews());
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);
+ mGlide.load(preview.getPreviewUrl()).centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostCard2VideoAutoplayViewHolder) holder).previewImageView);
} else {
((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
}
@@ -964,7 +976,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostCard2WithPreviewViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
}
- loadImage(holder);
+ ((PostCard2WithPreviewViewHolder) holder).imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ ((PostCard2WithPreviewViewHolder) holder).imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ loadImage(holder);
+ }
+ });
} else {
((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.GONE);
((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
@@ -1342,7 +1360,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostGalleryViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
}
- loadImage(holder);
+ ((PostGalleryViewHolder) holder).imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ ((PostGalleryViewHolder) holder).imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ loadImage(holder);
+ }
+ });
} else {
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
if (post.getPostType() == Post.VIDEO_TYPE) {
@@ -1400,7 +1424,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostGalleryViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
}
- loadImage(holder);
+ ((PostGalleryViewHolder) holder).imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ ((PostGalleryViewHolder) holder).imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ loadImage(holder);
+ }
+ });
} else {
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp);
@@ -1424,7 +1454,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostGalleryViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
}
- loadImage(holder);
+ ((PostGalleryViewHolder) holder).imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ ((PostGalleryViewHolder) holder).imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ loadImage(holder);
+ }
+ });
} else {
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link);
@@ -1458,7 +1494,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostGalleryViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
}
- loadImage(holder);
+ ((PostGalleryViewHolder) holder).imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ ((PostGalleryViewHolder) holder).imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ loadImage(holder);
+ }
+ });
} else {
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp);
@@ -1481,10 +1523,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
previewIndex = 0;
}
preview = previews.get(previewIndex);
- if (preview.getPreviewWidth() * preview.getPreviewHeight() > 5_000_000) {
+ if (preview.getPreviewWidth() * preview.getPreviewHeight() > mMaxResolution) {
for (int i = previews.size() - 1; i >= 1; i--) {
preview = previews.get(i);
- if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 5_000_000) {
+ if (preview.getPreviewWidth() * preview.getPreviewHeight() <= mMaxResolution) {
return preview;
}
}
@@ -1513,7 +1555,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostWithPreviewTypeViewHolder) holder).imageView);
} else {
- imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostWithPreviewTypeViewHolder) holder).imageView);
+ imageRequestBuilder.downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostWithPreviewTypeViewHolder) holder).imageView);
}
}
} else if (holder instanceof PostCompactBaseViewHolder) {
@@ -1553,7 +1595,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostGalleryViewHolder) holder).imageView);
} else {
- imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostGalleryViewHolder) holder).imageView);
+ imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostGalleryViewHolder) holder).imageView);
}
}
} else if (holder instanceof PostCard2WithPreviewViewHolder) {
@@ -1573,7 +1615,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostCard2WithPreviewViewHolder) holder).imageView);
} else {
- imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostCard2WithPreviewViewHolder) holder).imageView);
+ imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostCard2WithPreviewViewHolder) holder).imageView);
}
}
}
@@ -1741,6 +1783,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
mHideTextPostContent = hideTextPostContent;
}
+ public void setPostFeedMaxResolution(int postFeedMaxResolution) {
+ mMaxResolution = postFeedMaxResolution;
+ if (mSaveMemoryCenterInsideDownsampleStrategy != null) {
+ mSaveMemoryCenterInsideDownsampleStrategy.setThreshold(postFeedMaxResolution);
+ }
+ }
+
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
super.onViewRecycled(holder);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java
index bd735f90..499e92b2 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java
@@ -37,6 +37,7 @@ public class AspectRatioGifImageView extends GifImageView {
}
+ @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = this.getMeasuredWidth();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontEditTextPreference.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontEditTextPreference.java
new file mode 100644
index 00000000..bbdb1f80
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontEditTextPreference.java
@@ -0,0 +1,52 @@
+package ml.docilealligator.infinityforreddit.customviews;
+
+import android.content.Context;
+import android.graphics.Typeface;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.TextView;
+
+import androidx.preference.EditTextPreference;
+import androidx.preference.PreferenceViewHolder;
+
+import ml.docilealligator.infinityforreddit.CustomFontReceiver;
+
+public class CustomFontEditTextPreference extends EditTextPreference implements CustomFontReceiver {
+ private Typeface typeface;
+
+ public CustomFontEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ public CustomFontEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ public CustomFontEditTextPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public CustomFontEditTextPreference(Context context) {
+ super(context);
+ }
+
+ @Override
+ public void onBindViewHolder(PreferenceViewHolder holder) {
+ super.onBindViewHolder(holder);
+ if (typeface != null) {
+ View titleTextView = holder.findViewById(android.R.id.title);
+ if (titleTextView instanceof TextView) {
+ ((TextView) titleTextView).setTypeface(typeface);
+ }
+ View summaryTextView = holder.findViewById(android.R.id.summary);
+ if (summaryTextView instanceof TextView) {
+ ((TextView) summaryTextView).setTypeface(typeface);
+ }
+ }
+ }
+
+ @Override
+ public void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface) {
+ this.typeface = typeface;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangePostFeedMaxResolutionEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangePostFeedMaxResolutionEvent.java
new file mode 100644
index 00000000..ac83ae4a
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangePostFeedMaxResolutionEvent.java
@@ -0,0 +1,9 @@
+package ml.docilealligator.infinityforreddit.events;
+
+public class ChangePostFeedMaxResolutionEvent {
+ public int postFeedMaxResolution;
+
+ public ChangePostFeedMaxResolutionEvent(int postFeedMaxResolution) {
+ this.postFeedMaxResolution = postFeedMaxResolution;
+ }
+}
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 22071f55..cba59d00 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
@@ -109,6 +109,7 @@ import ml.docilealligator.infinityforreddit.events.ChangeMuteNSFWVideoEvent;
import ml.docilealligator.infinityforreddit.events.ChangeNSFWBlurEvent;
import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
import ml.docilealligator.infinityforreddit.events.ChangeOnlyDisablePreviewInVideoAndGifPostsEvent;
+import ml.docilealligator.infinityforreddit.events.ChangePostFeedMaxResolutionEvent;
import ml.docilealligator.infinityforreddit.events.ChangePostLayoutEvent;
import ml.docilealligator.infinityforreddit.events.ChangePullToRefreshEvent;
import ml.docilealligator.infinityforreddit.events.ChangeRememberMutingOptionInPostFeedEvent;
@@ -2089,6 +2090,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
}
+ @Subscribe
+ public void onChangePostFeedMaxResolutionEvent(ChangePostFeedMaxResolutionEvent event) {
+ if (mAdapter != null) {
+ mAdapter.setPostFeedMaxResolution(event.postFeedMaxResolution);
+ refreshAdapter();
+ }
+ }
+
private void refreshAdapter() {
int previousPosition = -1;
if (mLinearLayoutManager != null) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MiscellaneousPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MiscellaneousPreferenceFragment.java
index 0c9d5fa7..9fef58ab 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MiscellaneousPreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MiscellaneousPreferenceFragment.java
@@ -2,7 +2,9 @@ package ml.docilealligator.infinityforreddit.settings;
import android.content.SharedPreferences;
import android.os.Bundle;
+import android.widget.Toast;
+import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference;
import androidx.preference.SwitchPreference;
@@ -14,6 +16,7 @@ import javax.inject.Named;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat;
+import ml.docilealligator.infinityforreddit.events.ChangePostFeedMaxResolutionEvent;
import ml.docilealligator.infinityforreddit.events.ChangeSavePostFeedScrolledPositionEvent;
import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
@@ -41,6 +44,7 @@ public class MiscellaneousPreferenceFragment extends CustomFontPreferenceFragmen
ListPreference mainPageBackButtonActionListPreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_BACK_BUTTON_ACTION);
SwitchPreference savePostFeedScrolledPositionSwitch = findPreference(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION);
ListPreference languageListPreference = findPreference(SharedPreferencesUtils.LANGUAGE);
+ EditTextPreference postFeedMaxResolution = findPreference(SharedPreferencesUtils.POST_FEED_MAX_RESOLUTION);
if (mainPageBackButtonActionListPreference != null) {
mainPageBackButtonActionListPreference.setOnPreferenceChangeListener((preference, newValue) -> {
@@ -65,5 +69,22 @@ public class MiscellaneousPreferenceFragment extends CustomFontPreferenceFragmen
return true;
});
}
+
+ if (postFeedMaxResolution != null) {
+ postFeedMaxResolution.setOnPreferenceChangeListener((preference, newValue) -> {
+ try {
+ int resolution = Integer.parseInt((String) newValue);
+ if (resolution <= 0) {
+ Toast.makeText(activity, R.string.not_a_valid_number, Toast.LENGTH_SHORT).show();
+ return false;
+ }
+ EventBus.getDefault().post(new ChangePostFeedMaxResolutionEvent(resolution));
+ } catch (NumberFormatException e) {
+ Toast.makeText(activity, R.string.not_a_valid_number, Toast.LENGTH_SHORT).show();
+ return false;
+ }
+ 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 4ade7642..9417352d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
@@ -208,6 +208,7 @@ public class SharedPreferencesUtils {
public static final String SHOW_AUTHOR_AVATAR = "show_author_avatar";
public static final String ALWAYS_SHOW_CHILD_COMMENT_COUNT = "always_show_child_comment_count";
public static final String HIDE_UPVOTE_RATIO = "hide_upvote_ratio";
+ public static final String POST_FEED_MAX_RESOLUTION = "post_feed_max_resolution";
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";