fixed default app language on first start; the same fix made for video filter

This commit is contained in:
kosharskiy 2021-01-14 18:42:27 +02:00
parent 15aee422fa
commit 69a6d9ebfb
3 changed files with 34 additions and 16 deletions

View File

@ -19,16 +19,17 @@ package net.schueller.peertube.activity;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.PreferenceManager;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import net.schueller.peertube.R;
import java.util.Locale;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
public class CommonActivity extends AppCompatActivity {
@Override
@ -51,21 +52,31 @@ public class CommonActivity extends AppCompatActivity {
);
// Set language
String countryCode = sharedPref.getString(getString(R.string.pref_language_app_key), "en");
assert countryCode != null;
Locale locale = new Locale(countryCode);
String countryCode = sharedPref.getString(getString(R.string.pref_language_app_key), null);
if (countryCode == null) {
return;
}
setLocale(countryCode);
}
public void setLocale(String languageCode) {
Locale locale = new Locale(languageCode);
//Neither Chinese language choice was working, found this fix on stack overflow
if (countryCode.equals("zh-rCN"))
if (languageCode.equals("zh-rCN"))
locale = Locale.SIMPLIFIED_CHINESE;
if (countryCode.equals("zh-rTW"))
if (languageCode.equals("zh-rTW"))
locale = Locale.TRADITIONAL_CHINESE;
Locale.setDefault(locale);
Configuration config = getBaseContext().getResources().getConfiguration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
}
Resources resources = getResources();
Configuration config = resources.getConfiguration();
config.setLocale(locale);
resources.updateConfiguration(config, resources.getDisplayMetrics());
}
}

View File

@ -70,6 +70,8 @@ import net.schueller.peertube.service.VideoPlayerService;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import retrofit2.Call;
@ -321,7 +323,14 @@ public class VideoListActivity extends CommonActivity {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
String nsfw = sharedPref.getBoolean(getString(R.string.pref_show_nsfw_key), false) ? "both" : "false";
Set<String> languages = sharedPref.getStringSet(getString(R.string.pref_video_language_key), null);
Locale locale = getResources().getConfiguration().locale;
String country = locale.getLanguage();
HashSet<String> countries = new HashSet<>(1);
countries.add(country);
Set<String> languages = sharedPref.getStringSet(getString(R.string.pref_video_language_key), countries);
String apiBaseURL = APIUrlHelper.getUrlWithVersion(this);
GetVideoDataService service = RetrofitInstance.getRetrofitInstance(apiBaseURL, APIUrlHelper.useInsecureConnection(this)).create(GetVideoDataService.class);

View File

@ -4,7 +4,6 @@
<PreferenceCategory app:title="@string/settings_activity_look_and_feel_category_title" app:iconSpaceReserved="false">
<ListPreference
app:defaultValue="@array/empty_array"
app:entries="@array/supportedLanguagesArray"
app:entryValues="@array/supportedLanguagesValues"
app:key="@string/pref_language_app_key"
@ -40,7 +39,6 @@
app:iconSpaceReserved="false"/>
<MultiSelectListPreference
app:defaultValue="@array/empty_array"
app:entries="@array/languageArray"
app:entryValues="@array/languageValues"
app:key="@string/pref_video_language_key"