Add image quality preference
This commit is contained in:
parent
af2375948d
commit
0a8f28b1c6
121 changed files with 132 additions and 220 deletions
|
|
@ -24,7 +24,7 @@ import androidx.core.content.FileProvider;
|
|||
import org.schabi.newpipe.BuildConfig;
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.extractor.Image;
|
||||
import org.schabi.newpipe.util.PicassoHelper;
|
||||
import org.schabi.newpipe.util.image.PicassoHelper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
|
@ -251,7 +251,7 @@ public final class ShareUtils {
|
|||
// If loading of images has been disabled, don't try to generate a content preview
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
|
||||
&& !TextUtils.isEmpty(imagePreviewUrl)
|
||||
&& PicassoHelper.getShouldLoadImages()) {
|
||||
&& PicassoHelper.shouldLoadImages()) {
|
||||
|
||||
final ClipData clipData = generateClipDataForImagePreview(context, imagePreviewUrl);
|
||||
if (clipData != null) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package org.schabi.newpipe.util;
|
||||
package org.schabi.newpipe.util.image;
|
||||
|
||||
import static org.schabi.newpipe.MainActivity.DEBUG;
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||
|
|
@ -46,8 +46,7 @@ public final class PicassoHelper {
|
|||
@SuppressLint("StaticFieldLeak")
|
||||
private static Picasso picassoInstance;
|
||||
|
||||
private static boolean shouldLoadImages;
|
||||
private static ResolutionLevel preferredResolutionLevel = ResolutionLevel.HIGH;
|
||||
private static PreferredImageQuality preferredImageQuality = PreferredImageQuality.MEDIUM;
|
||||
|
||||
public static void init(final Context context) {
|
||||
picassoCache = new LruCache(10 * 1024 * 1024);
|
||||
|
|
@ -93,12 +92,12 @@ public final class PicassoHelper {
|
|||
picassoInstance.setIndicatorsEnabled(enabled); // useful for debugging
|
||||
}
|
||||
|
||||
public static void setShouldLoadImages(final boolean shouldLoadImages) {
|
||||
PicassoHelper.shouldLoadImages = shouldLoadImages;
|
||||
public static void setPreferredImageQuality(final PreferredImageQuality preferredImageQuality) {
|
||||
PicassoHelper.preferredImageQuality = preferredImageQuality;
|
||||
}
|
||||
|
||||
public static boolean getShouldLoadImages() {
|
||||
return shouldLoadImages;
|
||||
public static boolean shouldLoadImages() {
|
||||
return preferredImageQuality != PreferredImageQuality.NONE;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -231,17 +230,14 @@ public final class PicassoHelper {
|
|||
|
||||
@Nullable
|
||||
public static String choosePreferredImage(final List<Image> images) {
|
||||
if (!shouldLoadImages) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Comparator<Image> comparator;
|
||||
switch (preferredResolutionLevel) {
|
||||
switch (preferredImageQuality) {
|
||||
case NONE:
|
||||
return null;
|
||||
case HIGH:
|
||||
comparator = Comparator.comparingInt(Image::getHeight).reversed();
|
||||
break;
|
||||
default:
|
||||
case UNKNOWN:
|
||||
case MEDIUM:
|
||||
comparator = Comparator.comparingInt(image -> Math.abs(image.getHeight() - 450));
|
||||
break;
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package org.schabi.newpipe.util.image;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
|
||||
public enum PreferredImageQuality {
|
||||
NONE,
|
||||
LOW,
|
||||
MEDIUM,
|
||||
HIGH;
|
||||
|
||||
public static PreferredImageQuality fromPreferenceKey(final Context context, final String key) {
|
||||
if (context.getString(R.string.image_quality_none_key).equals(key)) {
|
||||
return NONE;
|
||||
} else if (context.getString(R.string.image_quality_low_key).equals(key)) {
|
||||
return LOW;
|
||||
} else if (context.getString(R.string.image_quality_high_key).equals(key)) {
|
||||
return HIGH;
|
||||
} else {
|
||||
return MEDIUM; // default to medium
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue