瀏覽代碼

[공통][New] 다이나믹 링크 처리
- 지정한 액티비티에서 열리지 않고, 항상 스플래시(런쳐)에서 열림
- 스플래시에 구분 코드 적용
- ContentsGateActivity 와 SplashActivity 에 중복 코드 리팩토링 필요

hyodong.min 6 年之前
父節點
當前提交
465f949639

+ 15 - 8
app/src/main/AndroidManifest.xml

@@ -35,6 +35,21 @@
 
         <category android:name="android.intent.category.LAUNCHER"/>
       </intent-filter>
+      <intent-filter>
+        <action android:name="android.intent.action.VIEW"/>
+
+        <category android:name="android.intent.category.DEFAULT"/>
+        <category android:name="android.intent.category.BROWSABLE"/>
+
+        <!-- firebase dynamic links -->
+        <data
+          android:host="lifeplus.co.kr/app"
+          android:scheme="http"/>
+        <data
+          android:host="lifeplus.co.kr/app"
+          android:scheme="https"/>
+
+      </intent-filter>
     </activity>
 
     <!-- Activity -->
@@ -52,14 +67,6 @@
           android:host="@string/kakaolink_host"
           android:scheme="@string/kakao_scheme"/>
 
-        <!-- firebase dynamic links -->
-        <data
-          android:host="lifeplus.co.kr/app"
-          android:scheme="http"/>
-        <data
-          android:host="lifeplus.co.kr/app"
-          android:scheme="https"/>
-
       </intent-filter>
     </activity>
     <activity

+ 3 - 3
app/src/main/java/kr/co/zumo/app/lifeplus/activity/ContentsGateActivity.java

@@ -63,6 +63,8 @@ public class ContentsGateActivity extends ActivityBaseSetup {
 
         ActivityDeliveryHelper.getInstance().setPackaging(contentsDeliveryBean);
         SuperModel.getInstance().setContentsLink(true);
+
+        next();
       }
       else {
         // event
@@ -74,6 +76,7 @@ public class ContentsGateActivity extends ActivityBaseSetup {
           public void onLoadSuccess(EventDetailBean eventDetailBean, int screenId, EventDeliveryBean eventDeliveryBean) {
             SuperModel.getInstance().setEventLink(true);
             ActivityDeliveryHelper.getInstance().setPackaging(eventDeliveryBean);
+
             next();
           }
 
@@ -92,12 +95,9 @@ public class ContentsGateActivity extends ActivityBaseSetup {
             loadingDriver.remove();
           }
         });
-
-        return;
       }
     }
 
-    next();
 
   }
 

+ 94 - 37
app/src/main/java/kr/co/zumo/app/lifeplus/activity/SplashActivity.java

@@ -4,30 +4,35 @@ import android.Manifest;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
-import android.os.Bundle;
+import android.net.Uri;
 import android.support.annotation.NonNull;
 import android.util.Log;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.util.Set;
+import com.google.android.gms.tasks.OnFailureListener;
+import com.google.android.gms.tasks.OnSuccessListener;
+import com.google.firebase.dynamiclinks.FirebaseDynamicLinks;
+import com.google.firebase.dynamiclinks.PendingDynamicLinkData;
 
 import io.reactivex.android.schedulers.AndroidSchedulers;
 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.bean.PushBean;
+import kr.co.zumo.app.lifeplus.bean.ContentsDeliveryBean;
+import kr.co.zumo.app.lifeplus.bean.EventDeliveryBean;
+import kr.co.zumo.app.lifeplus.bean.api.EventDetailBean;
+import kr.co.zumo.app.lifeplus.bean.api.LifeplusContentsBean;
+import kr.co.zumo.app.lifeplus.config.NetworkConfigProvider;
 import kr.co.zumo.app.lifeplus.model.SuperModel;
 import kr.co.zumo.app.lifeplus.model.SuperModelInit;
 import kr.co.zumo.app.lifeplus.network.NetworkWatcher;
 import kr.co.zumo.app.lifeplus.supervisor.ActivityDeliveryHelper;
-import kr.co.zumo.app.lifeplus.supervisor.PushMessageManager;
+import kr.co.zumo.app.lifeplus.tool.ShareKakaoTalk;
 import kr.co.zumo.app.lifeplus.util.PermissionUtil;
