aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-11-30 16:12:16 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-11-30 16:12:16 +0000
commit924128f09aa3c514bcbe74af65ad4feb05c774dc (patch)
tree7dd6bb841abfd4fd0cb09311aaccec16c57e46aa /app/src/main/java
parent4acf8611e72a3d25aff33f2fbaf3e5a10370aeec (diff)
downloadinfinity-for-reddit-924128f09aa3c514bcbe74af65ad4feb05c774dc.tar
infinity-for-reddit-924128f09aa3c514bcbe74af65ad4feb05c774dc.tar.gz
infinity-for-reddit-924128f09aa3c514bcbe74af65ad4feb05c774dc.tar.bz2
infinity-for-reddit-924128f09aa3c514bcbe74af65ad4feb05c774dc.tar.lz
infinity-for-reddit-924128f09aa3c514bcbe74af65ad4feb05c774dc.tar.xz
infinity-for-reddit-924128f09aa3c514bcbe74af65ad4feb05c774dc.tar.zst
infinity-for-reddit-924128f09aa3c514bcbe74af65ad4feb05c774dc.zip
Changing language is now available.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java15
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/MiscellaneousPreferenceFragment.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java2
3 files changed, 27 insertions, 3 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java
index e01c0430..ccc00968 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java
@@ -29,9 +29,11 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;
import java.lang.reflect.Field;
+import java.util.Locale;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
+import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.font.ContentFontFamily;
import ml.docilealligator.infinityforreddit.font.ContentFontStyle;
@@ -39,7 +41,6 @@ import ml.docilealligator.infinityforreddit.font.FontFamily;
import ml.docilealligator.infinityforreddit.font.FontStyle;
import ml.docilealligator.infinityforreddit.font.TitleFontFamily;
import ml.docilealligator.infinityforreddit.font.TitleFontStyle;
-import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.utils.CustomThemeSharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
@@ -64,6 +65,18 @@ public abstract class BaseActivity extends AppCompatActivity {
customThemeWrapper = getCustomThemeWrapper();
SharedPreferences mSharedPreferences = getDefaultSharedPreferences();
+
+ String language = mSharedPreferences.getString(SharedPreferencesUtils.LANGUAGE, SharedPreferencesUtils.LANGUAGE_DEFAULT_VALUE);
+ if (language.equals(SharedPreferencesUtils.LANGUAGE_DEFAULT_VALUE)) {
+ language = Resources.getSystem().getConfiguration().locale.getLanguage();
+ }
+ Locale locale = new Locale(language);
+ Locale.setDefault(locale);
+ Resources resources = getResources();
+ Configuration config = resources.getConfiguration();
+ config.setLocale(locale);
+ resources.updateConfiguration(config, resources.getDisplayMetrics());
+
boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
int systemThemeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2"));
immersiveInterface = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MiscellaneousPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MiscellaneousPreferenceFragment.java
index c27e7eec..f33dd57f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MiscellaneousPreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MiscellaneousPreferenceFragment.java
@@ -7,6 +7,7 @@ import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.preference.ListPreference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
@@ -15,10 +16,10 @@ import org.greenrobot.eventbus.EventBus;
import javax.inject.Inject;
import javax.inject.Named;
-import ml.docilealligator.infinityforreddit.events.ChangeSavePostFeedScrolledPositionEvent;
-import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.events.ChangeSavePostFeedScrolledPositionEvent;
+import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
public class MiscellaneousPreferenceFragment extends PreferenceFragmentCompat {
@@ -40,6 +41,7 @@ public class MiscellaneousPreferenceFragment extends PreferenceFragmentCompat {
SwitchPreference confirmToExitSwitch = findPreference(SharedPreferencesUtils.CONFIRM_TO_EXIT);
SwitchPreference savePostFeedScrolledPositionSwitch = findPreference(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION);
+ ListPreference languageListPreference = findPreference(SharedPreferencesUtils.LANGUAGE);
if (confirmToExitSwitch != null) {
confirmToExitSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
@@ -57,6 +59,13 @@ public class MiscellaneousPreferenceFragment extends PreferenceFragmentCompat {
return true;
});
}
+
+ if (languageListPreference != null) {
+ languageListPreference.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new RecreateActivityEvent());
+ return true;
+ });
+ }
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
index ebfa20fe..f6c3d5bd 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
@@ -144,6 +144,8 @@ public class SharedPreferencesUtils {
public static final String SWIPE_RIGHT_ACTION = "swipe_right_action";
public static final int SWIPE_ACITON_UPVOTE = 0;
public static final int SWIPE_ACITON_DOWNVOTE = 1;
+ public static final String LANGUAGE = "language";
+ public static final String LANGUAGE_DEFAULT_VALUE = "auto";
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
public static final String MAIN_PAGE_TAB_COUNT = "_main_page_tab_count";