diff --git a/common/src/main/java/com/yunbao/common/dialog/DebugDialog.java b/common/src/main/java/com/yunbao/common/dialog/DebugDialog.java index bde2acfbd..199516ba6 100644 --- a/common/src/main/java/com/yunbao/common/dialog/DebugDialog.java +++ b/common/src/main/java/com/yunbao/common/dialog/DebugDialog.java @@ -139,7 +139,7 @@ public class DebugDialog { EasyFloat.updateFloat("debug"); } }); - params.put("发包时间:"+ CommonAppConfig.BUILD_TIME, textView); + params.put("发包时间:" + CommonAppConfig.BUILD_TIME, textView); adapter.setParamMap(params); EasyFloat.with(mContext) 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 09b3f58e4..ed474af5f 100644 --- a/common/src/main/java/com/yunbao/common/dialog/OpenAdCenterDialogPopup.java +++ b/common/src/main/java/com/yunbao/common/dialog/OpenAdCenterDialogPopup.java @@ -4,6 +4,9 @@ import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.util.Log; +import android.view.View; +import android.view.ViewTreeObserver; +import android.view.WindowInsets; import android.webkit.WebView; import android.widget.ImageView; import android.widget.LinearLayout; @@ -11,6 +14,7 @@ import android.widget.LinearLayout; import androidx.annotation.NonNull; import com.lxj.xpopup.XPopup; +import com.lzf.easyfloat.enums.ShowPattern; import com.yunbao.common.R; import com.yunbao.common.activity.WebViewActivity; import com.yunbao.common.bean.OpenAdModel; @@ -75,34 +79,49 @@ 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() { + + + contentLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + boolean isShow = false; + @Override - public void run(DebugDialog dialog) { - dialog.show(); + public void onGlobalLayout() { + if (isShow) + return; + isShow = true; 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); + Log.i("-----弹窗-----", "高度:" + height + " 宽度:" + width + " 布局宽度: " + contentLayout.getWidth() + " 屏幕宽度: " + ScreenDimenUtil.getInstance().getScreenWdith()); + /*DebugDialog.getInstance(new DebugDialog.DebugDialogRunnable() { + @Override + public void run(DebugDialog dialog) { + dialog.setShowPattern(ShowPattern.ALL_TIME); + dialog.show(); + int width = contentLayout.getWidth() - DpUtil.dp2px(10); + int height = (int) (width * 1.5); + if (model.getModel() == OpenAdModel.MODEL_SQUARE) { + height = (int) (width * 1.2); + } + Log.i("-----弹窗-----", "弹框debug高宽 高度:" + height + " 宽度:" + width); + dialog.setParams(model.getName() + "弹框高宽", "高度:" + height + " 宽度:" + width); + } + });*/ + if (model.getPopupSort() == 1) { + setImage(model, width, height); + findViewById(R.id.layout).setOnClickListener(v -> dismiss()); + } else { + setWeb(model, width, height); + } + mClose.setOnClickListener(v -> dismiss()); + if (model.getShowTime() > 0) { + mClose.postDelayed(OpenAdCenterDialogPopup.this::dismiss, model.getShowTime()); + } } }); - if (model.getPopupSort() == 1) { - setImage(model,width,height); - findViewById(R.id.layout).setOnClickListener(v -> dismiss()); - } else { - setWeb(model,width,height); - } - mClose.setOnClickListener(v -> dismiss()); - if (model.getShowTime() > 0) { - mClose.postDelayed(this::dismiss, model.getShowTime()); - } + } private void setWeb(OpenAdModel model, int width, int height) { @@ -125,13 +144,14 @@ public class OpenAdCenterDialogPopup extends AbsDialogFullScreenPopupWindow { } else { url += "?uid=" + IMLoginManager.get(mContext).getUserInfo().getId() + "&token=" + IMLoginManager.get(mContext).getUserInfo().getToken(); } - Log.i("-----弹窗-----", "setWeb: "+url); + Log.i("-----弹窗-----", "setWeb: " + url); mWebView.loadUrl(url); contentLayout.addView(mWebView); } private void setImage(OpenAdModel model, int width, int height) { mImageView = new ImageView(mContext); + mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP); mImageView.setLayoutParams(new LinearLayout.LayoutParams(width, height)); mImageView.setOnClickListener(v -> { if ("home_page_banner_battle".equals(model.getOriginalUrl())) { 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 1e5f1d7d3..b49247ddd 100644 --- a/common/src/main/java/com/yunbao/common/manager/OpenAdManager.java +++ b/common/src/main/java/com/yunbao/common/manager/OpenAdManager.java @@ -50,9 +50,16 @@ public class OpenAdManager { public void close() { dismiss(); + clear(); + } + + public void clear() { runnableMap.clear(); showMap.clear(); list.clear(); + waitRunnableMap.clear(); + list = null; + runNowRunnable = null; } public void reset() { @@ -107,7 +114,12 @@ public class OpenAdManager { } private static long showTime = 0; - private OnItemClickListener onItemClickListener; + private OnItemClickListener onItemClickListener=new OnItemClickListener() { + @Override + public void onItemClick(String bean, int position) { + + } + }; public synchronized void show(int type, boolean isGuard) { showType = type; @@ -119,10 +131,10 @@ public class OpenAdManager { if (System.currentTimeMillis() - showTime < 100) { return; } - DebugDialog.getInstance(new DebugDialog.DebugDialogRunnable() { + /*DebugDialog.getInstance(new DebugDialog.DebugDialogRunnable() { @Override public void run(DebugDialog dialog) { - dialog.setShowPattern(ShowPattern.CURRENT_ACTIVITY); + dialog.setShowPattern(ShowPattern.ALL_TIME); dialog.show(); onItemClickListener = new OnItemClickListener() { @Override @@ -131,7 +143,7 @@ public class OpenAdManager { } }; } - }); + });*/ showTime = System.currentTimeMillis(); waitRunnableMap.clear(); runnableMap.clear(); @@ -258,30 +270,51 @@ public class OpenAdManager { Log.i(TAG, "run: " + model); if (model == null) { ToastUtil.showDebug("model为空"); + if (onItemClickListener != null) { + onItemClickListener.onItemClick("", -2); + } return; } if (!model.isInTime()) { ToastUtil.showDebug("不在展示时间内:" + model.getStartTime() + "|" + model.getEndTime()); + if (onItemClickListener != null) { + onItemClickListener.onItemClick("", -2); + } return; } if (isShow(model)) { ToastUtil.showDebug(model.getId() + "|model展示过了"); + if (onItemClickListener != null) { + onItemClickListener.onItemClick("", -2); + } return; } if (model.getType() != showType) { + if (onItemClickListener != null) { + onItemClickListener.onItemClick("", -2); + } return; } if (isShow(model)) { Log.i(TAG, "展示过:" + model); + if (onItemClickListener != null) { + onItemClickListener.onItemClick("", -2); + } return; } if (model.getType() == OpenAdModel.TYPE_HOME && !AppManager.getInstance().isMainActivity()) { Log.i(TAG, "首页类型弹窗,但当前不是首页"); + if (onItemClickListener != null) { + onItemClickListener.onItemClick("", -2); + } dismiss(); return; } if (model.getType() == TYPE_LIVE && !AppManager.getInstance().isLiveActivity()) { Log.i(TAG, "直播类型弹窗,但当前不是直播"); + if (onItemClickListener != null) { + onItemClickListener.onItemClick("", -2); + } dismiss(); return; } 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 6d686ce7d..33c5c65c4 100644 --- a/common/src/main/java/com/yunbao/common/utils/AppManager.java +++ b/common/src/main/java/com/yunbao/common/utils/AppManager.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.util.Log; import com.yunbao.common.BuildConfig; +import com.yunbao.common.manager.OpenAdManager; import java.util.Stack; @@ -51,19 +52,21 @@ public class AppManager { public void clear() { activityStack.clear(); + OpenAdManager.getInstance().clear(); } public boolean isMainActivity() { Activity lastActivity = getLastActivity(); - if(lastActivity==null){ + if (lastActivity == null) { return false; } return lastActivity.getClass().getSimpleName().contains("MainActivity"); } -//TODO 首页类型没展示完进直播间会不展示直播间的。 + + //TODO 首页类型没展示完进直播间会不展示直播间的。 public boolean isLiveActivity() { Activity lastActivity = getLastActivity(); - if(lastActivity==null){ + if (lastActivity == null) { return false; } return lastActivity.getClass().getSimpleName().contains("LiveAudienceActivity"); diff --git a/common/src/main/res/layout/dialog_open_center_ad.xml b/common/src/main/res/layout/dialog_open_center_ad.xml index 3e09feb6c..a67588370 100644 --- a/common/src/main/res/layout/dialog_open_center_ad.xml +++ b/common/src/main/res/layout/dialog_open_center_ad.xml @@ -12,11 +12,12 @@ android:layout_height="wrap_content" android:layout_marginStart="20dp" android:layout_marginEnd="20dp" + android:layout_marginBottom="12dp" android:orientation="vertical" - app:layout_constraintBottom_toTopOf="@+id/close" + app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - android:layout_marginBottom="12dp"> + app:layout_constraintTop_toTopOf="parent"> @@ -25,10 +26,10 @@ android:id="@+id/close" android:layout_width="24dp" android:layout_height="24dp" - android:layout_marginBottom="202dp" - app:layout_constraintBottom_toBottomOf="parent" + android:layout_marginTop="24dp" app:layout_constraintEnd_toEndOf="@+id/content_layout" app:layout_constraintStart_toStartOf="@+id/content_layout" + app:layout_constraintTop_toBottomOf="@+id/content_layout" app:srcCompat="@mipmap/ic_open_ad_close" /> \ No newline at end of file