From b1eed91fcc4ed5c65fa867de67c3c99d8fb6f194 Mon Sep 17 00:00:00 2001 From: dali Date: Mon, 17 Sep 2018 08:25:29 +0900 Subject: [PATCH] =?UTF-8?q?=EC=95=B1=EB=A7=81=ED=81=AC=EB=A5=BC=20?= =?UTF-8?q?=EC=A7=80=EC=9B=90=ED=95=A9=EB=8B=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 60 +++++++----- .../java/xyz/parti/catan/MainActivity.java | 97 +++++++++---------- .../catan/MyFirebaseMessagingService.java | 2 +- .../main/java/xyz/parti/catan/UfoWebView.java | 41 ++++---- .../main/java/xyz/parti/catan/UrlBundle.java | 54 +++++++++++ 5 files changed, 161 insertions(+), 93 deletions(-) create mode 100644 app/src/main/java/xyz/parti/catan/UrlBundle.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e4c4810..9bb0234 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + xmlns:android="http://schemas.android.com/apk/res/android"> + android:value="@string/default_notification_channel_id" /> + android:launchMode="singleInstance"> - - + + + + + + + + @@ -39,32 +46,29 @@ android:exported="false" android:icon="@mipmap/ic_copy_link" android:label="@string/copy_link_to_clipboard" - android:theme="@android:style/Theme.NoDisplay"> - + android:theme="@android:style/Theme.NoDisplay"> - + - + - + - + - + - + + android:value="${crashlyticsApiKey}" /> - + - + + + - + \ No newline at end of file diff --git a/app/src/main/java/xyz/parti/catan/MainActivity.java b/app/src/main/java/xyz/parti/catan/MainActivity.java index 4fe2fbf..e2a55b9 100644 --- a/app/src/main/java/xyz/parti/catan/MainActivity.java +++ b/app/src/main/java/xyz/parti/catan/MainActivity.java @@ -57,7 +57,6 @@ public class MainActivity extends AppCompatActivity implements UfoWebView.Listen { //private static final String KEY_UID = "xUID"; private static final String KEY_AUTHKEY = "xAK"; - public static final String PUSHARG_URL = "url"; public static final int LOADING_PROGRESS_THRESHOLD = 85; public static final int RC_SIGN_IN = 100; @@ -86,9 +85,8 @@ protected void onCreate(Bundle savedInstanceState) s_this = this; CatanApp.getApp().onStartup(); - if (m_webView != null) - { - // already initialized + if (m_webView != null) { + m_webView.bootstrap(new UrlBundle(getIntent())); return; } @@ -100,20 +98,8 @@ protected void onCreate(Bundle savedInstanceState) SocialAuthContract.init(this); initGoogleSignIn(); initFacebookSignIn(); - } - - @Override - public void onStart() - { - super.onStart(); - if (m_webView != null) - { - m_webView.onStart(this, parsePushBundleUrl(getIntent().getExtras())); - return; - } - - m_vwSplashScreen = findViewById(R.id.splash); + m_webView = new UfoWebView(this, findViewById(R.id.web), this); m_indicator = findViewById(R.id.indicator); m_indicator.setOnClickListener(new View.OnClickListener() { @Override @@ -121,34 +107,47 @@ public void onClick(View v) { m_webView.stopLoading(); } }); - m_webView = new UfoWebView(this, findViewById(R.id.web), this); + m_webView.bootstrap(new UrlBundle(getIntent())); + m_progressLayoutView = findViewById(R.id.progressLayout); m_progressBarView = findViewById(R.id.progressBar); m_progressBarView.setMax(100); m_progressBarView.setProgress(0); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) - { + createNotifiactionChannel(); + showSplashScreen(); + } + + private void showSplashScreen() { + m_vwSplashScreen = findViewById(R.id.splash); + // 1초간 스플래시 화면을 보여줍니다. + m_vwSplashScreen.postDelayed(new Runnable() { + @Override + public void run() { + m_vwSplashScreen.setVisibility(View.GONE); + } + }, 2000); + } + + private void createNotifiactionChannel() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // Create channel to show notifications. - String channelId = getString(R.string.default_notification_channel_id); + String channelId = getString(R.string.default_notification_channel_id); String channelName = getString(R.string.default_notification_channel_name); NotificationManager notificationManager = getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(new NotificationChannel(channelId, - channelName, NotificationManager.IMPORTANCE_LOW)); + channelName, NotificationManager.IMPORTANCE_LOW)); } + } - m_webView.onStart(this, parsePushBundleUrl(getIntent().getExtras())); + @Override + public void onStart() + { + super.onStart(); - // 1초간 스플래시 화면을 보여줍니다. - // iOS는 Launch스크린이 필수라서 대응하며 만든 기능입니다. 이 기능이 필요 없으면 연락주세요. - m_vwSplashScreen.postDelayed(new Runnable() - { - @Override - public void run() - { - m_vwSplashScreen.setVisibility(View.GONE); - } - }, 2000); + if (m_webView != null) { + m_webView.onStart(this); + } } @Override @@ -156,18 +155,17 @@ public void onStop() { super.onStop(); - if (m_webView != null) - { + if (m_webView != null) { m_webView.onStop(this); } } @Override - public void onNewIntent(Intent intent){ - super.onNewIntent(intent); - if (m_webView != null && intent != null) - { - m_webView.onBootstrapForPushNotification(parsePushBundleUrl(intent.getExtras())); + public void onNewIntent(Intent newIntent) { + super.onNewIntent(newIntent); + + if(this.m_webView != null) { + m_webView.bootstrap(new UrlBundle(newIntent)); } } @@ -196,16 +194,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); } - private String parsePushBundleUrl(Bundle bun) { - if (bun != null && bun.containsKey(PUSHARG_URL)) { - String url = bun.getString(PUSHARG_URL); - if (!Util.isNullOrEmpty(url)) { - return url; - } - } - return null; - } - @Override public void onBackPressed() { @@ -616,12 +604,18 @@ private void initFacebookSignIn() { LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback() { @Override public void onSuccess(LoginResult loginResult) { + if(m_webView != null) { + m_webView.bootstrap(); + } } @Override public void onCancel() { LoginManager.getInstance().logOut(); Util.toastShort(MainActivity.this, "로그인을 취소했습니다"); + if(m_webView != null && m_webView.canGoBack()) { + m_webView.goBack(); + } } @Override @@ -629,6 +623,9 @@ public void onError(FacebookException error) { Util.e("Facebook SignInResult: failed! %s", error.getMessage()); LoginManager.getInstance().logOut(); Util.toastShort(MainActivity.this, "다시 시도해 주세요"); + if(m_webView != null && m_webView.canGoBack()) { + m_webView.goBack(); + } } }); this.mFacebookAuthClient = callbackManager; diff --git a/app/src/main/java/xyz/parti/catan/MyFirebaseMessagingService.java b/app/src/main/java/xyz/parti/catan/MyFirebaseMessagingService.java index 175a4a7..aefda25 100644 --- a/app/src/main/java/xyz/parti/catan/MyFirebaseMessagingService.java +++ b/app/src/main/java/xyz/parti/catan/MyFirebaseMessagingService.java @@ -69,7 +69,7 @@ private void sendNotification(RemoteMessage rmsg) Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); - intent.putExtra(MainActivity.PUSHARG_URL, rmsg.getData().get("url")); + intent.putExtra(UrlBundle.PUSHARG_URL, rmsg.getData().get("url")); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); String channelId = getString(R.string.default_notification_channel_id); diff --git a/app/src/main/java/xyz/parti/catan/UfoWebView.java b/app/src/main/java/xyz/parti/catan/UfoWebView.java index 7b86f7e..a702c35 100644 --- a/app/src/main/java/xyz/parti/catan/UfoWebView.java +++ b/app/src/main/java/xyz/parti/catan/UfoWebView.java @@ -58,7 +58,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.regex.Matcher; import java.util.regex.Pattern; public class UfoWebView @@ -568,15 +567,8 @@ public UfoWebView(Activity act, View webView, Listener lsnr) } } - public void onStart(Activity act, String pushNotifiedUrl) { + public void onStart(Activity act) { registerReciver(act); - - String url; - if (pushNotifiedUrl == null) { - onBootstrap(getLastOnlineUrl(), null); - } else { - onBootstrapForPushNotification(pushNotifiedUrl); - } } public void onStop(Activity act) @@ -584,13 +576,32 @@ public void onStop(Activity act) act.unregisterReceiver(m_connectivityReceiver); } - public void onBootstrapForPushNotification(String pushNotifiedUrl) { + public void bootstrap(UrlBundle urlBundle) { + String pushNotificationUrl = urlBundle.getPushNotifiedUrl(); + String appLinkUrl = urlBundle.getAppLinkUrl(); + + if (pushNotificationUrl != null) { + m_currentUrl = pushNotificationUrl; + bootstrapForPushNotification(pushNotificationUrl); + } else if(appLinkUrl != null) { + m_currentUrl = appLinkUrl; + bootstrapForUrl(appLinkUrl, null); + } else { + bootstrapForUrl(getLastOnlineUrl(), null); + } + } + + public void bootstrap() { + bootstrapForUrl(getLastOnlineUrl(), null); + } + + private void bootstrapForPushNotification(String pushNotifiedUrl) { HashMap customHeader = new HashMap(); customHeader.put("X-Catan-Push-Notified", "true"); - onBootstrap(pushNotifiedUrl, customHeader); + bootstrapForUrl(pushNotifiedUrl, customHeader); } - private void onBootstrap(String url, Map customHeader) { + private void bootstrapForUrl(String url, Map customHeader) { if (!Util.isNetworkOnline(m_webView.getContext())) { onNetworkOffline(); return; @@ -799,7 +810,7 @@ public void run() { } if (TextUtils.isEmpty(m_basePageUrl)) { - return; + m_basePageUrl = UfoWebView.BASE_URL; } else if(m_basePageUrl.equals(backBrowserUrl)) { m_webView.goBack(); @@ -948,8 +959,4 @@ public boolean isLoading(int progress) { public void stopLoading() { m_webView.stopLoading(); } - - public void simpleGoBack() { - m_webView.goBack(); - } } diff --git a/app/src/main/java/xyz/parti/catan/UrlBundle.java b/app/src/main/java/xyz/parti/catan/UrlBundle.java new file mode 100644 index 0000000..df76016 --- /dev/null +++ b/app/src/main/java/xyz/parti/catan/UrlBundle.java @@ -0,0 +1,54 @@ +package xyz.parti.catan; + +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; + +public class UrlBundle { + public static final String PUSHARG_URL = "url"; + private final Intent intent; + private String pushBundleUrl = ""; + private String appLinkBundleUrl = ""; + + public UrlBundle(Intent intent) { + this.intent = intent; + } + + public String getPushNotifiedUrl() { + if(this.intent == null) { + return null; + } + if(!"".equals(this.pushBundleUrl)) { + return this.pushBundleUrl; + } + + Bundle bundle = intent.getExtras(); + if (bundle != null && bundle.containsKey(PUSHARG_URL)) { + String url = bundle.getString(PUSHARG_URL); + if (!Util.isNullOrEmpty(url)) { + this.pushBundleUrl = url; + return this.pushBundleUrl; + } + } + this.pushBundleUrl = null; + return this.pushBundleUrl; + } + + public String getAppLinkUrl() { + if(this.intent == null) { + return null; + } + if(!"".equals(this.appLinkBundleUrl)) { + return this.appLinkBundleUrl; + } + + String appLinkAction = intent.getAction(); + Uri appLinkData = intent.getData(); + if (Intent.ACTION_VIEW.equals(appLinkAction) && appLinkData != null) { + this.appLinkBundleUrl = appLinkData.toString(); + return this.appLinkBundleUrl; + } + this.appLinkBundleUrl = null; + return this.appLinkBundleUrl; + } +}