Thorium-android-app/app/src/main/java/net/schueller/peertube/activity/CommonActivity.java

72 lines
2.6 KiB
Java
Raw Normal View History

2019-01-06 14:13:05 +01:00
/*
2020-11-28 22:36:47 +01:00
* Copyright (C) 2020 Stefan Schüller <sschueller@techdroid.com>
2019-01-06 14:13:05 +01:00
*
* This program is free software: you can redistribute it and/or modify
2020-11-28 22:36:47 +01:00
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2019-01-06 14:13:05 +01:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2020-11-28 22:36:47 +01:00
* GNU Affero General Public License for more details.
2019-01-06 14:13:05 +01:00
*
2020-11-28 22:36:47 +01:00
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2019-01-06 14:13:05 +01:00
*/
package net.schueller.peertube.activity;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
2020-07-05 14:15:48 +02:00
import net.schueller.peertube.R;
2020-07-05 14:15:48 +02:00
import java.util.Locale;
public class CommonActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set Night Mode
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
2020-07-05 16:12:35 +02:00
AppCompatDelegate.setDefaultNightMode(sharedPref.getBoolean(getString(R.string.pref_dark_mode_key), false) ?
AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
// Set theme
setTheme(getResources().getIdentifier(
2020-07-05 14:15:48 +02:00
sharedPref.getString(
getString(R.string.pref_theme_key),
getString(R.string.app_default_theme)
),
"style",
getPackageName())
);
// Set language
2020-07-05 16:12:35 +02:00
String countryCode = sharedPref.getString(getString(R.string.pref_language_app_key), "en");
2020-07-05 14:15:48 +02:00
assert countryCode != null;
Locale locale = new Locale(countryCode);
//Neither Chinese language choice was working, found this fix on stack overflow
2020-07-05 14:15:48 +02:00
if (countryCode.equals("zh-rCN"))
locale = Locale.SIMPLIFIED_CHINESE;
2020-07-05 14:15:48 +02:00
if (countryCode.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());
}
}