Skip to content

Commit

Permalink
앱링크를 지원합니다
Browse files Browse the repository at this point in the history
  • Loading branch information
dali committed Sep 16, 2018
1 parent 382c2fe commit b1eed91
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 93 deletions.
60 changes: 35 additions & 25 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="xyz.parti.catan"
xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:name=".CatanApp"
Expand All @@ -18,19 +18,26 @@
android:resource="@color/colorIconBg" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>
android:value="@string/default_notification_channel_id" />

<activity
android:name=".MainActivity"
android:theme="@style/AppTheme.NoActionBar"
android:screenOrientation="sensorPortrait"
android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="adjustResize|stateHidden"
android:launchMode="singleInstance"
>
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="*.parti.xyz" />
</intent-filter>
</activity>

Expand All @@ -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">
</activity>
android:theme="@android:style/Theme.NoDisplay"></activity>

<service
android:name=".MyFirebaseMessagingService">
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name=".MyFirebaseInstanceIDService">
<service android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".MyJobService"
android:exported="false">
<service
android:name=".MyJobService"
android:exported="false">
<intent-filter>
<action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/>
<action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE" />
</intent-filter>
</service>

<meta-data
android:name="io.fabric.ApiKey"
android:value="${crashlyticsApiKey}"
/>
android:value="${crashlyticsApiKey}" />

<provider
android:name="android.support.v4.content.FileProvider"
Expand All @@ -77,28 +81,34 @@
</provider>

<!-- facebook -->
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />

<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>

</application>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
<uses-permission android:name="android.permission.CAMERA" />

</manifest>
97 changes: 47 additions & 50 deletions app/src/main/java/xyz/parti/catan/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand All @@ -100,74 +98,74 @@ 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
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
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));
}
}

Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -616,19 +604,28 @@ private void initFacebookSignIn() {
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@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
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
41 changes: 24 additions & 17 deletions app/src/main/java/xyz/parti/catan/UfoWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -568,29 +567,41 @@ 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)
{
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<String, String>();
customHeader.put("X-Catan-Push-Notified", "true");
onBootstrap(pushNotifiedUrl, customHeader);
bootstrapForUrl(pushNotifiedUrl, customHeader);
}

private void onBootstrap(String url, Map<String, String> customHeader) {
private void bootstrapForUrl(String url, Map<String, String> customHeader) {
if (!Util.isNetworkOnline(m_webView.getContext())) {
onNetworkOffline();
return;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -948,8 +959,4 @@ public boolean isLoading(int progress) {
public void stopLoading() {
m_webView.stopLoading();
}

public void simpleGoBack() {
m_webView.goBack();
}
}
Loading

0 comments on commit b1eed91

Please sign in to comment.