修改心愿单生成

This commit is contained in:
18401019693 2023-04-03 15:29:21 +08:00
parent a86cf97d74
commit 153d5ff159
17 changed files with 482 additions and 11 deletions

View File

@ -6,6 +6,8 @@
<uses-permission
android:name="android.permission.CALL_PHONE"
tools:node="remove" />
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION"
tools:ignore="ProtectedPermissions" />
<uses-permission
android:name="android.permission.READ_LOGS"
tools:ignore="ProtectedPermissions"
@ -92,6 +94,7 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:preserveLegacyExternalStorage="true"
android:requestLegacyExternalStorage="true"
android:theme="@style/AppTheme"

View File

@ -39,6 +39,7 @@ import com.yunbao.common.manager.imrongcloud.InstructorSendRewardProvider;
import com.yunbao.common.manager.imrongcloud.MessageIMManager;
import com.yunbao.common.manager.imrongcloud.RecommendLiveRoom;
import com.yunbao.common.manager.imrongcloud.RongcloudIMManager;
import com.yunbao.common.utils.AppManager;
import com.yunbao.common.utils.L;
import com.yunbao.common.utils.SpUtil;
import com.yunbao.live.socket.SocketRyClient;
@ -104,12 +105,14 @@ public class AppContext extends CommonAppContext {
return;
}
}
AppManager.getInstance().removeActivity(activity);
}
@Override
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
activities.add(new WeakReference<>(activity));
CrashSaveBean.getInstance().setActivitySize(activities);
AppManager.getInstance().addActivity(activity);
}
@Override

View File

@ -43,14 +43,14 @@ public abstract class AbsActivity extends AppCompatActivity {
protected List<LifeCycleListener> 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

View File

@ -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;

View File

@ -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<WishModel> 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<String>() {
setWishlistV2(type, gson.toJson(wishList), new HttpCallback<String>() {
@Override
public void onSuccess(String data) {
ToastUtil.show(data);

View File

@ -0,0 +1,130 @@
package com.yunbao.common.utils;
import android.app.Activity;
import java.util.Stack;
public class AppManager {
private static Stack<Activity> 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<Activity>();
}
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<Activity> 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) {
}
}
}

View File

@ -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<WishModel> 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<String>() {
setWishlistV2(type, gson.toJson(wishList), new HttpCallback<String>() {
@Override
public void onSuccess(String data) {
ToastUtil.show(data);

View File

@ -1116,4 +1116,6 @@ Limited ride And limited avatar frame</string>
<string name="live_use_discount_yes">Use</string>
<string name="live_use_wish">wish</string>
<string name="live_play_setting">Play setting</string>
<string name="live_language_setting">language setting</string>
<string name="traditional_chinese">Traditional Chinese</string>
</resources>

View File

@ -1114,5 +1114,7 @@
<string name="live_use_discount_yes">使用</string>
<string name="live_use_wish">心願</string>
<string name="live_play_setting">播放設置</string>
<string name="live_language_setting">語言設定</string>
<string name="traditional_chinese">繁體中文</string>
</resources>

View File

@ -60,6 +60,10 @@
<activity
android:name=".activity.SettingActivity"
android:screenOrientation="portrait" />
<activity
android:name=".activity.LanguageSettingActivity"
android:screenOrientation="portrait"
android:configChanges="locale|layoutDirection|keyboard" />
<activity
android:name=".activity.SearchActivity"
android:screenOrientation="portrait"

View File

@ -0,0 +1,54 @@
package com.yunbao.main.activity;
import android.app.Activity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.yunbao.common.activity.AbsActivity;
import com.yunbao.common.utils.AppManager;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
import com.yunbao.main.R;
import com.yunbao.main.utils.LanguageUtil;
import java.util.Locale;
import java.util.Stack;
public class LanguageSettingActivity extends AbsActivity {
private LinearLayout traditionalChinese, english;
private ImageView imgTraditionalChinese, imgEnglish;
@Override
protected int getLayoutId() {
return R.layout.activity_language_sett;
}
@Override
protected void main() {
super.main();
traditionalChinese = findViewById(R.id.traditional_chinese);
english = findViewById(R.id.english);
imgEnglish = findViewById(R.id.img_english);
imgTraditionalChinese = findViewById(R.id.img_traditional_chinese);
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.live_photo_btn_cancel), () -> 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<Activity> allActivityStacks = AppManager.getInstance().getAllActivityStacks();
for (int i = 0; i < allActivityStacks.size(); i++) {
LanguageUtil.shiftLanguage(locale, allActivityStacks.get(i),mContext);
}
}
}

View File

@ -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

View File

@ -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();
}
}
}

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="12dp" />
<solid android:color="#FFC821" />
</shape>
</item>
</selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="24dp">
<TextView
android:id="@+id/live_photo_btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="14dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:padding="2dp"
android:text="@string/live_photo_btn_cancel"
android:textColor="#666666"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="11dp"
android:text="@string/live_language_setting"
android:textColor="#333333"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="10dp"
android:layout_marginEnd="16dp"
android:background="@drawable/background_language"
android:paddingStart="10dp"
android:paddingTop="4dp"
android:paddingEnd="10dp"
android:paddingBottom="4dp"
android:text="@string/complete"
android:textColor="@color/white" />
</FrameLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#E9EDF0" />
<LinearLayout
android:id="@+id/traditional_chinese"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingStart="16dp"
android:text="@string/traditional_chinese"
android:textColor="#333333" />
<ImageView
android:id="@+id/img_traditional_chinese"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_marginEnd="16dp"
android:background="@drawable/icon_xuanzhong" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="#E9EDF0" />
<LinearLayout
android:id="@+id/english"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingStart="16dp"
android:text="English"
android:textColor="#333333" />
<ImageView
android:id="@+id/img_english"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_marginEnd="16dp"
android:background="@drawable/icon_xuanzhong" />
</LinearLayout>
</LinearLayout>

View File

@ -155,6 +155,37 @@
android:src="@mipmap/icon_arrow_right" />
</LinearLayout>
<LinearLayout
android:id="@+id/language_setting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:visibility="gone"
android:paddingTop="15dp"
android:paddingBottom="25dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:text="@string/live_language_setting"
android:textColor="#1E1F20"
android:textSize="16sp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<ImageView
android:layout_width="17dp"
android:layout_height="30dp"
android:layout_marginEnd="26.33dp"
android:src="@mipmap/icon_arrow_right" />
</LinearLayout>
</LinearLayout>
<LinearLayout