Skip to content

Commit

Permalink
Merge pull request #23 from Fueled/deep-link-module-support
Browse files Browse the repository at this point in the history
Implement multi module deep linking support
  • Loading branch information
julien-fueled authored Jun 6, 2017
2 parents b93dc0c + 7764c87 commit ac58a42
Show file tree
Hide file tree
Showing 31 changed files with 640 additions and 368 deletions.
72 changes: 60 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,68 @@ public class TestFragment extends Fragment implement FlowrFragment
String url = getArguments().getString(Flowr.DEEP_LINK_URL,"");
String id = getArguments().getString("id","");
```
To trigger the deep linking handling, simply call `open(Intent, Fragment))`
### Deep Linking Setup:
To generate your deep link handler you will need to annotate at least one class with the `@DeepLinkHandler` annotation. The name of the class annotated with the `@DeepLinkHandler` annotation would then be used as the name of the generated handler class with "Impl" appended at the end.
```java
getFlowr()
.open(getIntent(), HomeFragment.class)
.skipBackStack(true)
.displayFragment();
/** This will generate a MainDeepLinkHandlerImpl class */
@DeepLinkHandler
public class MainDeepLinkHandler {
}
```
However it is also possible to specify a custom name for the generated class by passing the desired class name as a string argument to the `@DeepLinkHandler` annotation.
```java
/** This will generate a MyDeepLinkHandler class */
@DeepLinkHandler("MyDeepLinkHandler")
public class MainActivity extends AbstractActivity {
}
```
If you have fragments across multiple modules, you will need to add the `@DeepLinkHandler` annotation to at least one class in each module.
```java
/** This will generate a LibraryDeepLinkHandlerImpl class */
@DeepLinkHandler
public class LibraryDeepLinkHandler {
}
```
Provide the list of generated deep link handlers to your flowr instance.
```java
public class MainActivity extends AbstractActivity {
private Flowr flowr;
public void getFlowr() {
if (flowr == null) {
flowr = new Flowr(...);
flowr.setDeepLinkHandlers(new MainDeepLinkHandlerImpl(), new LibraryDeepLinkHandlerImpl());
}
return flowr;
}
}
```
Finally to trigger the deep linking handling, simply call `open(Intent, Fragment))` from your `Activity#onCreate(Bundle)` method.
```java
public class MainActivity extends AbstractActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
...
getFlowr()
.open(getIntent(), HomeFragment.class)
.skipBackStack(true)
.displayFragment();
}
}
```
Additionally you can access a Fragment via the link attached to it:
Expand All @@ -261,13 +316,6 @@ getFlowr()
.displayFragment();
```
But don't forget to add those lines to your proguard config:
```
-keep public class * implements com.fueled.flowr.internal.FlowrConfig
-keep public class * implements com.fueled.flowr.internal.FlowrDeepLinkHandler
```
# License
Copyright 2016 Fueled
Expand Down
13 changes: 11 additions & 2 deletions extra/gradle/libraries.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ ext {
hamcrestVersion = '1.4-atlassian-1'
espressoVersion = '2.2.2'
mockitoVersion = '1.10.19'
compileTestingVersion = '0.10'
googleTruthVersion = '0.30'

javaPoetVersion = '1.8.0'
autoCommon = '0.8'
autoService = '1.0-rc3'


libraries = [
Expand All @@ -39,7 +43,10 @@ ext {

rxJava : "io.reactivex.rxjava2:rxjava:${rxJavaVersion}",
rxAndroid : "io.reactivex.rxjava2:rxandroid:${rxAndroidVersion}",
javaPoet : "com.squareup:javapoet:${javaPoetVersion}"
javaPoet : "com.squareup:javapoet:${javaPoetVersion}",

autoCommon : "com.google.auto:auto-common:${autoCommon}",
autoService : "com.google.auto.service:auto-service:${autoService}"
]

testLibraries = [
Expand All @@ -49,7 +56,9 @@ ext {
testRule : "com.android.support.test:rules:${tesetRunnerVersion}",
hamcrest : "org.hamcrest:hamcrest-library:${hamcrestVersion}",
espresso : "com.android.support.test.espresso:espresso-core:${espressoVersion}",
mockito : "org.mockito:mockito-core:${mockitoVersion}"
mockito : "org.mockito:mockito-core:${mockitoVersion}",
compileTesting : "com.google.testing.compile:compile-testing:${compileTestingVersion}",
googleTruth : "com.google.truth:truth:${googleTruthVersion}"
]

}
2 changes: 2 additions & 0 deletions flowr-annotations/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
apply plugin: 'java'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'checkstyle'
apply from: "../extra/checkstyle/checkstyle_java_library.gradle"

group = libraryGroup
version = libraryVersion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.fueled.flowr.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Created by [email protected] on 05/06/2017.
* Copyright (c) 2017 Fueled. All rights reserved.
*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface DeepLinkHandler {

/**
* The name of the generated deep link handler class, by default this will be the name
* of the class annotated with "Impl" appended at the end.
*
* @return the name to be used for the generated class.
*/
String value() default "";

}
13 changes: 13 additions & 0 deletions flowr-compiler/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import org.gradle.internal.jvm.Jvm

apply plugin: 'java'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'checkstyle'
apply from: "../extra/checkstyle/checkstyle_java_library.gradle"

group = libraryGroup
version = libraryVersion

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':flowr-annotations')

compile libraries.javaPoet
compile libraries.autoCommon
compile libraries.autoService

testCompile project(':flowr-mock-classes')
testCompile testLibraries.junit
testCompile testLibraries.hamcrest
testCompile testLibraries.junit
testCompile testLibraries.mockito
testCompile testLibraries.compileTesting
testCompile testLibraries.googleTruth
testCompile files(Jvm.current().getToolsJar())
}


Expand Down
Loading

0 comments on commit ac58a42

Please sign in to comment.