Skip to content

Instantly share code, notes, and snippets.

@S64
Last active May 22, 2019 02:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save S64/b06379aef94ce2337d67182743d6c9a6 to your computer and use it in GitHub Desktop.
Save S64/b06379aef94ce2337d67182743d6c9a6 to your computer and use it in GitHub Desktop.
public class WildlyIntentHelper {
private static final WildlyIntentHelper INSTANCE = new WildlyIntentHelper();
public static WildlyIntentHelper getInstance() {
return INSTANCE;
}
private static final LaunchPattern[] LAUNCH_PATTERNS;
public static class LaunchPattern {
public String scheme;
public String host;
public Pattern pathPattern;
public int idPosition;
public IntentGenerator generator;
}
public abstract static class IntentGenerator {
public abstract Intent generate(String id);
}
static {
LAUNCH_PATTERNS = new LaunchPattern[]{
new LaunchPattern() {{
scheme = "https";
host = "example.wantedly.com";
pathPattern = Pattern.compile("/example_content/.*");
idPosition = 1;
generator = new ExampleContentIntentGenerator(); // TODO
}},
new LaunchPattern() {{
scheme = "wtd";
host = "example_content";
pathPattern = Pattern.compile("/.*");
idPosition = 0;
generator = new ExampleContentIntentGenerator(); // TODO
}},
};
}
private WildlyIntentHelper() {
}
private Intent processIntent(Uri uri) {
String id = null;
for (LaunchPattern pattern : LAUNCH_PATTERNS) {
Matcher m = pattern.pathPattern.matcher(uri.getPath());
if (pattern.scheme.equals(uri.getScheme()) && pattern.host.equals(uri.getHost()) && m.matches()) {
Intent ret = pattern.generator.generate(uri.getPathSegments().get(pattern.idPosition));
if (ret != null) {
return ret;
}
}
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment