-
-
Save S64/b06379aef94ce2337d67182743d6c9a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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