New option: Settings->Miscellaneous->Post Feed Preview Max Resolution. Fix low resolution post previews when showing them for the first time. Tweak themed icon.

This commit is contained in:
Docile-Alligator 2022-03-06 10:41:02 +08:00
parent dc9725735b
commit 141abc654a
12 changed files with 220 additions and 44 deletions

View File

@ -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;
}
}

View File

@ -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);
}
}
}

View File

@ -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());
}
((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());
}
((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());
}
((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());
}
((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());
}
((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());
}
((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);

View File

@ -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();

View File

@ -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;
}
}

View File

@ -0,0 +1,9 @@
package ml.docilealligator.infinityforreddit.events;
public class ChangePostFeedMaxResolutionEvent {
public int postFeedMaxResolution;
public ChangePostFeedMaxResolutionEvent(int postFeedMaxResolution) {
this.postFeedMaxResolution = postFeedMaxResolution;
}
}

View File

@ -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) {

View File

@ -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;
});
}
}
}

View File

@ -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";

File diff suppressed because one or more lines are too long

View File

@ -637,6 +637,9 @@
<string name="settings_reddit_user_agreement_title">Reddit User Agreement</string>
<string name="settings_always_show_child_comment_count_title">Always Show the Number of Child Comments</string>
<string name="settings_hide_upvote_ratio_title">Hide Upvote Ratio</string>
<string name="settings_miscellaneous_dangerous_group_title">Dangerous</string>
<string name="settings_post_feed_max_resolution_warning_title">Increase the value to show previews in higher resolution, but the app may crash unexpectedly.</string>
<string name="settings_post_feed_max_resolution_title">Post Feed Preview Max Resolution (Width * Height)</string>
<string name="no_link_available">Cannot get the link</string>
@ -1283,4 +1286,6 @@
<string name="option_5_hint">Option 5</string>
<string name="option_6_hint">Option 6</string>
<string name="not_a_valid_number">Not a valid number</string>
</resources>

View File

@ -40,4 +40,18 @@
app:title="@string/settings_language_title"
app:useSimpleSummaryProvider="true" />
<ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceCategory
app:title="@string/settings_miscellaneous_dangerous_group_title" />
<ml.docilealligator.infinityforreddit.customviews.CustomFontPreference
app:icon="@drawable/ic_info_preference_24dp"
app:summary="@string/settings_post_feed_max_resolution_warning_title"
app:enabled="false" />
<ml.docilealligator.infinityforreddit.customviews.CustomFontEditTextPreference
app:defaultValue="5000000"
app:key="post_feed_max_resolution"
app:title="@string/settings_post_feed_max_resolution_title"
app:useSimpleSummaryProvider="true" />
</PreferenceScreen>