Skip to content

Commit

Permalink
修复某些情况下切换语种后配置没有保存的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
getActivity committed Jul 21, 2021
1 parent be92a8f commit 7a12693
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
Binary file modified MultiLanguages.apk
Binary file not shown.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 语种切换框架

* 码云地址:[Gitee](https://gitee.com/getActivity/MultiLanguages)
* 项目地址:[Github](https://github.com/getActivity/MultiLanguages)[码云](https://gitee.com/getActivity/MultiLanguages)

* [点击此处下载Demo](MultiLanguages.apk)

Expand All @@ -26,7 +26,7 @@ allprojects {
```groovy
dependencies {
// 语种切换框架:https://github.com/getActivity/MultiLanguages
implementation 'com.github.getActivity:MultiLanguages:6.8'
implementation 'com.github.getActivity:MultiLanguages:6.9'
}
```

Expand Down Expand Up @@ -199,6 +199,8 @@ public final class LanguagesWebView extends WebView {

* 悬浮窗框架:[XToast](https://github.com/getActivity/XToast)

* Shape 框架:[ShapeView](https://github.com/getActivity/ShapeView)

* Gson 解析容错:[GsonFactory](https://github.com/getActivity/GsonFactory)

* 日志查看框架:[Logcat](https://github.com/getActivity/Logcat)
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.hjq.language.demo"
minSdkVersion 16
targetSdkVersion 30
versionCode 68
versionName "6.8"
versionCode 69
versionName "6.9"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,27 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="自动" />
android:text="跟随系统" />

<RadioButton
android:id="@+id/rb_main_language_cn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginLeft="15dp"
android:text="简体" />

<RadioButton
android:id="@+id/rb_main_language_tw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginLeft="15dp"
android:text="繁体" />

<RadioButton
android:id="@+id/rb_main_language_en"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginLeft="15dp"
android:text="英语" />

</RadioGroup>
Expand Down
6 changes: 3 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ android {

defaultConfig {
minSdkVersion 14
versionCode 68
versionName "6.8"
versionCode 69
versionName "6.9"
}

android.libraryVariants.all { variant ->
// aar 输出文件名配置
variant.outputs.all { output ->
outputFileName = "language-${android.defaultConfig.versionName}.aar"
outputFileName = "${rootProject.name}-${android.defaultConfig.versionName}.aar"
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions library/src/main/java/com/hjq/language/MultiLanguages.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public static void updateAppLanguage(Context context) {
* 更新 Resources 的语种
*/
public static void updateAppLanguage(Resources resources) {
if (resources == null) {
return;
}
if (LanguagesUtils.getLocale(resources.getConfiguration()).equals(getAppLanguage())) {
return;
}
Expand All @@ -77,6 +80,7 @@ public static Locale getAppLanguage() {
* @return 语种是否发生改变了
*/
public static boolean setAppLanguage(Context context, Locale newLocale) {
LanguagesConfig.setAppLanguage(context, newLocale);
if (LanguagesUtils.getLocale(context).equals(newLocale)) {
return false;
}
Expand All @@ -88,7 +92,7 @@ public static boolean setAppLanguage(Context context, Locale newLocale) {
// 更新 Application 的语种
LanguagesUtils.updateLanguages(sApplication.getResources(), newLocale);
}
LanguagesConfig.setAppLanguage(context, newLocale);

LanguagesUtils.setDefaultLocale(context);
if (sLanguageListener != null) {
sLanguageListener.onAppLocaleChange(oldLocale, newLocale);
Expand Down Expand Up @@ -166,7 +170,7 @@ public static void setOnLanguageListener(OnLanguageListener listener) {
}

/**
* 设置保存的 SharedPreferences 文件名
* 设置保存的 SharedPreferences 文件名(请在 Application 初始化之前设置,可以放在 Application 中的代码块或者静态代码块)
*/
public static void setSharedPreferencesName(String name) {
LanguagesConfig.setSharedPreferencesName(name);
Expand Down

0 comments on commit 7a12693

Please sign in to comment.