|
|
@@ -14,12 +14,14 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.xzjmyk.pm.activity.AppConstant;
|
|
|
import com.xzjmyk.pm.activity.MyApplication;
|
|
|
import com.xzjmyk.pm.activity.bean.Friend;
|
|
|
+import com.xzjmyk.pm.activity.bean.message.SubMessage;
|
|
|
import com.xzjmyk.pm.activity.bean.message.SubscriptionMessage;
|
|
|
import com.xzjmyk.pm.activity.bean.message.XmppMessage;
|
|
|
import com.xzjmyk.pm.activity.broadcast.MsgBroadcast;
|
|
|
import com.xzjmyk.pm.activity.db.dao.ChatMessageDao;
|
|
|
import com.xzjmyk.pm.activity.db.dao.FriendDao;
|
|
|
import com.xzjmyk.pm.activity.db.dao.MessageDao;
|
|
|
+import com.xzjmyk.pm.activity.db.dao.SubsDao;
|
|
|
import com.xzjmyk.pm.activity.sortlist.BaseSortModel;
|
|
|
import com.xzjmyk.pm.activity.sortlist.PingYinUtil;
|
|
|
import com.xzjmyk.pm.activity.ui.MainActivity;
|
|
|
@@ -55,16 +57,14 @@ public class MessagePresenter implements HttpHandler.OnResultListener {
|
|
|
private final int LOAD_SUBS = 0x12;
|
|
|
private final int LOAD_PROCESS = 0x13;
|
|
|
|
|
|
- private final String SUB_READ_TIME = CommonUtil.getMaster() + "SUB_READ_TIME";//订阅好点击阅读时间
|
|
|
- private final String SUB_LOAD_TIME = CommonUtil.getMaster() + "SUB_LOAD_TIME";//订阅好下拉时间时间
|
|
|
+ private String SUB_READ_TIME;//订阅好点击阅读时间
|
|
|
|
|
|
private List<BaseSortModel<Friend>> mFriendList;
|
|
|
|
|
|
private Comparator<BaseSortModel<Friend>> erpComparator;
|
|
|
private IMessageView iMessageView;
|
|
|
private MainActivity ct;
|
|
|
- private String subReadTime;
|
|
|
- private String subLoadTime;
|
|
|
+ private String subReadTime;//订阅号点击时间
|
|
|
|
|
|
private String filter;//搜索数据
|
|
|
private int emnewsNum, subsNum, processNum, taskNum;//红点消息分类数量
|
|
|
@@ -91,8 +91,6 @@ public class MessagePresenter implements HttpHandler.OnResultListener {
|
|
|
if (iMessageView == null)
|
|
|
new NullPointerException("IMessageView 不能为空");
|
|
|
this.iMessageView = iMessageView;
|
|
|
- subReadTime = PreferenceUtils.getString(SUB_READ_TIME);
|
|
|
- subLoadTime = PreferenceUtils.getString(SUB_LOAD_TIME);
|
|
|
if (RECEIVER_LIST != null && RECEIVER_LIST.length > 0) {
|
|
|
IntentFilter dateFilter = new IntentFilter();
|
|
|
for (String f : RECEIVER_LIST)
|
|
|
@@ -102,14 +100,34 @@ public class MessagePresenter implements HttpHandler.OnResultListener {
|
|
|
}
|
|
|
|
|
|
public void loadData() {
|
|
|
+ SUB_READ_TIME = CommonUtil.getMaster() + "SUB_READ_TIME";//订阅好点击阅读时间
|
|
|
+ subReadTime = PreferenceUtils.getString(SUB_READ_TIME);
|
|
|
loadERPNews();//获取消息
|
|
|
loadTaskData();//获取任务接口
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(subLoadTime) || subLoadTime.compareTo(TimeUtils.s_long_2_str(System.currentTimeMillis())) < 0) {
|
|
|
- loadSubData();//获取订阅号接口
|
|
|
- PreferenceUtils.putString(SUB_LOAD_TIME, TimeUtils.s_long_2_str(System.currentTimeMillis()));
|
|
|
- }
|
|
|
loadProcessToDo();//获取审批流接口
|
|
|
+// loadSubMessage(); //TODO 发布版本先隐藏
|
|
|
+ loadSubData();
|
|
|
+ }
|
|
|
+
|
|
|
+ //下拉订阅号数据
|
|
|
+ private void loadSubMessage() {
|
|
|
+ //先判断数据库中是否有数据
|
|
|
+ List<SubMessage> messages = SubsDao.getInstance().queryByDate(TimeUtils.s_long_2_str(System.currentTimeMillis()));
|
|
|
+ if (ListUtils.isEmpty(messages)) {//如果没有数据,就去下载数据
|
|
|
+ loadSubData();
|
|
|
+ } else {//如果有数据,就判断是否显示红点
|
|
|
+ if (StringUtils.isEmpty(subReadTime) || subReadTime.compareTo(TimeUtils.s_long_2_str(System.currentTimeMillis())) < 0) {
|
|
|
+ //不是今天点击的就,显示订阅数量
|
|
|
+ int num = 0;
|
|
|
+ for (SubMessage e : messages) {
|
|
|
+ if (e.getStatus() == 0)
|
|
|
+ num += 1;
|
|
|
+ }
|
|
|
+ subsNum = num;
|
|
|
+ updateForUnReader();
|
|
|
+ iMessageView.updateHeaderView(2, num, num > 0 ? messages.get(0).getTitle() : "");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -296,7 +314,7 @@ public class MessagePresenter implements HttpHandler.OnResultListener {
|
|
|
updateForUnReader();
|
|
|
}
|
|
|
|
|
|
- private void handlerSub(JSONObject object) {
|
|
|
+ private void handlerSub(final JSONObject object) {
|
|
|
if (!StringUtils.isEmpty(subReadTime) && subReadTime.compareTo(TimeUtils.s_long_2_str(System.currentTimeMillis())) >= 0)
|
|
|
return;
|
|
|
List<SubscriptionMessage> messages = null;
|
|
|
@@ -308,12 +326,53 @@ public class MessagePresenter implements HttpHandler.OnResultListener {
|
|
|
num += 1;
|
|
|
}
|
|
|
}
|
|
|
+ //TODO 发布版本先隐藏
|
|
|
+// ThreadUtil.getInstance().addTask(new Runnable() {
|
|
|
+// @Override
|
|
|
+// public void run() {
|
|
|
+// try {
|
|
|
+// saveSubs2Db(object);
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// });
|
|
|
subsNum = num;
|
|
|
updateForUnReader();
|
|
|
- //TODO 判断订阅有没有新消息没读
|
|
|
iMessageView.updateHeaderView(2, num, num > 0 ? messages.get(0).getTITLE_() : "");
|
|
|
}
|
|
|
|
|
|
+ private void saveSubs2Db(JSONObject o) throws Exception {
|
|
|
+ JSONArray array = o.getJSONArray("data");
|
|
|
+ if (ListUtils.isEmpty(array)) return;
|
|
|
+ SubMessage message = null;
|
|
|
+ JSONObject object = null;
|
|
|
+ List<SubMessage> chche = new ArrayList<>();
|
|
|
+ message = new SubMessage();
|
|
|
+ message.setDate(TimeUtils.s_long_2_str(System.currentTimeMillis()));
|
|
|
+ message.setRead(true);
|
|
|
+ message.setStatus(0);
|
|
|
+ chche.add(message);
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
+ object = array.getJSONObject(i);
|
|
|
+ message = new SubMessage();
|
|
|
+ message.setCreateTime(object.getLong("CREATEDATE_"));
|
|
|
+ int status = object.getInteger("STATUS_");
|
|
|
+ message.setStatus(i == 0 ? 1 : 2);
|
|
|
+ message.setTitle(object.getString("TITLE_"));
|
|
|
+ message.setSubTitle(object.getString("SUMDATA_"));
|
|
|
+ message.setRead(status == 0 ? false : true);
|
|
|
+ message.setId(object.getInteger("ID_"));
|
|
|
+ message.setNumId(object.getInteger("NUM_ID_"));
|
|
|
+ message.setInstanceId(object.getInteger("INSTANCE_ID_"));
|
|
|
+ if (message.getCreateTime() == 0) continue;
|
|
|
+ message.setDate(TimeUtils.s_long_2_str(message.getCreateTime()));
|
|
|
+ chche.add(message);
|
|
|
+ }
|
|
|
+ if (ListUtils.isEmpty(chche)) return;
|
|
|
+ SubsDao.getInstance().createOrUpdata(chche);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 处理消息红点消息
|
|
|
*
|