aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorPatrick Demers <patrickdemers6@gmail.com>2022-11-02 12:24:38 +0000
committerGitHub <noreply@github.com>2022-11-02 12:24:38 +0000
commit28ca5e6bbec698d0922a49cc53a279594450552c (patch)
treec15b32d3097136bc096f9d8488305764082d60ba /app/src/main/java
parent0cab9663d4292a01f6f43e5b7419459105680da0 (diff)
downloadinfinity-for-reddit-28ca5e6bbec698d0922a49cc53a279594450552c.tar
infinity-for-reddit-28ca5e6bbec698d0922a49cc53a279594450552c.tar.gz
infinity-for-reddit-28ca5e6bbec698d0922a49cc53a279594450552c.tar.bz2
infinity-for-reddit-28ca5e6bbec698d0922a49cc53a279594450552c.tar.lz
infinity-for-reddit-28ca5e6bbec698d0922a49cc53a279594450552c.tar.xz
infinity-for-reddit-28ca5e6bbec698d0922a49cc53a279594450552c.tar.zst
infinity-for-reddit-28ca5e6bbec698d0922a49cc53a279594450552c.zip
Improve wiki link handling (#1184)
* handle wiki links with dashes and index wiki page * properly handle w vs wiki and links with wiki in it twice * remove beginning and end of line tokens from wiki regex * optimize wiki regex
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java14
1 files changed, 12 insertions, 2 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java
index 081d6d8a..58a0312b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java
@@ -50,7 +50,7 @@ public class LinkResolverActivity extends AppCompatActivity {
private static final String IMGUR_ALBUM_PATTERN = "/(album|a)/\\w+/?";
private static final String IMGUR_IMAGE_PATTERN = "/\\w+/?";
private static final String RPAN_BROADCAST_PATTERN = "/rpan/r/[\\w-]+/\\w+/?\\w+/?";
- private static final String WIKI_PATTERN = "/[rR]/[\\w-]+/(wiki|w)?(?:/\\w+)+";
+ private static final String WIKI_PATTERN = "/[rR]/[\\w-]+/(wiki|w)(?:/[\\w-]+)*";
private static final String GOOGLE_AMP_PATTERN = "/amp/s/amp.reddit.com/.*";
private static final String STREAMABLE_PATTERN = "/\\w+/?";
@@ -206,7 +206,17 @@ public class LinkResolverActivity extends AppCompatActivity {
deepLinkError(uri);
}
} else if (path.matches(WIKI_PATTERN)) {
- final String wikiPage = path.substring(path.lastIndexOf("/wiki/") + 6);
+ String[] pathSegments = path.split("/");
+ String wikiPage;
+ if (pathSegments.length == 4) {
+ wikiPage = "index";
+ } else {
+ int lengthThroughWiki = 0;
+ for (int i = 1; i <= 3; ++i) {
+ lengthThroughWiki += pathSegments[i].length() + 1;
+ }
+ wikiPage = path.substring(lengthThroughWiki);
+ }
Intent intent = new Intent(this, WikiActivity.class);
intent.putExtra(WikiActivity.EXTRA_SUBREDDIT_NAME, segments.get(1));
intent.putExtra(WikiActivity.EXTRA_WIKI_PATH, wikiPage);