|
|
@@ -3,6 +3,9 @@
|
|
|
*/
|
|
|
package kr.co.zumo.app.lifeplus.view.screen.notification;
|
|
|
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Looper;
|
|
|
+
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -15,6 +18,7 @@ import kr.co.zumo.app.lifeplus.model.Model;
|
|
|
import kr.co.zumo.app.lifeplus.model.module.APIError;
|
|
|
import kr.co.zumo.app.lifeplus.model.module.APIModuleListener;
|
|
|
import kr.co.zumo.app.lifeplus.model.module.APINoticeModule;
|
|
|
+import kr.co.zumo.app.lifeplus.push.PushMessageBroker;
|
|
|
import kr.co.zumo.app.lifeplus.supervisor.PushMessageManager;
|
|
|
import kr.co.zumo.app.lifeplus.util.Formatter;
|
|
|
import kr.co.zumo.app.lifeplus.view.Event;
|
|
|
@@ -29,7 +33,7 @@ import kr.co.zumo.app.lifeplus.view.Event;
|
|
|
* @history 민효동 [2018. 11. 2.] [최초 작성]
|
|
|
* @since 2018. 11. 2.
|
|
|
*/
|
|
|
-public class NotiModel extends Model {
|
|
|
+public class NotiModel extends Model implements PushMessageBroker.IPushMessageListener {
|
|
|
private Disposable disposable;
|
|
|
private List<NoticeBean> noticeBeans;
|
|
|
|
|
|
@@ -37,6 +41,7 @@ public class NotiModel extends Model {
|
|
|
|
|
|
public NotiModel() {
|
|
|
pushMessageManager = new PushMessageManager(PushMessageManager.getPushMessages());
|
|
|
+ PushMessageBroker.getInstance().registerObserver(this);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -45,6 +50,7 @@ public class NotiModel extends Model {
|
|
|
|
|
|
@Override
|
|
|
protected void destroyInternal() {
|
|
|
+ PushMessageBroker.getInstance().unregisterObserver(this);
|
|
|
disposeLoading();
|
|
|
noticeBeans = null;
|
|
|
}
|
|
|
@@ -81,11 +87,14 @@ public class NotiModel extends Model {
|
|
|
}
|
|
|
|
|
|
public List<NoticeBean> getNoticeBeans() {
|
|
|
- return noticeBeans;
|
|
|
+ List<NoticeBean> list = new ArrayList<>();
|
|
|
+ list.addAll(parsePushBeans());
|
|
|
+ list.addAll(noticeBeans);
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * FAQ 불러오기;
|
|
|
+ * 공지 불러오기;
|
|
|
*/
|
|
|
public void loadNotification() {
|
|
|
disposable =
|
|
|
@@ -98,8 +107,6 @@ public class NotiModel extends Model {
|
|
|
noticeBeans = new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
- parsePushBeans();
|
|
|
-
|
|
|
onResult(new Event.Builder(Event.RESULT).build());
|
|
|
}
|
|
|
|
|
|
@@ -111,26 +118,30 @@ public class NotiModel extends Model {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- private void parsePushBeans() {
|
|
|
+ private List<NoticeBean> parsePushBeans() {
|
|
|
// push beans 를 noticeBean 으로 변환
|
|
|
-
|
|
|
+ List<NoticeBean> noticeBeans = new ArrayList<>();
|
|
|
List<PushBean> list = pushMessageManager.getPushBeans();
|
|
|
int len = list.size();
|
|
|
PushBean bean;
|
|
|
- NoticeBean noticeBean;
|
|
|
for (int i = 0; i < len; ++i) {
|
|
|
bean = list.get(i);
|
|
|
- noticeBean = new NoticeBean();
|
|
|
- noticeBean.setCategory(NoticeBean.CATEGORY_NEWS);
|
|
|
- noticeBean.setContents(bean.getContents());
|
|
|
- noticeBean.setDate(Formatter.format(bean.getDateTime(), PushBean.DATE_FORMAT, NoticeBean.DATE_FORMAT));
|
|
|
- noticeBean.setEventId(bean.getItemNo());
|
|
|
- noticeBean.setNoticeNo("");
|
|
|
- noticeBean.setFlag(getNoticeFlagFromPush(bean.getPushType()));
|
|
|
- noticeBean.setViewType(NoticeBean.VIEW_TYPE_TEXT_LINK);
|
|
|
-
|
|
|
- noticeBeans.add(0, noticeBean);
|
|
|
+ noticeBeans.add(0, pushToNotice(bean));
|
|
|
}
|
|
|
+
|
|
|
+ return noticeBeans;
|
|
|
+ }
|
|
|
+
|
|
|
+ private NoticeBean pushToNotice(PushBean bean) {
|
|
|
+ NoticeBean noticeBean = new NoticeBean();
|
|
|
+ noticeBean.setCategory(NoticeBean.CATEGORY_NEWS);
|
|
|
+ noticeBean.setContents(bean.getContents());
|
|
|
+ noticeBean.setDate(Formatter.format(bean.getDateTime(), PushBean.DATE_FORMAT, NoticeBean.DATE_FORMAT));
|
|
|
+ noticeBean.setEventId(bean.getItemNo());
|
|
|
+ noticeBean.setNoticeNo("");
|
|
|
+ noticeBean.setFlag(getNoticeFlagFromPush(bean.getPushType()));
|
|
|
+ noticeBean.setViewType(NoticeBean.VIEW_TYPE_TEXT_LINK);
|
|
|
+ return noticeBean;
|
|
|
}
|
|
|
|
|
|
private static String getNoticeFlagFromPush(String pushType) {
|
|
|
@@ -153,4 +164,25 @@ public class NotiModel extends Model {
|
|
|
public void stopLoading() {
|
|
|
disposeLoading();
|
|
|
}
|
|
|
+
|
|
|
+ public void clearPushMessages() {
|
|
|
+ if (pushMessageManager.hasMessages()) {
|
|
|
+ pushMessageManager.clear();
|
|
|
+ PushMessageManager.savePushMessages(pushMessageManager);
|
|
|
+ dispatchMessage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void dispatchMessage() {
|
|
|
+ onResult(new Event.Builder(Event.PUSH).build());
|
|
|
+ }
|
|
|
+
|
|
|
+ /***********************************
|
|
|
+ * PushMessageBroker.IPushMessageListener
|
|
|
+ ***********************************/
|
|
|
+ @Override
|
|
|
+ public void onMessageReceived(PushBean bean) {
|
|
|
+ pushMessageManager.addPushBean(bean);
|
|
|
+ new Handler(Looper.getMainLooper()).post(this::dispatchMessage);
|
|
|
+ }
|
|
|
}
|