Jelajahi Sumber

[푸시][New] 노티 별 화면 이동 준비

hyodong.min 6 tahun lalu
induk
melakukan
d0f519feb6

+ 79 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/activity/PushGateActivity.java

@@ -0,0 +1,79 @@
+package kr.co.zumo.app.lifeplus.activity;
+
+import android.content.Intent;
+import android.util.Log;
+
+import kr.co.zumo.app.lifeplus.model.SuperModel;
+
+/**
+ * PushGateActivity
+ * - 푸시 노티를 통해서 앱 내부로 이동하려 할 때
+ *
+ * <pre>
+ * </pre>
+ *
+ * @author 하세미
+ * @version 1.0
+ * @history 하세미   [2018-11-06]   [최초 작성]
+ * @since 2018-11-06
+ */
+public class PushGateActivity extends ActivityBaseSetup {
+
+  public static final String PUSH_JSON = "push_json";
+
+  @Override
+  protected void setup() {
+
+    String json = getIntent().getStringExtra(PUSH_JSON);
+
+    if (null != json) {
+      Log.i("APP# ContentsGateActivity | onCreate", "| json: " + json);
+    }
+
+
+    /**
+     * 데이터만 준비한다.
+     *
+     * 모든 예외 사항들( 잠금 화면 등)을 넘어서 메인 컨텐츠 를 표시 할 수 있을 때 데이터를 이용해서 컨텐츠를 표시한다.
+     */
+
+    finish();
+
+    if (SuperModel.getInstance().isAppInitialized()) {
+      // 이미 앱 실행 중 -> 해당 화면으로 이동
+      // todo
+    }
+    else {
+      // 앱이 처음 실행이라면 스플래시부터 진행
+      // todo
+      Intent intent = new Intent(this, SplashActivity.class);
+      startActivity(intent);
+    }
+
+  }
+
+  @Override
+  protected boolean hasLayout() {
+    return false;
+  }
+
+  @Override
+  protected boolean allowCountActivity() {
+    return false;
+  }
+
+  @Override
+  protected void onAfterDestroy() {
+
+  }
+
+  @Override
+  protected void onBeforeDestroy() {
+
+  }
+
+  @Override
+  protected void onAfterNewIntent(Intent intent) {
+
+  }
+}

+ 23 - 12
app/src/main/java/kr/co/zumo/app/lifeplus/push/FirebasePushService.java

@@ -23,9 +23,11 @@ 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.activity.PushGateActivity;
 import kr.co.zumo.app.lifeplus.bean.PushBean;
 import kr.co.zumo.app.lifeplus.helper.FirebaseHelper;
+import kr.co.zumo.app.lifeplus.model.SuperModel;
+import kr.co.zumo.app.lifeplus.model.SuperModelInit;
 import kr.co.zumo.app.lifeplus.supervisor.PushMessageManager;
 
 
