diff options
Diffstat (limited to 'app/src/main/java')
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"; |