Merge pull request #469 from andrewrasch/link-handling-fixes

Update link handling for amp and v.redd.it
This commit is contained in:
Docile-Alligator 2021-09-23 20:00:57 +08:00 committed by GitHub
commit cf9829046a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 22 deletions

View File

@ -272,70 +272,100 @@
<data <data
android:host="www.reddit.com" android:host="www.reddit.com"
android:scheme="https" /> android:scheme="https"
android:pathPattern=".*"/>
<data <data
android:host="reddit.com" android:host="reddit.com"
android:scheme="https" /> android:scheme="https"
android:pathPattern=".*" />
<data
android:host="www.google.com"
android:scheme="https"
android:pathPattern="/amp/s/amp.reddit.com/.*" />
<data
android:host="v.redd.it"
android:scheme="https"
android:pathPattern=".*" />
<data <data
android:host="amp.reddit.com" android:host="amp.reddit.com"
android:scheme="https" /> android:scheme="https"
android:pathPattern=".*" />
<data <data
android:host="m.reddit.com" android:host="m.reddit.com"
android:scheme="https" /> android:scheme="https"
android:pathPattern=".*" />
<data <data
android:host="old.reddit.com" android:host="old.reddit.com"
android:scheme="https" /> android:scheme="https"
android:pathPattern=".*" />
<data <data
android:host="new.reddit.com" android:host="new.reddit.com"
android:scheme="https" /> android:scheme="https"
android:pathPattern=".*" />
<data <data
android:host="np.reddit.com" android:host="np.reddit.com"
android:scheme="https" /> android:scheme="https"
android:pathPattern=".*" />
<data <data
android:host="reddit.app.link" android:host="reddit.app.link"
android:scheme="https" /> android:scheme="https"
android:pathPattern=".*" />
<data <data
android:host="redd.it" android:host="redd.it"
android:scheme="https" /> android:scheme="https"
android:pathPattern=".*" />
<data <data
android:host="s.reddit.com" android:host="s.reddit.com"
android:scheme="https" /> android:scheme="https"
android:pathPattern=".*" />
<data <data
android:host="click.redditmail.com" android:host="click.redditmail.com"
android:scheme="https" /> android:scheme="https"
android:pathPattern=".*" />
<data <data
android:host="www.reddit.com" android:host="www.reddit.com"
android:scheme="http" /> android:scheme="http"
android:pathPattern=".*" />
<data <data
android:host="reddit.com" android:host="reddit.com"
android:scheme="http" /> android:scheme="http"
android:pathPattern=".*" />
<data <data
android:host="amp.reddit.com" android:host="amp.reddit.com"
android:scheme="http" /> android:scheme="http"
android:pathPattern=".*" />
<data <data
android:host="m.reddit.com" android:host="m.reddit.com"
android:scheme="http" /> android:scheme="http"
android:pathPattern=".*" />
<data <data
android:host="old.reddit.com" android:host="old.reddit.com"
android:scheme="http" /> android:scheme="http"
android:pathPattern=".*" />
<data <data
android:host="new.reddit.com" android:host="new.reddit.com"
android:scheme="http" /> android:scheme="http"
android:pathPattern=".*" />
<data <data
android:host="np.reddit.com" android:host="np.reddit.com"
android:scheme="http" /> android:scheme="http"
android:pathPattern=".*" />
<data <data
android:host="reddit.app.link" android:host="reddit.app.link"
android:scheme="http" /> android:scheme="http"
android:pathPattern=".*" />
<data <data
android:host="redd.it" android:host="redd.it"
android:scheme="http" /> android:scheme="http"
android:pathPattern=".*" />
<data <data
android:host="s.reddit.com" android:host="s.reddit.com"
android:scheme="http" /> android:scheme="http"
android:pathPattern=".*" />
<data <data
android:host="click.redditmail.com" android:host="click.redditmail.com"
android:scheme="http" /> android:scheme="http"
android:pathPattern=".*" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity

View File

@ -50,6 +50,7 @@ public class LinkResolverActivity extends AppCompatActivity {
private static final String IMGUR_IMAGE_PATTERN = "/\\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 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/.*";
@Inject @Inject
@Named("default") @Named("default")
@ -268,6 +269,13 @@ public class LinkResolverActivity extends AppCompatActivity {
} else { } else {
deepLinkError(uri); deepLinkError(uri);
} }
} else if (authority.contains("google.com") ){
if ( path.matches(GOOGLE_AMP_PATTERN) ) {
String url = path.substring(11, path.length()); // skipping past amp straight to reddit
handleUri(Uri.parse("https://" + url));
} else {
deepLinkError(uri);
}
} else { } else {
deepLinkError(uri); deepLinkError(uri);
} }