@@ -59,6 +61,9 @@ public class FirebasePushService extends FirebaseMessagingService {
     // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
     Log.d("APP# FirebasePushService | onMessageReceived", "|" + "From: " + remoteMessage.getFrom());
 
+    SuperModelInit.instant(getApplicationContext());
+
+
     // Check if message contains a data payload.
     if (remoteMessage.getData().size() > 0) {
       Log.d("APP# FirebasePushService | onMessageReceived", "|" + "Message data payload: " + remoteMessage.getData());
@@ -71,10 +76,17 @@ public class FirebasePushService extends FirebaseMessagingService {
       Log.d("APP# FirebasePushService | onMessageReceived", "|" + bean.toJson());
 
       PushMessageManager.savePushMessages(new PushMessageManager(PushMessageManager.getPushMessages()).addPushBean(bean));
-
-      sendNotification(bean.getTitle(), bean.getContents());
-
       PushMessageBroker.getInstance().push(bean);
+
+      // 노티를 표시할지 구분
+      if (PushMessageManager.isEventCode(bean.getScreenCode()) && SuperModel.getInstance().getPreferences().isPushEventEnabled()) {
+        // event 코드이고 수신 설정 시
+        sendNotification(bean);
+      }
+      else if (PushMessageManager.isContentsCode(bean.getScreenCode()) && SuperModel.getInstance().getPreferences().isPushContentsAndService()) {
+        // 컨텐츠 코드이고 수신 설정 시
+        sendNotification(bean);
+      }
     }
 
     // Check if message contains a notification payload.
@@ -91,15 +103,14 @@ public class FirebasePushService extends FirebaseMessagingService {
 
   /**
    * Create and show a simple notification containing the received FCM message.
-   *
-   * @param title       FCM message title received.
-   * @param messageBody FCM message body received.
    */
-  private void sendNotification(String title, String messageBody) {
-    Intent intent = new Intent(this, MainActivity.class);
-    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
-    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
-      PendingIntent.FLAG_ONE_SHOT);
+  private void sendNotification(PushBean bean) {
+    String title = bean.getTitle();
+    String messageBody = bean.getContents();
+    Intent intent = new Intent(this, PushGateActivity.class);
+//    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+    intent.putExtra(PushGateActivity.PUSH_JSON, bean.toJson());
+    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);
 
     String channelId = "lifeplus_channel_id";
     Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

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

@@ -30,6 +30,21 @@ import kr.co.zumo.app.lifeplus.util.StringUtil;
  */
 public class PushMessageManager {
 
+  /*
+  [CS2002] 고객센터 - 문의하기 등록화면
+  [MY1002] MY - 소멸예정 코인 화면
+  [EV2000] EVENT - 당첨자발표 화면
+  [EV0000] EVENT
+  [CO5000] 콘텐츠상세
+  [MY1003] MY 쿠폰
+   */
+  public static final String CODE_QNA = "CS2002";
+  public static final String CODE_EXTINCTION = "MY1002";
+  public static final String CODE_EVENT_WINNER = "EV2000";
+  public static final String CODE_EVENT_DETAIL = "EV0000";
+  public static final String CODE_CONTENTS = "CO5000";
+  public static final String CODE_MY_COUPON = "MY1003";
+
   @SerializedName("pushBeans")
   private List<PushBean> pushBeans;
 
@@ -109,4 +124,67 @@ public class PushMessageManager {
       SuperModel.getInstance().getPreferences().setPushMessages(json);
     }
   }
+
+  /**
+   * Event 푸시 인지 확인
+   * - 설정 - 푸시 알림에 '이벤트 정보 수신'에 해당함.
+   *
+   * @param code MY1000
+   * @return
+   */
+  public static boolean isEventCode(String code) {
+    String[] codes = new String[]{CODE_EVENT_WINNER, CODE_EVENT_DETAIL};
+    for (String s : codes) {
+      if (s.equals(code)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  /**
+   * Contents/Service 푸시 인지 확인
+   * - 설정 - 푸시 알림에 '컨텐츠/서비스 정보 수신'에 해당함.
+   *
+   * @param code
+   * @return
+   */
+  public static boolean isContentsCode(String code) {
+    String[] codes = new String[]{CODE_QNA, CODE_EXTINCTION, CODE_CONTENTS, CODE_MY_COUPON};
+    for (String s : codes) {
+      if (s.equals(code)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  public static int getScreendIdByCode(String code) {
+    @ScreenID.ID int id;
+    switch (code) {
+      case CODE_QNA:
+        id = ScreenID.MY_FAQ;
+        break;
+      case CODE_EXTINCTION:
+        id = ScreenID.MY_COIN_EXTINCT;
+        break;
+      case CODE_EVENT_WINNER:
+        id = ScreenID.EVENT_WINNER;
+        break;
+      case CODE_EVENT_DETAIL:
+        id = ScreenID.EVENT_DETAIL;
+        break;
+      case CODE_CONTENTS:
+        id = ScreenID.CONTENTS;
+        break;
+      case CODE_MY_COUPON:
+        id = ScreenID.COUPON_MALL;
+        break;
+      default:
+        id = ScreenID.MAIN;
+        break;
+    }
+
+    return id;
+  }
 }