diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-11-30 16:12:16 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-11-30 16:12:16 +0000 |
commit | 924128f09aa3c514bcbe74af65ad4feb05c774dc (patch) | |
tree | 7dd6bb841abfd4fd0cb09311aaccec16c57e46aa /app/src | |
parent | 4acf8611e72a3d25aff33f2fbaf3e5a10370aeec (diff) | |
download | infinity-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')
8 files changed, 83 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"; diff --git a/app/src/main/res/drawable-night/ic_language_24dp.xml b/app/src/main/res/drawable-night/ic_language_24dp.xml new file mode 100644 index 00000000..e6e0586d --- /dev/null +++ b/app/src/main/res/drawable-night/ic_language_24dp.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="#FFFFFF" + android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM18.92,8h-2.95c-0.32,-1.25 -0.78,-2.45 -1.38,-3.56 1.84,0.63 3.37,1.91 4.33,3.56zM12,4.04c0.83,1.2 1.48,2.53 1.91,3.96h-3.82c0.43,-1.43 1.08,-2.76 1.91,-3.96zM4.26,14C4.1,13.36 4,12.69 4,12s0.1,-1.36 0.26,-2h3.38c-0.08,0.66 -0.14,1.32 -0.14,2s0.06,1.34 0.14,2L4.26,14zM5.08,16h2.95c0.32,1.25 0.78,2.45 1.38,3.56 -1.84,-0.63 -3.37,-1.9 -4.33,-3.56zM8.03,8L5.08,8c0.96,-1.66 2.49,-2.93 4.33,-3.56C8.81,5.55 8.35,6.75 8.03,8zM12,19.96c-0.83,-1.2 -1.48,-2.53 -1.91,-3.96h3.82c-0.43,1.43 -1.08,2.76 -1.91,3.96zM14.34,14L9.66,14c-0.09,-0.66 -0.16,-1.32 -0.16,-2s0.07,-1.35 0.16,-2h4.68c0.09,0.65 0.16,1.32 0.16,2s-0.07,1.34 -0.16,2zM14.59,19.56c0.6,-1.11 1.06,-2.31 1.38,-3.56h2.95c-0.96,1.65 -2.49,2.93 -4.33,3.56zM16.36,14c0.08,-0.66 0.14,-1.32 0.14,-2s-0.06,-1.34 -0.14,-2h3.38c0.16,0.64 0.26,1.31 0.26,2s-0.1,1.36 -0.26,2h-3.38z"/> +</vector> diff --git a/app/src/main/res/drawable/ic_language_24dp.xml b/app/src/main/res/drawable/ic_language_24dp.xml new file mode 100644 index 00000000..b7840867 --- /dev/null +++ b/app/src/main/res/drawable/ic_language_24dp.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="#000000" + android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM18.92,8h-2.95c-0.32,-1.25 -0.78,-2.45 -1.38,-3.56 1.84,0.63 3.37,1.91 4.33,3.56zM12,4.04c0.83,1.2 1.48,2.53 1.91,3.96h-3.82c0.43,-1.43 1.08,-2.76 1.91,-3.96zM4.26,14C4.1,13.36 4,12.69 4,12s0.1,-1.36 0.26,-2h3.38c-0.08,0.66 -0.14,1.32 -0.14,2s0.06,1.34 0.14,2L4.26,14zM5.08,16h2.95c0.32,1.25 0.78,2.45 1.38,3.56 -1.84,-0.63 -3.37,-1.9 -4.33,-3.56zM8.03,8L5.08,8c0.96,-1.66 2.49,-2.93 4.33,-3.56C8.81,5.55 8.35,6.75 8.03,8zM12,19.96c-0.83,-1.2 -1.48,-2.53 -1.91,-3.96h3.82c-0.43,1.43 -1.08,2.76 -1.91,3.96zM14.34,14L9.66,14c-0.09,-0.66 -0.16,-1.32 -0.16,-2s0.07,-1.35 0.16,-2h4.68c0.09,0.65 0.16,1.32 0.16,2s-0.07,1.34 -0.16,2zM14.59,19.56c0.6,-1.11 1.06,-2.31 1.38,-3.56h2.95c-0.96,1.65 -2.49,2.93 -4.33,3.56zM16.36,14c0.08,-0.66 0.14,-1.32 0.14,-2s-0.06,-1.34 -0.14,-2h3.38c0.16,0.64 0.26,1.31 0.26,2s-0.1,1.36 -0.26,2h-3.38z"/> +</vector> diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 767e2fb9..37228db4 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -295,4 +295,32 @@ <item>1</item> </string-array> + <string-array name="settings_language"> + <item>Auto</item> + <item>Hrvatski</item> + <item>English</item> + <item>Française</item> + <item>Deutsche</item> + <item>हिंदी</item> + <item>Italiana</item> + <item>日本語</item> + <item>Português (BR)</item> + <item>Español</item> + <item>Türkçe</item> + </string-array> + + <string-array name="settings_language_values"> + <item>auto</item> + <item>hr</item> + <item>en</item> + <item>fr</item> + <item>de</item> + <item>hi</item> + <item>it</item> + <item>ja</item> + <item>pt-rBR</item> + <item>es</item> + <item>tr-rTR</item> + </string-array> + </resources>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fa386470..eac39901 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -507,6 +507,7 @@ <string name="settings_swipe_action_swipe_left_title">Swipe Left</string> <string name="settings_swipe_action_swipe_right_title">Swipe Right</string> <string name="settings_swipe_action_info_summary">Not applicable to post feed with more than 1 column or post detail.</string> + <string name="settings_language_title">Language</string> <string name="no_link_available">Cannot get the link</string> diff --git a/app/src/main/res/xml/miscellaneous_preferences.xml b/app/src/main/res/xml/miscellaneous_preferences.xml index f4274a5a..95532c33 100644 --- a/app/src/main/res/xml/miscellaneous_preferences.xml +++ b/app/src/main/res/xml/miscellaneous_preferences.xml @@ -25,4 +25,13 @@ app:title="@string/settings_respect_subreddit_recommended_comment_sort_type_title" app:summary="@string/settings_respect_subreddit_recommended_comment_sort_type_summary" /> + <ListPreference + app:defaultValue="auto" + app:entries="@array/settings_language" + app:entryValues="@array/settings_language_values" + app:key="language" + app:icon="@drawable/ic_language_24dp" + app:title="@string/settings_language_title" + app:useSimpleSummaryProvider="true" /> + </PreferenceScreen>
\ No newline at end of file |