change package name
This commit is contained in:
960
app/src/main/java/com/mango/moshen/MainActivity.java
Normal file
960
app/src/main/java/com/mango/moshen/MainActivity.java
Normal file
@@ -0,0 +1,960 @@
|
||||
package com.mango.moshen;
|
||||
|
||||
import static com.mango.core.channel_page.model.ChannelPageModel.KEY_FLAG_VALID_CHANNEL_PAGE;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.netease.nim.uikit.StatusBarUtil;
|
||||
import com.netease.nim.uikit.common.util.log.LogUtil;
|
||||
import com.netease.nim.uikit.common.util.string.StringUtil;
|
||||
import com.netease.nim.uikit.impl.cache.NimUserInfoCache;
|
||||
import com.netease.nimlib.sdk.NIMClient;
|
||||
import com.netease.nimlib.sdk.RequestCallbackWrapper;
|
||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomKickOutEvent;
|
||||
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
|
||||
import com.netease.nimlib.sdk.msg.model.RecentContact;
|
||||
import com.netease.nimlib.sdk.team.TeamService;
|
||||
import com.netease.nimlib.sdk.team.constant.TeamMessageNotifyTypeEnum;
|
||||
import com.netease.nimlib.sdk.team.model.Team;
|
||||
import com.netease.nimlib.sdk.uinfo.model.NimUserInfo;
|
||||
import com.orhanobut.logger.Logger;
|
||||
import com.tencent.bugly.crashreport.CrashReport;
|
||||
import com.trello.rxlifecycle3.android.ActivityEvent;
|
||||
import com.mango.moshen.application.ActivityStackManager;
|
||||
import com.mango.moshen.avroom.activity.AVRoomActivity;
|
||||
import com.mango.moshen.avroom.ktv.KtvMusicManager;
|
||||
import com.mango.moshen.avroom.newuserchargegift.NewUserChargeGiftDialog;
|
||||
import com.mango.moshen.base.BaseMvpActivity;
|
||||
import com.mango.moshen.common.widget.CircleImageView;
|
||||
import com.mango.moshen.common.widget.DragLayout;
|
||||
import com.mango.moshen.community.dynamic.view.DynamicDetailActivity;
|
||||
import com.mango.moshen.community.publish.view.PublishActivity;
|
||||
import com.mango.moshen.community.square.SquareFragment;
|
||||
import com.mango.moshen.family.view.activity.FamilyHomeActivity;
|
||||
import com.mango.moshen.home.HomeViewModel;
|
||||
import com.mango.moshen.home.dialog.NewUserHelloDialog;
|
||||
import com.mango.moshen.home.dialog.ProtocolUpdateDialog;
|
||||
import com.mango.moshen.home.fragment.ContactsListFragment;
|
||||
import com.mango.moshen.home.fragment.HomeFragment;
|
||||
import com.mango.moshen.home.fragment.MeFragment;
|
||||
import com.mango.moshen.home.presenter.MainPresenter;
|
||||
import com.mango.moshen.home.view.IMainView;
|
||||
import com.mango.moshen.home.widget.AnchorCardView;
|
||||
import com.mango.moshen.main.helper.NoticationsUiHelper;
|
||||
import com.mango.moshen.miniworld.activity.MiniWorldGuestPageActivity;
|
||||
import com.mango.moshen.module.Extras;
|
||||
import com.mango.moshen.module_hall.secretcode.PwdCodeMgr;
|
||||
import com.mango.moshen.quick_pass.QuickPassLoginAct;
|
||||
import com.mango.moshen.service.DaemonService;
|
||||
import com.mango.moshen.ui.im.ImInitHelper;
|
||||
import com.mango.moshen.ui.im.avtivity.NimP2PMessageActivity;
|
||||
import com.mango.moshen.ui.login.BindPhoneActivity;
|
||||
import com.mango.moshen.ui.login.fragment.AddUserInfoFragment;
|
||||
import com.mango.moshen.ui.patriarch.help.LimitEnterRoomHelper;
|
||||
import com.mango.moshen.ui.patriarch.help.PmDialogShowMrg;
|
||||
import com.mango.moshen.ui.utils.ImageLoadUtils;
|
||||
import com.mango.moshen.ui.utils.ImageLoadUtilsV2;
|
||||
import com.mango.moshen.ui.webview.CommonWebViewActivity;
|
||||
import com.mango.moshen.ui.widget.LivingIconView;
|
||||
import com.mango.moshen.ui.widget.MainTabLayout;
|
||||
import com.mango.moshen.utils.CleanLeakUtils;
|
||||
import com.mango.moshen.utils.PushMessageHandler;
|
||||
import com.mango.core.Constants;
|
||||
import com.mango.core.DemoCache;
|
||||
import com.mango.core.UriProvider;
|
||||
import com.mango.core.auth.AuthModel;
|
||||
import com.mango.core.auth.event.KickOutEvent;
|
||||
import com.mango.core.auth.event.LoginEvent;
|
||||
import com.mango.core.auth.event.LogoutEvent;
|
||||
import com.mango.core.channel_page.model.ChannelPageModel;
|
||||
import com.mango.core.community.event.SquareTaskEvent;
|
||||
import com.mango.core.community.event.UnReadCountEvent;
|
||||
import com.mango.core.home.bean.MainTabType;
|
||||
import com.mango.core.home.event.RefreshHomeDataEvent;
|
||||
import com.mango.core.home.event.VisitorUnreadCountEvent;
|
||||
import com.mango.core.home.model.GameHomeModel;
|
||||
import com.mango.core.home.model.HomeModel;
|
||||
import com.mango.core.initial.InitialModel;
|
||||
import com.mango.core.linked.LinkedModel;
|
||||
import com.mango.core.linked.bean.LinkedInfo;
|
||||
import com.mango.core.manager.AudioEngineManager;
|
||||
import com.mango.core.manager.AvRoomDataManager;
|
||||
import com.mango.core.manager.IMBroadcastManager;
|
||||
import com.mango.core.manager.IMMessageManager;
|
||||
import com.mango.core.manager.RoomEvent;
|
||||
import com.mango.core.patriarch.event.CloseMinRoomEvent;
|
||||
import com.mango.core.patriarch.event.ImPushMsgPmLimitTimeEvent;
|
||||
import com.mango.core.patriarch.event.PmDismissAllLimitDialogEvent;
|
||||
import com.mango.core.room.bean.RoomInfo;
|
||||
import com.mango.core.statistic.StatisticManager;
|
||||
import com.mango.core.statistic.protocol.StatisticsProtocol;
|
||||
import com.mango.core.user.UserModel;
|
||||
import com.mango.core.user.bean.UserInfo;
|
||||
import com.mango.core.user.event.LoadLoginUserInfoEvent;
|
||||
import com.mango.core.user.event.LoginUserInfoUpdateEvent;
|
||||
import com.mango.core.user.event.NeedBindPhoneEvent;
|
||||
import com.mango.core.user.event.NeedCompleteInfoEvent;
|
||||
import com.mango.core.utils.CurrentTimeUtils;
|
||||
import com.mango.core.utils.SharedPreferenceUtils;
|
||||
import com.mango.core.utils.StringUtils;
|
||||
import com.mango.xchat_android_library.base.factory.CreatePresenter;
|
||||
import com.mango.xchat_android_library.threadmgr.ThreadPoolManager;
|
||||
import com.mango.xchat_android_library.utils.JavaUtil;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@CreatePresenter(MainPresenter.class)
|
||||
public class MainActivity extends BaseMvpActivity<IMainView, MainPresenter>
|
||||
implements MainTabLayout.OnTabClickListener, IMainView, View.OnClickListener {
|
||||
|
||||
public static final String MSG_TAB = "msgTab";
|
||||
public static final String GAME_TAB = "gameTab";
|
||||
private static final String TAG = "MainActivity";
|
||||
private static final String EXTRA_APP_QUIT = "APP_QUIT";
|
||||
private final SparseArray<Fragment> fragmentArray = new SparseArray<>();
|
||||
private DragLayout avatarLayout;
|
||||
private TextView tvName;//最小化窗口名称
|
||||
private TextView tvId;//最小化窗口ID
|
||||
private CircleImageView avatarImage;
|
||||
private LinearLayout llDragInfo;
|
||||
private LivingIconView userLivingView;
|
||||
private View viewClose;
|
||||
private MainTabLayout mMainTabLayout;
|
||||
private AnchorCardView anchorCardView;
|
||||
private int mCurrentTabType = MainTabType.TAB_TYPE_HOME;
|
||||
/**
|
||||
* 房间最小化动画,换成属性动画,原先的补间动画影响了activity的生命周期
|
||||
*/
|
||||
private ObjectAnimator roomMinAnim;
|
||||
/**
|
||||
* 管理限制进房
|
||||
*/
|
||||
private LimitEnterRoomHelper limitEnterRoomHelper;
|
||||
private HomeViewModel homeViewModel;
|
||||
private boolean mResumed = false;
|
||||
@Nullable
|
||||
private Fragment tempFragment = null;
|
||||
|
||||
@Nullable
|
||||
private Runnable touchRunnable;
|
||||
|
||||
{
|
||||
fragmentArray.put(MainTabType.TAB_TYPE_HOME, new HomeFragment());
|
||||
fragmentArray.put(MainTabType.TAB_TYPE_MSG, new ContactsListFragment());
|
||||
fragmentArray.put(MainTabType.TAB_TYPE_SQUARE, new SquareFragment());
|
||||
fragmentArray.put(MainTabType.TAB_TYPE_ME, new MeFragment());
|
||||
}
|
||||
|
||||
public static void start(Context context) {
|
||||
start(context, null);
|
||||
}
|
||||
|
||||
public static void start(Context context, Intent extras) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(context, MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
if (extras != null) {
|
||||
intent.putExtras(extras);
|
||||
}
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt(Constants.KEY_MAIN_POSITION, mCurrentTabType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(@NotNull Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
mCurrentTabType = savedInstanceState.getInt(Constants.KEY_MAIN_POSITION);
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
homeViewModel = new ViewModelProvider(this).get(HomeViewModel.class);
|
||||
NimMiddleActivity.firstEnter = false;
|
||||
if (savedInstanceState != null) {
|
||||
mCurrentTabType = savedInstanceState.getInt(Constants.KEY_MAIN_POSITION);
|
||||
}
|
||||
setContentView(R.layout.activity_main);
|
||||
//自动登录
|
||||
AuthModel.get().autoLogin()
|
||||
.doOnError(throwable -> onNeedLogin())
|
||||
.subscribe();
|
||||
initView();
|
||||
InitialModel.get().getMainTabInfosLiveData().observeForever(mainTabInfos -> {
|
||||
if (mainTabInfos != null) {
|
||||
mMainTabLayout.setMainTabInfoList(mainTabInfos);
|
||||
}
|
||||
});
|
||||
initMaterialView();
|
||||
onParseIntent();
|
||||
updateDatas();
|
||||
updateRoomState();
|
||||
ImInitHelper.get().init();
|
||||
EventBus.getDefault().register(this);
|
||||
otherModelInit();
|
||||
|
||||
Observable.interval(15, TimeUnit.SECONDS)
|
||||
.compose(bindToLifecycle())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(aLong -> EventBus.getDefault().post(new RefreshHomeDataEvent()));
|
||||
|
||||
homeViewModel.getAnchorInfoLiveData().observe(this, anchorInfo -> {
|
||||
if (anchorInfo != null) {
|
||||
anchorCardView.setAnchorInfo(anchorInfo);
|
||||
DemoCache.saveAnchorCardView(2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void otherModelInit() {
|
||||
PwdCodeMgr.get().onCreateInit();
|
||||
//初始化线程池
|
||||
ThreadPoolManager.instance().init();
|
||||
IMBroadcastManager.get().onCreate();
|
||||
ImageLoadUtilsV2.init(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onReceiveChatRoomEvent(RoomEvent roomEvent) {
|
||||
super.onReceiveChatRoomEvent(roomEvent);
|
||||
if (roomEvent == null || roomEvent.getEvent() == RoomEvent.NONE) return;
|
||||
int event = roomEvent.getEvent();
|
||||
if (event == RoomEvent.ENTER_ROOM) {
|
||||
onEnter(AvRoomDataManager.get().mCurrentRoomInfo);
|
||||
} else if (event == RoomEvent.KICK_OUT_ROOM) {
|
||||
|
||||
ChatRoomKickOutEvent reason = roomEvent.getReason();
|
||||
if (reason == null) return;
|
||||
//加入黑名单,踢出房间回调
|
||||
ChatRoomKickOutEvent.ChatRoomKickOutReason reasonReason = reason.getReason();
|
||||
StatisticManager.Instance().onEvent(StatisticsProtocol.USER_KICKED_EVENT, "用户被踢");
|
||||
if (reasonReason == ChatRoomKickOutEvent.ChatRoomKickOutReason.BE_BLACKLISTED
|
||||
|| reasonReason == ChatRoomKickOutEvent.ChatRoomKickOutReason.KICK_OUT_BY_MANAGER
|
||||
|| reasonReason == ChatRoomKickOutEvent.ChatRoomKickOutReason.KICK_OUT_BY_CONFLICT_LOGIN
|
||||
|| reasonReason == ChatRoomKickOutEvent.ChatRoomKickOutReason.CHAT_ROOM_INVALID) {
|
||||
exitRoom(AvRoomDataManager.get().mCurrentRoomInfo);
|
||||
}
|
||||
} else if (event == RoomEvent.ROOM_EXIT) {
|
||||
exitRoom(roomEvent.getRoomInfo());
|
||||
} else if (event == RoomEvent.ROOM_CHAT_RECONNECTION) {
|
||||
updateRoomState();
|
||||
} else if (event == RoomEvent.MY_SELF_KICK_OUT_ROOM_BY_S_ADMIN) {
|
||||
AvRoomDataManager.get().addCurrentRoomLimitEnter();
|
||||
toast(R.string.kick_out_room_by_s_admin);
|
||||
StatisticManager.Instance().onEvent(StatisticsProtocol.USER_KICKED_EVENT, "用户被踢");
|
||||
getMvpPresenter().exitRoom();
|
||||
}
|
||||
}
|
||||
|
||||
private void closeOpenRoomAnimation() {
|
||||
stopRoomMinAnim();
|
||||
avatarLayout.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mResumed = true;
|
||||
if (avatarLayout.getVisibility() == View.VISIBLE) {
|
||||
userLivingView.start();
|
||||
}
|
||||
//这里是为了处理APP后台运行的情况下点击分享房间等LinkedMe链接的情况
|
||||
UserInfo userInfo = UserModel.get().getCacheLoginUserInfo();
|
||||
if (userInfo != null) {
|
||||
handleLinkedJump();
|
||||
if (userInfo.isShowLimitCharge() &&
|
||||
PmDialogShowMrg.get().isHasShow() &&
|
||||
DemoCache.readNewUserChargeGift() == 1) {
|
||||
StatisticManager.Instance().onEvent(StatisticsProtocol.EVENT_NUGIFT_POP_SHOW, "新人专享礼物弹窗曝光");
|
||||
NewUserChargeGiftDialog.start(context);
|
||||
DemoCache.saveNewUserChargeGift(2);
|
||||
}
|
||||
checkShowAnchorCardView();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkShowAnchorCardView() {
|
||||
if (touchRunnable != null || !mResumed || AvRoomDataManager.get().mCurrentRoomInfo != null)
|
||||
return;
|
||||
int anchorCardViewType = DemoCache.readAnchorCardView();
|
||||
if (anchorCardViewType == 2) {
|
||||
if (CurrentTimeUtils.getCurrentTime() - DemoCache.readAnchorCardViewTime() > 15 * 60 * 1000) {
|
||||
touchRunnable = () -> {
|
||||
touchRunnable = null;
|
||||
homeViewModel.requestAnchorInfo();
|
||||
};
|
||||
mMainTabLayout.postDelayed(touchRunnable, 5000);
|
||||
}
|
||||
} else if (anchorCardViewType == 1 || DemoCache.readLaunchCount() == 1) {
|
||||
homeViewModel.requestAnchorInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mResumed = false;
|
||||
if (avatarLayout.getVisibility() == View.VISIBLE) {
|
||||
userLivingView.stop();
|
||||
}
|
||||
mMainTabLayout.removeCallbacks(touchRunnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (touchRunnable == null) return super.onTouchEvent(event);
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
mMainTabLayout.removeCallbacks(touchRunnable);
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
mMainTabLayout.postDelayed(touchRunnable, 5000);
|
||||
break;
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
mMainTabLayout = findViewById(R.id.main_tab_layout);
|
||||
avatarLayout = findViewById(R.id.avatar_image_layout);
|
||||
tvName = findViewById(R.id.tv_name);
|
||||
tvId = findViewById(R.id.tv_id);
|
||||
|
||||
avatarImage = findViewById(R.id.avatar_image);
|
||||
userLivingView = findViewById(R.id.liv_user);
|
||||
viewClose = findViewById(R.id.view_close);
|
||||
llDragInfo = findViewById(R.id.ll_drag_info);
|
||||
userLivingView.setColor(Color.WHITE);
|
||||
mMainTabLayout.setOnTabClickListener(this);
|
||||
anchorCardView = findViewById(R.id.vs_anchor_card);
|
||||
}
|
||||
|
||||
private void updateDatas() {
|
||||
mMainTabLayout.setDefaultTabType(mCurrentTabType);
|
||||
handleNimIntent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
setIntent(intent);
|
||||
//这里退出登录,实际上mainActivity是没有销毁的,当从linkme 调起来时候这里需要检查一下登录状态。
|
||||
if (TextUtils.isEmpty(AuthModel.get().getTicket())) {
|
||||
onNeedLogin();
|
||||
return;
|
||||
}
|
||||
onParseIntent();
|
||||
handleNimIntent();
|
||||
}
|
||||
|
||||
private void onParseIntent() {
|
||||
Intent intent = getIntent();
|
||||
if (intent.hasExtra(EXTRA_APP_QUIT)) {
|
||||
onLogout();
|
||||
} else if (intent.hasExtra(Extras.EXTRA_JUMP_P2P)) {
|
||||
Intent data = intent.getParcelableExtra(Extras.EXTRA_DATA);
|
||||
String account = data.getStringExtra(Extras.EXTRA_ACCOUNT);
|
||||
if (!TextUtils.isEmpty(account)) {
|
||||
NimP2PMessageActivity.start(this, account);
|
||||
}
|
||||
} else if (intent.hasExtra(MSG_TAB) && intent.getBooleanExtra(MSG_TAB, false)) {
|
||||
if (mMainTabLayout != null) {
|
||||
mMainTabLayout.setDefaultTabType(MainTabType.TAB_TYPE_MSG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initMaterialView() {
|
||||
avatarLayout.setVisibility(View.GONE);
|
||||
avatarImage.setOnClickListener(this);
|
||||
llDragInfo.setOnClickListener(this);
|
||||
viewClose.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
CleanLeakUtils.fixInputMethodManagerLeak(MainActivity.this);
|
||||
super.onDestroy();
|
||||
ImInitHelper.get().unInit();
|
||||
EventBus.getDefault().unregister(this);
|
||||
stopRoomMinAnim();
|
||||
if (limitEnterRoomHelper != null) {
|
||||
limitEnterRoomHelper.release();
|
||||
}
|
||||
IMBroadcastManager.get().onDestroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* 双击返回键退出
|
||||
*/
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
|
||||
/**
|
||||
* 防止华为机型未加入白名单时按返回键回到桌面再锁屏后几秒钟进程被杀
|
||||
*/
|
||||
try {
|
||||
Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
|
||||
launcherIntent.addCategory(Intent.CATEGORY_HOME);
|
||||
startActivity(launcherIntent);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
moveTaskToBack(false);
|
||||
} catch (Exception e) {
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
try {
|
||||
moveTaskToBack(false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onLoginEvent(LoginEvent event) {
|
||||
onLogin(AuthModel.get().getCurrentUid());
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否绑定手机
|
||||
*/
|
||||
private void checkBindPhone() {
|
||||
BindPhoneActivity.start(context);
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onLogoutEvent(LogoutEvent event) {
|
||||
onLogout();
|
||||
PwdCodeMgr.get().onLogout();
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
public void onLogin(long uid) {
|
||||
Logger.e(TAG, "onLogin Success ~~~~");
|
||||
CrashReport.setUserId(this, uid + "");
|
||||
|
||||
Log.i("checkLostUser", "onLogin");
|
||||
|
||||
//登录成功查询未读信息数量
|
||||
mMainTabLayout.setUnReadDynamicCount(0);
|
||||
int unreadCount = IMMessageManager.get().queryUnreadMsg();
|
||||
mMainTabLayout.setMsgNum(unreadCount);
|
||||
openCommunityNotice();
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onLoadLoginUserInfoEvent(LoadLoginUserInfoEvent event) {
|
||||
firstLoadedUserInfo();
|
||||
}
|
||||
|
||||
public void onLogout() {
|
||||
Logger.e(TAG, "onLogout Success ~~~~");
|
||||
getMvpPresenter().exitRoom();
|
||||
QuickPassLoginAct.start(MainActivity.this);
|
||||
PmDialogShowMrg.get().onLogout();
|
||||
}
|
||||
|
||||
public void onNeedLogin() {
|
||||
NimMiddleActivity.openCommunity = false;
|
||||
QuickPassLoginAct.start(MainActivity.this);
|
||||
}
|
||||
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onKickedOutEvent(KickOutEvent event) {
|
||||
toast("您已被踢下线,若非正常行为,请及时修改密码");
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onReceiveRecentContactChanged(List<RecentContact> imMessages) {
|
||||
|
||||
int countIgnore = 0;
|
||||
for (RecentContact recentContact : imMessages) {
|
||||
|
||||
if (recentContact.getSessionType() == SessionTypeEnum.Team) {
|
||||
Team team = NIMClient.getService(TeamService.class).queryTeamBlock(recentContact.getContactId());
|
||||
if (team != null && team.getMessageNotifyType() == TeamMessageNotifyTypeEnum.Mute) {
|
||||
countIgnore += recentContact.getUnreadCount();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
int unreadCount = IMMessageManager.get().queryUnreadMsg() + countIgnore;
|
||||
mMainTabLayout.setMsgNum(unreadCount);
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onNeedCompleteInfo(NeedCompleteInfoEvent event) {
|
||||
getDialogManager().dismissDialog();
|
||||
UIHelper.showAddInfoAct(this);
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onLoginUserInfoUpdateEvent(LoginUserInfoUpdateEvent event) {
|
||||
int unreadCount = IMMessageManager.get().queryUnreadMsg();
|
||||
mMainTabLayout.setMsgNum(unreadCount);
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
private void updateRoomState() {
|
||||
RoomInfo roomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
||||
if (roomInfo != null) {
|
||||
UserModel.get().getUserInfo(roomInfo.getUid())
|
||||
.subscribe(userInfo -> {
|
||||
if (userInfo != null) {
|
||||
displayAvatarLayout(userInfo.getAvatar(), roomInfo.getTitle(), userInfo.getErbanNo());
|
||||
} else {
|
||||
NimUserInfo nimUserInfo = NimUserInfoCache.getInstance().getUserInfo(roomInfo.getUid() + "");
|
||||
if (nimUserInfo == null) {
|
||||
NimUserInfoCache.getInstance().getUserInfoFromRemote(roomInfo.getUid() + "", new RequestCallbackWrapper<NimUserInfo>() {
|
||||
@Override
|
||||
public void onResult(int i, NimUserInfo nimUserInfo, Throwable throwable) {
|
||||
if (nimUserInfo != null) {
|
||||
displayAvatarLayout(nimUserInfo.getAvatar(), roomInfo.getTitle(), userInfo.getUid());
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
displayAvatarLayout(nimUserInfo.getAvatar(), roomInfo.getTitle(), userInfo.getUid());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void startRoomMinAnim() {
|
||||
roomMinAnim = ObjectAnimator.ofFloat(avatarImage, "rotation", 0f, 360f);
|
||||
roomMinAnim.setDuration(10000);
|
||||
roomMinAnim.setRepeatCount(-1);
|
||||
roomMinAnim.setInterpolator(new LinearInterpolator());
|
||||
roomMinAnim.start();
|
||||
}
|
||||
|
||||
private void stopRoomMinAnim() {
|
||||
if (roomMinAnim != null) {
|
||||
roomMinAnim.cancel();
|
||||
roomMinAnim = null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void displayAvatarLayout(String avatar, String nickName, long uid) {
|
||||
avatarLayout.clearAnimation();
|
||||
avatarLayout.setVisibility(View.VISIBLE);
|
||||
tvName.setText(nickName);
|
||||
tvId.setText("ID:" + uid);
|
||||
userLivingView.start();
|
||||
stopRoomMinAnim();
|
||||
startRoomMinAnim();
|
||||
ImageLoadUtils.loadAvatar(MainActivity.this, avatar, avatarImage);
|
||||
}
|
||||
|
||||
public void onEnter(RoomInfo roomInfo) {
|
||||
updateRoomState();
|
||||
DaemonService.start(this, roomInfo);
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
@Override
|
||||
public void onTabClick(int tabType) {
|
||||
|
||||
Fragment showFragment = fragmentArray.get(tabType);
|
||||
if (showFragment == tempFragment) return;
|
||||
|
||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
if (!showFragment.isAdded()) {
|
||||
transaction.add(R.id.main_fragment, showFragment, null);
|
||||
}
|
||||
transaction.show(showFragment);
|
||||
if (tempFragment != null) transaction.hide(tempFragment);
|
||||
tempFragment = showFragment;
|
||||
if (!isDestroyed()) transaction.commitNowAllowingStateLoss();
|
||||
mCurrentTabType = tabType;
|
||||
|
||||
//每次点击我的都更新当前用户信息
|
||||
if (mCurrentTabType == MainTabType.TAB_TYPE_ME) {
|
||||
UserModel.get().updateCurrentUserInfo().subscribe();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitRoom(RoomInfo roomInfo) {
|
||||
closeOpenRoomAnimation();
|
||||
//ktv退出的时候需要用到
|
||||
if (AudioEngineManager.get().isOpenKtv() && roomInfo != null) {
|
||||
KtvMusicManager.INSTANCE.deleteUserAllChooseMusic(roomInfo.getUid()).subscribe();
|
||||
AudioEngineManager.get().closeKtvModel();
|
||||
}
|
||||
DaemonService.stop(MainActivity.this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 第一次加载到用户信息
|
||||
*/
|
||||
@SuppressLint("CheckResult")
|
||||
private void firstLoadedUserInfo() {
|
||||
//青少年弹窗处理
|
||||
PmDialogShowMrg.get().handle(new WeakReference<>(this));
|
||||
|
||||
//通知栏权限判断
|
||||
NoticationsUiHelper.handle(this, getDialogManager());
|
||||
|
||||
handleChannelPageInfo();
|
||||
|
||||
checkProtocolUpdate();
|
||||
|
||||
// 互动消息未读数量
|
||||
HomeModel.INSTANCE.getUnreadCount(AuthModel.get().getCurrentUid())
|
||||
.compose(bindUntilEvent(ActivityEvent.DESTROY))
|
||||
.subscribe((integer, throwable) -> {
|
||||
if (integer != null) {
|
||||
EventBus.getDefault().post(new UnReadCountEvent(integer));
|
||||
}
|
||||
});
|
||||
checkShowAnchorCardView();
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
private void checkProtocolUpdate() {
|
||||
UserModel.get()
|
||||
.getProtocolInfo()
|
||||
.compose(bindUntilEvent(ActivityEvent.DESTROY))
|
||||
.subscribe(protocolInfo -> {
|
||||
float version = (float) SharedPreferenceUtils.get(ProtocolUpdateDialog.SP_KEY, 0f);
|
||||
//第一次打开APP不弹,因为闪屏页已经弹了!
|
||||
if (version == 0f) {
|
||||
SharedPreferenceUtils.put(ProtocolUpdateDialog.SP_KEY, protocolInfo.getVer());
|
||||
} else if (version < protocolInfo.getVer()) {
|
||||
new ProtocolUpdateDialog(MainActivity.this, protocolInfo).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转优先级 闪屏→linkedMe→邀请码→新用户打招呼引导→渠道指定房间
|
||||
*/
|
||||
@SuppressLint("CheckResult")
|
||||
private void handleChannelPageInfo() {
|
||||
|
||||
if (handleSplashJump()) return;
|
||||
if (handleLinkedJump()) return;
|
||||
|
||||
//渠道落地页和邀请码跳转只需要完善资料后处理一次
|
||||
String spKey = KEY_FLAG_VALID_CHANNEL_PAGE + AuthModel.get().getCurrentUid();
|
||||
if ((boolean) SharedPreferenceUtils.get(spKey, true)) {
|
||||
SharedPreferenceUtils.put(spKey, false);
|
||||
checkInviteUserInRoom();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查邀请码跳转
|
||||
*/
|
||||
@SuppressLint("CheckResult")
|
||||
private void checkInviteUserInRoom() {
|
||||
if (!TextUtils.isEmpty(AddUserInfoFragment.INVITE_USER_CODE)) {
|
||||
ChannelPageModel.get().checkInviteUserInRoom(AddUserInfoFragment.INVITE_USER_CODE)
|
||||
.subscribe(inviteUserInfo -> {
|
||||
if (inviteUserInfo.isInRoom()) {
|
||||
if (inviteUserInfo.getFromType() == 0) {
|
||||
AVRoomActivity.start(context, inviteUserInfo.getRoomUid());
|
||||
} else {
|
||||
AVRoomActivity.startForFromType(context,
|
||||
inviteUserInfo.getRoomUid(),
|
||||
inviteUserInfo.getFromType(),
|
||||
inviteUserInfo.getInviteNick(),
|
||||
String.valueOf(inviteUserInfo.getInviteUid()));
|
||||
}
|
||||
} else {
|
||||
checkNewUserInRoom();
|
||||
}
|
||||
}, throwable -> checkNewUserInRoom());
|
||||
AddUserInfoFragment.INVITE_USER_CODE = "";
|
||||
} else {
|
||||
checkNewUserInRoom();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
private void checkNewUserInRoom() {
|
||||
ChannelPageModel.get().checkNewUserInRoom()
|
||||
.subscribe(newUserHelloInfo -> {
|
||||
if (newUserHelloInfo.getSayHello()) {
|
||||
NewUserHelloDialog.Companion.newInstance(newUserHelloInfo).show(context);
|
||||
} else {
|
||||
checkChannelPageInRoom();
|
||||
}
|
||||
}, throwable -> checkChannelPageInRoom());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理渠道落地页
|
||||
*/
|
||||
@SuppressLint("CheckResult")
|
||||
private void checkChannelPageInRoom() {
|
||||
GameHomeModel.get().getRoomShortcut()
|
||||
.compose(bindUntilEvent(ActivityEvent.DESTROY))
|
||||
.subscribe(uid -> {
|
||||
if (StringUtils.toLong(uid) != 0) {
|
||||
AVRoomActivity.start(context, StringUtils.toLong(uid));
|
||||
}
|
||||
},
|
||||
Throwable::printStackTrace);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true 如果处理了跳转
|
||||
*/
|
||||
private boolean handleSplashJump() {
|
||||
if (getIntent().hasExtra("url") && getIntent().hasExtra("type")) {
|
||||
LogUtil.print("点击了闪屏");
|
||||
//如果没有渠道页,就按原来的逻辑即可
|
||||
int type = getIntent().getIntExtra("type", 0);
|
||||
String url = getIntent().getStringExtra("url");
|
||||
if (type == 3) {
|
||||
Intent intent = new Intent(context, CommonWebViewActivity.class);
|
||||
intent.putExtra("url", url);
|
||||
startActivity(intent);
|
||||
} else if (type == 2) {
|
||||
AVRoomActivity.start(context, Long.parseLong(url));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true 如果处理了跳转
|
||||
*/
|
||||
public boolean handleLinkedJump() {
|
||||
LinkedInfo linkedInfo = LinkedModel.get().getLinkedInfo();
|
||||
LinkedModel.get().setLinkedInfo(null);
|
||||
|
||||
if (linkedInfo == null || linkedInfo.getType() == null) {
|
||||
return false;
|
||||
}
|
||||
LogUtil.print("linkedme跳转");
|
||||
// 跳转
|
||||
if (!StringUtil.isEmpty(linkedInfo.getRoomUid()) && linkedInfo.getType().equals("2")) {
|
||||
AVRoomActivity.start(this, Long.parseLong(linkedInfo.getRoomUid()));
|
||||
} else if (!StringUtil.isEmpty(linkedInfo.getFamilyId()) && linkedInfo.getType().equals("4")) {
|
||||
FamilyHomeActivity.start(this, linkedInfo.getFamilyId());
|
||||
} else if (!TextUtils.isEmpty(linkedInfo.getUrl()) && linkedInfo.getType().equals("3")) {
|
||||
CommonWebViewActivity.start(context, UriProvider.getLinkUrl(linkedInfo.getUrl()));
|
||||
} else if (!TextUtils.isEmpty(linkedInfo.getWorldId()) && linkedInfo.getType().equals("5")) {
|
||||
MiniWorldGuestPageActivity.start(context, linkedInfo.getWorldId());
|
||||
} else if (linkedInfo.getType().equals("6") && !TextUtils.isEmpty(linkedInfo.getWorldId()) &&
|
||||
!TextUtils.isEmpty(linkedInfo.getDynamicId())) {
|
||||
DynamicDetailActivity.start(context, JavaUtil.str2long(linkedInfo.getDynamicId()),
|
||||
JavaUtil.str2long(linkedInfo.getWorldId()), 6);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public LimitEnterRoomHelper getLimitEnterRoomHelper() {
|
||||
if (limitEnterRoomHelper == null) {
|
||||
limitEnterRoomHelper = new LimitEnterRoomHelper();
|
||||
}
|
||||
return limitEnterRoomHelper;
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onImPushMsgPmLimitTimeEvent(ImPushMsgPmLimitTimeEvent event) {
|
||||
//先判断Avroom存不存在,存在的话则不处理,avroom会处理
|
||||
WeakReference<Activity> reference = ActivityStackManager.getInstance().getAvRoomActWeakRef();
|
||||
if (reference != null && reference.get() != null) {
|
||||
return;
|
||||
}
|
||||
getLimitEnterRoomHelper().handleThisContext(this, event.getData(), true, this::handlePmExitRoom);
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onPmDismissAllLimitDialogEvent(PmDismissAllLimitDialogEvent event) {
|
||||
if (limitEnterRoomHelper != null) {
|
||||
limitEnterRoomHelper.dismissDialog();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onUnReadCount(UnReadCountEvent event) {
|
||||
mMainTabLayout.setUnReadDynamicCount(event.getTotal());
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void SquarePublish(SquareTaskEvent event) {
|
||||
if (getDialogManager() != null) {
|
||||
PublishActivity.start(getDialogManager());
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePmExitRoom() {
|
||||
if (AvRoomDataManager.get().mCurrentRoomInfo != null) {
|
||||
closeOpenRoomAnimation();
|
||||
getMvpPresenter().exitRoom();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onCloseMinRoomEvent(CloseMinRoomEvent event) {
|
||||
//如果房间存在,就关闭
|
||||
if (AvRoomDataManager.get().mCurrentRoomInfo != null) {
|
||||
handlePmExitRoom();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理开房限制时长
|
||||
*/
|
||||
public void handleOpenRoomWhenPmLimit(String error) {
|
||||
getLimitEnterRoomHelper().handleThisContext(this, error, false, this::handlePmExitRoom);
|
||||
}
|
||||
|
||||
/**
|
||||
* 云信通知栏跳转的处理
|
||||
*/
|
||||
private void handleNimIntent() {
|
||||
openCommunityNotice();
|
||||
|
||||
Intent intent = getIntent();
|
||||
if (intent == null) {
|
||||
return;
|
||||
}
|
||||
boolean isNimPush = intent.getBooleanExtra(NimMiddleActivity.EXTRA_IS_NIM_PUSH, false);
|
||||
if (isNimPush && mMainTabLayout != null) {
|
||||
mMainTabLayout.setDefaultTabType(MainTabType.TAB_TYPE_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击互动通知通知栏,重启进程打开互动通知页
|
||||
*/
|
||||
private void openCommunityNotice() {
|
||||
if (NimMiddleActivity.delayOpenCommunity) {
|
||||
return;
|
||||
}
|
||||
if (NimMiddleActivity.openCommunity) {
|
||||
NimMiddleActivity.openCommunity = false;
|
||||
if (NimMiddleActivity.skipType == 0) return;
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (NimMiddleActivity.skipType == PushMessageHandler.PAYLOAD_SKIPTYPE_INVITE_FANS &&
|
||||
NimMiddleActivity.payloadUid > 0) {
|
||||
AVRoomActivity.start(MainActivity.this, NimMiddleActivity.payloadUid);
|
||||
} else if (NimMiddleActivity.skipType == PushMessageHandler.PAYLOAD_SKIPTYPE_PRIVATE_MSG &&
|
||||
NimMiddleActivity.payloadUid > 0) {
|
||||
NimP2PMessageActivity.start(MainActivity.this, NimMiddleActivity.payloadUid + "");
|
||||
} else if (NimMiddleActivity.skipType == PushMessageHandler.PAYLOAD_SKIPTYPE_H5 &&
|
||||
!TextUtils.isEmpty(NimMiddleActivity.payloadUrl)) {
|
||||
CommonWebViewActivity.start(MainActivity.this, NimMiddleActivity.payloadUrl);
|
||||
}
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onNeedBindPhoneEvent(NeedBindPhoneEvent event) {
|
||||
checkBindPhone();
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
||||
public void onVisitorUnreadCountEvent(VisitorUnreadCountEvent event) {
|
||||
if (mMainTabLayout != null) {
|
||||
mMainTabLayout.setUnreadVisitorCount(event.getVisitNum());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.avatar_image:
|
||||
case R.id.ll_drag_info:
|
||||
RoomInfo roomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
||||
if (roomInfo != null) {
|
||||
AVRoomActivity.start(MainActivity.this, roomInfo.getUid());
|
||||
} else {
|
||||
toast("-房间信息为空-");
|
||||
}
|
||||
|
||||
break;
|
||||
case R.id.view_close:
|
||||
StatisticManager.Instance().onEvent(StatisticsProtocol.EVENT_ROOM_MINIMIZE_CLOSED,
|
||||
"房间最小化关闭按钮");
|
||||
MainActivity.this.getMvpPresenter().exitRoom();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needSteepStateBar() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setStatusBar() {
|
||||
super.setStatusBar();
|
||||
StatusBarUtil.transparencyBar(this);
|
||||
StatusBarUtil.StatusBarLightMode(this);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user