Преглед на файлове

[알림][New] 푸시 내용을 알림에 표시한다.

hyodong.min преди 6 години
родител
ревизия
367671974c

+ 1 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/activity/ActivityBaseScreen.java

@@ -25,7 +25,7 @@ public abstract class ActivityBaseScreen extends ActivityBase {
   @Override
   protected final void renderScreen() {
 
-    if (SuperModel.getInstance().isInitialized()) {
+    if (SuperModel.getInstance().isAppInitialized()) {
       render();
     }
     else {

+ 1 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/activity/AppInitializer.java

@@ -32,7 +32,7 @@ public class AppInitializer {
    */
   public static void init(Context context) {
 
-    if (SuperModel.getInstance().isInitialized() == false) {
+    if (SuperModel.getInstance().isAppInitialized() == false) {
 
       SuperModelInit.init(context);
 

+ 1 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/activity/KakaoTalkActivity.java

@@ -58,7 +58,7 @@ public class KakaoTalkActivity extends ActivityBaseSetup {
 
     finish();
 
-    if (SuperModel.getInstance().isInitialized()) {
+    if (SuperModel.getInstance().isAppInitialized()) {
       // 이미 앱 실행 중 -> 바로 컨텐츠 보여줌.
       doOnLink();
     }

+ 1 - 2
app/src/main/java/kr/co/zumo/app/lifeplus/activity/SplashActivity.java

@@ -12,7 +12,6 @@ import io.reactivex.disposables.CompositeDisposable;
 import io.reactivex.schedulers.Schedulers;
 import kr.co.zumo.app.R;
 import kr.co.zumo.app.lifeplus.application.App;
-import kr.co.zumo.app.lifeplus.helper.FirebaseHelper;
 import kr.co.zumo.app.lifeplus.model.SuperModel;
 import kr.co.zumo.app.lifeplus.network.NetworkWatcher;
 import kr.co.zumo.app.lifeplus.util.PermissionUtil;
@@ -38,7 +37,7 @@ public class SplashActivity extends ActivityBaseSetup {
     Context context = App.getInstance().getContext();
 
     // 앱이 실행 중인지 판단한다.
-    if (SuperModel.getInstance().isInitialized()) {
+    if (SuperModel.getInstance().isAppInitialized()) {
       Log.e("APP#  SplashActivity | onCreate", "|" + " restart from call...........");
       finish();
     }

+ 107 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/bean/PushBean.java

@@ -0,0 +1,107 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.bean;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * PushBean
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2019. 2. 1.]   [최초 작성]
+ * @since 2019. 2. 1.
+ */
+public class PushBean extends JsonBeanBase {
+  /*
+  {
+      "pageId": "MY1002",
+      "pushGubun": "COIN",
+      "body": "OOOO코인 (OO월 OO일) 소멸 예정!\nMY코인에서 소멸 예정 코인을 확인하세요~",
+      "title": "[Lifeplus]",
+      "locationKey": "201901310000045166",
+      "sendTime": "2019-02-01 15:05:56",
+      "appSaveYn": "Y"
+  }
+   */
+
+  public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
+
+  public static final String PUSH_TYPE_COIN = "COIN";
+  public static final String PUSH_TYPE_EVENT = "EVENT";
+  public static final String PUSH_TYPE_COUPON = "COUPON";
+
+  @SerializedName("pageId")
+  private String screenId;
+  @SerializedName("pushGubun")
+  private String pushType;  // 푸시 컨텐츠 타입(pushGubun): COIN, EVENT, COUPON
+  @SerializedName("body")
+  private String contents;
+  @SerializedName("title")
+  private String title;
+  @SerializedName("locationKey")
+  private String itemNo;
+  @SerializedName("sendTime")
+  private String dateTime;  // "2019-02-01 15:05:56"
+  @SerializedName("appSaveYn")
+  private String needSaving;
+
+  public String getScreenId() {
+    return screenId;
+  }
+
+  public void setScreenId(String screenId) {
+    this.screenId = screenId;
+  }
+
+  public String getPushType() {
+    return pushType;
+  }
+
+  public void setPushType(String pushType) {
+    this.pushType = pushType;
+  }
+
+  public String getContents() {
+    return contents;
+  }
+
+  public void setContents(String contents) {
+    this.contents = contents;
+  }
+
+  public String getTitle() {
+    return title;
+  }
+
+  public void setTitle(String title) {
+    this.title = title;
+  }
+
+  public String getItemNo() {
+    return itemNo;
+  }
+
+  public void setItemNo(String itemNo) {
+    this.itemNo = itemNo;
+  }
+
+  public String getDateTime() {
+    return dateTime;
+  }
+
+  public void setDateTime(String dateTime) {
+    this.dateTime = dateTime;
+  }
+
+  public String getNeedSaving() {
+    return needSaving;
+  }
+
+  public void setNeedSaving(String needSaving) {
+    this.needSaving = needSaving;
+  }
+}

+ 6 - 19
app/src/main/java/kr/co/zumo/app/lifeplus/bean/api/NoticeBean.java

@@ -20,6 +20,8 @@ import kr.co.zumo.app.lifeplus.util.StringUtil;
  */
 public class NoticeBean extends JsonBeanBase {
 
+  public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
+
   public static final String CATEGORY_NOTICE = "0";
   public static final String CATEGORY_NEWS = "1";
 
@@ -52,6 +54,9 @@ public class NoticeBean extends JsonBeanBase {
       case FLAG_NEWS_COIN:
         result = newsFlags[0];
         break;
+      case FLAG_NEWS_COUPON:
+        result = newsFlags[1];
+        break;
       case FLAG_NEWS_WINNER:
         result = newsFlags[2];
         break;
@@ -62,24 +67,6 @@ public class NoticeBean extends JsonBeanBase {
     return result;
   }
 
-  /*
-  카테고리: 공지사항, 소식
-
-  - 공지사항
-  Flag : 공지, 당첨자 발표
-
-  - 소식
-  - Flag : 코인, 쿠폰, 당첨
-
-  {
-      "zumoCmngSqno": 201901290000000608,
-      "cmngType": "1",
-      "cmngTitl": "asdasd",
-      "zumoCmngCten": "<p>ㅁㅇㅁㄴㅇㄴㅁㅇ</p>",
-      "frstRgstDttm": "2019-01-29 10:50:02"
-  },
-  */
-
   @SerializedName("zumoCmngSqno")
   private String noticeNo;
   @SerializedName("category")
@@ -160,7 +147,7 @@ public class NoticeBean extends JsonBeanBase {
     if (null == viewType && null != flag && flag.equals(FLAG_NOTICE_NOTICE) || flag.equals(FLAG_NOTICE_NOTICE)) {
       viewType = VIEW_TYPE_NOTICE;
     }
-    if(StringUtil.isEmpty(viewType)) {
+    if (StringUtil.isEmpty(viewType)) {
       viewType = VIEW_TYPE_NOTICE;
     }
     return viewType;

+ 13 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/model/LifeplusPreferences.java

@@ -38,6 +38,7 @@ public class LifeplusPreferences {
   public final static String TUTORIAL_BUCKET_LIST_DETAIL_DONE = "tutorial_bucket_list_detail_done";
   public final static String PROMOTION_SKIP_TIME = "current_time_millis";
   public final static String TAG_LATEST_LIST = "tag_latest_list";
+  public final static String PUSH_MESSAGES = "push_messages";
 
 
   /**
@@ -318,4 +319,16 @@ public class LifeplusPreferences {
     return preferences.get(TAG_LATEST_LIST, "");
   }
 
+  /**
+   * Push messages 저장
+   *
+   * @param string
+   */
+  public void setPushMessages(String string) {
+    preferences.put(PUSH_MESSAGES, string);
+  }
+
+  public String getPushMessages() {
+    return preferences.get(PUSH_MESSAGES, "");
+  }
 }

+ 11 - 5
app/src/main/java/kr/co/zumo/app/lifeplus/model/SuperModel.java

@@ -39,10 +39,16 @@ public final class SuperModel implements IMemberStatusManager {
     return ourInstance;
   }
 
-  private boolean initialized = false;
+  private boolean isAppInitialized = false;
 
-  public boolean isInitialized() {
-    return initialized;
+  public boolean isAppInitialized() {
+    return isAppInitialized;
+  }
+
+  private boolean hasPreferences = false;
+
+  public boolean hasPreferences() {
+    return hasPreferences;
   }
 
   private String deviceUuid;
@@ -61,10 +67,9 @@ public final class SuperModel implements IMemberStatusManager {
 
   /**
    * 초기화. SplashActivity 에서 호출된다.
-   *
    */
   public void init() {
-    initialized = true;
+    isAppInitialized = true;
   }
 
   /**
@@ -74,6 +79,7 @@ public final class SuperModel implements IMemberStatusManager {
    */
   public void setPreferences(LifeplusPreferences preferences) {
     this.preferences = preferences;
+    hasPreferences = null != this.preferences;
   }
 
   /**

+ 13 - 2
app/src/main/java/kr/co/zumo/app/lifeplus/model/SuperModelInit.java

@@ -27,7 +27,18 @@ public class SuperModelInit {
    */
   public static void init(Context context) {
     SuperModel.getInstance().init();
-    SuperModel.getInstance().setPreferences(new LifeplusPreferences(new BaseSharedPreferences(PreferenceManager.getDefaultSharedPreferences(context))));
-    SuperModel.getInstance().setDeviceId(AppUtil.getDeviceId(context));
+    instant(context);
+  }
+
+  /**
+   * APP 이외의 곳 (widget, service 등) SuperModel 을 사용하고 싶을 때 데이터만 세팅
+   *
+   * @param context
+   */
+  public static void instant(Context context) {
+    if (SuperModel.getInstance().hasPreferences() == false) {
+      SuperModel.getInstance().setPreferences(new LifeplusPreferences(new BaseSharedPreferences(PreferenceManager.getDefaultSharedPreferences(context))));
+      SuperModel.getInstance().setDeviceId(AppUtil.getDeviceId(context));
+    }
   }
 }

+ 0 - 3
app/src/main/java/kr/co/zumo/app/lifeplus/network/api/LifeplusAPIRepository.java

@@ -482,7 +482,6 @@ public class LifeplusAPIRepository implements LifeplusAPI {
     return new LifeplusAPIService().getEventDetail(bean);
   }
 
-  // -------------------------------------------------------
   @Override
   public Single<CoinInfoResultBean> getCoinInfo(CoinInfoRequestBean bean) {
     /**
@@ -541,6 +540,4 @@ public class LifeplusAPIRepository implements LifeplusAPI {
   public Single<LifeplusAPIBean> registerQuestion(QuestionRequestBean bean) {
     return new LifeplusAPIService().registerQuestion(bean);
   }
-
-
 }

+ 13 - 21
app/src/main/java/kr/co/zumo/app/lifeplus/push/FirebasePushService.java

@@ -18,12 +18,15 @@ import android.util.Log;
 import com.google.firebase.messaging.FirebaseMessagingService;
 import com.google.firebase.messaging.RemoteMessage;
 import com.google.gson.Gson;
+import com.google.gson.JsonElement;
 
 import java.util.Map;
 
 import kr.co.zumo.app.R;
 import kr.co.zumo.app.lifeplus.activity.MainActivity;
+import kr.co.zumo.app.lifeplus.bean.PushBean;
 import kr.co.zumo.app.lifeplus.helper.FirebaseHelper;
+import kr.co.zumo.app.lifeplus.supervisor.PushMessageManager;
 
 
 /**
@@ -58,9 +61,6 @@ public class FirebasePushService extends FirebaseMessagingService {
   // 메시지 수신
   @Override
   public void onMessageReceived(RemoteMessage remoteMessage) {
-    Log.i("APP# FirebasePushService | onMessageReceived", "|" + "onMessageReceived");
-
-    // TODO(developer): Handle FCM messages here.
     // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
     Log.d("APP# FirebasePushService | onMessageReceived", "|" + "From: " + remoteMessage.getFrom());
 
@@ -68,22 +68,16 @@ public class FirebasePushService extends FirebaseMessagingService {
     if (remoteMessage.getData().size() > 0) {
       Log.d("APP# FirebasePushService | onMessageReceived", "|" + "Message data payload: " + remoteMessage.getData());
 
-      if (/* Check if data needs to be processed by long running job */ true) {
-        // For long-running tasks (10 seconds or more) use Firebase Job Dispatcher.
-//        scheduleJob();
-      }
-      else {
-        // Handle message within 10 seconds
-//        handleNow();
-      }
-
       Map<String, String> data = remoteMessage.getData();
-      String title = data.get("title");
-      String message = data.get("content");
 
-      Log.d("APP# FirebasePushService | onMessageReceived", "|" + new Gson().toJson(data));
+      Gson gson = new Gson();
+      JsonElement jsonElement = gson.toJsonTree(data);
+      PushBean bean = gson.fromJson(jsonElement, PushBean.class);
+      Log.d("APP# FirebasePushService | onMessageReceived", "|" + bean.toJson());
+
+      PushMessageManager.savePushMessages(new PushMessageManager(PushMessageManager.getPushMessages()).addPushBean(bean));
 
-      sendNotification(title, message);
+      sendNotification(bean.getTitle(), bean.getContents());
     }
 
     // Check if message contains a notification payload.
@@ -91,13 +85,11 @@ public class FirebasePushService extends FirebaseMessagingService {
 
       String title = remoteMessage.getNotification().getTitle();
       String message = remoteMessage.getNotification().getBody();
-      Log.d("APP# FirebasePushService | onMessageReceived", "| getNotice" + " title: " + title + ", message: " + message);
+      Log.d("APP# FirebasePushService | onMessageReceived", "| notification" + " title: " + title + ", message: " + message);
 
-      sendNotification(title, message);
+//      sendNotification(title, message);
     }
 
-    // Also if you intend on generating your own notifications as a result of a received FCM
-    // message, here is where that should be initiated. See sendNotification method below.
   }
 
   //  /**
@@ -111,7 +103,7 @@ public class FirebasePushService extends FirebaseMessagingService {
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
       PendingIntent.FLAG_ONE_SHOT);
 
-    String channelId = "id";
+    String channelId = "lifeplus_channel_id";
     Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
     NotificationCompat.Builder notificationBuilder =
       new NotificationCompat.Builder(this, channelId)

+ 84 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/supervisor/PushMessageManager.java

@@ -0,0 +1,84 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.supervisor;
+
+import android.util.Log;
+
+import com.google.gson.Gson;
+import com.google.gson.annotations.SerializedName;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import kr.co.zumo.app.lifeplus.application.App;
+import kr.co.zumo.app.lifeplus.bean.PushBean;
+import kr.co.zumo.app.lifeplus.bean.api.LifeplusData;
+import kr.co.zumo.app.lifeplus.model.SuperModel;
+import kr.co.zumo.app.lifeplus.model.SuperModelInit;
+import kr.co.zumo.app.lifeplus.util.StringUtil;
+
+/**
+ * PushMessageManager
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2019. 2. 1.]   [최초 작성]
+ * @since 2019. 2. 1.
+ */
+public class PushMessageManager {
+
+  @SerializedName("pushBeans")
+  private List<PushBean> pushBeans;
+
+  public PushMessageManager(List<PushBean> pushBeans) {
+    this.pushBeans = pushBeans;
+  }
+
+  public PushMessageManager addPushBean(PushBean bean) {
+    if (LifeplusData.isTrue(bean.getNeedSaving())) {
+      Log.i("APP# PushMessageManager | addPushBean", "|" + "add: " + bean.toJson());
+      pushBeans.add(bean);
+    }
+    return this;
+  }
+
+  public void clear() {
+    pushBeans.clear();
+  }
+
+  public List<PushBean> getPushBeans() {
+    return pushBeans;
+  }
+
+  public String toJson() {
+    return new Gson().toJson(this);
+  }
+
+
+  /***********************************
+   * static
+   ***********************************/
+  public static List<PushBean> getPushMessages() {
+    SuperModelInit.init(App.getInstance().getContext());
+    String data = SuperModel.getInstance().getPreferences().getPushMessages();
+    PushMessageManager manager = new Gson().fromJson(data, PushMessageManager.class);
+
+    if (null == manager) {
+      manager = new PushMessageManager(new ArrayList<>());
+    }
+    Log.w("APP# PushMessageManager | getPushMessages", "|" + "   json   get - " + manager.toJson());
+    return manager.getPushBeans();
+  }
+
+  public static void savePushMessages(PushMessageManager manager) {
+    SuperModelInit.init(App.getInstance().getContext());
+    String json = manager.toJson();
+    if (StringUtil.isFull(json)) {
+      Log.w("APP# PushMessageManager | savePushMessages", "|" + "   json    - " + json);
+      SuperModel.getInstance().getPreferences().setPushMessages(json);
+    }
+  }
+}

+ 55 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/notification/NotiModel.java

@@ -3,16 +3,20 @@
  */
 package kr.co.zumo.app.lifeplus.view.screen.notification;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import io.reactivex.disposables.Disposable;
-import kr.co.zumo.app.lifeplus.bean.api.NoticeResultBean;
+import kr.co.zumo.app.lifeplus.bean.PushBean;
 import kr.co.zumo.app.lifeplus.bean.api.NoticeBean;
+import kr.co.zumo.app.lifeplus.bean.api.NoticeResultBean;
 import kr.co.zumo.app.lifeplus.bean.api.RequestBean;
 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.supervisor.PushMessageManager;
+import kr.co.zumo.app.lifeplus.util.Formatter;
 import kr.co.zumo.app.lifeplus.view.Event;
 
 /**
@@ -29,9 +33,16 @@ public class NotiModel extends Model {
   private Disposable disposable;
   private List<NoticeBean> noticeBeans;
 
+  private PushMessageManager pushMessageManager;
+
+  public NotiModel() {
+    pushMessageManager = new PushMessageManager(PushMessageManager.getPushMessages());
+  }
+
   @Override
   protected void createViewInternal() {
   }
+
   @Override
   protected void destroyInternal() {
     disposeLoading();
@@ -82,6 +93,13 @@ public class NotiModel extends Model {
           @Override
           public void onApiSuccess(NoticeResultBean resultBean) {
             noticeBeans = resultBean.getData();
+
+            if (null == noticeBeans) {
+              noticeBeans = new ArrayList<>();
+            }
+
+            parsePushBeans();
+
             onResult(new Event.Builder(Event.RESULT).build());
           }
 
@@ -93,6 +111,42 @@ public class NotiModel extends Model {
       );
   }
 
+  private void parsePushBeans() {
+    // push beans 를 noticeBean 으로 변환
+
+    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);
+    }
+  }
+
+  private static String getNoticeFlagFromPush(String pushType) {
+    switch (pushType) {
+      case PushBean.PUSH_TYPE_COIN:
+        return NoticeBean.FLAG_NEWS_COIN;
+      case PushBean.PUSH_TYPE_COUPON:
+        return NoticeBean.FLAG_NEWS_COUPON;
+      case PushBean.PUSH_TYPE_EVENT:
+        return NoticeBean.FLAG_NEWS_WINNER;
+      default:
+        break;
+    }
+    return NoticeBean.FLAG_NEWS_COIN;
+  }
+
   /**
    * 로드 중지
    */