fix 重复调用弹窗接口

This commit is contained in:
zlzw 2023-09-21 11:14:01 +08:00
parent bcd8f7af52
commit 4e4b5f90bb

View File

@ -49,13 +49,21 @@ public class OpenAdManager {
}
private void init(boolean isShow) {
if (list != null && list.isEmpty()) {
return;
}
LiveNetManager.get(CommonAppContext.getTopActivity())
.activityPopup(new HttpCallback<List<OpenAdModel>>() {
@Override
public void onSuccess(List<OpenAdModel> data) {
if (data == null || data.isEmpty()) {
Log.i(TAG, "onSuccess: 没有数据");
list = new ArrayList<>();
return;
}
list = data;
if (isShow) {
show(TYPE_HOME,false);
show(TYPE_HOME, false);
}
}
@ -67,31 +75,31 @@ public class OpenAdManager {
}
public synchronized void show(int type,boolean isGuard) {
if (list==null) {
public synchronized void show(int type, boolean isGuard) {
if (list == null) {
init(true);
return;
}
showType=type;
showType = type;
for (OpenAdModel model : list) {
if (model.getType() == type) {
if(type==OpenAdModel.TYPE_LIVE && !model.userIsPermission(isGuard)){
if (type == OpenAdModel.TYPE_LIVE && !model.userIsPermission(isGuard)) {
continue;
}
if (runnableMap.containsKey(model.getId())) {
AdRunnable runnable = runnableMap.get(model.getId());
if (runnable != null) {
Log.d(TAG, "reset: "+model);
Log.d(TAG, "reset: " + model);
handler.removeCallbacks(runnable);
runnableMap.remove(model.getId());
}
}
if (!isShow(model)) {
Log.i(TAG, "show: "+model);
Log.i(TAG, "show: " + model);
handler.postDelayed(new AdRunnable(model), model.getDelayShowTime());
}else{
Log.i(TAG, "notshow: "+model);
} else {
Log.i(TAG, "notshow: " + model);
}
}
@ -101,10 +109,10 @@ public class OpenAdManager {
}
public synchronized void dismiss() {
Log.d(TAG, "准备dismiss:"+runnableMap.size() );
Log.d(TAG, "准备dismiss:" + runnableMap.size());
for (Integer model : runnableMap.keySet()) {
AdRunnable runnable = runnableMap.get(model);
Log.d(TAG, "dismiss:"+runnable);
Log.d(TAG, "dismiss:" + runnable);
if (runnable != null) {
runnable.dismiss();
handler.removeCallbacks(runnable);
@ -127,13 +135,14 @@ public class OpenAdManager {
this.model = model;
runnableMap.put(model.getId(), this);
}
public void dismiss(){
Log.e(TAG, "dismiss: "+model );
public void dismiss() {
Log.e(TAG, "dismiss: " + model);
}
@Override
public synchronized void run() {
Log.i(TAG, "run: "+model);
Log.i(TAG, "run: " + model);
if (model == null) {
ToastUtil.showDebug("model为空");
return;
@ -146,7 +155,7 @@ public class OpenAdManager {
ToastUtil.showDebug(model.getId() + "|model展示过了");
return;
}
if(model.getType()!=showType){
if (model.getType() != showType) {
return;
}
showMap.put(model.getId(), true);