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