Merge branch 'feature/language-selector'

This commit is contained in:
sk
2022-12-09 20:56:09 +01:00
4 changed files with 122 additions and 1 deletions

View File

@@ -2,6 +2,14 @@ package org.joinmastodon.android;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Build;
import android.os.LocaleList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
public class GlobalUserPreferences{
public static boolean playGifs;
@@ -17,6 +25,21 @@ public class GlobalUserPreferences{
public static boolean voteButtonForSingleChoice;
public static ThemePreference theme;
public static ColorPreference color;
public static List<String> recentLanguages;
private static String defaultRecentLanguages;
static {
List<Locale> systemLocales = new ArrayList<>();;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
systemLocales.add(Resources.getSystem().getConfiguration().locale);
} else {
LocaleList localeList = Resources.getSystem().getConfiguration().getLocales();
for (int i = 0; i < localeList.size(); i++) systemLocales.add(localeList.get(i));
}
defaultRecentLanguages = systemLocales.stream().map(Locale::getLanguage).collect(Collectors.joining(","));
}
private static SharedPreferences getPrefs(){
return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE);
@@ -37,6 +60,7 @@ public class GlobalUserPreferences{
voteButtonForSingleChoice=prefs.getBoolean("voteButtonForSingleChoice", true);
theme=ThemePreference.values()[prefs.getInt("theme", 0)];
color=ColorPreference.values()[prefs.getInt("color", 0)];
recentLanguages=Arrays.stream(prefs.getString("recentLanguages", defaultRecentLanguages).split(",")).filter(s->!s.isEmpty()).collect(Collectors.toList());
}
public static void save(){
@@ -53,6 +77,7 @@ public class GlobalUserPreferences{
.putBoolean("disableMarquee", disableMarquee)
.putInt("theme", theme.ordinal())
.putInt("color", color.ordinal())
.putString("recentLanguages", String.join(",", recentLanguages))
.apply();
}