多语言切换
This commit is contained in:
parent
32e3584fef
commit
bfbbe54308
@ -80,6 +80,7 @@ public class AppContext extends CommonAppContext {
|
||||
public LiveImDeletUtil liveImDeletUtil;
|
||||
private final static List<WeakReference<Activity>> activities = new ArrayList<>();
|
||||
|
||||
|
||||
private static final class AdjustLifecycleCallbacks implements ActivityLifecycleCallbacks {
|
||||
@Override
|
||||
public void onActivityResumed(Activity activity) {
|
||||
|
@ -27,6 +27,7 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.glide.ImgLoader;
|
||||
import com.yunbao.common.interfaces.LifeCycleListener;
|
||||
import com.yunbao.common.manager.IMLoginManager;
|
||||
import com.yunbao.common.utils.ClickUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -48,6 +49,7 @@ public abstract class AbsActivity extends AppCompatActivity {
|
||||
Resources res = super.getResources();
|
||||
Configuration config = new Configuration();
|
||||
config.setToDefaults();
|
||||
config.locale = IMLoginManager.get(this).getLocaleLanguage();
|
||||
res.updateConfiguration(config, res.getDisplayMetrics());
|
||||
return res;
|
||||
}
|
||||
|
@ -14,6 +14,26 @@ public class LiveClassBean {
|
||||
private boolean isAll;
|
||||
private String des;
|
||||
private boolean checked;
|
||||
private String chinese;
|
||||
private String english;
|
||||
|
||||
public String getChinese() {
|
||||
return chinese;
|
||||
}
|
||||
|
||||
public LiveClassBean setChinese(String chinese) {
|
||||
this.chinese = chinese;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getEnglish() {
|
||||
return english;
|
||||
}
|
||||
|
||||
public LiveClassBean setEnglish(String english) {
|
||||
this.english = english;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
|
@ -19,6 +19,7 @@ import com.yunbao.common.event.FollowEvent;
|
||||
import com.yunbao.common.interfaces.CommonCallback;
|
||||
import com.yunbao.common.manager.APKManager;
|
||||
import com.yunbao.common.manager.IMLoginManager;
|
||||
import com.yunbao.common.manager.LiveClassManager;
|
||||
import com.yunbao.common.manager.NewLevelManager;
|
||||
import com.yunbao.common.utils.L;
|
||||
import com.yunbao.common.utils.MD5Util;
|
||||
@ -156,7 +157,7 @@ public class CommonHttpUtil {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
locale = context.getResources().getConfiguration().getLocales().get(0);
|
||||
} else {
|
||||
locale = context.getResources().getConfiguration().locale;
|
||||
locale = IMLoginManager.get(context).getLocaleLanguage();
|
||||
}
|
||||
if (locale.getLanguage().equals("zh")) {
|
||||
lang = "chinese";
|
||||
@ -202,6 +203,10 @@ public class CommonHttpUtil {
|
||||
JSONArray levelArray = obj.getJSONArray("levelanchor_new");
|
||||
new NewLevelManager(context).UpAnchorDataLevel(levelArray.toJSONString());
|
||||
}
|
||||
if (obj.containsKey("liveclass")) {//缓存直播间分类
|
||||
JSONArray levelArray = obj.getJSONArray("liveclass");
|
||||
new LiveClassManager(context).UpDataLiveClass(levelArray.toJSONString());
|
||||
}
|
||||
if (obj.containsKey("apk_ver")) {
|
||||
APKManager.get().setApkVer(obj.getString("apk_ver"));
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ import com.yunbao.common.views.floatingview.APPEasyFloat;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* 登录者信息管理
|
||||
*/
|
||||
@ -46,6 +48,20 @@ public class IMLoginManager extends BaseCacheManager {
|
||||
private final String STATUS_ANCHOR_SAY = "anchorSay";
|
||||
private final String STATUS_ANCHOR_CALL = "anchorCallMe";
|
||||
|
||||
private final String KEY_LANGUAGE = "language";
|
||||
|
||||
public void setLanguage(boolean isEnglish) {
|
||||
put(KEY_LANGUAGE, isEnglish);
|
||||
}
|
||||
|
||||
public Locale getLocaleLanguage() {
|
||||
if (!getBoolean(KEY_LANGUAGE, false)) {
|
||||
return Locale.SIMPLIFIED_CHINESE;
|
||||
} else {
|
||||
return new Locale("en", "rUS");
|
||||
}
|
||||
}
|
||||
|
||||
public void setDefaultBubbleUrl(String defaultBubbleUrl) {
|
||||
put(keyDefaultBubbleUrl, defaultBubbleUrl);
|
||||
}
|
||||
@ -55,7 +71,6 @@ public class IMLoginManager extends BaseCacheManager {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setXiaJBG(boolean xjbg) {
|
||||
put(xiaJBG, xjbg);
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
package com.yunbao.common.manager;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.yunbao.common.bean.LiveClassBean;
|
||||
import com.yunbao.common.bean.NewLevelModel;
|
||||
import com.yunbao.common.manager.base.BaseCacheManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LiveClassManager extends BaseCacheManager {
|
||||
private final String KEY_LIVE_CLASS = "keyLiveClass";
|
||||
private List<LiveClassBean> liveClass = new ArrayList<>();
|
||||
|
||||
public LiveClassManager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存等级图标
|
||||
*
|
||||
* @param json
|
||||
*/
|
||||
public void UpDataLiveClass(String json) {
|
||||
liveClass = new Gson().fromJson(json, new TypeToken<List<LiveClassBean>>() {
|
||||
}.getType());
|
||||
put(KEY_LIVE_CLASS, liveClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取等级数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<LiveClassBean> getLiveClass() {
|
||||
return getList(KEY_LIVE_CLASS, new TypeToken<List<LiveClassBean>>() {
|
||||
}.getType());
|
||||
}
|
||||
}
|
1129
common/src/main/res/values-en-rUS/string.xml
Normal file
1129
common/src/main/res/values-en-rUS/string.xml
Normal file
File diff suppressed because it is too large
Load Diff
@ -9,9 +9,9 @@ ext {
|
||||
]
|
||||
manifestPlaceholders = [
|
||||
//正式、
|
||||
serverHost : "https://napi.yaoulive.com",
|
||||
// serverHost : "https://napi.yaoulive.com",
|
||||
//测试
|
||||
// serverHost : "https ://ceshi.yaoulive.com",
|
||||
serverHost : "https://ceshi.yaoulive.com",
|
||||
|
||||
//腾讯地图
|
||||
txMapAppKey : "EOZBZ-ASLCU-4XPV3-BDCHZ-4E3Q7-H4BWB",
|
||||
|
@ -1,10 +1,13 @@
|
||||
package com.yunbao.main.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.yunbao.common.activity.AbsActivity;
|
||||
import com.yunbao.common.manager.IMLoginManager;
|
||||
import com.yunbao.common.utils.AppManager;
|
||||
import com.yunbao.common.views.weight.ViewClicksAntiShake;
|
||||
import com.yunbao.main.R;
|
||||
@ -16,6 +19,7 @@ import java.util.Stack;
|
||||
public class LanguageSettingActivity extends AbsActivity {
|
||||
private LinearLayout traditionalChinese, english;
|
||||
private ImageView imgTraditionalChinese, imgEnglish;
|
||||
private Locale locale;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
@ -25,6 +29,14 @@ public class LanguageSettingActivity extends AbsActivity {
|
||||
@Override
|
||||
protected void main() {
|
||||
super.main();
|
||||
locale = IMLoginManager.get(mContext).getLocaleLanguage();
|
||||
if (locale == Locale.SIMPLIFIED_CHINESE) {
|
||||
findViewById(R.id.img_english).setVisibility(View.GONE);
|
||||
findViewById(R.id.img_traditional_chinese).setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
findViewById(R.id.img_english).setVisibility(View.VISIBLE);
|
||||
findViewById(R.id.img_traditional_chinese).setVisibility(View.GONE);
|
||||
}
|
||||
traditionalChinese = findViewById(R.id.traditional_chinese);
|
||||
english = findViewById(R.id.english);
|
||||
imgEnglish = findViewById(R.id.img_english);
|
||||
@ -33,13 +45,23 @@ public class LanguageSettingActivity extends AbsActivity {
|
||||
ViewClicksAntiShake.clicksAntiShake(traditionalChinese, new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||
@Override
|
||||
public void onViewClicks() {
|
||||
changeAllActivitysLanguage(Locale.SIMPLIFIED_CHINESE);
|
||||
locale = Locale.SIMPLIFIED_CHINESE;
|
||||
findViewById(R.id.img_english).setVisibility(View.GONE);
|
||||
findViewById(R.id.img_traditional_chinese).setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
ViewClicksAntiShake.clicksAntiShake(english, new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||
@Override
|
||||
public void onViewClicks() {
|
||||
changeAllActivitysLanguage(Locale.US);
|
||||
locale = new Locale("en", "rUS");
|
||||
findViewById(R.id.img_english).setVisibility(View.VISIBLE);
|
||||
findViewById(R.id.img_traditional_chinese).setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.complete), new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||
@Override
|
||||
public void onViewClicks() {
|
||||
changeAllActivitysLanguage(locale);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -47,8 +69,12 @@ public class LanguageSettingActivity extends AbsActivity {
|
||||
private void changeAllActivitysLanguage(Locale locale) {
|
||||
Stack<Activity> allActivityStacks = AppManager.getInstance().getAllActivityStacks();
|
||||
for (int i = 0; i < allActivityStacks.size(); i++) {
|
||||
if (!(allActivityStacks.get(i) instanceof LanguageSettingActivity)) {
|
||||
LanguageUtil.shiftLanguage(locale, allActivityStacks.get(i), mContext);
|
||||
}
|
||||
|
||||
}
|
||||
IMLoginManager.get(mContext).setLanguage(locale != Locale.SIMPLIFIED_CHINESE);
|
||||
startActivity(new Intent(mContext, MainActivity.class));
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
@ -3,19 +3,21 @@ package com.yunbao.main.adapter;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.os.Build;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.yunbao.common.bean.LiveClassBean;
|
||||
import com.yunbao.common.interfaces.OnItemClickListener;
|
||||
import com.yunbao.main.R;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class MainHomeLivesClassAdapter extends RecyclerView.Adapter<MainHomeLivesClassAdapter.Vh> {
|
||||
|
||||
@ -71,6 +73,7 @@ public class MainHomeLivesClassAdapter extends RecyclerView.Adapter<MainHomeLive
|
||||
|
||||
class Vh extends RecyclerView.ViewHolder {
|
||||
TextView mName;
|
||||
|
||||
public Vh(View itemView) {
|
||||
super(itemView);
|
||||
mName = (TextView) itemView.findViewById(R.id.tv_class_name);
|
||||
@ -80,7 +83,18 @@ public class MainHomeLivesClassAdapter extends RecyclerView.Adapter<MainHomeLive
|
||||
@SuppressLint("NewApi")
|
||||
void setData(LiveClassBean bean, int position) {
|
||||
itemView.setTag(position);
|
||||
mName.setText(bean.getName());
|
||||
Locale locale;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
locale = mContext.getResources().getConfiguration().getLocales().get(0);
|
||||
} else {
|
||||
locale = mContext.getResources().getConfiguration().locale;
|
||||
}
|
||||
if (locale.getLanguage().equals("zh")) {
|
||||
mName.setText(bean.getChinese());
|
||||
} else {
|
||||
mName.setText(bean.getEnglish());
|
||||
}
|
||||
|
||||
if (position == choice) {
|
||||
mName.setBackgroundResource(R.drawable.button_ffc621);
|
||||
mName.setTextColor(Color.parseColor("#FFC621"));
|
||||
|
@ -7,8 +7,6 @@ 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;
|
||||
|
||||
@ -42,9 +40,8 @@ public class LanguageUtil {
|
||||
DisplayMetrics dm = resources.getDisplayMetrics();
|
||||
config.locale = locale;
|
||||
resources.updateConfiguration(config, dm);
|
||||
if (!(activity instanceof MainActivity)) {
|
||||
activity.recreate();
|
||||
}
|
||||
activity.finish();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,7 @@ package com.yunbao.main.views;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Outline;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@ -14,7 +11,6 @@ import android.view.ViewGroup;
|
||||
import android.view.ViewOutlineProvider;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@ -29,7 +25,6 @@ import com.yunbao.common.activity.WebViewActivity;
|
||||
import com.yunbao.common.adapter.RefreshAdapter;
|
||||
import com.yunbao.common.bean.AnchorRecommendModel;
|
||||
import com.yunbao.common.bean.BannerBean;
|
||||
import com.yunbao.common.bean.ConfigBean;
|
||||
import com.yunbao.common.bean.LiveBean;
|
||||
import com.yunbao.common.bean.LiveClassBean;
|
||||
import com.yunbao.common.bean.WeekListBean;
|
||||
@ -37,10 +32,10 @@ import com.yunbao.common.custom.CommonRefreshView;
|
||||
import com.yunbao.common.custom.ItemDecoration;
|
||||
import com.yunbao.common.http.HttpCallback;
|
||||
import com.yunbao.common.interfaces.OnItemClickListener;
|
||||
import com.yunbao.common.manager.LiveClassManager;
|
||||
import com.yunbao.common.utils.DialogUitl;
|
||||
import com.yunbao.common.utils.MicStatusManager;
|
||||
import com.yunbao.common.utils.RouteUtil;
|
||||
import com.yunbao.common.utils.ShareUtil;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.common.views.CustomViewHolder;
|
||||
import com.yunbao.live.event.LiveRoomChangeEvent;
|
||||
@ -59,7 +54,6 @@ import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -272,9 +266,7 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement
|
||||
mClassRecyclerViewTop = (RecyclerView) findViewById(R.id.classRecyclerView_top);
|
||||
mClassRecyclerViewTop.setHasFixedSize(true);
|
||||
mClassRecyclerViewTop.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
|
||||
ConfigBean configBean = CommonAppConfig.getInstance().getConfig();
|
||||
if (configBean != null) {
|
||||
List<LiveClassBean> list = configBean.getLiveClass();
|
||||
List<LiveClassBean> list = new LiveClassManager(mContext).getLiveClass();
|
||||
if (list != null && list.size() > 0) {
|
||||
List<LiveClassBean> targetList = new ArrayList<>();
|
||||
if (list.size() <= 6) {
|
||||
@ -304,7 +296,6 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement
|
||||
mClassRecyclerViewTop.setAdapter(topAdapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
View headView = mAdapter.getHeadView();
|
||||
mBanner = (Banner) headView.findViewById(R.id.banner);
|
||||
mRefreshView.initData();
|
||||
|
@ -93,9 +93,9 @@ public class MainHomeViewHolder extends AbsMainHomeParentViewHolder {
|
||||
@Override
|
||||
protected String[] getTitles() {
|
||||
return new String[]{
|
||||
WordUtil.getString(R.string.follow),
|
||||
WordUtil.getString(R.string.hot),
|
||||
WordUtil.getString(R.string.recomment),
|
||||
mContext.getString(R.string.follow),
|
||||
mContext.getString(R.string.hot),
|
||||
mContext.getString(R.string.recomment),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/complete"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
|
@ -161,7 +161,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:visibility="gone"
|
||||
android:visibility="visible"
|
||||
android:paddingTop="15dp"
|
||||
android:paddingBottom="25dp">
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user