Improve locale settings
This commit is contained in:
parent
e90c555c18
commit
8574a14ed2
@ -1,6 +1,7 @@
|
|||||||
package com.topjohnwu.magisk;
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
@ -24,6 +25,7 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
|
|||||||
private Unbinder unbinder;
|
private Unbinder unbinder;
|
||||||
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
||||||
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
||||||
|
SearchView search;
|
||||||
|
|
||||||
private ApplicationAdapter appAdapter;
|
private ApplicationAdapter appAdapter;
|
||||||
|
|
||||||
@ -37,14 +39,14 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_magisk_hide, container, false);
|
View view = inflater.inflate(R.layout.fragment_magisk_hide, container, false);
|
||||||
unbinder = ButterKnife.bind(this, view);
|
unbinder = ButterKnife.bind(this, view);
|
||||||
|
|
||||||
mSwipeRefreshLayout.setRefreshing(true);
|
mSwipeRefreshLayout.setRefreshing(true);
|
||||||
mSwipeRefreshLayout.setOnRefreshListener(() -> appAdapter.refresh());
|
mSwipeRefreshLayout.setOnRefreshListener(appAdapter::refresh);
|
||||||
|
|
||||||
appAdapter = new ApplicationAdapter();
|
appAdapter = new ApplicationAdapter(requireActivity());
|
||||||
recyclerView.setAdapter(appAdapter);
|
recyclerView.setAdapter(appAdapter);
|
||||||
|
|
||||||
searchListener = new SearchView.OnQueryTextListener() {
|
searchListener = new SearchView.OnQueryTextListener() {
|
||||||
@ -61,7 +63,7 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getActivity().setTitle(R.string.magiskhide);
|
requireActivity().setTitle(R.string.magiskhide);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
@ -69,7 +71,7 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
inflater.inflate(R.menu.menu_magiskhide, menu);
|
inflater.inflate(R.menu.menu_magiskhide, menu);
|
||||||
SearchView search = (SearchView) menu.findItem(R.id.app_search).getActionView();
|
search = (SearchView) menu.findItem(R.id.app_search).getActionView();
|
||||||
search.setOnQueryTextListener(searchListener);
|
search.setOnQueryTextListener(searchListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +89,6 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
|
|||||||
@Override
|
@Override
|
||||||
public void onPublish(int topic, Object[] result) {
|
public void onPublish(int topic, Object[] result) {
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
appAdapter.filter(null);
|
appAdapter.filter(search.getQuery().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.topjohnwu.magisk;
|
|||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
@ -14,7 +15,6 @@ import com.topjohnwu.superuser.ContainerApp;
|
|||||||
import com.topjohnwu.superuser.Shell;
|
import com.topjohnwu.superuser.Shell;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class MagiskManager extends ContainerApp {
|
public class MagiskManager extends ContainerApp {
|
||||||
@ -58,8 +58,13 @@ public class MagiskManager extends ContainerApp {
|
|||||||
} catch (PackageManager.NameNotFoundException ignored) {}
|
} catch (PackageManager.NameNotFoundException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
LocaleManager.setLocale();
|
LocaleManager.setLocale(this);
|
||||||
Data.loadConfig();
|
Data.loadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
|
super.onConfigurationChanged(newConfig);
|
||||||
|
LocaleManager.setLocale(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
|||||||
mm.mDB.setSettings(key, Utils.getPrefsInt(prefs, key));
|
mm.mDB.setSettings(key, Utils.getPrefsInt(prefs, key));
|
||||||
break;
|
break;
|
||||||
case Const.Key.LOCALE:
|
case Const.Key.LOCALE:
|
||||||
LocaleManager.setLocale();
|
LocaleManager.setLocale(mm);
|
||||||
Topic.publish(false, Topic.RELOAD_ACTIVITY);
|
Topic.publish(false, Topic.RELOAD_ACTIVITY);
|
||||||
break;
|
break;
|
||||||
case Const.Key.UPDATE_CHANNEL:
|
case Const.Key.UPDATE_CHANNEL:
|
||||||
|
@ -31,7 +31,7 @@ public class SplashActivity extends Activity {
|
|||||||
Data.importPrefs();
|
Data.importPrefs();
|
||||||
|
|
||||||
// Dynamic detect all locales
|
// Dynamic detect all locales
|
||||||
new LocaleManager.LoadLocale().exec();
|
LocaleManager.loadAvailableLocales();
|
||||||
|
|
||||||
// Create notification channel on Android O
|
// Create notification channel on Android O
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
package com.topjohnwu.magisk.adapters;
|
package com.topjohnwu.magisk.adapters;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -13,9 +18,8 @@ import android.widget.ImageView;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.Const;
|
import com.topjohnwu.magisk.Const;
|
||||||
import com.topjohnwu.magisk.Data;
|
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
import com.topjohnwu.magisk.asyncs.ParallelTask;
|
import com.topjohnwu.magisk.utils.LocaleManager;
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.superuser.Shell;
|
import com.topjohnwu.superuser.Shell;
|
||||||
|
|
||||||
@ -34,26 +38,63 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
|
|||||||
private PackageManager pm;
|
private PackageManager pm;
|
||||||
private ApplicationFilter filter;
|
private ApplicationFilter filter;
|
||||||
|
|
||||||
public ApplicationAdapter() {
|
public ApplicationAdapter(Context context) {
|
||||||
fullList = showList = Collections.emptyList();
|
fullList = showList = Collections.emptyList();
|
||||||
hideList = Collections.emptyList();
|
hideList = Collections.emptyList();
|
||||||
filter = new ApplicationFilter();
|
filter = new ApplicationFilter();
|
||||||
pm = Data.MM().getPackageManager();
|
pm = context.getPackageManager();
|
||||||
new LoadApps().exec();
|
AsyncTask.THREAD_POOL_EXECUTOR.execute(this::loadApps);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_app, parent, false);
|
||||||
|
return new ViewHolder(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getLabel(ApplicationInfo info) {
|
||||||
|
if (info.labelRes > 0) {
|
||||||
|
try {
|
||||||
|
Resources res = pm.getResourcesForApplication(info);
|
||||||
|
Configuration config = new Configuration();
|
||||||
|
config.setLocale(LocaleManager.locale);
|
||||||
|
res.updateConfiguration(config, res.getDisplayMetrics());
|
||||||
|
return res.getString(info.labelRes);
|
||||||
|
} catch (PackageManager.NameNotFoundException ignored) { /* Impossible */ }
|
||||||
|
}
|
||||||
|
return info.loadLabel(pm).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadApps() {
|
||||||
|
fullList = pm.getInstalledApplications(0);
|
||||||
|
hideList = Shell.su("magiskhide --ls").exec().getOut();
|
||||||
|
for (Iterator<ApplicationInfo> i = fullList.iterator(); i.hasNext(); ) {
|
||||||
|
ApplicationInfo info = i.next();
|
||||||
|
if (Const.HIDE_BLACKLIST.contains(info.packageName) || !info.enabled) {
|
||||||
|
i.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(fullList, (a, b) -> {
|
||||||
|
boolean ah = hideList.contains(a.packageName);
|
||||||
|
boolean bh = hideList.contains(b.packageName);
|
||||||
|
if (ah == bh) {
|
||||||
|
return getLabel(a).toLowerCase().compareTo(getLabel(b).toLowerCase());
|
||||||
|
} else if (ah) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Topic.publish(false, Topic.MAGISK_HIDE_DONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||||
View mView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_app, parent, false);
|
|
||||||
return new ViewHolder(mView);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
|
||||||
ApplicationInfo info = showList.get(position);
|
ApplicationInfo info = showList.get(position);
|
||||||
|
|
||||||
holder.appIcon.setImageDrawable(info.loadIcon(pm));
|
holder.appIcon.setImageDrawable(info.loadIcon(pm));
|
||||||
holder.appName.setText(info.loadLabel(pm));
|
holder.appName.setText(getLabel(info));
|
||||||
holder.appPackage.setText(info.packageName);
|
holder.appPackage.setText(info.packageName);
|
||||||
|
|
||||||
holder.checkBox.setOnCheckedChangeListener(null);
|
holder.checkBox.setOnCheckedChangeListener(null);
|
||||||
@ -79,7 +120,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
new LoadApps().exec();
|
AsyncTask.THREAD_POOL_EXECUTOR.execute(this::loadApps);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
@ -109,7 +150,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
|
|||||||
showList = new ArrayList<>();
|
showList = new ArrayList<>();
|
||||||
String filter = constraint.toString().toLowerCase();
|
String filter = constraint.toString().toLowerCase();
|
||||||
for (ApplicationInfo info : fullList) {
|
for (ApplicationInfo info : fullList) {
|
||||||
if (lowercaseContains(info.loadLabel(pm).toString(), filter)
|
if (lowercaseContains(getLabel(info), filter)
|
||||||
|| lowercaseContains(info.packageName, filter)) {
|
|| lowercaseContains(info.packageName, filter)) {
|
||||||
showList.add(info);
|
showList.add(info);
|
||||||
}
|
}
|
||||||
@ -123,37 +164,4 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
|
|||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LoadApps extends ParallelTask<Void, Void, Void> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... voids) {
|
|
||||||
fullList = pm.getInstalledApplications(0);
|
|
||||||
hideList = Shell.su("magiskhide --ls").exec().getOut();
|
|
||||||
for (Iterator<ApplicationInfo> i = fullList.iterator(); i.hasNext(); ) {
|
|
||||||
ApplicationInfo info = i.next();
|
|
||||||
if (Const.HIDE_BLACKLIST.contains(info.packageName) || !info.enabled) {
|
|
||||||
i.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Collections.sort(fullList, (a, b) -> {
|
|
||||||
boolean ah = hideList.contains(a.packageName);
|
|
||||||
boolean bh = hideList.contains(b.packageName);
|
|
||||||
if (ah == bh) {
|
|
||||||
return a.loadLabel(pm).toString().toLowerCase().compareTo(
|
|
||||||
b.loadLabel(pm).toString().toLowerCase());
|
|
||||||
} else if (ah) {
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Void v) {
|
|
||||||
Topic.publish(false, Topic.MAGISK_HIDE_DONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.topjohnwu.magisk.components;
|
package com.topjohnwu.magisk.components;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -19,11 +20,12 @@ public abstract class FlavorActivity extends AppCompatActivity implements Topic.
|
|||||||
private ActivityResultListener activityResultListener;
|
private ActivityResultListener activityResultListener;
|
||||||
static int[] EMPTY_INT_ARRAY = new int[0];
|
static int[] EMPTY_INT_ARRAY = new int[0];
|
||||||
|
|
||||||
public FlavorActivity() {
|
@Override
|
||||||
super();
|
protected void attachBaseContext(Context base) {
|
||||||
Configuration configuration = new Configuration();
|
super.attachBaseContext(base);
|
||||||
configuration.setLocale(LocaleManager.locale);
|
Configuration config = base.getResources().getConfiguration();
|
||||||
applyOverrideConfiguration(configuration);
|
config.setLocale(LocaleManager.locale);
|
||||||
|
applyOverrideConfiguration(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,7 +25,7 @@ public class SuReceiver extends BroadcastReceiver {
|
|||||||
String command, action;
|
String command, action;
|
||||||
Policy policy;
|
Policy policy;
|
||||||
|
|
||||||
MagiskManager mm = Utils.getMagiskManager(context);
|
MagiskManager mm = Data.MM();
|
||||||
|
|
||||||
if (intent == null) return;
|
if (intent == null) return;
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ public class SuReceiver extends BroadcastReceiver {
|
|||||||
policy = mm.mDB.getPolicy(fromUid);
|
policy = mm.mDB.getPolicy(fromUid);
|
||||||
if (policy == null) {
|
if (policy == null) {
|
||||||
try {
|
try {
|
||||||
policy = new Policy(fromUid, context.getPackageManager());
|
policy = new Policy(fromUid, mm.getPackageManager());
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
@ -59,20 +59,19 @@ public class SuReceiver extends BroadcastReceiver {
|
|||||||
String message;
|
String message;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "allow":
|
case "allow":
|
||||||
message = context.getString(R.string.su_allow_toast, policy.appName);
|
message = mm.getString(R.string.su_allow_toast, policy.appName);
|
||||||
log.action = true;
|
log.action = true;
|
||||||
break;
|
break;
|
||||||
case "deny":
|
case "deny":
|
||||||
message = context.getString(R.string.su_deny_toast, policy.appName);
|
message = mm.getString(R.string.su_deny_toast, policy.appName);
|
||||||
log.action = false;
|
log.action = false;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (policy.notification && Data.suNotificationType == Const.Value.NOTIFICATION_TOAST) {
|
if (policy.notification && Data.suNotificationType == Const.Value.NOTIFICATION_TOAST)
|
||||||
Utils.toast(message, Toast.LENGTH_SHORT);
|
Utils.toast(message, Toast.LENGTH_SHORT);
|
||||||
}
|
|
||||||
|
|
||||||
if (mode == Const.Value.NOTIFY_NORMAL_LOG && policy.logging) {
|
if (mode == Const.Value.NOTIFY_NORMAL_LOG && policy.logging) {
|
||||||
toUid = intent.getIntExtra("to.uid", -1);
|
toUid = intent.getIntExtra("to.uid", -1);
|
||||||
|
@ -2,13 +2,13 @@ package com.topjohnwu.magisk.utils;
|
|||||||
|
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.Const;
|
import com.topjohnwu.magisk.Const;
|
||||||
import com.topjohnwu.magisk.Data;
|
import com.topjohnwu.magisk.Data;
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
import com.topjohnwu.magisk.asyncs.ParallelTask;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -21,14 +21,14 @@ public class LocaleManager {
|
|||||||
public final static Locale defaultLocale = Locale.getDefault();
|
public final static Locale defaultLocale = Locale.getDefault();
|
||||||
public static List<Locale> locales;
|
public static List<Locale> locales;
|
||||||
|
|
||||||
public static void setLocale() {
|
public static void setLocale(MagiskManager mm) {
|
||||||
MagiskManager mm = Data.MM();
|
|
||||||
String localeConfig = mm.prefs.getString(Const.Key.LOCALE, "");
|
String localeConfig = mm.prefs.getString(Const.Key.LOCALE, "");
|
||||||
if (localeConfig.isEmpty()) {
|
if (localeConfig.isEmpty()) {
|
||||||
locale = defaultLocale;
|
locale = defaultLocale;
|
||||||
} else {
|
} else {
|
||||||
locale = Locale.forLanguageTag(localeConfig);
|
locale = Locale.forLanguageTag(localeConfig);
|
||||||
}
|
}
|
||||||
|
Locale.setDefault(locale);
|
||||||
Resources res = mm.getResources();
|
Resources res = mm.getResources();
|
||||||
Configuration config = res.getConfiguration();
|
Configuration config = res.getConfiguration();
|
||||||
config.setLocale(locale);
|
config.setLocale(locale);
|
||||||
@ -36,58 +36,41 @@ public class LocaleManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getString(Locale locale, @StringRes int id) {
|
public static String getString(Locale locale, @StringRes int id) {
|
||||||
Configuration config = Data.MM().getResources().getConfiguration();
|
Configuration config = new Configuration();
|
||||||
config.setLocale(locale);
|
config.setLocale(locale);
|
||||||
return getString(config, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getString(Configuration config, @StringRes int id) {
|
|
||||||
return Data.MM().createConfigurationContext(config).getString(id);
|
return Data.MM().createConfigurationContext(config).getString(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Locale> getAvailableLocale() {
|
public static void loadAvailableLocales() {
|
||||||
List<Locale> locales = new ArrayList<>();
|
AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
|
||||||
HashSet<String> set = new HashSet<>();
|
locales = new ArrayList<>();
|
||||||
MagiskManager mm = Data.MM();
|
HashSet<String> set = new HashSet<>();
|
||||||
Locale locale;
|
Resources res = Data.MM().getResources();
|
||||||
|
Locale locale;
|
||||||
|
|
||||||
@StringRes int compareId = R.string.download_file_error;
|
@StringRes int compareId = R.string.download_file_error;
|
||||||
|
|
||||||
// Add default locale
|
// Add default locale
|
||||||
locales.add(Locale.ENGLISH);
|
locales.add(Locale.ENGLISH);
|
||||||
set.add(getString(Locale.ENGLISH, compareId));
|
set.add(getString(Locale.ENGLISH, compareId));
|
||||||
|
|
||||||
// Add some special locales
|
// Add some special locales
|
||||||
locales.add(Locale.TAIWAN);
|
locales.add(Locale.TAIWAN);
|
||||||
set.add(getString(Locale.TAIWAN, compareId));
|
set.add(getString(Locale.TAIWAN, compareId));
|
||||||
locale = new Locale("pt", "BR");
|
locale = new Locale("pt", "BR");
|
||||||
locales.add(locale);
|
locales.add(locale);
|
||||||
set.add(getString(locale, compareId));
|
set.add(getString(locale, compareId));
|
||||||
|
|
||||||
// Other locales
|
// Other locales
|
||||||
Configuration config = mm.getResources().getConfiguration();
|
for (String s : res.getAssets().getLocales()) {
|
||||||
for (String s : mm.getAssets().getLocales()) {
|
locale = Locale.forLanguageTag(s);
|
||||||
locale = Locale.forLanguageTag(s);
|
if (set.add(getString(locale, compareId))) {
|
||||||
config.setLocale(locale);
|
locales.add(locale);
|
||||||
if (set.add(getString(config, compareId))) {
|
}
|
||||||
locales.add(locale);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Collections.sort(locales, (a, b) -> a.getDisplayName(a).compareTo(b.getDisplayName(b)));
|
Collections.sort(locales, (a, b) -> a.getDisplayName(a).compareTo(b.getDisplayName(b)));
|
||||||
|
|
||||||
return locales;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class LoadLocale extends ParallelTask<Void, Void, Void> {
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... voids) {
|
|
||||||
locales = getAvailableLocale();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Void aVoid) {
|
|
||||||
Topic.publish(Topic.LOCAL_FETCH_DONE);
|
Topic.publish(Topic.LOCAL_FETCH_DONE);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user