udpate
This commit is contained in:
parent
acf20107c1
commit
cff607eabb
@ -1,34 +1,31 @@
|
||||
package com.yunbao.common.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import com.yunbao.common.CommonAppContext;
|
||||
import com.yunbao.common.bean.BaseModel;
|
||||
import com.yunbao.common.bean.MessageSayHiBean;
|
||||
import com.yunbao.common.bean.MessageSayHiStartBean;
|
||||
import com.yunbao.common.bean.MessageUserInfoBean;
|
||||
import com.yunbao.common.dialog.MessageChatNotifyDialog;
|
||||
import com.yunbao.common.dialog.MessageSayHiNotifyDialog;
|
||||
import com.yunbao.common.http.base.HttpCallback;
|
||||
import com.yunbao.common.http.live.LiveNetManager;
|
||||
import com.yunbao.common.interfaces.OnItemClickListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class MessageSayHiNotifyManager {
|
||||
private static final String TAG = "打招呼定时器";
|
||||
private static MessageSayHiNotifyManager instance;
|
||||
private Timer timer = null;
|
||||
private Handler timer = new Handler(Looper.getMainLooper());
|
||||
private boolean isInit = false;
|
||||
private boolean isStopShow = false;
|
||||
private boolean isShowDialog = false;
|
||||
private boolean isRun = false;
|
||||
private boolean isCancelDialog = true;
|
||||
private Runnable runnable;
|
||||
private MessageSayHiBean hiBean;
|
||||
private List<MessageUserInfoBean> startListNotifyList = new ArrayList<>();
|
||||
private String lastActivity;
|
||||
@ -53,12 +50,11 @@ public class MessageSayHiNotifyManager {
|
||||
return;
|
||||
}
|
||||
isCancelDialog = data.isCancelDialog();
|
||||
timer = new Timer();
|
||||
timer.schedule(createTask(), data.getNextTime() * 1000L);
|
||||
hiBean = new MessageSayHiBean();
|
||||
hiBean.setModel("init");
|
||||
hiBean.setNextTime(data.getNextTime());
|
||||
hiBean.setOldTime(data.getNextTime());
|
||||
timer.postDelayed(createTask(), data.getNextTime() * 1000L);
|
||||
Log.i(TAG, "onSuccess: 初始化定时器,第一轮时间:" + data.getNextTime());
|
||||
}
|
||||
|
||||
@ -83,13 +79,12 @@ public class MessageSayHiNotifyManager {
|
||||
Log.i(TAG, "onSuccess: 定时器为关,不再轮训 " + data);
|
||||
return;
|
||||
}
|
||||
if (data.getStatus() == 0) {
|
||||
timer = new Timer();
|
||||
timer.schedule(createTask(), data.getNextTime() * 1000L);
|
||||
return;
|
||||
}
|
||||
data.setOldTime(hiBean.getNextTime());
|
||||
hiBean = data;
|
||||
if (data.getUser() == null || data.getStatus()==0) {
|
||||
timer.postDelayed(createTask(), data.getNextTime() * 1000L);
|
||||
return;
|
||||
}
|
||||
Log.i(TAG, "onSuccess: 展示弹框时间:" + data);
|
||||
showDialog();
|
||||
}
|
||||
@ -110,17 +105,16 @@ public class MessageSayHiNotifyManager {
|
||||
return;
|
||||
}
|
||||
if (hiBean == null) return;
|
||||
Log.i(TAG, "reload: 重载定时器,当前Activity:" + AppManager.getInstance().getLastActivity() + "|等待:" + hiBean.getNextTime());
|
||||
Log.i(TAG, "reload: 重载定时器,当前Activity:" + AppManager.getInstance().getLastActivity() + "|等待:" + hiBean);
|
||||
isStopShow = false;
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
timer.removeCallbacks(runnable);
|
||||
}
|
||||
timer = new Timer();
|
||||
if (hiBean.getStatus() == -2) {
|
||||
Log.i(TAG, "reload: -2的bean = " + hiBean);
|
||||
timer.schedule(createTask(), hiBean.getOldTime() * 1000L);
|
||||
timer.postDelayed(createTask(), hiBean.getOldTime() * 1000L);
|
||||
} else {
|
||||
timer.schedule(createTask(), hiBean.getNextTime() * 1000L);
|
||||
timer.postDelayed(createTask(), hiBean.getNextTime() * 1000L);
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,41 +127,30 @@ public class MessageSayHiNotifyManager {
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
Log.i(TAG, "stop: 停止定时器,当前Activity:" + AppManager.getInstance().getLastActivity());
|
||||
Log.i(TAG, "stop: 停止定时器,当前Activity:" + AppManager.getInstance().getLastActivity() + "|" + hiBean);
|
||||
isStopShow = true;
|
||||
if(hiBean!=null) {
|
||||
if (hiBean != null) {
|
||||
hiBean.setStatus(-2);
|
||||
}
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
timer.removeCallbacks(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
private TimerTask createTask() {
|
||||
private Runnable createTask() {
|
||||
isRun = true;
|
||||
return new TimerTask() {
|
||||
runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
}
|
||||
cancel();
|
||||
if (hiBean.getStatus() == -2) {
|
||||
if (hiBean != null && hiBean.getStatus() == -2 && !"init".equals(hiBean.getModel())) {
|
||||
showDialog();
|
||||
return;
|
||||
}
|
||||
Log.i(TAG, "run: 定时器到点,启动下一轮");
|
||||
next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cancel() {
|
||||
isRun = false;
|
||||
Log.i(TAG, "cancel: 定时器内部取消");
|
||||
return super.cancel();
|
||||
}
|
||||
};
|
||||
return runnable;
|
||||
}
|
||||
|
||||
public void push(Context mContext, MessageUserInfoBean userInfo) {
|
||||
@ -200,7 +183,7 @@ public class MessageSayHiNotifyManager {
|
||||
return;
|
||||
}
|
||||
if (isStopShow) {
|
||||
Log.i(TAG, "showDialog: 非目标页面,停止展示");
|
||||
Log.i(TAG, "showDialog: 非目标页面,停止展示:" + hiBean);
|
||||
hiBean.setStatus(-2);
|
||||
lastActivity = null;
|
||||
isRun = false;
|
||||
@ -235,8 +218,7 @@ public class MessageSayHiNotifyManager {
|
||||
|
||||
Log.i(TAG, "onSuccess: 启动定时器,下一轮时间:" + hiBean.getNextTime() + "秒");
|
||||
hiBean.setStatus(1);
|
||||
timer = new Timer();
|
||||
timer.schedule(createTask(), hiBean.getNextTime() * 1000L);
|
||||
timer.postDelayed(createTask(), hiBean.getNextTime() * 1000L);
|
||||
}).setCancelable(isCancelDialog)
|
||||
.showDialog();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user