Add code review suggestions.
This commit is contained in:
parent
b90a566dd8
commit
3b80547976
|
@ -1,7 +1,5 @@
|
|||
package org.schabi.newpipe.extractor.stream;
|
||||
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
|
||||
|
||||
import org.schabi.newpipe.extractor.MediaFormat;
|
||||
import org.schabi.newpipe.extractor.services.youtube.ItagItem;
|
||||
import org.schabi.newpipe.extractor.utils.LocaleCompat;
|
||||
|
|
|
@ -2,15 +2,22 @@ package org.schabi.newpipe.extractor.utils;
|
|||
|
||||
import java.util.Locale;
|
||||
|
||||
public class LocaleCompat {
|
||||
/**
|
||||
* This class contains a simple implementation of {@link Locale#forLanguageTag(String)} for Android
|
||||
* API levels below 21 (Lollipop). This is needed as core library desugaring does not backport that
|
||||
* method as of this writing.
|
||||
*
|
||||
* Relevant issue: https://issuetracker.google.com/issues/171182330
|
||||
*/
|
||||
public final class LocaleCompat {
|
||||
private LocaleCompat() {
|
||||
}
|
||||
|
||||
// Source: LocaleListCompat's private forLanguageTagCompat() method.
|
||||
// Use Locale.forLanguageTag() on API level >= 21 instead.
|
||||
// Source: The AndroidX LocaleListCompat class's private forLanguageTagCompat() method.
|
||||
// Use Locale.forLanguageTag() on Android API level >= 21 / Java instead.
|
||||
public static Locale forLanguageTag(final String str) {
|
||||
if (str.contains("-")) {
|
||||
String[] args = str.split("-", -1);
|
||||
final String[] args = str.split("-", -1);
|
||||
if (args.length > 2) {
|
||||
return new Locale(args[0], args[1], args[2]);
|
||||
} else if (args.length > 1) {
|
||||
|
@ -19,7 +26,7 @@ public class LocaleCompat {
|
|||
return new Locale(args[0]);
|
||||
}
|
||||
} else if (str.contains("_")) {
|
||||
String[] args = str.split("_", -1);
|
||||
final String[] args = str.split("_", -1);
|
||||
if (args.length > 2) {
|
||||
return new Locale(args[0], args[1], args[2]);
|
||||
} else if (args.length > 1) {
|
||||
|
|
Loading…
Reference in New Issue