-
Notifications
You must be signed in to change notification settings - Fork 306
/
Copy pathDeepLinkActivity.java
45 lines (38 loc) · 1.71 KB
/
DeepLinkActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.automattic.simplenote;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.automattic.simplenote.utils.AuthUtils;
import com.automattic.simplenote.utils.IntentUtils;
import com.automattic.simplenote.utils.WidgetUtils;
import net.openid.appauth.RedirectUriReceiverActivity;
import java.util.Locale;
public class DeepLinkActivity extends AppCompatActivity {
private static final String AUTHENTICATION_SCHEME = "auth";
private static final String LOGIN_SCHEME = "login";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Uri uri = getIntent().getData();
if (uri.getHost().equals(AUTHENTICATION_SCHEME)) {
Intent intent = new Intent(this, RedirectUriReceiverActivity.class);
intent.setData(uri);
startActivity(intent);
} else if (uri.getHost().equals(LOGIN_SCHEME)) {
Intent intent = IntentUtils.maybeAliasedIntent(getApplicationContext());
Simplenote app = (Simplenote) getApplication();
String email = AuthUtils.extractEmailFromMagicLink(uri);
if (app.isLoggedIn() &&
!email.toLowerCase(Locale.US).equals(app.getUserEmail().toLowerCase(Locale.US))) {
intent.putExtra(NotesActivity.KEY_ALREADY_LOGGED_IN, true);
} else {
AuthUtils.magicLinkLogin((Simplenote) getApplication(), uri);
}
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
finish();
}
}