2022-09-15 22:51:46 +08:00
|
|
|
|
package com.mango.moshen.base;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
|
2022-09-15 22:51:46 +08:00
|
|
|
|
import static com.mango.core.Constants.DEBUG_MAX_UID;
|
|
|
|
|
import static com.mango.core.im.custom.bean.CustomAttachment.CUSTOM_MESS_HEAD_NOBLE;
|
|
|
|
|
import static com.mango.core.im.custom.bean.CustomAttachment.CUSTOM_MESS_SUB_OPENNOBLE;
|
|
|
|
|
import static com.mango.core.im.custom.bean.CustomAttachment.CUSTOM_MESS_SUB_RENEWNOBLE;
|
2023-02-28 22:21:58 +08:00
|
|
|
|
import static com.mango.core.im.custom.bean.CustomAttachment.CUSTOM_MSG_ALL_SERVICE_GIFT;
|
2022-11-26 19:51:06 +08:00
|
|
|
|
import static com.mango.core.im.custom.bean.CustomAttachment.CUSTOM_MSG_HEADER_TYPE_GIFT;
|
2022-09-15 22:51:46 +08:00
|
|
|
|
import static com.mango.core.im.custom.bean.CustomAttachment.CUSTOM_MSG_RED_PACKAGE;
|
|
|
|
|
import static com.mango.core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ALL_DIAMOND;
|
|
|
|
|
import static com.mango.core.im.custom.bean.CustomAttachment.CUSTOM_MSG_VIP;
|
|
|
|
|
import static com.mango.core.im.custom.bean.CustomAttachment.CUSTOM_MSG_VIP_USER_ALL_UPGRADE;
|
|
|
|
|
import static com.mango.xchat_android_library.utils.UIUtils.getActivityByContext;
|
2021-12-30 15:23:43 +08:00
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
import android.annotation.SuppressLint;
|
2021-03-25 17:53:50 +08:00
|
|
|
|
import android.app.ActivityManager;
|
2023-02-28 22:21:58 +08:00
|
|
|
|
import android.app.Dialog;
|
2021-03-25 17:53:50 +08:00
|
|
|
|
import android.content.ComponentName;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.graphics.Typeface;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.text.Spannable;
|
|
|
|
|
import android.text.SpannableString;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.text.style.StyleSpan;
|
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
|
import android.view.Menu;
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.Window;
|
|
|
|
|
import android.view.WindowManager;
|
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
2021-03-25 17:53:50 +08:00
|
|
|
|
import androidx.annotation.ColorInt;
|
2020-05-13 19:08:14 +08:00
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
2020-07-07 18:47:11 +08:00
|
|
|
|
import com.google.gson.Gson;
|
2022-11-26 19:51:06 +08:00
|
|
|
|
import com.mango.core.noble.AllServiceGiftProtocol;
|
2023-02-28 22:21:58 +08:00
|
|
|
|
import com.mango.moshen.ui.widget.dialog.AllServiceGiftDialog;
|
|
|
|
|
import com.mango.moshen.ui.widget.dialog.AllServiceGiftLevelOneDialog;
|
|
|
|
|
import com.mango.moshen.ui.widget.dialog.AllServiceGiftLevelThreeDialog;
|
|
|
|
|
import com.mango.moshen.ui.widget.dialog.AllServiceGiftLevelTwoDialog;
|
|
|
|
|
import com.mango.xchat_android_library.utils.JavaUtil;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
import com.netease.nim.uikit.common.util.log.LogUtil;
|
|
|
|
|
import com.netease.nimlib.sdk.NIMSDK;
|
|
|
|
|
import com.netease.nimlib.sdk.Observer;
|
|
|
|
|
import com.netease.nimlib.sdk.msg.model.BroadcastMessage;
|
|
|
|
|
import com.orhanobut.logger.Logger;
|
|
|
|
|
import com.readystatesoftware.systembartint.SystemBarTintManager;
|
|
|
|
|
import com.tbruyelle.rxpermissions2.RxPermissions;
|
2020-05-12 12:31:13 +08:00
|
|
|
|
import com.trello.rxlifecycle3.android.ActivityEvent;
|
|
|
|
|
import com.trello.rxlifecycle3.components.support.RxAppCompatActivity;
|
2022-09-15 22:51:46 +08:00
|
|
|
|
import com.mango.moshen.MiddleActivity;
|
|
|
|
|
import com.mango.moshen.NimMiddleActivity;
|
|
|
|
|
import com.mango.moshen.R;
|
|
|
|
|
import com.mango.moshen.application.XChatApplication;
|
|
|
|
|
import com.mango.moshen.avroom.activity.AVRoomActivity;
|
|
|
|
|
import com.mango.moshen.avroom.firstcharge.FirstChargeDialog;
|
|
|
|
|
import com.mango.moshen.avroom.redpackage.RedPackageGoRoomDialog;
|
|
|
|
|
import com.mango.moshen.avroom.redpackage.RedPackageOpenDialog;
|
|
|
|
|
import com.mango.moshen.common.LoadingFragment;
|
|
|
|
|
import com.mango.moshen.common.NetworkErrorFragment;
|
|
|
|
|
import com.mango.moshen.common.NoDataFragment;
|
|
|
|
|
import com.mango.moshen.common.ReloadFragment;
|
|
|
|
|
import com.mango.moshen.common.permission.PermissionActivity;
|
|
|
|
|
import com.mango.moshen.common.widget.StatusLayout;
|
|
|
|
|
import com.mango.moshen.common.widget.dialog.DialogManager;
|
|
|
|
|
import com.mango.moshen.common.widget.dialog.DialogUiHelper;
|
|
|
|
|
import com.mango.moshen.ui.im.avtivity.NimP2PMessageActivity;
|
|
|
|
|
import com.mango.moshen.ui.login.AddUserInfoActivity;
|
|
|
|
|
import com.mango.moshen.ui.login.LoginCodeActivity;
|
|
|
|
|
import com.mango.moshen.ui.login.LoginPhoneActivity;
|
|
|
|
|
import com.mango.moshen.ui.pay.ChargeActivity;
|
|
|
|
|
import com.mango.moshen.ui.setting.ResetPasswordActivity;
|
|
|
|
|
import com.mango.moshen.ui.widget.DefaultToolBar;
|
|
|
|
|
import com.mango.moshen.ui.widget.dialog.AllServiceVipLevelUPDialog;
|
|
|
|
|
import com.mango.moshen.ui.widget.dialog.OpenNobleGlobalNoticeDialog;
|
|
|
|
|
import com.mango.moshen.utils.UserUtils;
|
|
|
|
|
import com.mango.moshen.mentoring_relationship.dialog.GrabApprenticesNoticeDialog;
|
|
|
|
|
import com.mango.xchat_android_constants.XChatConstants;
|
|
|
|
|
import com.mango.core.bean.BaseProtocol;
|
|
|
|
|
import com.mango.core.manager.AvRoomDataManager;
|
|
|
|
|
import com.mango.core.manager.IMNetEaseManager;
|
|
|
|
|
import com.mango.core.manager.RoomEvent;
|
|
|
|
|
import com.mango.core.mentoring_relationship.event.GrabApprenticesEvent;
|
|
|
|
|
import com.mango.core.newbie.NewbieHelloInfo;
|
|
|
|
|
import com.mango.core.newbie.event.NewbieHelloDialogEvent;
|
|
|
|
|
import com.mango.core.noble.NobleInfo;
|
|
|
|
|
import com.mango.core.noble.NobleProtocol;
|
|
|
|
|
import com.mango.core.redpackage.RedPackageNotifyInfo;
|
|
|
|
|
import com.mango.core.room.bean.RoomInfo;
|
|
|
|
|
import com.mango.core.room.model.AvRoomModel;
|
|
|
|
|
import com.mango.core.statistic.StatisticManager;
|
|
|
|
|
import com.mango.core.statistic.protocol.StatisticsProtocol;
|
|
|
|
|
import com.mango.core.user.UserModel;
|
|
|
|
|
import com.mango.core.utils.net.RxHelper;
|
|
|
|
|
import com.mango.core.vip.VipMessageInfo;
|
|
|
|
|
import com.mango.xchat_android_library.rxbus.RxBus;
|
|
|
|
|
import com.mango.xchat_android_library.utils.NetworkUtils;
|
|
|
|
|
import com.mango.xchat_android_library.utils.SingleToastUtil;
|
|
|
|
|
import com.mango.xchat_android_library.utils.UIUtils;
|
|
|
|
|
import com.mango.xchat_android_library.utils.codec.DESUtils;
|
|
|
|
|
import com.mango.xchat_android_library.utils.config.BasicConfig;
|
|
|
|
|
import com.mango.xchat_android_library.utils.log.MLog;
|
2022-12-27 10:47:21 +08:00
|
|
|
|
import com.mango.moshen.ui.widget.dialog.AllServiceGiftLevelCeremonyDialog;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
|
2021-03-25 17:53:50 +08:00
|
|
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
|
|
|
import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
import java.lang.ref.WeakReference;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.util.ArrayList;
|
2023-02-28 22:21:58 +08:00
|
|
|
|
import java.util.LinkedList;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import io.reactivex.Observable;
|
|
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
|
|
import io.reactivex.disposables.CompositeDisposable;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author alvin hwang
|
|
|
|
|
*/
|
|
|
|
|
public abstract class BaseActivity extends RxAppCompatActivity
|
2022-05-09 11:37:05 +08:00
|
|
|
|
implements IDataStatus, DialogManagerInterface {
|
2020-04-02 10:43:40 +08:00
|
|
|
|
|
2021-12-15 16:26:40 +08:00
|
|
|
|
/**
|
|
|
|
|
* --------------------------------------------------
|
|
|
|
|
* -------------------------数据状态状态相关-------------
|
|
|
|
|
* --------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
protected static final String STATUS_TAG = "STATUS_TAG";
|
|
|
|
|
private final RxPermissions rxPermissions = new RxPermissions(this);
|
2020-04-02 10:43:40 +08:00
|
|
|
|
protected TitleBar mTitleBar;
|
|
|
|
|
protected DefaultToolBar mToolBar;
|
|
|
|
|
protected CompositeDisposable mCompositeDisposable;
|
|
|
|
|
protected Context context;
|
2021-12-15 16:26:40 +08:00
|
|
|
|
protected volatile GrabApprenticesNoticeDialog dialog;
|
|
|
|
|
private DialogManager mDialogManager;
|
|
|
|
|
private BroadcastObserver broadcastObserver;
|
|
|
|
|
private OpenNobleGlobalNoticeDialog mNoticeDialog;
|
|
|
|
|
private boolean isShowingChargeDialog;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
|
2023-02-28 22:21:58 +08:00
|
|
|
|
private Dialog giftDialog;
|
|
|
|
|
private LinkedList<AllServiceGiftProtocol.DataBean> giftList;
|
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
context = this;
|
|
|
|
|
mCompositeDisposable = new CompositeDisposable();
|
|
|
|
|
if (needSteepStateBar()) {
|
|
|
|
|
setStatusBar();
|
|
|
|
|
}
|
2021-03-25 17:53:50 +08:00
|
|
|
|
mCompositeDisposable.add(IMNetEaseManager.get().getChatRoomEventObservable()
|
|
|
|
|
.subscribe(roomEvent -> {
|
|
|
|
|
if (roomEvent == null) return;
|
|
|
|
|
onReceiveChatRoomEvent(roomEvent);
|
|
|
|
|
}));
|
|
|
|
|
registerNimBroadcastMessage(true);
|
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-25 17:53:50 +08:00
|
|
|
|
protected void onReceiveChatRoomEvent(RoomEvent roomEvent) {
|
|
|
|
|
}
|
2020-04-02 10:43:40 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 注册云信全服广播接收器
|
|
|
|
|
*
|
|
|
|
|
* @param register true为注册,false为注销
|
|
|
|
|
*/
|
|
|
|
|
protected void registerNimBroadcastMessage(boolean register) {
|
|
|
|
|
if (broadcastObserver == null) {
|
|
|
|
|
broadcastObserver = new BroadcastObserver(this);
|
|
|
|
|
}
|
|
|
|
|
NIMSDK.getMsgServiceObserve().observeBroadcastMessage(broadcastObserver, register);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 当前Activity 是否有效
|
|
|
|
|
*/
|
|
|
|
|
protected boolean isValid() {
|
|
|
|
|
return !isFinishing() && !isDestroyed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initToolBar(int resId) {
|
|
|
|
|
initToolBar(getString(resId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initToolBar(CharSequence title) {
|
2021-03-25 17:53:50 +08:00
|
|
|
|
mToolBar = findViewById(R.id.toolbar);
|
2020-04-02 10:43:40 +08:00
|
|
|
|
if (mToolBar != null) {
|
|
|
|
|
mToolBar.setCenterTitle(title);
|
|
|
|
|
mToolBar.setNavigationIcon(R.drawable.arrow_left);
|
2021-03-25 17:53:50 +08:00
|
|
|
|
mToolBar.setNavigationOnClickListener(v -> onLeftClickListener());
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initTitleBar() {
|
2020-04-11 11:24:14 +08:00
|
|
|
|
mTitleBar = findViewById(R.id.title_bar);
|
2020-04-02 10:43:40 +08:00
|
|
|
|
if (mTitleBar != null) {
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && needSteepStateBar()) {
|
2020-04-22 12:00:54 +08:00
|
|
|
|
mTitleBar.setImmersive(false);
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|
|
|
|
|
mTitleBar.setBackgroundColor(getResources().getColor(R.color.white));
|
|
|
|
|
mTitleBar.setTitleColor(getResources().getColor(R.color.text_primary));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initTitleBar(int title) {
|
|
|
|
|
initTitleBar(getResources().getString(title));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initTitleBar(String title) {
|
2021-03-25 17:53:50 +08:00
|
|
|
|
mTitleBar = findViewById(R.id.title_bar);
|
|
|
|
|
if (mTitleBar != null) {
|
|
|
|
|
mTitleBar.setTitle(title);
|
|
|
|
|
mTitleBar.setImmersive(false);
|
|
|
|
|
mTitleBar.setTitleColor(getResources().getColor(R.color.back_font));
|
|
|
|
|
mTitleBar.setLeftImageResource(R.drawable.arrow_left);
|
|
|
|
|
mTitleBar.setCommonBackgroundColor(getResources().getColor(R.color.transparent));
|
|
|
|
|
mTitleBar.setLeftClickListener(v -> onLeftClickListener());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initWhiteTitleBar(String title) {
|
2020-04-22 12:00:54 +08:00
|
|
|
|
mTitleBar = findViewById(R.id.title_bar);
|
2020-04-02 10:43:40 +08:00
|
|
|
|
if (mTitleBar != null) {
|
|
|
|
|
mTitleBar.setTitle(title);
|
|
|
|
|
mTitleBar.setImmersive(false);
|
2021-12-02 19:01:15 +08:00
|
|
|
|
mTitleBar.setTitleColor(getResources().getColor(R.color.text_title_white));
|
|
|
|
|
mTitleBar.setLeftImageResource(R.drawable.arrow_left);
|
2020-04-09 21:29:09 +08:00
|
|
|
|
mTitleBar.setCommonBackgroundColor(getResources().getColor(R.color.transparent));
|
2021-03-25 17:53:50 +08:00
|
|
|
|
mTitleBar.setLeftClickListener(v -> onLeftClickListener());
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-25 17:53:50 +08:00
|
|
|
|
public void initTitleBar(String title, TitleBar.Action action) {
|
2020-04-22 12:00:54 +08:00
|
|
|
|
mTitleBar = findViewById(R.id.title_bar);
|
2020-04-02 10:43:40 +08:00
|
|
|
|
if (mTitleBar != null) {
|
|
|
|
|
mTitleBar.setTitle(title);
|
|
|
|
|
mTitleBar.setImmersive(false);
|
2021-03-25 17:53:50 +08:00
|
|
|
|
mTitleBar.setTitleColor(getResources().getColor(R.color.back_font));
|
|
|
|
|
mTitleBar.setLeftImageResource(R.drawable.arrow_left);
|
|
|
|
|
mTitleBar.setLeftClickListener(v -> onLeftClickListener());
|
|
|
|
|
// action
|
|
|
|
|
if (action != null) {
|
|
|
|
|
mTitleBar.addAction(action);
|
|
|
|
|
}
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void onLeftClickListener() {
|
|
|
|
|
finish();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected boolean needSteepStateBar() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置沉浸式状态栏
|
|
|
|
|
*/
|
|
|
|
|
protected void setStatusBar() {
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
|
|
|
//透明状态栏
|
|
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
|
|
|
|
//透明导航栏
|
|
|
|
|
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
|
|
|
|
|
}
|
|
|
|
|
// create our manager instance after the content view is set
|
|
|
|
|
SystemBarTintManager tintManager = new SystemBarTintManager(this);
|
|
|
|
|
// enable status bar tint
|
|
|
|
|
tintManager.setStatusBarTintEnabled(true);
|
|
|
|
|
// enable navigation bar tint
|
|
|
|
|
tintManager.setNavigationBarTintEnabled(true);
|
|
|
|
|
tintManager.setTintColor(Color.parseColor("#00000000"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通知栏白底黑字
|
|
|
|
|
*
|
|
|
|
|
* @param isDark true:黑色
|
|
|
|
|
*/
|
|
|
|
|
public void StatusBarLightModes(boolean isDark) {
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
|
getWindow().setStatusBarColor(getResources().getColor(R.color.white));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
|
if (isDark) {
|
|
|
|
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
|
|
|
|
} else {
|
|
|
|
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取状态栏的高度
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
protected int getStatusBarHeight() {
|
|
|
|
|
try {
|
|
|
|
|
Class<?> c = Class.forName("com.android.internal.R$dimen");
|
|
|
|
|
Object obj = c.newInstance();
|
|
|
|
|
Field field = c.getField("status_bar_height");
|
|
|
|
|
int x = Integer.parseInt(field.get(obj).toString());
|
|
|
|
|
return getResources().getDimensionPixelSize(x);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setContentView(int layoutResID) {
|
|
|
|
|
super.setContentView(layoutResID);
|
|
|
|
|
initTitleBar();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 是否需要渲染成主题色的status bar
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
protected boolean shouldConfigStatusBar() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onStart() {
|
|
|
|
|
super.onStart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onStop() {
|
|
|
|
|
super.onStop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
registerNimBroadcastMessage(false);
|
|
|
|
|
if (mCompositeDisposable != null) {
|
|
|
|
|
mCompositeDisposable.dispose();
|
|
|
|
|
mCompositeDisposable = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mNoticeDialog != null && mNoticeDialog.isShowing()) {
|
|
|
|
|
mNoticeDialog.dismiss();
|
|
|
|
|
mNoticeDialog = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
LogUtil.i(this.getClass().getName(), "onDestroy");
|
|
|
|
|
|
|
|
|
|
/* ImageLoadUtils.clearMemory(this);*/
|
|
|
|
|
|
|
|
|
|
}
|
2021-03-25 17:53:50 +08:00
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
@Override
|
|
|
|
|
public DialogManager getDialogManager() {
|
|
|
|
|
if (mDialogManager == null) {
|
|
|
|
|
mDialogManager = new DialogManager(this);
|
|
|
|
|
mDialogManager.setCanceledOnClickOutside(false);
|
|
|
|
|
}
|
|
|
|
|
return mDialogManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
|
Fragment fragment = getTopFragment();
|
|
|
|
|
if (fragment != null && fragment instanceof BaseFragment) {
|
|
|
|
|
if (((BaseFragment) fragment).onKeyDown(keyCode, event)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
|
Fragment fragment = getTopFragment();
|
|
|
|
|
if (fragment != null && fragment instanceof BaseFragment) {
|
|
|
|
|
fragment.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
}
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Fragment getTopFragment() {
|
|
|
|
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
|
|
|
|
List<Fragment> fragments = fragmentManager.getFragments();
|
|
|
|
|
if (fragments != null) {
|
|
|
|
|
for (Fragment fragment : fragments) {
|
|
|
|
|
if (fragment != null && fragment.isVisible()) {
|
|
|
|
|
return fragment;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBackPressed() {
|
|
|
|
|
hideIME();
|
|
|
|
|
try {
|
|
|
|
|
super.onBackPressed();
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
MLog.error(this, ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
case android.R.id.home:
|
|
|
|
|
Fragment fragment = getTopFragment();
|
|
|
|
|
if (fragment != null && fragment instanceof BaseFragment) {
|
|
|
|
|
if (fragment.onOptionsItemSelected(item)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onBackPressed();
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onMenuOpened(int featureId, Menu menu) {
|
|
|
|
|
if (featureId == Window.FEATURE_ACTION_BAR && menu != null) {
|
|
|
|
|
if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
|
|
|
|
|
try {
|
|
|
|
|
Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
|
|
|
|
|
m.setAccessible(true);
|
|
|
|
|
m.invoke(menu, true);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return super.onMenuOpened(featureId, menu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取backstack top
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Fragment getLastFragment() {
|
|
|
|
|
List<Fragment> fragments = getSupportFragmentManager().getFragments();
|
|
|
|
|
if (null != fragments && fragments.size() > 0) {
|
|
|
|
|
for (int i = fragments.size() - 1; i >= 0; i--) {
|
|
|
|
|
Fragment f = fragments.get(i);
|
|
|
|
|
if (f != null && f instanceof BaseFragment) {
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-15 16:26:40 +08:00
|
|
|
|
/**
|
|
|
|
|
* 网络连接变化
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* 网络连接变化
|
|
|
|
|
*/
|
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
/**
|
|
|
|
|
* @param fragmentName Fragment.class.getName()
|
|
|
|
|
*/
|
|
|
|
|
public void popFragment(String fragmentName) {
|
|
|
|
|
getSupportFragmentManager().popBackStack(fragmentName, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getTopFragmentName() {
|
|
|
|
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
|
|
|
|
if (fragmentManager.getBackStackEntryCount() > 0) {
|
|
|
|
|
return fragmentManager.getBackStackEntryAt(fragmentManager.getBackStackEntryCount() - 1).getName();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void updateBottomBar(boolean isShow) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressLint("CheckResult")
|
|
|
|
|
@Override
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
|
StatisticManager.Instance().onResume(this);
|
|
|
|
|
//GlideApp.with(this).resumeRequests();
|
|
|
|
|
RxBus.get().toFlowable(String.class)
|
|
|
|
|
.compose(bindUntilEvent(ActivityEvent.PAUSE))
|
|
|
|
|
.subscribe((s) -> {
|
|
|
|
|
if (XChatConstants.SHOW.equals(s)) {
|
|
|
|
|
getDialogManager().showProgressDialog(this, "请稍后...", true);
|
|
|
|
|
} else if (XChatConstants.HIDE.equals(s)) {
|
|
|
|
|
getDialogManager().dismissDialog();
|
|
|
|
|
}
|
|
|
|
|
}, throwable -> {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
RxBus.get()
|
|
|
|
|
.toFlowable(GrabApprenticesEvent.class)
|
|
|
|
|
.compose(bindUntilEvent(ActivityEvent.PAUSE))
|
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
.subscribe(this::onGrabApprenticesEvent);
|
|
|
|
|
|
|
|
|
|
IMNetEaseManager.get().getChatRoomEventObservable()
|
|
|
|
|
.compose(bindUntilEvent(ActivityEvent.PAUSE))
|
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
.subscribe(this::onRoomEventReceived);
|
|
|
|
|
|
2023-02-28 22:21:58 +08:00
|
|
|
|
if (giftList != null) {
|
|
|
|
|
giftList.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onPause() {
|
|
|
|
|
super.onPause();
|
|
|
|
|
//remove connective changed broadcast receiver
|
|
|
|
|
StatisticManager.Instance().onPause(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected boolean checkActivityValid() {
|
|
|
|
|
return UIUtils.checkActivityValid(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public View.OnClickListener getLoadListener() {
|
|
|
|
|
return new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
onReloadDate();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 网络错误重新加载数据
|
|
|
|
|
*/
|
|
|
|
|
public void onReloadDate() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public View.OnClickListener getLoadMoreListener() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public View.OnClickListener getNoMobileLiveDataListener() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void showLoading() {
|
|
|
|
|
showLoading(0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void showLoading(View view) {
|
|
|
|
|
showLoading(view, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-25 17:53:50 +08:00
|
|
|
|
public void showReload(@ColorInt int bgColor) {
|
|
|
|
|
showReload(0, bgColor);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
@Override
|
|
|
|
|
public void showReload() {
|
|
|
|
|
showReload(0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void showNoData() {
|
|
|
|
|
showNoData(0, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void showNoLogin() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressLint("ResourceType")
|
|
|
|
|
@Override
|
|
|
|
|
public void showLoading(int drawable, int tips) {
|
|
|
|
|
if (!checkActivityValid()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
View status = findViewById(R.id.status_layout);
|
|
|
|
|
if (status == null || status.getId() <= 0) {
|
|
|
|
|
MLog.error(this, "xuwakao, had not set layout id ");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Fragment fragment = LoadingFragment.newInstance(drawable, tips);
|
|
|
|
|
getSupportFragmentManager().beginTransaction().replace(status.getId(), fragment, STATUS_TAG).commitAllowingStateLoss();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void showLoading(View view, int drawable, int tips) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressLint("ResourceType")
|
|
|
|
|
@Override
|
|
|
|
|
public void showReload(int drawable, int tips) {
|
|
|
|
|
if (!checkActivityValid()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
View status = findViewById(R.id.status_layout);
|
|
|
|
|
if (status == null || status.getId() <= 0) {
|
|
|
|
|
MLog.error(this, "xuwakao, had not set layout id ");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ReloadFragment fragment = ReloadFragment.newInstance(drawable, tips);
|
|
|
|
|
fragment.setListener(getLoadListener());
|
|
|
|
|
getSupportFragmentManager().beginTransaction().replace(status.getId(), fragment, STATUS_TAG).commitAllowingStateLoss();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void showReload(View view, int drawable, int tips) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void showNoData(CharSequence charSequence) {
|
|
|
|
|
showNoData(0, charSequence);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressLint("ResourceType")
|
|
|
|
|
@Override
|
|
|
|
|
public void showNoData(int drawable, CharSequence charSequence) {
|
|
|
|
|
if (!checkActivityValid()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
View status = findViewById(R.id.status_layout);
|
|
|
|
|
if (status == null || status.getId() <= 0) {
|
|
|
|
|
MLog.error(this, "xuwakao, had not set layout id ");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
NoDataFragment fragment = NoDataFragment.newInstance(drawable, charSequence);
|
|
|
|
|
fragment.setListener(getLoadListener());
|
|
|
|
|
getSupportFragmentManager().beginTransaction().replace(status.getId(), fragment, STATUS_TAG).commitAllowingStateLoss();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void showNoData(View view, int drawable, CharSequence charSequence) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressLint("ResourceType")
|
|
|
|
|
@Override
|
|
|
|
|
public void showNetworkErr() {
|
|
|
|
|
if (!checkActivityValid()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
View status = findViewById(R.id.status_layout);
|
|
|
|
|
if (status == null || status.getId() <= 0) {
|
|
|
|
|
MLog.error(this, "xuwakao, had not set layout id ");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
NetworkErrorFragment fragment = new NetworkErrorFragment();
|
|
|
|
|
fragment.setListener(getLoadListener());
|
|
|
|
|
getSupportFragmentManager().beginTransaction().replace(status.getId(), fragment, STATUS_TAG).commitAllowingStateLoss();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void hideStatus() {
|
|
|
|
|
Fragment fragment = getSupportFragmentManager().findFragmentByTag(STATUS_TAG);
|
|
|
|
|
if (fragment != null) {
|
|
|
|
|
getSupportFragmentManager().beginTransaction().remove(fragment).commitAllowingStateLoss();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void showPageError(int tips) {
|
|
|
|
|
if (!checkActivityValid()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
View more = findViewById(R.id.loading_more);
|
|
|
|
|
if (more == null) {
|
|
|
|
|
MLog.error(this, "xuwakao, showReload more is NULL");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
StatusLayout statusLayout = (StatusLayout) more.getParent();
|
|
|
|
|
statusLayout.showErrorPage(tips, getLoadMoreListener());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void showPageError(View view, int tips) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void showPageLoading() {
|
|
|
|
|
if (!checkActivityValid()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
View more = findViewById(R.id.loading_more);
|
|
|
|
|
if (more == null) {
|
|
|
|
|
MLog.error(this, "xuwakao, showReload more is NULL");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
StatusLayout statusLayout = (StatusLayout) more.getParent();
|
|
|
|
|
statusLayout.showLoadMore();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 当前网络是否可用
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public boolean isNetworkAvailable() {
|
|
|
|
|
return NetworkUtils.isNetworkStrictlyAvailable(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean checkNetToast() {
|
|
|
|
|
boolean flag = isNetworkAvailable();
|
|
|
|
|
if (!flag) {
|
|
|
|
|
SingleToastUtil.showToast(BasicConfig.INSTANCE.getAppContext(), R.string.str_network_not_capable);
|
|
|
|
|
}
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* --------------------------------------------------
|
|
|
|
|
* -------------------------UI基本功能------------------
|
|
|
|
|
* --------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
public void hideIME() {
|
|
|
|
|
View v = getCurrentFocus();
|
|
|
|
|
if (null != v)
|
|
|
|
|
hideIME(v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void hideIME(View v) {
|
|
|
|
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void showIME(final View vv) {
|
|
|
|
|
View v = vv;
|
|
|
|
|
if (null == v) {
|
|
|
|
|
v = getCurrentFocus();
|
|
|
|
|
if (null == v)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
|
|
|
|
|
.showSoftInput(v, InputMethodManager.SHOW_FORCED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 当前无Fragment 或 无Fragment添加 视为顶部激活状态
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public boolean isTopActive() {
|
|
|
|
|
|
|
|
|
|
if (isTopActivity()) {
|
|
|
|
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
|
|
|
|
|
|
|
|
|
List<Fragment> fragments = fragmentManager.getFragments();
|
|
|
|
|
if (fragments == null || fragments.size() == 0) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
int size = fragments.size();
|
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
|
//TODO why null?
|
|
|
|
|
if (fragments.get(i) != null && fragments.get(i).isAdded())
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isTopActivity() {
|
|
|
|
|
return UIUtils.isTopActivity(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通用消息提示
|
|
|
|
|
*
|
|
|
|
|
* @param resId
|
|
|
|
|
*/
|
|
|
|
|
public void toast(int resId) {
|
|
|
|
|
toast(resId, Toast.LENGTH_SHORT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void toast(String toast) {
|
|
|
|
|
toast(toast, Toast.LENGTH_SHORT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通用消息提示
|
|
|
|
|
*
|
|
|
|
|
* @param resId
|
|
|
|
|
* @param length
|
|
|
|
|
*/
|
|
|
|
|
public void toast(int resId, int length) {
|
2021-11-16 15:00:41 +08:00
|
|
|
|
SingleToastUtil.showToast(resId);
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void toast(String toast, int length) {
|
2021-11-16 15:00:41 +08:00
|
|
|
|
SingleToastUtil.showToast(toast);
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressLint("CheckResult")
|
|
|
|
|
public void checkPermission(PermissionActivity.CheckPermListener listener, int resString, String... mPerms) {
|
2020-07-27 18:00:04 +08:00
|
|
|
|
/**
|
|
|
|
|
* 权限回调接口
|
|
|
|
|
*/
|
2020-04-02 10:43:40 +08:00
|
|
|
|
rxPermissions.request(mPerms)
|
|
|
|
|
.subscribe(aBoolean -> {
|
|
|
|
|
if (aBoolean && listener != null) {
|
|
|
|
|
listener.superPermission();
|
|
|
|
|
}
|
|
|
|
|
}, Throwable::printStackTrace);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressLint("CheckResult")
|
|
|
|
|
public Observable<Boolean> checkPermission(String... mPerms) {
|
|
|
|
|
return rxPermissions.request(mPerms);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 接收到全局广播信息
|
|
|
|
|
*
|
|
|
|
|
* @param body 信息实体
|
|
|
|
|
*/
|
|
|
|
|
protected void onReceivedNimBroadcastMessage(String body) {
|
|
|
|
|
if (!isNeedToHandleBroadcastMessageActivity()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
BaseProtocol baseProtocol;
|
|
|
|
|
try {
|
|
|
|
|
baseProtocol = JSON.parseObject(body, BaseProtocol.class);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
baseProtocol = null;
|
|
|
|
|
}
|
|
|
|
|
if (baseProtocol == null) return;
|
|
|
|
|
|
2020-08-12 10:46:23 +08:00
|
|
|
|
int second = baseProtocol.getSecond();
|
2020-04-02 10:43:40 +08:00
|
|
|
|
switch (baseProtocol.getFirst()) {
|
|
|
|
|
case CUSTOM_MESS_HEAD_NOBLE:
|
|
|
|
|
if (second == CUSTOM_MESS_SUB_OPENNOBLE || second == CUSTOM_MESS_SUB_RENEWNOBLE) {
|
|
|
|
|
NobleProtocol.DataBean data = JSON.parseObject(String.valueOf(baseProtocol.getData()), NobleProtocol.DataBean.class);
|
|
|
|
|
NobleInfo nobleInfo;
|
|
|
|
|
if (data == null || (nobleInfo = data.getNobleInfo()) == null || (data.getUid() < DEBUG_MAX_UID && !XChatApplication.isDebug()))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int type = data.getType();
|
|
|
|
|
String nick = data.getNick();
|
|
|
|
|
String content = null;
|
|
|
|
|
String noticeBefore = getString(R.string.global_notice_before);
|
|
|
|
|
if (type == 1) {
|
|
|
|
|
//恭喜 xxxx 开通“国王”贵族,速来膜拜
|
|
|
|
|
if (TextUtils.isEmpty(data.getRoomTitle())) {
|
|
|
|
|
content = noticeBefore + getString(R.string.noble_open_notice, nick, nobleInfo.getName());
|
|
|
|
|
} else {
|
|
|
|
|
content = noticeBefore + getString(R.string.noble_open_in_room_notice, nick, nobleInfo.getName(),
|
|
|
|
|
String.valueOf(data.getRoomErbanNo()), data.getRoomTitle());
|
|
|
|
|
}
|
|
|
|
|
} else if (type == 2) {
|
|
|
|
|
//恭喜 xxxx 续费“国王”贵族
|
|
|
|
|
content = noticeBefore + getString(R.string.noble_reopen_notice, nick, nobleInfo.getName());
|
|
|
|
|
}
|
|
|
|
|
if (!TextUtils.isEmpty(content)) {
|
|
|
|
|
|
|
|
|
|
String nobleName = nobleInfo.getName();
|
|
|
|
|
Spannable spannable = new SpannableString(content);
|
|
|
|
|
|
|
|
|
|
spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, noticeBefore.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
|
|
|
|
|
|
int start = content.lastIndexOf(nick);
|
|
|
|
|
int end = start + nick.length();
|
|
|
|
|
spannable.setSpan(new StyleSpan(Typeface.BOLD), start - 1, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
|
start = content.lastIndexOf(nobleName);
|
|
|
|
|
end = start + nobleName.length();
|
|
|
|
|
spannable.setSpan(new StyleSpan(Typeface.BOLD), start - 1, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
|
if (!isFinishing()) {
|
|
|
|
|
if (mNoticeDialog != null && mNoticeDialog.isShowing())
|
|
|
|
|
mNoticeDialog.dismiss();
|
|
|
|
|
mNoticeDialog = new OpenNobleGlobalNoticeDialog(this, spannable);
|
|
|
|
|
mNoticeDialog.show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2020-07-07 18:47:11 +08:00
|
|
|
|
case CUSTOM_MSG_RED_PACKAGE:
|
2020-07-23 14:04:44 +08:00
|
|
|
|
if (baseProtocol.getSecond() == CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ALL_DIAMOND) {
|
2021-12-15 16:26:40 +08:00
|
|
|
|
if (this instanceof AddUserInfoActivity ||
|
|
|
|
|
UserUtils.getUserInfo() == null ||
|
|
|
|
|
AvRoomDataManager.get().isSelfGamePlaying())
|
2020-07-23 14:04:44 +08:00
|
|
|
|
return;
|
|
|
|
|
RedPackageNotifyInfo notifyInfo = new Gson().fromJson(String.valueOf(baseProtocol.getData()), RedPackageNotifyInfo.class);
|
|
|
|
|
RoomInfo roomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
|
|
|
|
if (roomInfo != null && roomInfo.getUid() == notifyInfo.getRoomUid() && context instanceof AVRoomActivity) {
|
|
|
|
|
RedPackageOpenDialog.Companion.newInstance(notifyInfo).show(this);
|
|
|
|
|
} else {
|
|
|
|
|
RedPackageGoRoomDialog.Companion.newInstance(notifyInfo).show(this);
|
|
|
|
|
}
|
2020-07-07 18:47:11 +08:00
|
|
|
|
}
|
2022-01-10 14:55:24 +08:00
|
|
|
|
case CUSTOM_MSG_VIP:
|
|
|
|
|
if (baseProtocol.getSecond() == CUSTOM_MSG_VIP_USER_ALL_UPGRADE) {
|
|
|
|
|
VipMessageInfo vipMessageInfo = new Gson().fromJson(String.valueOf(baseProtocol.getData()), VipMessageInfo.class);
|
2022-01-11 16:44:34 +08:00
|
|
|
|
if (vipMessageInfo != null && !TextUtils.isEmpty(vipMessageInfo.getFloatPic())) {
|
2022-01-10 14:55:24 +08:00
|
|
|
|
new AllServiceVipLevelUPDialog(context, vipMessageInfo).show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2022-11-26 19:51:06 +08:00
|
|
|
|
case CUSTOM_MSG_HEADER_TYPE_GIFT:
|
|
|
|
|
if (!isValid()) return;
|
|
|
|
|
if (this instanceof AddUserInfoActivity ||
|
|
|
|
|
UserUtils.getUserInfo() == null)
|
|
|
|
|
return;
|
|
|
|
|
AllServiceGiftProtocol.DataBean data = JSON.parseObject(String.valueOf(baseProtocol.getData()), AllServiceGiftProtocol.DataBean.class);
|
2023-02-28 22:21:58 +08:00
|
|
|
|
if (data == null || data.getGiftUrl() == null) return;
|
|
|
|
|
if (data.isCeremonyGift()) {
|
|
|
|
|
new AllServiceGiftLevelCeremonyDialog(context, data).show();
|
|
|
|
|
} else {
|
|
|
|
|
if (!isValid()) return;
|
|
|
|
|
if (giftList == null) {
|
|
|
|
|
giftList = new LinkedList<>();
|
|
|
|
|
}
|
|
|
|
|
int second2 = baseProtocol.getSecond();
|
|
|
|
|
giftList.add(data);
|
|
|
|
|
if (second2 == CUSTOM_MSG_ALL_SERVICE_GIFT) {
|
|
|
|
|
if (giftDialog != null && giftDialog.isShowing()) {
|
|
|
|
|
// 如果当前以及有礼物弹窗在展示,则需要等到他 dismiss 后再显示下一个
|
|
|
|
|
AllServiceGiftProtocol.DataBean dataBean = giftList.peekFirst();
|
|
|
|
|
if (dataBean != null) {
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
giftDialog.dismiss();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
showGiftDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-11-26 19:51:06 +08:00
|
|
|
|
break;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-28 22:21:58 +08:00
|
|
|
|
private void showGiftDialog() {
|
|
|
|
|
if (giftList.size() == 0) return;
|
|
|
|
|
giftDialog = generateAllServiceGiftDialog(this, giftList.peekFirst());
|
|
|
|
|
giftDialog.setOnDismissListener(dialog -> {
|
|
|
|
|
giftList.pollFirst();
|
|
|
|
|
AllServiceGiftProtocol.DataBean dataBean = giftList.peekFirst();
|
|
|
|
|
if (dataBean != null) {
|
|
|
|
|
if (isValid()) {
|
|
|
|
|
showGiftDialog();
|
|
|
|
|
} else {
|
|
|
|
|
giftList.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
try {
|
|
|
|
|
giftDialog.show();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AllServiceGiftDialog generateAllServiceGiftDialog(Context context, AllServiceGiftProtocol.DataBean dataBean) {
|
|
|
|
|
switch (JavaUtil.str2int(dataBean.getLevelNum())) {
|
|
|
|
|
default:
|
|
|
|
|
case AllServiceGiftDialog.ALL_SERVICE_GIFT_LEVEL_1:
|
|
|
|
|
return new AllServiceGiftLevelOneDialog(context, dataBean);
|
|
|
|
|
|
|
|
|
|
case AllServiceGiftDialog.ALL_SERVICE_GIFT_LEVEL_2:
|
|
|
|
|
|
|
|
|
|
return new AllServiceGiftLevelTwoDialog(context, dataBean);
|
|
|
|
|
|
|
|
|
|
case AllServiceGiftDialog.ALL_SERVICE_GIFT_LEVEL_3:
|
|
|
|
|
return new AllServiceGiftLevelThreeDialog(context, dataBean);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
public void onGrabApprenticesEvent(GrabApprenticesEvent event) {
|
|
|
|
|
if (!isTopActivity()) return;
|
|
|
|
|
if (dialog != null && dialog.isAdded()) {
|
|
|
|
|
dialog.dismiss();
|
|
|
|
|
}
|
|
|
|
|
dialog = new GrabApprenticesNoticeDialog();
|
|
|
|
|
dialog.show(getSupportFragmentManager());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onRoomEventReceived(RoomEvent roomEvent) {
|
|
|
|
|
switch (roomEvent.getEvent()) {
|
|
|
|
|
case RoomEvent.RECHARGE:
|
|
|
|
|
onNeedCharge();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RoomEvent.RADISH_NOT_ENOUGH:
|
|
|
|
|
DialogUiHelper.showRadishNotEnoughDialog(this, null);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RoomEvent.GIFT_OUT_OF_DATE:
|
|
|
|
|
SingleToastUtil.showToast(roomEvent.getMessage());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String DESAndBase64(String psw) {
|
|
|
|
|
String pwd = "";
|
|
|
|
|
try {
|
|
|
|
|
pwd = DESUtils.DESAndBase64Encrypt(psw);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return pwd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 把不需要处理云信广播的activity 添加到这里。
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private boolean isNeedToHandleBroadcastMessageActivity() {
|
2022-09-28 16:32:35 +08:00
|
|
|
|
if (UserUtils.isPmMode()) return false;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
List<Class> acts = new ArrayList<>();
|
2020-04-10 16:48:04 +08:00
|
|
|
|
acts.add(LoginPhoneActivity.class);
|
|
|
|
|
acts.add(LoginCodeActivity.class);
|
2021-04-22 17:52:31 +08:00
|
|
|
|
acts.add(ResetPasswordActivity.class);
|
2020-04-02 10:43:40 +08:00
|
|
|
|
acts.add(AddUserInfoActivity.class);
|
|
|
|
|
acts.add(MiddleActivity.class);
|
|
|
|
|
acts.add(NimMiddleActivity.class);
|
|
|
|
|
|
|
|
|
|
for (Class act : acts) {
|
|
|
|
|
if (this.getClass().isInstance(act)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-08 14:23:46 +08:00
|
|
|
|
@SuppressLint("CheckResult")
|
2020-04-02 10:43:40 +08:00
|
|
|
|
private void onNeedCharge() {
|
|
|
|
|
if (isShowingChargeDialog) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
isShowingChargeDialog = true;
|
|
|
|
|
|
2022-01-08 14:23:46 +08:00
|
|
|
|
UserModel.get().getCurrentUserInfo()
|
|
|
|
|
.compose(bindToLifecycle())
|
|
|
|
|
.doOnError(throwable -> isShowingChargeDialog = false)
|
|
|
|
|
.subscribe(
|
|
|
|
|
userInfo -> {
|
|
|
|
|
if (userInfo.isFirstCharge()) {
|
|
|
|
|
isShowingChargeDialog = false;
|
|
|
|
|
FirstChargeDialog.start(context);
|
|
|
|
|
} else {
|
|
|
|
|
new DialogManager(context).showOkCancelDialog(getString(R.string.tips_need_charge),
|
|
|
|
|
new DialogManager.OkCancelDialogListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onOk() {
|
|
|
|
|
isShowingChargeDialog = false;
|
2022-05-06 18:53:17 +08:00
|
|
|
|
StatisticManager.Instance().onEvent(StatisticsProtocol.EVENT_NOT_ENOUGH_TO_RECHARGE,
|
2022-01-08 14:23:46 +08:00
|
|
|
|
"余额不足_去充值:送礼物");
|
|
|
|
|
ChargeActivity.start(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onCancel() {
|
|
|
|
|
isShowingChargeDialog = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-25 17:53:50 +08:00
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
|
|
public void onReceiveHello(NewbieHelloDialogEvent event) {
|
|
|
|
|
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
|
|
|
|
|
if (am == null) return;
|
|
|
|
|
ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
|
|
|
|
|
if (cn == null) return;
|
|
|
|
|
if (cn.getShortClassName().equals(getActivityByContext(context).getLocalClassName())) {
|
|
|
|
|
showHelloDialog(event.getHelloInfo());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 打招呼
|
|
|
|
|
*
|
|
|
|
|
* @param helloInfo
|
|
|
|
|
*/
|
|
|
|
|
private void showHelloDialog(final NewbieHelloInfo helloInfo) {
|
|
|
|
|
String message = helloInfo.getMessage();
|
|
|
|
|
int gender = helloInfo.getGender();
|
|
|
|
|
String nick = helloInfo.getNick();
|
|
|
|
|
String avatar = helloInfo.getAvatar();
|
|
|
|
|
getDialogManager().showNewbieHelloDialog(avatar, gender, nick, message, "去找TA", "忽略", true, new DialogManager.OkCancelDialogListener() {
|
|
|
|
|
@SuppressLint("CheckResult")
|
|
|
|
|
@Override
|
|
|
|
|
public void onOk() {
|
|
|
|
|
if (helloInfo.getInRoomUid() == 0) {
|
|
|
|
|
NimP2PMessageActivity.start(context, helloInfo.getUid());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AvRoomModel.get()
|
|
|
|
|
.getUserRoom(Long.parseLong(helloInfo.getUid()))
|
|
|
|
|
.compose(RxHelper.singleMainResult())
|
|
|
|
|
.compose(RxHelper.handleSchAndExce())
|
|
|
|
|
.compose(bindToLifecycle())
|
|
|
|
|
.subscribe((roomInfo, throwable) -> {
|
|
|
|
|
if (throwable == null) {
|
|
|
|
|
if (roomInfo != null && roomInfo.getUid() > 0 && roomInfo.getUid() == helloInfo.getInRoomUid()) {
|
|
|
|
|
AVRoomActivity.startForFromType(context, helloInfo.getInRoomUid(),
|
|
|
|
|
AVRoomActivity.FROM_TYPE_USER, nick, helloInfo.getUid());
|
|
|
|
|
} else {
|
|
|
|
|
SingleToastUtil.showToast("来聊聊天嘛~");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
SingleToastUtil.showToast("来聊聊天嘛~");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, context);
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-15 16:26:40 +08:00
|
|
|
|
private static class BroadcastObserver implements Observer<BroadcastMessage> {
|
|
|
|
|
private final WeakReference<BaseActivity> mReference;
|
|
|
|
|
|
|
|
|
|
BroadcastObserver(BaseActivity baseMvpActivity) {
|
|
|
|
|
mReference = new WeakReference<>(baseMvpActivity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onEvent(BroadcastMessage broadcastMessage) {
|
|
|
|
|
if (broadcastMessage != null) {
|
|
|
|
|
String contentStr = broadcastMessage.getContent();
|
|
|
|
|
Logger.i("全局广播:" + contentStr);
|
|
|
|
|
if (TextUtils.isEmpty(contentStr)) return;
|
|
|
|
|
BaseActivity baseMvpActivity = mReference.get();
|
|
|
|
|
if (baseMvpActivity == null) return;
|
|
|
|
|
if (baseMvpActivity.isValid()) {
|
|
|
|
|
JSONObject jsonObject;
|
|
|
|
|
try {
|
|
|
|
|
jsonObject = JSON.parseObject(contentStr);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
jsonObject = null;
|
|
|
|
|
}
|
|
|
|
|
if (jsonObject == null) return;
|
|
|
|
|
if (jsonObject.containsKey("body")) {
|
|
|
|
|
String body = jsonObject.getString("body");
|
|
|
|
|
if (TextUtils.isEmpty(body)) return;
|
|
|
|
|
baseMvpActivity.onReceivedNimBroadcastMessage(body);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|