Merge branch 'master' into 'master'

last fixes for 0.103.1

Closes #1018, #943, and #1010

See merge request !515
This commit is contained in:
Hans-Christoph Steiner 2017-05-12 21:58:34 +00:00
commit 94e4ded672
4 changed files with 30 additions and 89 deletions

View File

@ -1,3 +1,21 @@
### 0.103.1 (2017-05-12)
* Various stability fixes
* Bits of text no longer randomly switches to English
* Fix send F-Droid via Bluetooth on Android 7.x
### 0.103 (2017-05-02)
* Complete overhaul of the user experience
* Complete support for localization, including app descriptions
* Support for screenshots, graphics, and "What's New" texts
* Stable support for F-Droid Privileged Extension
### 0.102.3 (2017-04-01)
* Fix issue with installing from the wrong repo (#909)

View File

@ -197,7 +197,7 @@ public class FDroidApp extends Application {
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Languages.setLanguage(this, Preferences.get().getLanguage(), false);
Languages.setLanguage(this);
}
@Override
@ -214,8 +214,7 @@ public class FDroidApp extends Application {
.build());
}
Preferences.setup(this);
Languages.setup(getClass(), R.string.pref_language_default);
Languages.setLanguage(this, Preferences.get().getLanguage(), false);
Languages.setLanguage(this);
ACRA.init(this);
if (isAcraProcess()) {

View File

@ -4,13 +4,12 @@ import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Locale;
@ -26,12 +25,9 @@ public final class Languages {
private static final Locale DEFAULT_LOCALE;
private static final Locale TIBETAN = new Locale("bo");
private static final Locale CHINESE_HONG_KONG = new Locale("zh", "HK");
private static final String DEFAULT_STRING = "System Default";
private static Locale locale;
private static Languages singleton;
private static Class<?> clazz;
private static int resId;
private static Map<String, String> tmpMap = new TreeMap<>();
private static Map<String, String> nameMap;
@ -40,23 +36,8 @@ public final class Languages {
}
private Languages(Activity activity) {
AssetManager assets = activity.getAssets();
Configuration config = activity.getResources().getConfiguration();
// Resources() requires DisplayMetrics, but they are only needed for drawables
DisplayMetrics ignored = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(ignored);
Resources resources;
Set<Locale> localeSet = new LinkedHashSet<>();
Locale currentLocale = config.locale;
for (Locale locale : LOCALES_TO_TEST) {
config.locale = locale;
resources = new Resources(assets, ignored, config);
if (!TextUtils.equals(DEFAULT_STRING, resources.getString(resId))
|| locale.equals(Locale.ENGLISH)) {
localeSet.add(locale);
}
}
config.locale = currentLocale;
localeSet.addAll(Arrays.asList(LOCALES_TO_TEST));
for (Locale locale : localeSet) {
if (locale.equals(TIBETAN)) {
@ -74,39 +55,13 @@ public final class Languages {
}
// remove the current system language from the menu
tmpMap.remove(currentLocale.getLanguage());
tmpMap.remove(Locale.getDefault().getLanguage());
/* SYSTEM_DEFAULT is a fake one for displaying in a chooser menu. */
tmpMap.put(USE_SYSTEM_DEFAULT, activity.getString(resId));
tmpMap.put(USE_SYSTEM_DEFAULT, activity.getString(R.string.pref_language_default));
nameMap = Collections.unmodifiableMap(tmpMap);
}
/**
* Get the instance of {@link Languages} to work with, providing the
* {@link Activity} that is will be working as part of, as well as the
* {@code resId} that has the exact string "Use System Default",
* i.e. {@code R.string.use_system_default}.
* <p/>
* That string resource {@code resId} is also used to find the supported
* translations: if an included translation has a translated string that
* matches that {@code resId}, then that language will be included as a
* supported language.
*
* @param clazz the {@link Class} of the default {@code Activity},
* usually the main {@code Activity} from where the
* Settings is launched from.
* @param resId the string resource ID to for the string "System Default",
* e.g. {@code R.string.pref_language_default}
*/
public static void setup(Class<?> clazz, int resId) {
if (Languages.clazz == null) {
Languages.clazz = clazz;
Languages.resId = resId;
} else {
throw new RuntimeException("Languages singleton was already initialized, duplicate call to Languages.setup()!");
}
}
/**
* @param activity the {@link Activity} this is working as part of
* @return the singleton to work with
@ -124,16 +79,17 @@ public final class Languages {
* or different than the current system-wide locale. The preference is cleared
* if the language matches the system-wide locale or "System Default" is chosen.
*/
public static void setLanguage(final ContextWrapper contextWrapper, String language, boolean refresh) {
public static void setLanguage(final ContextWrapper contextWrapper) {
if (Build.VERSION.SDK_INT >= 24) {
Utils.debugLog(TAG, "Languages.setLanguage() ignored on >= android-24");
Preferences.get().clearLanguage();
return;
}
String language = Preferences.get().getLanguage();
if (TextUtils.equals(language, DEFAULT_LOCALE.getLanguage())) {
Preferences.get().clearLanguage();
locale = DEFAULT_LOCALE;
} else if (locale != null && TextUtils.equals(locale.getLanguage(), language) && (!refresh)) {
} else if (locale != null && TextUtils.equals(locale.getLanguage(), language)) {
return; // already configured
} else if (language == null || language.equals(USE_SYSTEM_DEFAULT)) {
Preferences.get().clearLanguage();
@ -212,12 +168,9 @@ public final class Languages {
CHINESE_HONG_KONG,
TIBETAN,
new Locale("af"),
new Locale("am"),
new Locale("ar"),
new Locale("az"),
new Locale("be"),
new Locale("bg"),
new Locale("bn"),
new Locale("ca"),
new Locale("cs"),
new Locale("da"),
@ -228,58 +181,29 @@ public final class Languages {
new Locale("eu"),
new Locale("fa"),
new Locale("fi"),
new Locale("gl"),
new Locale("he"),
new Locale("hi"),
new Locale("hr"),
new Locale("hu"),
new Locale("hy"),
new Locale("in"),
new Locale("hy"),
new Locale("in"),
new Locale("id"),
new Locale("is"),
new Locale("it"),
new Locale("iw"),
new Locale("ka"),
new Locale("kk"),
new Locale("km"),
new Locale("kn"),
new Locale("ky"),
new Locale("lo"),
new Locale("lt"),
new Locale("lv"),
new Locale("mk"),
new Locale("ml"),
new Locale("mn"),
new Locale("mr"),
new Locale("ms"),
new Locale("my"),
new Locale("nb"),
new Locale("ne"),
new Locale("nl"),
new Locale("pl"),
new Locale("pt"),
new Locale("rm"),
new Locale("ro"),
new Locale("ru"),
new Locale("sc"),
new Locale("si"),
new Locale("sk"),
new Locale("sl"),
new Locale("sn"),
new Locale("sq"),
new Locale("sr"),
new Locale("sv"),
new Locale("sw"),
new Locale("ta"),
new Locale("te"),
new Locale("th"),
new Locale("tl"),
new Locale("tr"),
new Locale("uk"),
new Locale("ur"),
new Locale("uz"),
new Locale("vi"),
new Locale("zu"),
};
}

View File

@ -158,7 +158,7 @@ public class PreferencesFragment extends PreferenceFragment
entrySummary(key);
if (changing) {
Activity activity = getActivity();
Languages.setLanguage(activity, Preferences.get().getLanguage(), false);
Languages.setLanguage(activity);
RepoProvider.Helper.clearEtags(getContext());
UpdateService.updateNow(getContext());