+import kr.co.zumo.app.lifeplus.util.StringUtil;
+import kr.co.zumo.app.lifeplus.view.IWaiterCallable;
+import kr.co.zumo.app.lifeplus.view.animation.LoadingDriver;
+import kr.co.zumo.app.lifeplus.view.screen.event.EventDetailDelegate;
 
 /**
  * Splash 화면
@@ -46,38 +51,90 @@ public class SplashActivity extends ActivityBaseSetup {
 
   @Override
   protected void setup() {
-
-    Context context = App.getInstance().getContext();
-
-    // has push message ?
-    Bundle bundle = getIntent().getExtras();
-    if (null != bundle) {
-      // push message 는 pageId 가 있어야한다.
-      if(bundle.get("pageId") != null ) {
-        Log.d("APP# SplashActivity | setup", "| extras: " + bundle);
-        JSONObject json = new JSONObject();
-        Set<String> keys = bundle.keySet();
-        for (String key : keys) {
-          try {
-            json.put(key, JSONObject.wrap(bundle.get(key)));
-          } catch (JSONException e) {
-            //Handle exception here
+    FirebaseDynamicLinks.getInstance()
+      .getDynamicLink(getIntent())
+      .addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
+        @Override
+        public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
+          // Get deep link from result (may be null if no link is found)
+          Uri uri = null;
+          if (pendingDynamicLinkData != null) {
+            uri = pendingDynamicLinkData.getLink();
+
+            final String itemNo = null != uri ? uri.getQueryParameter(ShareKakaoTalk.CONTENTS_ITEM_NO) : "";
+            final String page = null != uri ? uri.getQueryParameter(ShareKakaoTalk.CONTENTS_ITEM_PAGE) : "0";
+            final String pageType = null != uri ? uri.getQueryParameter(ShareKakaoTalk.LINK_TYPE) : ShareKakaoTalk.LINK_TYPE_CONTENTS;
+
+            Log.i("APP# SplashActivity | setup", "|" + " pageType: " + pageType + " itemNo: " + itemNo + ", page: " + page);
+
+            if (StringUtil.isFull(itemNo)) {
+
+              if (ShareKakaoTalk.LINK_TYPE_CONTENTS.equals(pageType)) {
+                // contents 데이터 준비
+                LifeplusContentsBean lifeplusContentsBean = new LifeplusContentsBean();
+                lifeplusContentsBean.setItemNo(itemNo);
+
+                ContentsDeliveryBean contentsDeliveryBean = new ContentsDeliveryBean.Builder(lifeplusContentsBean).pageIndex(Integer.parseInt(page)).build();
+
+                ActivityDeliveryHelper.getInstance().setPackaging(contentsDeliveryBean);
+                SuperModel.getInstance().setContentsLink(true);
+
+                next();
+              }
+              else {
+                // event
+                // 이벤트 구분 후 전달해야한다.
+                SuperModelInit.instant(getApplicationContext());
+                NetworkConfigProvider.init();
+                LoadingDriver loadingDriver = new LoadingDriver();
+                new EventDetailDelegate().loadEvent(itemNo, new EventDetailDelegate.IEventDetailDelegateListener() {
+                  @Override
+                  public void onLoadSuccess(EventDetailBean eventDetailBean, int screenId, EventDeliveryBean eventDeliveryBean) {
+                    SuperModel.getInstance().setEventLink(true);
+                    ActivityDeliveryHelper.getInstance().setPackaging(eventDeliveryBean);
+                    next();
+                  }
+
+                  @Override
+                  public void onLoadFail(String errorMessage) {
+                    Log.e("APP#  ContentsGateActivity | onLoadFail", "|" + errorMessage);
+                    next();
+                  }
+                }, new IWaiterCallable() {
+                  @Override
+                  public void showWaiter() {
+                    loadingDriver.create(SplashActivity.this, 10);
+                  }
+
+                  @Override
+                  public void hideWaiter() {
+                    loadingDriver.remove();
+                  }
+                });
+              }
+            }
+          }
+          else {
+            next();
           }
         }
+      })
+      .addOnFailureListener(this, new OnFailureListener() {
+        @Override
+        public void onFailure(@NonNull Exception e) {
+          Log.e("APP#  SplashActivity | onFailure", "|" + "e -> " + e);
+          next();
+        }
+      });
+  }
 
-        Gson gson = new GsonBuilder().create();
-
-        PushBean bean = gson.fromJson(json.toString(), PushBean.class);
-        Log.d("APP# SplashActivity | setup", "|" + bean.toJson());
+  private void next() {
+    setupInternal();
+  }
 
-        SuperModelInit.instant(getApplicationContext());
-        PushMessageManager.onReceived(bean);
+  protected void setupInternal() {
 
-        // fixme PushGateActivity 와 중복되는 부분이 있다.
-        ActivityDeliveryHelper.getInstance().setPackaging(bean);
-        SuperModel.getInstance().setPushLink(true);
-      }
-    }
+    Context context = App.getInstance().getContext();
 
     // 앱이 실행 중인지 판단한다.
     if (SuperModel.getInstance().isAppInitialized()) {