diff --git a/deeplinkdispatch-processor/build.gradle b/deeplinkdispatch-processor/build.gradle index c5d9cfb0..ea5da89b 100644 --- a/deeplinkdispatch-processor/build.gradle +++ b/deeplinkdispatch-processor/build.gradle @@ -10,6 +10,9 @@ dependencies { testCompile 'junit:junit:4.12' testCompile 'org.assertj:assertj-core:1.7.0' + testCompile 'com.google.android:android:4.1.1.4' + testCompile 'com.google.testing.compile:compile-testing:0.6' + testCompile files(org.gradle.internal.jvm.Jvm.current().getToolsJar()) } modifyPom { @@ -24,8 +27,8 @@ modifyPom { scm { url PROJECT_URL - connection 'scm:https://git.musta.ch/airbnb/DeepLinkDispatch.git' - developerConnection 'scm:git@git.musta.ch:airbnb/DeepLinkDispatch.git' + connection 'scm:https://gitub.com/airbnb/DeepLinkDispatch.git' + developerConnection 'scm:git@gitub.com:airbnb/DeepLinkDispatch.git' } licenses { diff --git a/deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/internal/DeepLinkAnnotatedElement.java b/deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkAnnotatedElement.java similarity index 92% rename from deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/internal/DeepLinkAnnotatedElement.java rename to deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkAnnotatedElement.java index 7a3da1ca..4de85696 100644 --- a/deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/internal/DeepLinkAnnotatedElement.java +++ b/deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkAnnotatedElement.java @@ -13,13 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.airbnb.deeplinkdispatch.internal; - -import com.airbnb.deeplinkdispatch.DeepLinkEntry; +package com.airbnb.deeplinkdispatch; import javax.lang.model.element.Element; -public class DeepLinkAnnotatedElement { +final class DeepLinkAnnotatedElement { private final String host; private final String path; diff --git a/deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/internal/DeepLinkProcessor.java b/deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkProcessor.java similarity index 89% rename from deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/internal/DeepLinkProcessor.java rename to deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkProcessor.java index ef120d3d..c94a7127 100644 --- a/deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/internal/DeepLinkProcessor.java +++ b/deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkProcessor.java @@ -13,15 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.airbnb.deeplinkdispatch.internal; +package com.airbnb.deeplinkdispatch; import com.google.auto.service.AutoService; - -import com.airbnb.deeplinkdispatch.DeepLink; -import com.airbnb.deeplinkdispatch.DeepLinkEntry; -import com.airbnb.deeplinkdispatch.DeepLinkRegistry; -import com.airbnb.deeplinkdispatch.DeepLinks; -import com.airbnb.deeplinkdispatch.Loader; import com.squareup.javapoet.ClassName; import com.squareup.javapoet.FieldSpec; import com.squareup.javapoet.JavaFile; @@ -56,22 +50,19 @@ public class DeepLinkProcessor extends AbstractProcessor { private Filer filer; private Messager messager; - @Override - public synchronized void init(ProcessingEnvironment processingEnv) { + @Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); filer = processingEnv.getFiler(); messager = processingEnv.getMessager(); } - @Override - public Set getSupportedAnnotationTypes() { + @Override public Set getSupportedAnnotationTypes() { Set annotations = new LinkedHashSet<>(); annotations.add(DeepLink.class.getCanonicalName()); return annotations; } - @Override - public SourceVersion getSupportedSourceVersion() { + @Override public SourceVersion getSupportedSourceVersion() { return SourceVersion.latestSupported(); } @@ -88,7 +79,7 @@ public boolean process(Set annotations, RoundEnvironment String[] deepLinks = element.getAnnotation(DeepLinks.class).value(); DeepLinkEntry.Type type = kind == ElementKind.CLASS - ? DeepLinkEntry.Type.CLASS : DeepLinkEntry.Type.METHOD; + ? DeepLinkEntry.Type.CLASS : DeepLinkEntry.Type.METHOD; for (String deepLink : deepLinks) { deepLinkElements.add(new DeepLinkAnnotatedElement(deepLink, element, type)); } @@ -103,7 +94,7 @@ public boolean process(Set annotations, RoundEnvironment DeepLink deepLink = element.getAnnotation(DeepLink.class); DeepLinkEntry.Type type = kind == ElementKind.CLASS - ? DeepLinkEntry.Type.CLASS : DeepLinkEntry.Type.METHOD; + ? DeepLinkEntry.Type.CLASS : DeepLinkEntry.Type.METHOD; deepLinkElements.add(new DeepLinkAnnotatedElement(deepLink.value(), element, type)); } @@ -134,11 +125,11 @@ private void generateRegistry(List elements) throws IO for (DeepLinkAnnotatedElement element : elements) { String hostPath = element.getPath().equals("") - ? element.getHost() : element.getHost() + "/" + element.getPath(); + ? element.getHost() : element.getHost() + "/" + element.getPath(); String type = "DeepLinkEntry.Type." + element.getAnnotationType().toString(); - String activity = element.getActivity(); + ClassName activity = ClassName.bestGuess(element.getActivity()); Object method = element.getMethod() == null ? null : element.getMethod(); - loadMethod.addStatement("registry.registerDeepLink($S, $L, $S, $S)", + loadMethod.addStatement("registry.registerDeepLink($S, $L, $T.class, $S)", hostPath, type, activity, method); } @@ -197,7 +188,7 @@ private void generateDeepLinkActivity() throws IOException { .addStatement("parameterMap.put(queryParameter, uri.getQueryParameter(queryParameter))") .endControlFlow() .beginControlFlow("try") - .addStatement("Class c = Class.forName(entry.getActivity())") + .addStatement("Class c = entry.getActivityClass()") .addStatement("$T intent", ClassName.get("android.content", "Intent")) .beginControlFlow("if (entry.getType() == DeepLinkEntry.Type.CLASS)") .addStatement("intent = new Intent(this, c)") @@ -226,9 +217,6 @@ private void generateDeepLinkActivity() throws IOException { .addStatement("intent.putExtra(DeepLink.IS_DEEP_LINK, true)") .addStatement("startActivity(intent)") .addStatement("notifyListener(false, uri, null)") - .nextControlFlow("catch (ClassNotFoundException exception)") - .addStatement( - "notifyListener(true, uri, \"Deep link to non-existent class: \" + entry.getActivity())") .nextControlFlow("catch (NoSuchMethodException exception)") .addStatement( "notifyListener(true, uri, \"Deep link to non-existent method: \" + entry.getMethod())") @@ -242,8 +230,8 @@ private void generateDeepLinkActivity() throws IOException { .addStatement("finish()") .endControlFlow() .nextControlFlow("else") - .addStatement( - "notifyListener(true, uri, \"No registered entity to handle deep link: \" + uri.toString())") + .addStatement("notifyListener(true, uri, \"No registered entity to handle deep link: \"" + + " + uri.toString())") .addStatement("finish()") .endControlFlow() .build(); diff --git a/deeplinkdispatch-processor/src/test/java/com/airbnb/deeplinkdispatch/DeepLinkProcessorTest.java b/deeplinkdispatch-processor/src/test/java/com/airbnb/deeplinkdispatch/DeepLinkProcessorTest.java new file mode 100644 index 00000000..9a346318 --- /dev/null +++ b/deeplinkdispatch-processor/src/test/java/com/airbnb/deeplinkdispatch/DeepLinkProcessorTest.java @@ -0,0 +1,35 @@ +package com.airbnb.deeplinkdispatch; + +import com.google.testing.compile.JavaFileObjects; + +import org.junit.Test; + +import javax.tools.JavaFileObject; + +import static com.google.common.truth.Truth.assert_; +import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource; + +public class DeepLinkProcessorTest { + @Test public void testProcessor() { + JavaFileObject sampleActivity = JavaFileObjects + .forSourceString("SampleActivity", "package com.example;" + + "import com.airbnb.deeplinkdispatch.DeepLink; " + + "@DeepLink(\"example.com/deepLink\") public class SampleActivity {}"); + + assert_().about(javaSource()) + .that(sampleActivity) + .processedWith(new DeepLinkProcessor()) + .compilesWithoutError() + .and() + .generatesSources( + JavaFileObjects.forResource("DeepLinkActivity.java"), + JavaFileObjects.forSourceString("DeepLinkLoader", +"package com.airbnb.deeplinkdispatch;\n" + +"import com.example.SampleActivity;\n" + +"public final class DeepLinkLoader implements Loader {\n" + +" public void load(DeepLinkRegistry registry) {\n" + +" registry.registerDeepLink(\"example.com/deepLink\", DeepLinkEntry.Type.CLASS, SampleActivity.class, null);\n" + +" }\n" + +"}\n")); + } +} \ No newline at end of file diff --git a/deeplinkdispatch-processor/src/test/resources/DeepLinkActivity.java b/deeplinkdispatch-processor/src/test/resources/DeepLinkActivity.java new file mode 100644 index 00000000..14de2cd8 --- /dev/null +++ b/deeplinkdispatch-processor/src/test/resources/DeepLinkActivity.java @@ -0,0 +1,87 @@ +package com.airbnb.deeplinkdispatch; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.util.Log; +import java.lang.Override; +import java.lang.String; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Map; + +public class DeepLinkActivity extends Activity { + private static final String TAG = DeepLinkActivity.class.getSimpleName(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Loader loader = new com.airbnb.deeplinkdispatch.DeepLinkLoader(); + DeepLinkRegistry registry = new DeepLinkRegistry(loader); + Uri uri = getIntent().getData(); + String hostPath = uri.getHost() + uri.getPath(); + DeepLinkEntry entry = registry.parseUri(hostPath); + if (entry != null) { + Map parameterMap = entry.getParameters(hostPath); + for (String queryParameter : uri.getQueryParameterNames()) { + if (parameterMap.containsKey(queryParameter)) { + Log.w(TAG, "Duplicate parameter name in path and query param: " + queryParameter); + } + parameterMap.put(queryParameter, uri.getQueryParameter(queryParameter)); + } + try { + Class c = entry.getActivityClass(); + Intent intent; + if (entry.getType() == DeepLinkEntry.Type.CLASS) { + intent = new Intent(this, c); + } else { + Method method = c.getMethod(entry.getMethod(), Context.class); + intent = (Intent) method.invoke(c, this); + } + if (intent.getAction() == null) { + intent.setAction(getIntent().getAction()); + } + if (intent.getData() == null) { + intent.setData(getIntent().getData()); + } + Bundle parameters; + if (getIntent().getExtras() != null) { + parameters = new Bundle(getIntent().getExtras()); + } else { + parameters = new Bundle(); + } + for (Map.Entry parameterEntry : parameterMap.entrySet()) { + parameters.putString(parameterEntry.getKey(), parameterEntry.getValue()); + } + intent.putExtras(parameters); + intent.putExtra(DeepLink.IS_DEEP_LINK, true); + startActivity(intent); + notifyListener(false, uri, null); + } catch (NoSuchMethodException exception) { + notifyListener(true, uri, "Deep link to non-existent method: " + entry.getMethod()); + } catch (IllegalAccessException exception) { + notifyListener(true, uri, "Could not deep link to method: " + entry.getMethod()); + } catch(InvocationTargetException exception) { + notifyListener(true, uri, "Could not deep link to method: " + entry.getMethod()); + } finally { + finish(); + } + } else { + notifyListener(true, uri, "No registered entity to handle deep link: " + uri.toString()); + finish(); + } + } + + private void notifyListener(boolean isError, Uri uri, String errorMessage) { + if (getApplication() instanceof DeepLinkCallback) { + DeepLinkCallback listener = (DeepLinkCallback) getApplication(); + if (!isError) { + listener.onSuccess(uri.toString()); + } else { + listener.onError(new DeepLinkError(uri.toString(), errorMessage)); + } + } + } +} diff --git a/deeplinkdispatch/build.gradle b/deeplinkdispatch/build.gradle index 54cd28c6..797add67 100644 --- a/deeplinkdispatch/build.gradle +++ b/deeplinkdispatch/build.gradle @@ -23,8 +23,8 @@ modifyPom { scm { url PROJECT_URL - connection 'scm:https://git.musta.ch/airbnb/DeepLinkDispatch.git' - developerConnection 'scm:git@git.musta.ch:airbnb/DeepLinkDispatch.git' + connection 'scm:https://gitub.com/airbnb/DeepLinkDispatch.git' + developerConnection 'scm:git@gitub.com:airbnb/DeepLinkDispatch.git' } licenses { diff --git a/deeplinkdispatch/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkEntry.java b/deeplinkdispatch/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkEntry.java index 74a167f4..fb75edd9 100644 --- a/deeplinkdispatch/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkEntry.java +++ b/deeplinkdispatch/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkEntry.java @@ -21,7 +21,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public class DeepLinkEntry { +final class DeepLinkEntry { private static final String PARAM_VALUE = "([a-zA-Z0-9]*)"; private static final String PARAM = "([a-zA-Z][a-zA-Z0-9_-]*)"; @@ -30,7 +30,7 @@ public class DeepLinkEntry { private final String hostPath; private final String regex; private final Type type; - private final String activity; + private final Class activityClass; private final String method; public enum Type { @@ -38,11 +38,11 @@ public enum Type { METHOD } - public DeepLinkEntry(String hostPath, Type type, String activity, String method) { + public DeepLinkEntry(String hostPath, Type type, Class activityClass, String method) { this.hostPath = hostPath; this.regex = generateLookupString(hostPath); this.type = type; - this.activity = activity; + this.activityClass = activityClass; this.method = method; } @@ -54,8 +54,8 @@ public Type getType() { return type; } - public String getActivity() { - return activity; + public Class getActivityClass() { + return activityClass; } public String getMethod() { diff --git a/deeplinkdispatch/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkRegistry.java b/deeplinkdispatch/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkRegistry.java index dfeb2a84..4f71de8c 100644 --- a/deeplinkdispatch/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkRegistry.java +++ b/deeplinkdispatch/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkRegistry.java @@ -20,9 +20,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public class DeepLinkRegistry { +final class DeepLinkRegistry { - private List registry = new LinkedList<>(); + private final List registry = new LinkedList<>(); public DeepLinkRegistry(Loader loader) { if (loader != null) { @@ -33,14 +33,14 @@ public DeepLinkRegistry(Loader loader) { /** * Registers the deep link that DeepLinkActivity will handle, along with where to delegate * - * @param hostPath the combined host and path of the deep link - * @param type whether its a class level annotation or method level - * @param activity the activity to delegate the deep link to - * @param method the method used to generate the Intent + * @param hostPath the combined host and path of the deep link + * @param type whether its a class level annotation or method level + * @param activityClass the activity class to delegate the deep link to + * @param method the method used to generate the Intent */ - public void registerDeepLink(String hostPath, DeepLinkEntry.Type type, String activity, + public void registerDeepLink(String hostPath, DeepLinkEntry.Type type, Class activityClass, String method) { - registry.add(new DeepLinkEntry(hostPath, type, activity, method)); + registry.add(new DeepLinkEntry(hostPath, type, activityClass, method)); } /** diff --git a/deeplinkdispatch/src/main/java/com/airbnb/deeplinkdispatch/Loader.java b/deeplinkdispatch/src/main/java/com/airbnb/deeplinkdispatch/Loader.java index d19ac7db..a887ed37 100644 --- a/deeplinkdispatch/src/main/java/com/airbnb/deeplinkdispatch/Loader.java +++ b/deeplinkdispatch/src/main/java/com/airbnb/deeplinkdispatch/Loader.java @@ -15,6 +15,6 @@ */ package com.airbnb.deeplinkdispatch; -public interface Loader { +interface Loader { void load(DeepLinkRegistry registry); } diff --git a/deeplinkdispatch/src/test/java/com/airbnb/deeplinkdispatch/DeepLinkEntryTest.java b/deeplinkdispatch/src/test/java/com/airbnb/deeplinkdispatch/DeepLinkEntryTest.java new file mode 100644 index 00000000..660b7732 --- /dev/null +++ b/deeplinkdispatch/src/test/java/com/airbnb/deeplinkdispatch/DeepLinkEntryTest.java @@ -0,0 +1,27 @@ +package com.airbnb.deeplinkdispatch; + +import org.junit.Test; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DeepLinkEntryTest { + @Test public void testSingleParam() { + DeepLinkEntry entry = new DeepLinkEntry( + "foo/{bar}", DeepLinkEntry.Type.CLASS, String.class, null); + + Map parameters = entry.getParameters("foo/myData"); + + assertThat(parameters.get("bar")).isEqualTo("myData"); + } + + @Test public void testTwoParams() { + DeepLinkEntry entry = new DeepLinkEntry( + "test/{param1}/{param2}", DeepLinkEntry.Type.CLASS, String.class, null); + + Map parameters = entry.getParameters("test/12345/alice"); + assertThat(parameters.get("param1")).isEqualTo("12345"); + assertThat(parameters.get("param2")).isEqualTo("alice"); + } +} diff --git a/deeplinkdispatch/src/test/java/com/airbnb/deeplinkdispatch/DeepLinkRegistryTest.java b/deeplinkdispatch/src/test/java/com/airbnb/deeplinkdispatch/DeepLinkRegistryTest.java new file mode 100644 index 00000000..a9313851 --- /dev/null +++ b/deeplinkdispatch/src/test/java/com/airbnb/deeplinkdispatch/DeepLinkRegistryTest.java @@ -0,0 +1,41 @@ +package com.airbnb.deeplinkdispatch; + +import org.junit.Before; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DeepLinkRegistryTest { + + private DeepLinkRegistry registry; + + @Before public void setUp() { + registry = new DeepLinkRegistry(null); + } + + @Test public void testSingleParameter() { + registry.registerDeepLink("test/{param1}", DeepLinkEntry.Type.CLASS, String.class, null); + + DeepLinkEntry entry = registry.parseUri("test/12345"); + + assertThat(entry).isNotNull(); + } + + @Test public void testTwoParameters() { + registry.registerDeepLink( + "test/{param1}/{param2}", DeepLinkEntry.Type.CLASS, String.class, null); + + DeepLinkEntry entry = registry.parseUri("test/12345/alice"); + + assertThat(entry).isNotNull(); + } + + @Test public void testEntryNotFound() { + registry.registerDeepLink( + "test/{param1}/{param2}", DeepLinkEntry.Type.CLASS, String.class, null); + + DeepLinkEntry entry = registry.parseUri("blah/232"); + + assertThat(entry).isNull(); + } +} diff --git a/deeplinkdispatch/src/test/java/deeplinkdispatch/DeepLinkRegistryTest.java b/deeplinkdispatch/src/test/java/deeplinkdispatch/DeepLinkRegistryTest.java deleted file mode 100644 index 16bf5fcc..00000000 --- a/deeplinkdispatch/src/test/java/deeplinkdispatch/DeepLinkRegistryTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package deeplinkdispatch; - -import com.airbnb.deeplinkdispatch.DeepLinkEntry; -import com.airbnb.deeplinkdispatch.DeepLinkRegistry; - -import org.junit.Assert; -import org.junit.Test; - -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DeepLinkRegistryTest { - - @Test public void testSingleParameter() { - String hostPath = "test/{param1}"; - - DeepLinkRegistry registry = new DeepLinkRegistry(null); - registry.registerDeepLink(hostPath, DeepLinkEntry.Type.CLASS, "TestActivity", null); - - String inputHostPath = "test/12345"; - DeepLinkEntry entry = registry.parseUri(inputHostPath); - Assert.assertNotNull(entry); - - Map parameters = entry.getParameters(inputHostPath); - assertThat(parameters.get("param1")).isEqualTo("12345"); - } - - @Test public void testTwoParameters() { - String hostPath = "test/{param1}/{param2}"; - - DeepLinkRegistry registry = new DeepLinkRegistry(null); - registry.registerDeepLink(hostPath, DeepLinkEntry.Type.CLASS, "TestActivity", null); - - String inputHostPath = "test/12345/alice"; - DeepLinkEntry entry = registry.parseUri(inputHostPath); - Assert.assertNotNull(entry); - - Map parameters = entry.getParameters(inputHostPath); - assertThat(parameters.get("param1")).isEqualTo("12345"); - assertThat(parameters.get("param2")).isEqualTo("alice"); - } -} diff --git a/gradle.properties b/gradle.properties index 931f3e98..f9d24a74 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,5 @@ PROJECT_VERSION=1.1.0 PROJECT_GROUP_ID=com.airbnb -PROJECT_URL=https://git.musta.ch/airbnb/deeplinkdispatch -PROJECT_DESCRIPTION=Library designed to handle deep linking in an Android application. \ No newline at end of file +PROJECT_URL=https://gitub.com/airbnb/deeplinkdispatch +PROJECT_DESCRIPTION=Library designed to handle deep linking in an Android application. +org.gradle.daemon=false \ No newline at end of file diff --git a/sample/src/main/java/com/airbnb/deeplinkdispatch/sample/MainActivity.java b/sample/src/main/java/com/airbnb/deeplinkdispatch/sample/MainActivity.java index 2fecca60..f9668c6e 100644 --- a/sample/src/main/java/com/airbnb/deeplinkdispatch/sample/MainActivity.java +++ b/sample/src/main/java/com/airbnb/deeplinkdispatch/sample/MainActivity.java @@ -25,15 +25,14 @@ import com.airbnb.deeplinkdispatch.DeepLinks; @DeepLinks({"classDeepLink", "otherClassDeepLink", "example.com/deepLink"}) -// You can also register multiple deep links for a particular activity to handle: -// @DeepLinks({@DeepLink(host = "classDeepLink"), @DeepLink(host="anotherClassDeepLink")}) +// You can also register a single deep link for a particular activity to handle: +// @DeepLink("example.com/something") public class MainActivity extends AppCompatActivity { private static String ACTION_DEEP_LINK_METHOD = "deep_link_method"; private static String ACTION_DEEP_LINK_COMPLEX = "deep_link_complex"; - @Override - protected void onCreate(Bundle savedInstanceState) { + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); @@ -60,16 +59,12 @@ protected void onCreate(Bundle savedInstanceState) { @DeepLink("methodDeepLink/{param1}") public static Intent intentForDeepLinkMethod(Context context) { - Intent intent = new Intent(context, MainActivity.class); - intent.setAction(ACTION_DEEP_LINK_METHOD); - return intent; + return new Intent(context, MainActivity.class).setAction(ACTION_DEEP_LINK_METHOD); } @DeepLink("host/somePath/{arbitraryNumber}") public static Intent intentForComplexMethod(Context context) { - Intent intent = new Intent(context, MainActivity.class); - intent.setAction(ACTION_DEEP_LINK_COMPLEX); - return intent; + return new Intent(context, MainActivity.class).setAction(ACTION_DEEP_LINK_COMPLEX); } private void showToast(String message) { diff --git a/sample/src/main/java/com/airbnb/deeplinkdispatch/sample/SampleApplication.java b/sample/src/main/java/com/airbnb/deeplinkdispatch/sample/SampleApplication.java index 016b8aaf..032c389e 100644 --- a/sample/src/main/java/com/airbnb/deeplinkdispatch/sample/SampleApplication.java +++ b/sample/src/main/java/com/airbnb/deeplinkdispatch/sample/SampleApplication.java @@ -25,13 +25,11 @@ public class SampleApplication extends Application implements DeepLinkCallback { private static final String TAG = "DeepLinkDispatch"; - @Override - public void onSuccess(String uri) { - Log.i(TAG, "Successful deep link: " + uri.toString()); + @Override public void onSuccess(String uri) { + Log.i(TAG, "Successful deep link: " + uri); } - @Override - public void onError(DeepLinkError error) { + @Override public void onError(DeepLinkError error) { Log.e(TAG, "Deep Link Error: " + error.getErrorMessage()); } }