diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 6f4878418..3fedf332c 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -6,6 +6,8 @@
+
(activity));
CrashSaveBean.getInstance().setActivitySize(activities);
+ AppManager.getInstance().addActivity(activity);
}
@Override
diff --git a/common/src/main/java/com/yunbao/common/activity/AbsActivity.java b/common/src/main/java/com/yunbao/common/activity/AbsActivity.java
index e75bf5ae6..42fa80d32 100644
--- a/common/src/main/java/com/yunbao/common/activity/AbsActivity.java
+++ b/common/src/main/java/com/yunbao/common/activity/AbsActivity.java
@@ -43,14 +43,14 @@ public abstract class AbsActivity extends AppCompatActivity {
protected List mLifeCycleListeners;
protected boolean isFullWindow;
- @Override
- public Resources getResources() {
- Resources res = super.getResources();
- Configuration config = new Configuration();
- config.setToDefaults();
- res.updateConfiguration(config, res.getDisplayMetrics());
- return res;
- }
+// @Override
+// public Resources getResources() {
+// Resources res = super.getResources();
+// Configuration config = new Configuration();
+// config.setToDefaults();
+// res.updateConfiguration(config, res.getDisplayMetrics());
+// return res;
+// }
@Override
diff --git a/common/src/main/java/com/yunbao/common/bean/WishModel.java b/common/src/main/java/com/yunbao/common/bean/WishModel.java
index b1bf7e722..136fbe952 100644
--- a/common/src/main/java/com/yunbao/common/bean/WishModel.java
+++ b/common/src/main/java/com/yunbao/common/bean/WishModel.java
@@ -1,5 +1,8 @@
package com.yunbao.common.bean;
+import androidx.room.Transaction;
+
+import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class WishModel extends BaseModel {
@@ -29,7 +32,7 @@ public class WishModel extends BaseModel {
@SerializedName("price")
private int price;
@SerializedName("isShow")
- private int isShow = -1;
+ private transient int isShow = -1;
public int getIsShow() {
return isShow;
diff --git a/common/src/main/java/com/yunbao/common/fragment/LiveNewWishListFragment.java b/common/src/main/java/com/yunbao/common/fragment/LiveNewWishListFragment.java
index f7c912e08..897c19eb9 100644
--- a/common/src/main/java/com/yunbao/common/fragment/LiveNewWishListFragment.java
+++ b/common/src/main/java/com/yunbao/common/fragment/LiveNewWishListFragment.java
@@ -10,6 +10,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import com.lxj.xpopup.XPopup;
import com.yunbao.common.R;
import com.yunbao.common.adapter.LiveNewWishAdapter;
@@ -23,6 +24,7 @@ import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.views.LiveNewWishGiftPopup;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
+import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
@@ -100,8 +102,17 @@ public class LiveNewWishListFragment extends BaseFragment {
public void saveWish() {
List wishList = liveNewWishAdapter.getWishList();
wishList.remove(wishList.size() - 1);
+ // 1. Gson构造器
+ GsonBuilder builder = new GsonBuilder();
+ // 2. 排除使用特定修饰符的字段
+ builder.excludeFieldsWithModifiers(Modifier.TRANSIENT);
+ // 3. 格式良好的输出
+ builder.setPrettyPrinting();
+ // 4. 创建Gson对象
+ Gson gson = builder.create();
+
LiveNetManager.get(getContext()).
- setWishlistV2(type, new Gson().toJson(wishList), new HttpCallback() {
+ setWishlistV2(type, gson.toJson(wishList), new HttpCallback() {
@Override
public void onSuccess(String data) {
ToastUtil.show(data);
diff --git a/common/src/main/java/com/yunbao/common/utils/AppManager.java b/common/src/main/java/com/yunbao/common/utils/AppManager.java
new file mode 100644
index 000000000..95f7d5a83
--- /dev/null
+++ b/common/src/main/java/com/yunbao/common/utils/AppManager.java
@@ -0,0 +1,130 @@
+package com.yunbao.common.utils;
+
+import android.app.Activity;
+
+import java.util.Stack;
+
+public class AppManager {
+
+ private static Stack activityStack;
+
+ public AppManager() {
+ }
+
+ /**
+ * 单一实例
+ */
+ public static AppManager getInstance() {
+ return SingleApp.INSTANCE;
+ }
+
+ public static class SingleApp {
+ public static AppManager INSTANCE = new AppManager();
+ }
+
+ /**
+ * 添加Activity到堆栈
+ */
+ public void addActivity(Activity activity) {
+ if (activityStack == null) {
+ activityStack = new Stack();
+ }
+ activityStack.add(activity);
+ }
+
+ /**
+ * 移除Activity
+ */
+ public void removeActivity(Activity activity) {
+ activityStack.remove(activity);
+ }
+
+ /**
+ * 获取指定的Activity
+ */
+ public static Activity getActivity(Class> cls) {
+ if (activityStack != null)
+ for (Activity activity : activityStack) {
+ if (activity.getClass().equals(cls)) {
+ return activity;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * 获取当前显示Activity(堆栈中最后一个传入的activity)
+ */
+ public Activity getLastActivity() {
+ Activity activity = activityStack.lastElement();
+ return activity;
+ }
+
+ /**
+ * 获取所有Activity
+ */
+ public Stack getAllActivityStacks() {
+ return activityStack;
+ }
+
+ /**
+ * 结束指定的Activity
+ */
+ public void finishActivity(Activity activity) {
+ if (activity != null) {
+ if (!activity.isFinishing()) {
+ activity.finish();
+ activityStack.remove(activity);
+ }
+ }
+ }
+
+ /**
+ * 结束指定类名的Activity
+ */
+ public void finishActivity(Class> cls) {
+ for (Activity activity : activityStack) {
+ if (activity.getClass().equals(cls)) {
+ finishActivity(activity);
+ break;
+ }
+ }
+ }
+
+ /**
+ * 结束除当前传入以外所有Activity
+ */
+ public void finishOthersActivity(Class> cls) {
+ if (activityStack != null)
+ for (Activity activity : activityStack) {
+ if (!activity.getClass().equals(cls)) {
+ activity.finish();
+ }
+ }
+ }
+
+ /**
+ * 结束所有Activity
+ */
+ public void finishAllActivity() {
+ if (activityStack != null)
+ for (Activity activity : activityStack) {
+ activity.finish();
+ }
+ activityStack.clear();
+ }
+
+
+ /**
+ * 退出应用程序
+ */
+ public void AppExit() {
+ try {
+ finishAllActivity();
+ android.os.Process.killProcess(android.os.Process.myPid());// 杀死该应用进程
+ System.exit(0);
+ } catch (Exception e) {
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/common/src/main/java/com/yunbao/common/views/LiveNewWishListPopup.java b/common/src/main/java/com/yunbao/common/views/LiveNewWishListPopup.java
index b4a636abc..a2b6f830b 100644
--- a/common/src/main/java/com/yunbao/common/views/LiveNewWishListPopup.java
+++ b/common/src/main/java/com/yunbao/common/views/LiveNewWishListPopup.java
@@ -14,6 +14,7 @@ import androidx.viewpager2.widget.ViewPager2;
import com.google.android.material.tabs.TabLayout;
import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BottomPopupView;
import com.yunbao.common.R;
@@ -33,6 +34,7 @@ import com.yunbao.common.views.weight.ViewClicksAntiShake;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
+import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
@@ -286,8 +288,16 @@ public class LiveNewWishListPopup extends BottomPopupView {
break;
}
List wishList = new ArrayList<>();
+ // 1. Gson构造器
+ GsonBuilder builder = new GsonBuilder();
+ // 2. 排除使用特定修饰符的字段
+ builder.excludeFieldsWithModifiers(Modifier.TRANSIENT);
+ // 3. 格式良好的输出
+ builder.setPrettyPrinting();
+ // 4. 创建Gson对象
+ Gson gson = builder.create();
LiveNetManager.get(getContext()).
- setWishlistV2(type, new Gson().toJson(wishList), new HttpCallback() {
+ setWishlistV2(type, gson.toJson(wishList), new HttpCallback() {
@Override
public void onSuccess(String data) {
ToastUtil.show(data);
diff --git a/common/src/main/res/values-en/strings.xml b/common/src/main/res/values-en/strings.xml
index 81ad887c4..6a63d995c 100644
--- a/common/src/main/res/values-en/strings.xml
+++ b/common/src/main/res/values-en/strings.xml
@@ -1116,4 +1116,6 @@ Limited ride And limited avatar frame
Use
wish
Play setting
+ language setting
+ Traditional Chinese
diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml
index 3939bc3ce..d7ef14ef8 100644
--- a/common/src/main/res/values/strings.xml
+++ b/common/src/main/res/values/strings.xml
@@ -1114,5 +1114,7 @@
使用
心願
播放設置
+ 語言設定
+ 繁體中文
diff --git a/main/src/main/AndroidManifest.xml b/main/src/main/AndroidManifest.xml
index e9afd0342..950e8e921 100644
--- a/main/src/main/AndroidManifest.xml
+++ b/main/src/main/AndroidManifest.xml
@@ -60,6 +60,10 @@
+
onBackPressed());
+ ViewClicksAntiShake.clicksAntiShake(traditionalChinese, new ViewClicksAntiShake.ViewClicksCallBack() {
+ @Override
+ public void onViewClicks() {
+ changeAllActivitysLanguage(Locale.SIMPLIFIED_CHINESE);
+ }
+ });
+ ViewClicksAntiShake.clicksAntiShake(english, new ViewClicksAntiShake.ViewClicksCallBack() {
+ @Override
+ public void onViewClicks() {
+ changeAllActivitysLanguage(Locale.US);
+ }
+ });
+ }
+
+ private void changeAllActivitysLanguage(Locale locale) {
+ Stack allActivityStacks = AppManager.getInstance().getAllActivityStacks();
+ for (int i = 0; i < allActivityStacks.size(); i++) {
+ LanguageUtil.shiftLanguage(locale, allActivityStacks.get(i),mContext);
+ }
+
+ }
+}
diff --git a/main/src/main/java/com/yunbao/main/activity/SettingActivity.java b/main/src/main/java/com/yunbao/main/activity/SettingActivity.java
index 1da67ee61..2acb7ded4 100644
--- a/main/src/main/java/com/yunbao/main/activity/SettingActivity.java
+++ b/main/src/main/java/com/yunbao/main/activity/SettingActivity.java
@@ -144,6 +144,13 @@ public class SettingActivity extends AbsActivity implements OnItemClickListener<
startActivity(new Intent(SettingActivity.this, MsgSettActivity.class));
}
});
+ //语言设置
+ ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.language_setting), new ViewClicksAntiShake.ViewClicksCallBack() {
+ @Override
+ public void onViewClicks() {
+ startActivity(new Intent(SettingActivity.this, LanguageSettingActivity.class));
+ }
+ });
//屏蔽礼物特效
ViewClicksAntiShake.clicksAntiShake(studioGiftEffects, new ViewClicksAntiShake.ViewClicksCallBack() {
@Override
diff --git a/main/src/main/java/com/yunbao/main/utils/LanguageUtil.java b/main/src/main/java/com/yunbao/main/utils/LanguageUtil.java
new file mode 100644
index 000000000..c18836014
--- /dev/null
+++ b/main/src/main/java/com/yunbao/main/utils/LanguageUtil.java
@@ -0,0 +1,95 @@
+package com.yunbao.main.utils;
+
+import android.app.Activity;
+import android.app.backup.BackupManager;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.util.DisplayMetrics;
+
+import com.yunbao.main.activity.MainActivity;
+
+import java.lang.reflect.Method;
+import java.util.Locale;
+
+public class LanguageUtil {
+
+ /**
+ * 这个方法虽然更新了资源但是只能以后的界面生效,之前没有finish的页面还是保留原来的语言
+ *
+ * @param locale
+ * @param context
+ */
+ public static void shiftLanguage(Locale locale, Context context) {
+ Resources resources = context.getResources();
+ Configuration config = resources.getConfiguration();
+ DisplayMetrics dm = resources.getDisplayMetrics();
+ config.locale = locale;
+ resources.updateConfiguration(config, dm);
+
+ }
+
+ /**
+ * 这个方法是为了让全部的activity都修改语言
+ *
+ * @param locale
+ * @param activity
+ * @param context
+ */
+ public static void shiftLanguage(Locale locale, Activity activity, Context context) {
+ Resources resources = context.getResources();
+ Configuration config = resources.getConfiguration();
+ DisplayMetrics dm = resources.getDisplayMetrics();
+ config.locale = locale;
+ resources.updateConfiguration(config, dm);
+ if (!(activity instanceof MainActivity)) {
+ activity.recreate();
+ }
+
+ }
+
+ public static void updateLanguage(Locale locale) {
+ try {
+ Object objIActMag, objActMagNative;
+ Class clzIActMag = Class.forName("android.app.IActivityManager");
+
+ Class clzActMagNative = Class
+ .forName("android.app.ActivityManagerNative");
+ //amn = ActivityManagerNative.getDefault();
+ Method mtdActMagNative$getDefault = clzActMagNative
+ .getDeclaredMethod("getDefault");
+ objIActMag = mtdActMagNative$getDefault.invoke(clzActMagNative);
+ // objIActMag = amn.getConfiguration();
+ Method mtdIActMag$getConfiguration = clzIActMag
+ .getDeclaredMethod("getConfiguration");
+ Configuration config = (Configuration) mtdIActMag$getConfiguration.invoke(objIActMag);
+ // set the locale to the new value
+ config.locale = locale;
+
+ //持久化 config.userSetLocale = true;
+ Class clzConfig = Class
+ .forName("android.content.res.Configuration");
+ java.lang.reflect.Field userSetLocale = clzConfig
+ .getField("userSetLocale");
+ userSetLocale.set(config, true);
+
+ //如果有阿拉伯语,必须加上,否则阿拉伯语与其它语言切换时,布局与文字方向不会改变
+ Method setLayoutDirection = clzConfig
+ .getDeclaredMethod("setLayoutDirection", Locale.class);
+ setLayoutDirection.invoke(config, locale);
+
+ // 此处需要声明权限:android.permission.CHANGE_CONFIGURATION
+ // 会重新调用 onCreate();
+ Class[] clzParams = {Configuration.class};
+ // objIActMag.updateConfiguration(config);
+ Method mtdIActMag$updateConfiguration = clzIActMag
+ .getDeclaredMethod("updateConfiguration", clzParams);
+
+ mtdIActMag$updateConfiguration.invoke(objIActMag, config);
+ BackupManager.dataChanged("com.android.providers.settings");
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/main/src/main/res/drawable/background_language.xml b/main/src/main/res/drawable/background_language.xml
new file mode 100644
index 000000000..7c342c273
--- /dev/null
+++ b/main/src/main/res/drawable/background_language.xml
@@ -0,0 +1,9 @@
+
+
+ -
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main/src/main/res/drawable/icon_xuanzhong.png b/main/src/main/res/drawable/icon_xuanzhong.png
new file mode 100644
index 000000000..24b810cdd
Binary files /dev/null and b/main/src/main/res/drawable/icon_xuanzhong.png differ
diff --git a/main/src/main/res/layout/activity_language_sett.xml b/main/src/main/res/layout/activity_language_sett.xml
new file mode 100644
index 000000000..725f459a7
--- /dev/null
+++ b/main/src/main/res/layout/activity_language_sett.xml
@@ -0,0 +1,107 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main/src/main/res/layout/activity_setting.xml b/main/src/main/res/layout/activity_setting.xml
index b5a61cd29..4cfbcf7f5 100644
--- a/main/src/main/res/layout/activity_setting.xml
+++ b/main/src/main/res/layout/activity_setting.xml
@@ -155,6 +155,37 @@
android:src="@mipmap/icon_arrow_right" />
+
+
+
+
+
+
+
+
+
+
+