Files
yinmeng-android/app/src/main/java/com/mango/moshen/application/GlobalHandleManager.java
2022-10-13 17:21:30 +08:00

156 lines
5.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.mango.moshen.application;
import android.app.Activity;
import com.mango.core.activity.bean.LotteryInfo;
import com.mango.core.level.event.CharmLevelUpEvent;
import com.mango.core.level.event.LevelUpEvent;
import com.mango.core.manager.AvRoomDataManager;
import com.mango.core.pay.bean.ShowCommonWebEvent;
import com.mango.core.pay.event.NewUserChargeEvent;
import com.mango.core.recall.bean.CheckLostUserInfo;
import com.mango.core.recall.event.CheckLostUserEvent;
import com.mango.core.relation.cp.CpInviteInfo;
import com.mango.core.upgrade.event.ImPushUpdateAppEvent;
import com.mango.core.user.UserModel;
import com.mango.core.utils.ActivityUtil;
import com.mango.core.utils.SharedPreferenceUtils;
import com.mango.core.vip.VipUpgradeEvent;
import com.mango.moshen.avroom.newuserchargegift.NewUserChargePrizeDialog;
import com.mango.moshen.relation.cp.dialog.CpGlobalDialog;
import com.mango.moshen.ui.webview.CommonWebViewActivity;
import com.mango.moshen.ui.widget.LevelUpDialog;
import com.mango.moshen.ui.widget.RecallDialog;
import com.mango.moshen.ui.widget.lottery_dialog.LotteryDialogManager;
import com.mango.moshen.utils.UserUtils;
import com.mango.moshen.vip.VipUpgradeDialog;
import com.tencent.bugly.beta.Beta;
import com.trello.rxlifecycle3.components.support.RxAppCompatActivity;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.lang.ref.WeakReference;
/**
* 全局处理比如App弹窗
* create by lvzebiao @2019/8/14
*/
public class GlobalHandleManager {
private GlobalHandleManager() {
}
public static GlobalHandleManager get() {
return Helper.INSTANCE;
}
public void init() {
EventBus.getDefault().register(this);
}
public void unInit() {
EventBus.getDefault().unregister(this);
}
public Activity getActivity() {
WeakReference<Activity> weakReference = ActivityStackManager.getInstance()
.getTopUpgradeWeakRef();
if (weakReference == null || weakReference.get() == null) {
return null;
}
return weakReference.get();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onImPushUpdateAppEvent(ImPushUpdateAppEvent event) {
Activity activity = getActivity();
if (activity == null) return;
if (ActivityUtil.isCanShowAppCompatDialog(activity) && activity instanceof RxAppCompatActivity) {
Beta.checkUpgrade();
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onReceiveLotteryActivity(LotteryInfo lotteryInfo) {
Activity activity = getActivity();
if (activity == null) return;
if (UserUtils.isPmMode()) return;
LotteryDialogManager.checkLotteryDialog(activity);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onVipUpgradeEvent(VipUpgradeEvent vipUpgradeEvent) {
Activity activity = getActivity();
if (activity == null) return;
if (UserUtils.isPmMode()) return;
UserModel.get().onlyUpdateLoginUserInfoCache();
VipUpgradeDialog.newInstance(vipUpgradeEvent.getVipInfo()).show(activity);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onCpInviteEvent(CpInviteInfo entity) {
Activity activity = getActivity();
if (activity == null) return;
if (UserUtils.isPmMode()) return;
CpGlobalDialog.newInstance(entity, activity).openDialog();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onNewUserChargeEvent(NewUserChargeEvent event) {
Activity activity = getActivity();
if (activity == null) return;
if (UserUtils.isPmMode()) return;
new NewUserChargePrizeDialog(activity, event.getChargeProdTitle(), event.getFirstChargeRewardList()).openDialog();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onShowCommonWebEvent(ShowCommonWebEvent event) {
if (UserUtils.isPmMode()) return;
CommonWebViewActivity.start(event.getContext(), event.getUrl());
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onReceiveRecallStatus(CheckLostUserEvent event) {
Activity activity = getActivity();
if (activity == null) return;
//如果没有获取到当前登录用户的信息,不弹出提示
if (UserModel.get().getCacheLoginUserInfo() == null) {
return;
}
if (UserUtils.isPmMode()) return;
CheckLostUserInfo checkLostUserInfo = (CheckLostUserInfo) event.getData();
boolean goBackOnce = (boolean) SharedPreferenceUtils.get(RecallDialog.GO_BACK_ONCE, false);
if (!goBackOnce && !event.isFailed() && checkLostUserInfo.isLostUser() && !checkLostUserInfo.isClaimedAward())
RecallDialog.start(activity);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onReceiveLevelUpActivity(LevelUpEvent event) {
Activity activity = getActivity();
if (activity == null) return;
if (AvRoomDataManager.get().isSelfGamePlaying()) return;
if (UserUtils.isPmMode()) return;
LevelUpDialog.start(activity, event.getLevelName(), true);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onReceiveCharmLevelUpActivity(CharmLevelUpEvent event) {
Activity activity = getActivity();
if (activity == null) return;
if (AvRoomDataManager.get().isSelfGamePlaying()) return;
if (UserUtils.isPmMode()) return;
LevelUpDialog.start(activity, event.getLevelName(), false);
}
private static final class Helper {
private static final GlobalHandleManager INSTANCE = new GlobalHandleManager();
}
}