1095 lines
37 KiB
Java
1095 lines
37 KiB
Java
package com.yizhuan.erban.base;
|
||
|
||
import android.annotation.SuppressLint;
|
||
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 androidx.annotation.ColorInt;
|
||
import androidx.fragment.app.Fragment;
|
||
import androidx.fragment.app.FragmentManager;
|
||
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;
|
||
|
||
import com.alibaba.fastjson.JSON;
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.google.gson.Gson;
|
||
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;
|
||
import com.trello.rxlifecycle3.android.ActivityEvent;
|
||
import com.yizhuan.erban.R;
|
||
import com.yizhuan.erban.application.XChatApplication;
|
||
import com.yizhuan.erban.avroom.activity.AVRoomActivity;
|
||
import com.yizhuan.erban.avroom.redpackage.RedPackageGoRoomDialog;
|
||
import com.yizhuan.erban.avroom.redpackage.RedPackageOpenDialog;
|
||
import com.yizhuan.erban.common.LoadingFragment;
|
||
import com.yizhuan.erban.common.NetworkErrorFragment;
|
||
import com.yizhuan.erban.common.NoDataFragment;
|
||
import com.yizhuan.erban.common.ReloadFragment;
|
||
import com.yizhuan.erban.common.permission.PermissionActivity;
|
||
import com.yizhuan.erban.common.widget.StatusLayout;
|
||
import com.yizhuan.erban.common.widget.dialog.DialogManager;
|
||
import com.yizhuan.erban.common.widget.dialog.DialogUiHelper;
|
||
import com.yizhuan.erban.reciever.ConnectiveChangedReceiver;
|
||
import com.yizhuan.erban.ui.login.AddUserInfoActivity;
|
||
import com.yizhuan.erban.ui.login.LoginActivity;
|
||
import com.yizhuan.erban.ui.pay.ChargeActivity;
|
||
import com.yizhuan.erban.ui.widget.DefaultToolBar;
|
||
import com.yizhuan.erban.ui.widget.dialog.OpenNobleGlobalNoticeDialog;
|
||
import com.yizhuan.erban.utils.UserUtils;
|
||
import com.yizhuan.tutu.mentoring_relationship.dialog.GrabApprenticesNoticeDialog;
|
||
import com.yizhuan.xchat_android_constants.XChatConstants;
|
||
import com.yizhuan.xchat_android_core.bean.BaseProtocol;
|
||
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
|
||
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
|
||
import com.yizhuan.xchat_android_core.manager.RoomEvent;
|
||
import com.yizhuan.xchat_android_core.mentoring_relationship.event.GrabApprenticesEvent;
|
||
import com.yizhuan.xchat_android_core.noble.AllServiceGiftProtocol;
|
||
import com.yizhuan.xchat_android_core.noble.NobleInfo;
|
||
import com.yizhuan.xchat_android_core.noble.NobleProtocol;
|
||
import com.yizhuan.xchat_android_core.redpackage.RedPackageNotifyInfo;
|
||
import com.yizhuan.xchat_android_core.room.bean.RoomInfo;
|
||
import com.yizhuan.xchat_android_core.statistic.StatisticManager;
|
||
import com.yizhuan.xchat_android_library.base.AbstractMvpActivity;
|
||
import com.yizhuan.xchat_android_library.base.AbstractMvpPresenter;
|
||
import com.yizhuan.xchat_android_library.base.IMvpBaseView;
|
||
import com.yizhuan.xchat_android_library.rxbus.RxBus;
|
||
import com.yizhuan.xchat_android_library.utils.ImeUtil;
|
||
import com.yizhuan.xchat_android_library.utils.NetworkUtils;
|
||
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
|
||
import com.yizhuan.xchat_android_library.utils.UIUtils;
|
||
import com.yizhuan.xchat_android_library.utils.config.BasicConfig;
|
||
import com.yizhuan.xchat_android_library.utils.log.MLog;
|
||
|
||
import java.lang.ref.WeakReference;
|
||
import java.lang.reflect.Field;
|
||
import java.lang.reflect.Method;
|
||
import java.util.LinkedList;
|
||
import java.util.List;
|
||
|
||
import io.reactivex.Observable;
|
||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||
import io.reactivex.disposables.CompositeDisposable;
|
||
|
||
import static com.yizhuan.xchat_android_core.Constants.DEBUG_MAX_UID;
|
||
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MESS_HEAD_NOBLE;
|
||
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MESS_SUB_OPENNOBLE;
|
||
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MESS_SUB_RENEWNOBLE;
|
||
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_RED_PACKAGE;
|
||
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ALL_DIAMOND;
|
||
|
||
|
||
/**
|
||
* @author alvin hwang
|
||
*/
|
||
public abstract class BaseMvpActivity<V extends IMvpBaseView, P extends AbstractMvpPresenter<V>> extends AbstractMvpActivity<V, P>
|
||
implements IDataStatus, ConnectiveChangedReceiver.ConnectiveChangedListener, DialogManagerInterface {
|
||
|
||
private static final String TAG = "BaseMvpActivity";
|
||
|
||
private DialogManager mDialogManager;
|
||
protected TitleBar mTitleBar;
|
||
protected DefaultToolBar mToolBar;
|
||
protected CompositeDisposable mCompositeDisposable;
|
||
private volatile LinkedList<AllServiceGiftProtocol.DataBean> giftList;
|
||
private BroadcastObserver broadcastObserver;
|
||
|
||
protected Context context;
|
||
|
||
@Override
|
||
protected void onCreate(Bundle savedInstanceState) {
|
||
super.onCreate(savedInstanceState);
|
||
context = this;
|
||
mCompositeDisposable = new CompositeDisposable();
|
||
if (setBgColor() > 0) {
|
||
getWindow().setBackgroundDrawableResource(setBgColor());
|
||
}
|
||
if (needSteepStateBar()) {
|
||
setStatusBar();
|
||
}
|
||
mCompositeDisposable.add(IMNetEaseManager.get().getChatRoomEventObservable()
|
||
.subscribe(roomEvent -> {
|
||
if (roomEvent == null) return;
|
||
onReceiveChatRoomEvent(roomEvent);
|
||
}));
|
||
registerNimBroadcastMessage(true);
|
||
|
||
}
|
||
|
||
protected void onReceiveChatRoomEvent(RoomEvent roomEvent) {
|
||
}
|
||
|
||
/**
|
||
* 注册云信全服广播接收器
|
||
*
|
||
* @param register true为注册,false为注销
|
||
*/
|
||
private void registerNimBroadcastMessage(boolean register) {
|
||
if (broadcastObserver == null) {
|
||
broadcastObserver = new BroadcastObserver(this);
|
||
}
|
||
NIMSDK.getMsgServiceObserve().observeBroadcastMessage(broadcastObserver, register);
|
||
}
|
||
|
||
public void initToolBar(int resId) {
|
||
initToolBar(getString(resId));
|
||
}
|
||
|
||
public void initToolBar(CharSequence title) {
|
||
mToolBar = (DefaultToolBar) findViewById(R.id.toolbar);
|
||
if (mToolBar != null) {
|
||
mToolBar.setCenterTitle(title);
|
||
mToolBar.setNavigationIcon(R.drawable.arrow_left);
|
||
mToolBar.setNavigationOnClickListener(v -> onLeftClickListener());
|
||
}
|
||
}
|
||
|
||
public void initTitleBar() {
|
||
mTitleBar = (TitleBar) findViewById(R.id.title_bar);
|
||
if (mTitleBar != null) {
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && needSteepStateBar()) {
|
||
mTitleBar.setImmersive(true);
|
||
}
|
||
mTitleBar.setBackgroundColor(getResources().getColor(R.color.white));
|
||
mTitleBar.setTitleColor(getResources().getColor(R.color.text_primary));
|
||
}
|
||
}
|
||
|
||
public void initTitleBar(String title) {
|
||
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(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
onLeftClickListener();
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
public void initTitleBar(String title, boolean whiteModel) {
|
||
mTitleBar = findViewById(R.id.title_bar);
|
||
if (mTitleBar != null) {
|
||
mTitleBar.setTitle(title);
|
||
mTitleBar.setImmersive(false);
|
||
mTitleBar.setTitleColor(getResources().getColor(
|
||
whiteModel ? R.color.white : R.color.back_font));
|
||
mTitleBar.setLeftImageResource(
|
||
whiteModel ? R.drawable.arrow_left_white : R.drawable.arrow_left);
|
||
mTitleBar.setCommonBackgroundColor(getResources().getColor(
|
||
whiteModel ? R.color.transparent : R.color.transparent)
|
||
);
|
||
mTitleBar.setLeftClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
onLeftClickListener();
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
public void initTitleBar(int title) {
|
||
initTitleBar(getResources().getString(title));
|
||
}
|
||
|
||
public void initTitleBar(String title, TitleBar.Action action) {
|
||
mTitleBar = (TitleBar) 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.setLeftClickListener(v -> onLeftClickListener());
|
||
// action
|
||
if (action != null) {
|
||
mTitleBar.addAction(action);
|
||
}
|
||
}
|
||
}
|
||
|
||
protected void onLeftClickListener() {
|
||
finish();
|
||
}
|
||
|
||
protected boolean needSteepStateBar() {
|
||
return false;
|
||
}
|
||
|
||
protected int setBgColor() {
|
||
return 0;
|
||
}
|
||
|
||
/**
|
||
* 设置沉浸式状态栏
|
||
*/
|
||
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"));
|
||
}
|
||
|
||
/**
|
||
* 获取状态栏的高度
|
||
*
|
||
* @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);*/
|
||
|
||
if (XChatApplication.isDebug()) {
|
||
XChatApplication.getRefWatcher(this).watch(this);
|
||
}
|
||
|
||
}
|
||
|
||
@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 instanceof BaseMvpFragment)) {
|
||
fragment.onActivityResult(requestCode, resultCode, data);
|
||
}
|
||
super.onActivityResult(requestCode, resultCode, data);
|
||
}
|
||
|
||
public Fragment getTopFragment() {
|
||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||
@SuppressLint("RestrictedApi")
|
||
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() {
|
||
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() {
|
||
@SuppressLint("RestrictedApi")
|
||
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;
|
||
}
|
||
|
||
/**
|
||
* @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;
|
||
}
|
||
|
||
@SuppressLint("CheckResult")
|
||
@Override
|
||
protected void onResume() {
|
||
super.onResume();
|
||
//add connective changed broadcast receiver
|
||
// ConnectiveChangedReceiver.getInstance().registerConnectiveChange(this);
|
||
StatisticManager.Instance().onResume(this);
|
||
// TODO: 2018/2/25 bug fixed
|
||
// TODO: 2018/2/25 java.lang.RuntimeException:Unable to resume activity
|
||
// TODO: 2018/2/25 {com.yizhuan.erban/com.yizhuan.erban.other.activity.SplashActivity}: java.lang.ClassCastException: int[] cannot be cast to java.lang.Object[]
|
||
//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);
|
||
}
|
||
|
||
@Override
|
||
protected void onPause() {
|
||
hideIME();
|
||
super.onPause();
|
||
//remove connective changed broadcast receiver
|
||
// ConnectiveChangedReceiver.getInstance().unRegisterConnectiveChange(this);
|
||
|
||
StatisticManager.Instance().onPause(this);
|
||
|
||
// TODO: 2018/2/25 java.lang.IllegalStateException: You cannot call Glide.get() in registerComponents(), use the provided Glide instance instead
|
||
// GlideApp.with(this).pauseRequests();
|
||
}
|
||
|
||
|
||
/**
|
||
* wifi 转 2G/3G/4G
|
||
*/
|
||
@Override
|
||
public void wifiChange2MobileData() {
|
||
|
||
}
|
||
|
||
/**
|
||
* 有网络变为无网络
|
||
*/
|
||
@Override
|
||
public void change2NoConnection() {
|
||
if (isTopActive()) {
|
||
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 连上wifi
|
||
*/
|
||
@Override
|
||
public void connectiveWifi() {
|
||
if (isTopActive()) {
|
||
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 连上移动数据网络
|
||
*/
|
||
@Override
|
||
public void connectiveMobileData() {
|
||
if (isTopActive()) {
|
||
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 移动数据网络 改为连上wifi
|
||
*/
|
||
@Override
|
||
public void mobileDataChange2Wifi() {
|
||
|
||
}
|
||
|
||
protected boolean checkActivityValid() {
|
||
return UIUtils.checkActivityValid(this);
|
||
}
|
||
|
||
/**
|
||
* 弹出登录框
|
||
*
|
||
* @return
|
||
*/
|
||
public void showLoginDialog() {
|
||
// if (mLoginDialog == null) {
|
||
// mLoginDialog = new LoginPopupDialog(this, new OnClickLoginPopupListener(this));
|
||
// }
|
||
ImeUtil.hideIME(this);
|
||
// mLoginDialog.show();
|
||
}
|
||
|
||
protected static final String STATUS_TAG = "STATUS_TAG";
|
||
|
||
@Override
|
||
public View.OnClickListener getLoadListener() {
|
||
return 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);
|
||
}
|
||
|
||
@Override
|
||
public void showReload() {
|
||
showReload(0, 0);
|
||
}
|
||
|
||
@Override
|
||
public void showNoData() {
|
||
showNoData(0, "");
|
||
}
|
||
|
||
@Override
|
||
public void showNoLogin() {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void showLoading(int drawable, int tips) {
|
||
if (!checkActivityValid()) {
|
||
return;
|
||
}
|
||
|
||
View status = findViewById(R.id.status_layout);
|
||
if (status == null) {
|
||
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) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void showReload(int drawable, int tips) {
|
||
showReload(drawable, tips, 1);
|
||
}
|
||
|
||
public void showReload(@ColorInt int bgColor) {
|
||
showReload(0, 0, bgColor);
|
||
}
|
||
|
||
public void showReload(int drawable, int tips, @ColorInt int bgColor) {
|
||
if (!checkActivityValid()) {
|
||
return;
|
||
}
|
||
|
||
View status = findViewById(R.id.status_layout);
|
||
if (status == null) {
|
||
MLog.error(this, "xuwakao, had not set layout id ");
|
||
return;
|
||
}
|
||
ReloadFragment fragment = ReloadFragment.newInstance(drawable, tips, bgColor);
|
||
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);
|
||
}
|
||
|
||
@Override
|
||
public void showNoData(int drawable, CharSequence charSequence) {
|
||
if (!checkActivityValid()) {
|
||
return;
|
||
}
|
||
|
||
View status = findViewById(R.id.status_layout);
|
||
if (status == null) {
|
||
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) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void showNetworkErr() {
|
||
if (!checkActivityValid()) {
|
||
return;
|
||
}
|
||
|
||
View status = findViewById(R.id.status_layout);
|
||
if (status == null) {
|
||
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;
|
||
}
|
||
|
||
|
||
public void hideIME() {
|
||
View v = getCurrentFocus();
|
||
if (null != v)
|
||
hideIME(v);
|
||
}
|
||
|
||
public void hideIME(View v) {
|
||
InputMethodManager imm = (InputMethodManager) BasicConfig.INSTANCE.getAppContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||
if (imm != null && imm.isActive()) {
|
||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||
}
|
||
}
|
||
|
||
public void showIME(final View vv) {
|
||
View v = vv;
|
||
if (null == v) {
|
||
v = getCurrentFocus();
|
||
if (null == v)
|
||
return;
|
||
}
|
||
((InputMethodManager) BasicConfig.INSTANCE.getAppContext().getSystemService(INPUT_METHOD_SERVICE))
|
||
.showSoftInput(v, InputMethodManager.SHOW_FORCED);
|
||
}
|
||
|
||
/**
|
||
* 当前无Fragment 或 无Fragment添加 视为顶部激活状态
|
||
*
|
||
* @return
|
||
*/
|
||
public boolean isTopActive() {
|
||
|
||
if (isTopActivity()) {
|
||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||
|
||
@SuppressLint("RestrictedApi")
|
||
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) {
|
||
SingleToastUtil.showToast(BasicConfig.INSTANCE.getAppContext(), resId, length);
|
||
}
|
||
|
||
public void toast(String toast, int length) {
|
||
SingleToastUtil.showToast(BasicConfig.INSTANCE.getAppContext(), toast, length);
|
||
}
|
||
|
||
|
||
private void configStatusBar() {
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||
Window window = getWindow();
|
||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||
window.setStatusBarColor(getResources().getColor(R.color.white));
|
||
|
||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||
Window window = getWindow();
|
||
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||
|
||
// 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.setTintResource(R.color.white);
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 权限回调接口
|
||
*/
|
||
private PermissionActivity.CheckPermListener mListener;
|
||
|
||
private RxPermissions rxPermissions = new RxPermissions(this);
|
||
|
||
@SuppressLint("CheckResult")
|
||
public void checkPermission(PermissionActivity.CheckPermListener listener,
|
||
int resString, String... mPerms) {
|
||
mListener = listener;
|
||
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);
|
||
}
|
||
|
||
/**
|
||
* 当前Activity 是否有效
|
||
*/
|
||
protected boolean isValid() {
|
||
return !isFinishing() && !isDestroyed();
|
||
}
|
||
|
||
/**
|
||
* 接收到全局广播信息
|
||
*
|
||
* @param body 信息实体
|
||
*/
|
||
protected void onReceivedNimBroadcastMessage(String body) {
|
||
|
||
BaseProtocol baseProtocol;
|
||
try {
|
||
baseProtocol = JSON.parseObject(body, BaseProtocol.class);
|
||
} catch (Exception e) {
|
||
baseProtocol = null;
|
||
}
|
||
|
||
if (baseProtocol == null) return;
|
||
|
||
switch (baseProtocol.getFirst()) {
|
||
case CUSTOM_MESS_HEAD_NOBLE:
|
||
int second = baseProtocol.getSecond();
|
||
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 (mNoticeDialog != null && mNoticeDialog.isShowing())
|
||
mNoticeDialog.dismiss();
|
||
mNoticeDialog = new OpenNobleGlobalNoticeDialog(this, spannable);
|
||
mNoticeDialog.show();
|
||
}
|
||
}
|
||
break;
|
||
|
||
case CUSTOM_MSG_RED_PACKAGE:
|
||
switch (baseProtocol.getSecond()) {
|
||
case CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ALL_DIAMOND:
|
||
if (context instanceof AddUserInfoActivity || context instanceof LoginActivity || UserUtils.getUserInfo() == null)
|
||
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 {
|
||
LogUtil.e("Red_Base:"+AvRoomDataManager.get().serverRedEnvelopeSwitch);
|
||
if (roomInfo != null && roomInfo.getUid() != notifyInfo.getRoomUid() && AvRoomDataManager.get().serverRedEnvelopeSwitch && context instanceof AVRoomActivity){
|
||
RedPackageGoRoomDialog.Companion.newInstance(notifyInfo).show(this);
|
||
}else if (roomInfo == null){
|
||
RedPackageGoRoomDialog.Companion.newInstance(notifyInfo).show(this);
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
private OpenNobleGlobalNoticeDialog mNoticeDialog;
|
||
|
||
public static class BroadcastObserver implements Observer<BroadcastMessage> {
|
||
private WeakReference<BaseMvpActivity> mReference;
|
||
|
||
public BroadcastObserver(BaseMvpActivity 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;
|
||
BaseMvpActivity 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);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 通知栏白底黑字
|
||
*
|
||
* @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);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
protected volatile GrabApprenticesNoticeDialog dialog;
|
||
|
||
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;
|
||
}
|
||
}
|
||
|
||
private boolean isShowingChargeDialog;
|
||
|
||
private void onNeedCharge() {
|
||
if (isShowingChargeDialog) {
|
||
return;
|
||
}
|
||
isShowingChargeDialog = true;
|
||
new DialogManager(this).showOkCancelDialog(getString(R.string.tips_need_charge),
|
||
new DialogManager.OkCancelDialogListener() {
|
||
@Override
|
||
public void onOk() {
|
||
isShowingChargeDialog = false;
|
||
ChargeActivity.start(context);
|
||
}
|
||
|
||
@Override
|
||
public void onCancel() {
|
||
isShowingChargeDialog = false;
|
||
}
|
||
});
|
||
}
|
||
} |