fixed default app language on first start; the same fix made for video filter
This commit is contained in:
parent
15aee422fa
commit
69a6d9ebfb
@ -19,16 +19,17 @@ package net.schueller.peertube.activity;
|
|||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import androidx.appcompat.app.AppCompatDelegate;
|
|
||||||
|
|
||||||
import net.schueller.peertube.R;
|
import net.schueller.peertube.R;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.app.AppCompatDelegate;
|
||||||
|
|
||||||
public class CommonActivity extends AppCompatActivity {
|
public class CommonActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -51,21 +52,31 @@ public class CommonActivity extends AppCompatActivity {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Set language
|
// Set language
|
||||||
String countryCode = sharedPref.getString(getString(R.string.pref_language_app_key), "en");
|
String countryCode = sharedPref.getString(getString(R.string.pref_language_app_key), null);
|
||||||
assert countryCode != null;
|
|
||||||
Locale locale = new Locale(countryCode);
|
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
|
//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;
|
locale = Locale.SIMPLIFIED_CHINESE;
|
||||||
if (countryCode.equals("zh-rTW"))
|
if (languageCode.equals("zh-rTW"))
|
||||||
locale = Locale.TRADITIONAL_CHINESE;
|
locale = Locale.TRADITIONAL_CHINESE;
|
||||||
|
|
||||||
Locale.setDefault(locale);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,8 @@ import net.schueller.peertube.service.VideoPlayerService;
|
|||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
@ -321,7 +323,14 @@ public class VideoListActivity extends CommonActivity {
|
|||||||
|
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
String nsfw = sharedPref.getBoolean(getString(R.string.pref_show_nsfw_key), false) ? "both" : "false";
|
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);
|
String apiBaseURL = APIUrlHelper.getUrlWithVersion(this);
|
||||||
|
|
||||||
GetVideoDataService service = RetrofitInstance.getRetrofitInstance(apiBaseURL, APIUrlHelper.useInsecureConnection(this)).create(GetVideoDataService.class);
|
GetVideoDataService service = RetrofitInstance.getRetrofitInstance(apiBaseURL, APIUrlHelper.useInsecureConnection(this)).create(GetVideoDataService.class);
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
<PreferenceCategory app:title="@string/settings_activity_look_and_feel_category_title" app:iconSpaceReserved="false">
|
<PreferenceCategory app:title="@string/settings_activity_look_and_feel_category_title" app:iconSpaceReserved="false">
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
app:defaultValue="@array/empty_array"
|
|
||||||
app:entries="@array/supportedLanguagesArray"
|
app:entries="@array/supportedLanguagesArray"
|
||||||
app:entryValues="@array/supportedLanguagesValues"
|
app:entryValues="@array/supportedLanguagesValues"
|
||||||
app:key="@string/pref_language_app_key"
|
app:key="@string/pref_language_app_key"
|
||||||
@ -40,7 +39,6 @@
|
|||||||
app:iconSpaceReserved="false"/>
|
app:iconSpaceReserved="false"/>
|
||||||
|
|
||||||
<MultiSelectListPreference
|
<MultiSelectListPreference
|
||||||
app:defaultValue="@array/empty_array"
|
|
||||||
app:entries="@array/languageArray"
|
app:entries="@array/languageArray"
|
||||||
app:entryValues="@array/languageValues"
|
app:entryValues="@array/languageValues"
|
||||||
app:key="@string/pref_video_language_key"
|
app:key="@string/pref_video_language_key"
|
||||||
|
Loading…
Reference in New Issue
Block a user