diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index 1cf9e05fb..bb6bcaa68 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -30,6 +30,7 @@ import com.tencent.imsdk.v2.V2TIMGroupMemberInfo; import com.tencent.imsdk.v2.V2TIMManager; import com.tencent.imsdk.v2.V2TIMSimpleMsgListener; import com.tencent.imsdk.v2.V2TIMUserInfo; +import com.yunbao.common.manager.OpenAdManager; import com.yunbao.common.utils.MobclickAgent; import com.yunbao.common.BuildConfig; import com.yunbao.common.CommonAppConfig; @@ -37,7 +38,6 @@ import com.yunbao.common.CommonAppContext; import com.yunbao.common.Constants; import com.yunbao.common.bean.AnchorStartLiveBean; import com.yunbao.common.bean.CrashSaveBean; -import com.yunbao.common.dialog.DebugDialog; import com.yunbao.common.event.SudGameSocketImEvent; import com.yunbao.common.manager.imrongcloud.InstructorSendReward; import com.yunbao.common.manager.imrongcloud.InstructorSendRewardProvider; @@ -54,6 +54,7 @@ import com.yunbao.live.socket.SocketRyClient; import com.yunbao.live.utils.LiveImDeletUtil; import com.yunbao.live.views.PortraitLiveManager; import com.yunbao.live.views.RecommendLiveRoomProvider; +import com.yunbao.main.activity.LoginActivity; import com.yunbao.main.activity.MsgSettActivity; import org.greenrobot.eventbus.EventBus; @@ -108,20 +109,25 @@ public class AppContext extends CommonAppContext { @Override public void onActivityDestroyed(@NonNull Activity activity) { + AppManager.getInstance().removeActivity(activity); for (WeakReference reference : activities) { if (reference.get() == activity) { activities.remove(reference); return; } } - AppManager.getInstance().removeActivity(activity); + } @Override public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { activities.add(new WeakReference<>(activity)); + if(activity instanceof LoginActivity){ + AppManager.getInstance().clear(); + } CrashSaveBean.getInstance().setActivitySize(activities); AppManager.getInstance().addActivity(activity); + OpenAdManager.getInstance().dismiss(); } @Override diff --git a/common/src/main/java/com/yunbao/common/bean/OpenAdModel.java b/common/src/main/java/com/yunbao/common/bean/OpenAdModel.java index 3a8777ae9..7bc948149 100644 --- a/common/src/main/java/com/yunbao/common/bean/OpenAdModel.java +++ b/common/src/main/java/com/yunbao/common/bean/OpenAdModel.java @@ -112,7 +112,7 @@ public class OpenAdModel extends BaseModel { public String getUrl() { if (!url.startsWith("http://") || !url.startsWith("https://")) { - url = CommonAppConfig.HOST + url; + url = CommonAppConfig.HOST + (url.startsWith("/") ? url : "/" + url); } return url + "?t=" + System.currentTimeMillis() / 1000; } diff --git a/common/src/main/java/com/yunbao/common/dialog/OpenAdCenterDialogPopup.java b/common/src/main/java/com/yunbao/common/dialog/OpenAdCenterDialogPopup.java index f75c323dc..dc1ddb287 100644 --- a/common/src/main/java/com/yunbao/common/dialog/OpenAdCenterDialogPopup.java +++ b/common/src/main/java/com/yunbao/common/dialog/OpenAdCenterDialogPopup.java @@ -4,13 +4,11 @@ import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.util.Log; -import android.view.ViewGroup; import android.webkit.WebView; import android.widget.ImageView; import android.widget.LinearLayout; import androidx.annotation.NonNull; -import androidx.constraintlayout.widget.ConstraintLayout; import com.lxj.xpopup.XPopup; import com.yunbao.common.R; @@ -28,8 +26,6 @@ import com.yunbao.common.utils.ScreenDimenUtil; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import java.util.Map; - public class OpenAdCenterDialogPopup extends AbsDialogFullScreenPopupWindow { private ImageView mImageView; private LinearLayout contentLayout; @@ -79,11 +75,29 @@ public class OpenAdCenterDialogPopup extends AbsDialogFullScreenPopupWindow { Log.e("-----弹窗-----", "onCreate: 创建弹窗"); contentLayout = findViewById(R.id.content_layout); mClose = findViewById(R.id.close); + int width = ScreenDimenUtil.getInstance().getScreenWdith() - DpUtil.dp2px(10); + int height = (int) (width * 1.5); + if (model.getModel() == OpenAdModel.MODEL_SQUARE) { + height = (int) (width * 1.2); + } + Log.i("-----弹窗-----", "高度:" + height+" 宽度:"+width); + DebugDialog.getInstance(new DebugDialog.DebugDialogRunnable() { + @Override + public void run(DebugDialog dialog) { + dialog.show(); + int width = ScreenDimenUtil.getInstance().getScreenWdith() - DpUtil.dp2px(10); + int height = (int) (width * 1.5); + if (model.getModel() == OpenAdModel.MODEL_SQUARE) { + height = (int) (width * 1.2); + } + dialog.setParams(model.getName()+"弹框高宽","高度:" + height+" 宽度:"+width); + } + }); if (model.getSort() == 1) { - setImage(model); + setImage(model,width,height); findViewById(R.id.layout).setOnClickListener(v -> dismiss()); } else { - setWeb(model); + setWeb(model,width,height); } mClose.setOnClickListener(v -> dismiss()); if (model.getShowTime() > 0) { @@ -91,12 +105,7 @@ public class OpenAdCenterDialogPopup extends AbsDialogFullScreenPopupWindow { } } - private void setWeb(OpenAdModel model) { - int width = ScreenDimenUtil.getInstance().getScreenWdith() - DpUtil.dp2px(20); - int height = (int) (width * 1.4); - if (model.getModel() == OpenAdModel.MODEL_SQUARE) { - height = (int) (width * 1.2); - } + private void setWeb(OpenAdModel model, int width, int height) { WebView mWebView = new WebView(mContext); mWebView.setLayoutParams(new LinearLayout.LayoutParams(width, height)); mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext((Activity) mContext, mWebView).setPageClose(true).setLiveZhuangBana(false), "androidObject"); @@ -121,12 +130,7 @@ public class OpenAdCenterDialogPopup extends AbsDialogFullScreenPopupWindow { contentLayout.addView(mWebView); } - private void setImage(OpenAdModel model) { - int width = ScreenDimenUtil.getInstance().getScreenWdith() - DpUtil.dp2px(20); - int height = (int) (width * 1.4); - if (model.getModel() == OpenAdModel.MODEL_SQUARE) { - height = (int) (width * 1.2); - } + private void setImage(OpenAdModel model, int width, int height) { mImageView = new ImageView(mContext); mImageView.setLayoutParams(new LinearLayout.LayoutParams(width, height)); mImageView.setOnClickListener(v -> { diff --git a/common/src/main/java/com/yunbao/common/manager/OpenAdManager.java b/common/src/main/java/com/yunbao/common/manager/OpenAdManager.java index 4aaa0ea2e..3f32f965c 100644 --- a/common/src/main/java/com/yunbao/common/manager/OpenAdManager.java +++ b/common/src/main/java/com/yunbao/common/manager/OpenAdManager.java @@ -1,10 +1,12 @@ package com.yunbao.common.manager; +import android.app.Activity; import android.content.Context; import android.os.Handler; import android.os.Looper; import android.util.Log; +import com.lzf.easyfloat.enums.ShowPattern; import com.yunbao.common.CommonAppContext; import com.yunbao.common.bean.OpenAdModel; import com.yunbao.common.dialog.DebugDialog; @@ -42,18 +44,6 @@ public class OpenAdManager { private OpenAdManager() { showMap = new HashMap<>(); - DebugDialog.getInstance(new DebugDialog.DebugDialogRunnable() { - @Override - public void run(DebugDialog dialog) { - dialog.show(); - onItemClickListener = new OnItemClickListener() { - @Override - public void onItemClick(String bean, int position) { - dialog.setParams(bean, "剩余:" + position); - } - }; - } - }); init(false); } @@ -65,6 +55,7 @@ public class OpenAdManager { } public void reset() { + Log.i(TAG, "reset: "); next(); } @@ -80,13 +71,14 @@ public class OpenAdManager { if (list != null && list.isEmpty()) { return; } - Context context = CommonAppContext.getTopActivity(); + Context context = AppManager.getInstance().getMainActivity(); if (context == null) { context = CommonAppContext.sInstance; } if (context == null) { return; } + LiveNetManager.get(context).activityPopup(new HttpCallback>() { @Override public void onSuccess(List data) { @@ -126,6 +118,19 @@ public class OpenAdManager { if (System.currentTimeMillis() - showTime < 100) { return; } + DebugDialog.getInstance(new DebugDialog.DebugDialogRunnable() { + @Override + public void run(DebugDialog dialog) { + dialog.setShowPattern(ShowPattern.CURRENT_ACTIVITY); + dialog.show(); + onItemClickListener = new OnItemClickListener() { + @Override + public void onItemClick(String bean, int position) { + dialog.setParams(bean, "剩余:" + position); + } + }; + } + }); showTime = System.currentTimeMillis(); for (OpenAdModel model : list) { if (model.getType() == type) { @@ -247,6 +252,17 @@ public class OpenAdManager { Log.i(TAG, "展示过:" + model); return; } + if (model.getType() == OpenAdModel.TYPE_HOME && !AppManager.getInstance().isMainActivity()) { + Log.i(TAG, "首页类型弹窗,但当前不是首页"); + dismiss(); + return; + } + if (model.getType() == TYPE_LIVE && !AppManager.getInstance().isLiveActivity()) { + Log.i(TAG, "直播类型弹窗,但当前不是直播"); + dismiss(); + return; + } + showMap.put(model.getId(), true); if (model.getShowModel() == OpenAdModel.SHOW_DIY) { String nextTime = String.valueOf(System.currentTimeMillis() + (Long.parseLong(model.getSection()) * 60 * 1000)); diff --git a/common/src/main/java/com/yunbao/common/utils/AppManager.java b/common/src/main/java/com/yunbao/common/utils/AppManager.java index f27c2815a..16580d954 100644 --- a/common/src/main/java/com/yunbao/common/utils/AppManager.java +++ b/common/src/main/java/com/yunbao/common/utils/AppManager.java @@ -1,6 +1,7 @@ package com.yunbao.common.utils; import android.app.Activity; +import android.util.Log; import com.yunbao.common.BuildConfig; @@ -11,7 +12,7 @@ public class AppManager { private static Stack activityStack; public AppManager() { - activityStack=new Stack<>(); + activityStack = new Stack<>(); } /** @@ -36,18 +37,38 @@ public class AppManager { return activity; } } - return null; + return getLastActivity(); } public Activity getLiveActivity() { for (Activity activity : activityStack) { - if (activity.getClass().getSimpleName().contains("LiveAudienceActivity")) { + if (activity.getClass().getSimpleName().contains("LiveActivity")) { return activity; } } return null; } + public void clear() { + activityStack.clear(); + } + + public boolean isMainActivity() { + Activity lastActivity = getLastActivity(); + if(lastActivity==null){ + return false; + } + return lastActivity.getClass().getSimpleName().contains("MainActivity"); + } + + public boolean isLiveActivity() { + Activity lastActivity = getLastActivity(); + if(lastActivity==null){ + return false; + } + return lastActivity.getClass().getSimpleName().contains("LiveActivity"); + } + public static class SingleApp { public static AppManager INSTANCE = new AppManager(); } @@ -59,6 +80,10 @@ public class AppManager { if (activityStack == null) { activityStack = new Stack(); } + //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>class com.yunbao.main.activity.MsgAddressBookActivity + if (getActivity(activity.getClass()) != null) { + activityStack.remove(getActivity(activity.getClass())); + } activityStack.add(activity); }