mirror of
https://github.com/revanced/revanced-patches.git
synced 2025-05-31 05:50:25 +02:00
fix(YouTube): Better handle incorrect duplicate translations
This commit is contained in:
parent
d519a8c81f
commit
20abac5212
@ -1,7 +1,11 @@
|
||||
package app.revanced.extension.shared;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.*;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@ -18,6 +22,7 @@ import android.os.Looper;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceGroup;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
@ -738,9 +743,9 @@ public class Utils {
|
||||
* then the preferences are left unsorted.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void sortPreferenceGroups(@NonNull PreferenceGroup group) {
|
||||
public static void sortPreferenceGroups(PreferenceGroup group) {
|
||||
Sort groupSort = Sort.fromKey(group.getKey(), Sort.UNSORTED);
|
||||
SortedMap<String, Preference> preferences = new TreeMap<>();
|
||||
List<Pair<String, Preference>> preferences = new ArrayList<>();
|
||||
|
||||
for (int i = 0, prefCount = group.getPreferenceCount(); i < prefCount; i++) {
|
||||
Preference preference = group.getPreference(i);
|
||||
@ -769,17 +774,21 @@ public class Utils {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
preferences.put(sortValue, preference);
|
||||
preferences.add(new Pair<>(sortValue, preference));
|
||||
}
|
||||
|
||||
Collections.sort(preferences, (pair1, pair2)
|
||||
-> pair1.first.compareToIgnoreCase(pair2.first));
|
||||
|
||||
int index = 0;
|
||||
for (Preference pref : preferences.values()) {
|
||||
for (Pair<String, Preference> pair : preferences) {
|
||||
int order = index++;
|
||||
Preference pref = pair.second;
|
||||
|
||||
// Move any screens, intents, and the one off About preference to the top.
|
||||
if (pref instanceof PreferenceScreen || pref instanceof ReVancedAboutPreference
|
||||
|| pref.getIntent() != null) {
|
||||
// Arbitrary high number.
|
||||
// Any arbitrary large number.
|
||||
order -= 1000;
|
||||
}
|
||||
|
||||
|
@ -6,9 +6,8 @@ import android.util.AttributeSet;
|
||||
import android.util.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import app.revanced.extension.shared.Utils;
|
||||
|
||||
@ -46,17 +45,24 @@ public class SortedListPreference extends ListPreference {
|
||||
}
|
||||
|
||||
List<Pair<CharSequence, CharSequence>> firstEntries = new ArrayList<>(firstEntriesToPreserve);
|
||||
SortedMap<String, Pair<CharSequence, CharSequence>> lastEntries = new TreeMap<>();
|
||||
|
||||
// Android does not have a triple class like Kotlin, So instead use a nested pair.
|
||||
// Cannot easily use a SortedMap, because if two entries incorrectly have
|
||||
// identical names then the duplicates entries are not preserved.
|
||||
List<Pair<String, Pair<CharSequence, CharSequence>>> lastEntries = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < entrySize; i++) {
|
||||
Pair<CharSequence, CharSequence> pair = new Pair<>(entries[i], entryValues[i]);
|
||||
if (i < firstEntriesToPreserve) {
|
||||
firstEntries.add(pair);
|
||||
} else {
|
||||
lastEntries.put(Utils.removePunctuationToLowercase(pair.first), pair);
|
||||
lastEntries.add(new Pair<>(Utils.removePunctuationToLowercase(pair.first), pair));
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(lastEntries, (pair1, pair2)
|
||||
-> pair1.first.compareToIgnoreCase(pair2.first));
|
||||
|
||||
CharSequence[] sortedEntries = new CharSequence[entrySize];
|
||||
CharSequence[] sortedEntryValues = new CharSequence[entrySize];
|
||||
|
||||
@ -67,9 +73,10 @@ public class SortedListPreference extends ListPreference {
|
||||
i++;
|
||||
}
|
||||
|
||||
for (Pair<CharSequence, CharSequence> pair : lastEntries.values()) {
|
||||
sortedEntries[i] = pair.first;
|
||||
sortedEntryValues[i] = pair.second;
|
||||
for (Pair<String, Pair<CharSequence, CharSequence>> outer : lastEntries) {
|
||||
Pair<CharSequence, CharSequence> inner = outer.second;
|
||||
sortedEntries[i] = inner.first;
|
||||
sortedEntryValues[i] = inner.second;
|
||||
i++;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user