Convert newpipe/util/image/PreferredImageQuality to kotlin
This commit is contained in:
parent
982d412210
commit
6038c80024
2 changed files with 38 additions and 39 deletions
|
|
@ -1,39 +0,0 @@
|
||||||
package org.schabi.newpipe.util.image;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import org.schabi.newpipe.R;
|
|
||||||
import org.schabi.newpipe.extractor.Image;
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Image.ResolutionLevel toResolutionLevel() {
|
|
||||||
switch (this) {
|
|
||||||
case LOW:
|
|
||||||
return Image.ResolutionLevel.LOW;
|
|
||||||
case MEDIUM:
|
|
||||||
return Image.ResolutionLevel.MEDIUM;
|
|
||||||
case HIGH:
|
|
||||||
return Image.ResolutionLevel.HIGH;
|
|
||||||
default:
|
|
||||||
case NONE:
|
|
||||||
return Image.ResolutionLevel.UNKNOWN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2023-2025 NewPipe contributors <https://newpipe.net>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.schabi.newpipe.util.image
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import org.schabi.newpipe.R
|
||||||
|
import org.schabi.newpipe.extractor.Image.ResolutionLevel
|
||||||
|
|
||||||
|
enum class PreferredImageQuality {
|
||||||
|
NONE,
|
||||||
|
LOW,
|
||||||
|
MEDIUM,
|
||||||
|
HIGH;
|
||||||
|
|
||||||
|
fun toResolutionLevel(): ResolutionLevel {
|
||||||
|
return when (this) {
|
||||||
|
LOW -> ResolutionLevel.LOW
|
||||||
|
MEDIUM -> ResolutionLevel.MEDIUM
|
||||||
|
HIGH -> ResolutionLevel.HIGH
|
||||||
|
NONE -> ResolutionLevel.UNKNOWN
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
fun fromPreferenceKey(context: Context, key: String?): PreferredImageQuality {
|
||||||
|
return when (key) {
|
||||||
|
context.getString(R.string.image_quality_none_key) -> NONE
|
||||||
|
context.getString(R.string.image_quality_low_key) -> LOW
|
||||||
|
context.getString(R.string.image_quality_high_key) -> HIGH
|
||||||
|
else -> MEDIUM // default to medium
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue