From f27f7c12a8ae712d48623af87f1b8aff7fa61425 Mon Sep 17 00:00:00 2001 From: Hermes Junior Date: Mon, 11 May 2020 01:16:31 +0200 Subject: Handle Reddit app links. --- .../infinityforreddit/Activity/LinkResolverActivity.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index f932427f..ff39b7f3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -56,6 +56,10 @@ public class LinkResolverActivity extends AppCompatActivity { ((Infinity) getApplication()).getAppComponent().inject(this); Uri uri = getIntent().getData(); + handleUri(uri); + } + + private void handleUri(Uri uri) { if (uri == null) { Toast.makeText(this, R.string.no_link_available, Toast.LENGTH_SHORT).show(); finish(); @@ -73,7 +77,10 @@ public class LinkResolverActivity extends AppCompatActivity { String authority = uri.getAuthority(); if (authority != null && (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app"))) { - if (path.matches(POST_PATTERN)) { + if (authority.equals("reddit.app.link") && path.isEmpty()) { + String redirect = uri.getQueryParameter("$og_redirect"); + handleUri(Uri.parse(redirect)); + } else if (path.matches(POST_PATTERN)) { List segments = uri.getPathSegments(); int commentsIndex = segments.lastIndexOf("comments"); if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { -- cgit v1.2.3 From b31c96b2d9f35d622dd9415306296d46a194a0cb Mon Sep 17 00:00:00 2001 From: Hermes Junior Date: Mon, 11 May 2020 01:17:14 +0200 Subject: Handle Reddit home links. --- .../infinityforreddit/Activity/LinkResolverActivity.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index ff39b7f3..145e311e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -80,6 +80,9 @@ public class LinkResolverActivity extends AppCompatActivity { if (authority.equals("reddit.app.link") && path.isEmpty()) { String redirect = uri.getQueryParameter("$og_redirect"); handleUri(Uri.parse(redirect)); + } else if (path.isEmpty()) { + Intent intent = new Intent(this, MainActivity.class); + startActivity(intent); } else if (path.matches(POST_PATTERN)) { List segments = uri.getPathSegments(); int commentsIndex = segments.lastIndexOf("comments"); -- cgit v1.2.3 From a2dc0b1c0d51d74ca5c3c5942af2b113ebbd27be Mon Sep 17 00:00:00 2001 From: Hermes Junior Date: Mon, 11 May 2020 03:25:50 +0200 Subject: Handle other comment links. --- .../infinityforreddit/Activity/LinkResolverActivity.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index 145e311e..76ed0e1b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -31,7 +31,7 @@ public class LinkResolverActivity extends AppCompatActivity { public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; private static final String POST_PATTERN = "/r/\\w+/comments/\\w+/{0,1}\\w+/{0,1}"; - private static final String COMMENT_PATTERN = "/r/\\w+/comments/\\w+/{0,1}\\w+/\\w+/{0,1}"; + private static final String COMMENT_PATTERN = "/(r|u|user)/\\w+/comments/\\w+/{0,1}\\w+/\\w+/{0,1}"; private static final String SUBREDDIT_PATTERN = "/[rR]/\\w+/{0,1}"; private static final String USER_PATTERN_1 = "/user/\\w+/{0,1}"; private static final String USER_PATTERN_2 = "/[uU]/\\w+/{0,1}"; @@ -76,6 +76,8 @@ public class LinkResolverActivity extends AppCompatActivity { String newAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME); String authority = uri.getAuthority(); + List segments = uri.getPathSegments(); + if (authority != null && (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app"))) { if (authority.equals("reddit.app.link") && path.isEmpty()) { String redirect = uri.getQueryParameter("$og_redirect"); @@ -84,7 +86,6 @@ public class LinkResolverActivity extends AppCompatActivity { Intent intent = new Intent(this, MainActivity.class); startActivity(intent); } else if (path.matches(POST_PATTERN)) { - List segments = uri.getPathSegments(); int commentsIndex = segments.lastIndexOf("comments"); if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { Intent intent = new Intent(this, ViewPostDetailActivity.class); @@ -96,7 +97,6 @@ public class LinkResolverActivity extends AppCompatActivity { deepLinkError(uri); } } else if (path.matches(COMMENT_PATTERN)) { - List segments = uri.getPathSegments(); int commentsIndex = segments.lastIndexOf("comments"); if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { Intent intent = new Intent(this, ViewPostDetailActivity.class); @@ -125,13 +125,13 @@ public class LinkResolverActivity extends AppCompatActivity { } } else if (path.matches(USER_PATTERN_1)) { Intent intent = new Intent(this, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, path.substring(6)); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, segments.get(1)); intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); startActivity(intent); } else if (path.matches(USER_PATTERN_2)) { Intent intent = new Intent(this, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, path.substring(3)); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, segments.get(1)); intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); startActivity(intent); -- cgit v1.2.3 From adf8fa4e6a859029ac2d17ee79296e2afcda5b7a Mon Sep 17 00:00:00 2001 From: Hermes Junior Date: Mon, 11 May 2020 03:39:35 +0200 Subject: Improve some regex of link resolver. --- .../infinityforreddit/Activity/LinkResolverActivity.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index 76ed0e1b..defe8e3a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -31,10 +31,9 @@ public class LinkResolverActivity extends AppCompatActivity { public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; private static final String POST_PATTERN = "/r/\\w+/comments/\\w+/{0,1}\\w+/{0,1}"; - private static final String COMMENT_PATTERN = "/(r|u|user)/\\w+/comments/\\w+/{0,1}\\w+/\\w+/{0,1}"; + private static final String COMMENT_PATTERN = "/(r|u|U|user)/\\w+/comments/\\w+/{0,1}\\w+/\\w+/{0,1}"; private static final String SUBREDDIT_PATTERN = "/[rR]/\\w+/{0,1}"; - private static final String USER_PATTERN_1 = "/user/\\w+/{0,1}"; - private static final String USER_PATTERN_2 = "/[uU]/\\w+/{0,1}"; + private static final String USER_PATTERN = "/([uU]|user)/\\w+/{0,1}"; private static final String SIDEBAR_PATTERN = "/[rR]/\\w+/about/sidebar"; private static final String MULTIREDDIT_PATTERN = "/user/\\w+/m/\\w+/{0,1}"; private static final String REDD_IT_POST_PATTERN = "/\\w+/{0,1}"; @@ -123,13 +122,7 @@ public class LinkResolverActivity extends AppCompatActivity { intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); startActivity(intent); } - } else if (path.matches(USER_PATTERN_1)) { - Intent intent = new Intent(this, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, segments.get(1)); - intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); - startActivity(intent); - } else if (path.matches(USER_PATTERN_2)) { + } else if (path.matches(USER_PATTERN)) { Intent intent = new Intent(this, ViewUserDetailActivity.class); intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, segments.get(1)); intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); -- cgit v1.2.3 From ccecc2b511bffc9711bd41b15aabccc2d179b9cd Mon Sep 17 00:00:00 2001 From: Hermes Junior Date: Tue, 12 May 2020 00:27:53 +0200 Subject: Handle alternative multireddit URL. --- .../infinityforreddit/Activity/LinkResolverActivity.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index defe8e3a..bacb5a68 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -36,6 +36,7 @@ public class LinkResolverActivity extends AppCompatActivity { private static final String USER_PATTERN = "/([uU]|user)/\\w+/{0,1}"; private static final String SIDEBAR_PATTERN = "/[rR]/\\w+/about/sidebar"; private static final String MULTIREDDIT_PATTERN = "/user/\\w+/m/\\w+/{0,1}"; + private static final String MULTIREDDIT_PATTERN_2 = "/[rR]/(\\w+\\+?)+/?"; private static final String REDD_IT_POST_PATTERN = "/\\w+/{0,1}"; @Inject @@ -136,6 +137,13 @@ public class LinkResolverActivity extends AppCompatActivity { Intent intent = new Intent(this, ViewMultiRedditDetailActivity.class); intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_PATH, path); startActivity(intent); + } else if (path.matches(MULTIREDDIT_PATTERN_2)) { + String subredditName = path.substring(3); + Intent intent = new Intent(this, ViewSubredditDetailActivity.class); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditName); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); } else if (authority.equals("redd.it") && path.matches(REDD_IT_POST_PATTERN)) { Intent intent = new Intent(this, ViewPostDetailActivity.class); intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, path.substring(1)); -- cgit v1.2.3 From 8ddae6164978f7fa1a262dec6b57f230b727b3f8 Mon Sep 17 00:00:00 2001 From: OHermesJunior Date: Tue, 12 May 2020 00:46:42 +0200 Subject: More little improvements for regex. --- .../infinityforreddit/Activity/LinkResolverActivity.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index bacb5a68..6719fe54 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -30,14 +30,14 @@ public class LinkResolverActivity extends AppCompatActivity { public static final String EXTRA_MESSAGE_FULLNAME = "ENF"; public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; - private static final String POST_PATTERN = "/r/\\w+/comments/\\w+/{0,1}\\w+/{0,1}"; - private static final String COMMENT_PATTERN = "/(r|u|U|user)/\\w+/comments/\\w+/{0,1}\\w+/\\w+/{0,1}"; - private static final String SUBREDDIT_PATTERN = "/[rR]/\\w+/{0,1}"; - private static final String USER_PATTERN = "/([uU]|user)/\\w+/{0,1}"; + private static final String POST_PATTERN = "/r/\\w+/comments/\\w+/?\\w+/?"; + private static final String COMMENT_PATTERN = "/(r|u|U|user)/\\w+/comments/\\w+/?\\w+/\\w+/?"; + private static final String SUBREDDIT_PATTERN = "/[rR]/\\w+/?"; + private static final String USER_PATTERN = "/(u|U|user)/\\w+/?"; private static final String SIDEBAR_PATTERN = "/[rR]/\\w+/about/sidebar"; - private static final String MULTIREDDIT_PATTERN = "/user/\\w+/m/\\w+/{0,1}"; + private static final String MULTIREDDIT_PATTERN = "/user/\\w+/m/\\w+/?"; private static final String MULTIREDDIT_PATTERN_2 = "/[rR]/(\\w+\\+?)+/?"; - private static final String REDD_IT_POST_PATTERN = "/\\w+/{0,1}"; + private static final String REDD_IT_POST_PATTERN = "/\\w+/?"; @Inject @Named("default") -- cgit v1.2.3