Merge pull request #250 from kosharskiy/bugfix_app_language_on_first_start
fixed default app language on first start
This commit is contained in:
commit
fba1acc71d
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user