mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-04-30 19:53:12 -04:00
Merge branch 'locales-list' into 'master'
Improve locales list ordering of less common languages See merge request fdroid/fdroidclient!1382
This commit is contained in:
@@ -34,7 +34,6 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
@@ -50,7 +49,6 @@ import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.os.ConfigurationCompat;
|
||||
import androidx.core.os.LocaleListCompat;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
@@ -237,29 +235,27 @@ public class FDroidApp extends Application implements androidx.work.Configuratio
|
||||
super.onConfigurationChanged(newConfig);
|
||||
Languages.setLanguage(this);
|
||||
App.systemLocaleList = null;
|
||||
updateLanguagesIfNecessary();
|
||||
}
|
||||
|
||||
private void updateLanguagesIfNecessary() {
|
||||
// update the descriptions based on the new language preferences
|
||||
SharedPreferences atStartTime = getAtStartTimeSharedPreferences();
|
||||
final String lastLocaleKey = "lastLocale";
|
||||
String lastLocale = atStartTime.getString(lastLocaleKey, null);
|
||||
String currentLocale;
|
||||
if (Build.VERSION.SDK_INT < 24) {
|
||||
currentLocale = newConfig.locale.toString();
|
||||
} else {
|
||||
currentLocale = newConfig.getLocales().toString();
|
||||
}
|
||||
if (!TextUtils.equals(lastLocale, currentLocale)) {
|
||||
String lastLocales = atStartTime.getString(lastLocaleKey, null);
|
||||
String currentLocales = App.getLocales().toString();
|
||||
if (!TextUtils.equals(lastLocales, currentLocales)) {
|
||||
Log.i(TAG, "Locales changed. Old: " + lastLocales + " New: " + currentLocales);
|
||||
onLanguageChanged(getApplicationContext());
|
||||
}
|
||||
atStartTime.edit().putString(lastLocaleKey, currentLocale).apply();
|
||||
atStartTime.edit().putString(lastLocaleKey, currentLocales).apply();
|
||||
}
|
||||
|
||||
public static void onLanguageChanged(Context context) {
|
||||
FDroidDatabase db = DBHelper.getDb(context);
|
||||
Single.fromCallable(() -> {
|
||||
long now = System.currentTimeMillis();
|
||||
LocaleListCompat locales =
|
||||
ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration());
|
||||
LocaleListCompat locales = App.getLocales();
|
||||
db.afterLocalesChanged(locales);
|
||||
Log.d(TAG, "Updating DB locales took: " + (System.currentTimeMillis() - now) + "ms");
|
||||
return true;
|
||||
@@ -392,6 +388,11 @@ public class FDroidApp extends Application implements androidx.work.Configuratio
|
||||
}
|
||||
atStartTime.edit().putInt("build-version", Build.VERSION.SDK_INT).apply();
|
||||
|
||||
if (!preferences.isIndexNeverUpdated()) {
|
||||
// if system locales have changed since the app's last run, refresh cache as necessary
|
||||
updateLanguagesIfNecessary();
|
||||
}
|
||||
|
||||
final String queryStringKey = "http-downloader-query-string";
|
||||
if (preferences.sendVersionAndUUIDToServers()) {
|
||||
queryString = atStartTime.getString(queryStringKey, null);
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -19,7 +18,6 @@ import android.util.Log;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.pm.PackageInfoCompat;
|
||||
import androidx.core.os.ConfigurationCompat;
|
||||
import androidx.core.os.LocaleListCompat;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
@@ -75,7 +73,13 @@ public class App implements Comparable<App>, Parcelable {
|
||||
public static LocaleListCompat getLocales() {
|
||||
LocaleListCompat cached = systemLocaleList;
|
||||
if (cached == null) {
|
||||
cached = ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration());
|
||||
// Tries to get the device locales list set by the user in system settings.
|
||||
// The official docs are less than apparent in this regard, but empirically,
|
||||
// `ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration())`
|
||||
// seems to push back languages marked "May not be available in some apps"
|
||||
// in Settings UI while `LocaleListCompat.getDefault()` appears to preserve
|
||||
// the user-preferred order so we prefer the latter here
|
||||
cached = LocaleListCompat.getDefault();
|
||||
systemLocaleList = cached;
|
||||
}
|
||||
return cached;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.fdroid.database
|
||||
|
||||
import android.content.res.Resources
|
||||
import androidx.core.os.ConfigurationCompat.getLocales
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import org.fdroid.CompatibilityChecker
|
||||
import org.fdroid.index.IndexFormatVersion.ONE
|
||||
@@ -24,7 +22,7 @@ internal class DbV1StreamReceiver(
|
||||
private val compatibilityChecker: CompatibilityChecker,
|
||||
) : IndexV1StreamReceiver {
|
||||
|
||||
private val locales: LocaleListCompat = getLocales(Resources.getSystem().configuration)
|
||||
private val locales: LocaleListCompat = LocaleListCompat.getDefault()
|
||||
|
||||
override fun receive(repo: RepoV2, version: Long) {
|
||||
db.getRepositoryDao().clear(repoId)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.fdroid.database
|
||||
|
||||
import android.content.res.Resources
|
||||
import androidx.core.os.ConfigurationCompat.getLocales
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import org.fdroid.CompatibilityChecker
|
||||
@@ -13,7 +11,7 @@ internal class DbV2DiffStreamReceiver(
|
||||
private val compatibilityChecker: CompatibilityChecker,
|
||||
) : IndexV2DiffStreamReceiver {
|
||||
|
||||
private val locales: LocaleListCompat = getLocales(Resources.getSystem().configuration)
|
||||
private val locales: LocaleListCompat = LocaleListCompat.getDefault()
|
||||
|
||||
override fun receiveRepoDiff(version: Long, repoJsonObject: JsonObject) {
|
||||
db.getRepositoryDao().updateRepository(repoId, version, repoJsonObject)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.fdroid.database
|
||||
|
||||
import android.content.res.Resources
|
||||
import androidx.core.os.ConfigurationCompat.getLocales
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import kotlinx.serialization.SerializationException
|
||||
import org.fdroid.CompatibilityChecker
|
||||
@@ -23,7 +21,7 @@ internal class DbV2StreamReceiver(
|
||||
private val compatibilityChecker: CompatibilityChecker,
|
||||
) : IndexV2StreamReceiver {
|
||||
|
||||
private val locales: LocaleListCompat = getLocales(Resources.getSystem().configuration)
|
||||
private val locales: LocaleListCompat = LocaleListCompat.getDefault()
|
||||
private var clearedRepoData = false
|
||||
private val nonNullFileV2: (FileV2?) -> Unit = { fileV2 ->
|
||||
if (fileV2 != null) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.fdroid.repo
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.net.Uri
|
||||
import androidx.core.os.ConfigurationCompat.getLocales
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import kotlinx.serialization.SerializationException
|
||||
import org.fdroid.database.Repository
|
||||
@@ -24,7 +22,7 @@ internal class RepoV1Fetcher(
|
||||
private val repoUriBuilder: RepoUriBuilder,
|
||||
) : RepoFetcher {
|
||||
|
||||
private val locales: LocaleListCompat = getLocales(Resources.getSystem().configuration)
|
||||
private val locales: LocaleListCompat = LocaleListCompat.getDefault()
|
||||
|
||||
@Throws(SigningException::class, SerializationException::class)
|
||||
override suspend fun fetchRepo(
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.fdroid.repo
|
||||
|
||||
import android.content.res.Resources
|
||||
import androidx.core.os.ConfigurationCompat.getLocales
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import org.fdroid.LocaleChooser.getBestLocale
|
||||
import org.fdroid.database.AppOverviewItem
|
||||
@@ -79,7 +77,7 @@ internal open class RepoV2StreamReceiver(
|
||||
)
|
||||
}
|
||||
|
||||
private val locales: LocaleListCompat = getLocales(Resources.getSystem().configuration)
|
||||
private val locales: LocaleListCompat = LocaleListCompat.getDefault()
|
||||
|
||||
override fun receive(repo: RepoV2, version: Long) {
|
||||
receiver.onRepoReceived(
|
||||
|
||||
Reference in New Issue
Block a user