Skip to content

Commit ac58a42

Browse files
author
julien-fueled
authored
Merge pull request #23 from Fueled/deep-link-module-support
Implement multi module deep linking support
2 parents b93dc0c + 7764c87 commit ac58a42

File tree

31 files changed

+640
-368
lines changed

31 files changed

+640
-368
lines changed

README.md

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,68 @@ public class TestFragment extends Fragment implement FlowrFragment
235235
String url = getArguments().getString(Flowr.DEEP_LINK_URL,"");
236236
String id = getArguments().getString("id","");
237237
```
238-
To trigger the deep linking handling, simply call `open(Intent, Fragment))`
238+
239+
### Deep Linking Setup:
240+
241+
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.
239242
240243
```java
241-
getFlowr()
242-
.open(getIntent(), HomeFragment.class)
243-
.skipBackStack(true)
244-
.displayFragment();
244+
/** This will generate a MainDeepLinkHandlerImpl class */
245+
@DeepLinkHandler
246+
public class MainDeepLinkHandler {
247+
}
248+
```
249+
250+
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.
251+
252+
```java
253+
/** This will generate a MyDeepLinkHandler class */
254+
@DeepLinkHandler("MyDeepLinkHandler")
255+
public class MainActivity extends AbstractActivity {
256+
}
257+
```
258+
259+
If you have fragments across multiple modules, you will need to add the `@DeepLinkHandler` annotation to at least one class in each module.
260+
261+
```java
262+
/** This will generate a LibraryDeepLinkHandlerImpl class */
263+
@DeepLinkHandler
264+
public class LibraryDeepLinkHandler {
265+
}
266+
```
267+
268+
Provide the list of generated deep link handlers to your flowr instance.
269+
270+
```java
271+
public class MainActivity extends AbstractActivity {
272+
273+
private Flowr flowr;
274+
275+
public void getFlowr() {
276+
if (flowr == null) {
277+
flowr = new Flowr(...);
278+
flowr.setDeepLinkHandlers(new MainDeepLinkHandlerImpl(), new LibraryDeepLinkHandlerImpl());
279+
}
280+
281+
return flowr;
282+
}
283+
}
284+
```
285+
286+
Finally to trigger the deep linking handling, simply call `open(Intent, Fragment))` from your `Activity#onCreate(Bundle)` method.
287+
288+
```java
289+
public class MainActivity extends AbstractActivity {
290+
291+
@Override
292+
protected void onCreate(Bundle savedInstanceState) {
293+
...
294+
getFlowr()
295+
.open(getIntent(), HomeFragment.class)
296+
.skipBackStack(true)
297+
.displayFragment();
298+
}
299+
}
245300
```
246301
247302
Additionally you can access a Fragment via the link attached to it:
@@ -261,13 +316,6 @@ getFlowr()
261316
.displayFragment();
262317
```
263318
264-
But don't forget to add those lines to your proguard config:
265-
266-
```
267-
-keep public class * implements com.fueled.flowr.internal.FlowrConfig
268-
-keep public class * implements com.fueled.flowr.internal.FlowrDeepLinkHandler
269-
```
270-
271319
# License
272320
273321
Copyright 2016 Fueled

extra/gradle/libraries.gradle

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ ext {
2828
hamcrestVersion = '1.4-atlassian-1'
2929
espressoVersion = '2.2.2'
3030
mockitoVersion = '1.10.19'
31+
compileTestingVersion = '0.10'
32+
googleTruthVersion = '0.30'
3133

3234
javaPoetVersion = '1.8.0'
35+
autoCommon = '0.8'
36+
autoService = '1.0-rc3'
3337

3438

3539
libraries = [
@@ -39,7 +43,10 @@ ext {
3943

4044
rxJava : "io.reactivex.rxjava2:rxjava:${rxJavaVersion}",
4145
rxAndroid : "io.reactivex.rxjava2:rxandroid:${rxAndroidVersion}",
42-
javaPoet : "com.squareup:javapoet:${javaPoetVersion}"
46+
javaPoet : "com.squareup:javapoet:${javaPoetVersion}",
47+
48+
autoCommon : "com.google.auto:auto-common:${autoCommon}",
49+
autoService : "com.google.auto.service:auto-service:${autoService}"
4350
]
4451

4552
testLibraries = [
@@ -49,7 +56,9 @@ ext {
4956
testRule : "com.android.support.test:rules:${tesetRunnerVersion}",
5057
hamcrest : "org.hamcrest:hamcrest-library:${hamcrestVersion}",
5158
espresso : "com.android.support.test.espresso:espresso-core:${espressoVersion}",
52-
mockito : "org.mockito:mockito-core:${mockitoVersion}"
59+
mockito : "org.mockito:mockito-core:${mockitoVersion}",
60+
compileTesting : "com.google.testing.compile:compile-testing:${compileTestingVersion}",
61+
googleTruth : "com.google.truth:truth:${googleTruthVersion}"
5362
]
5463

5564
}

flowr-annotations/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
apply plugin: 'java'
22
apply plugin: 'com.github.dcendents.android-maven'
3+
apply plugin: 'checkstyle'
4+
apply from: "../extra/checkstyle/checkstyle_java_library.gradle"
35

46
group = libraryGroup
57
version = libraryVersion
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fueled.flowr.annotations;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* Created by [email protected] on 05/06/2017.
10+
* Copyright (c) 2017 Fueled. All rights reserved.
11+
*/
12+
@Retention(RetentionPolicy.SOURCE)
13+
@Target(ElementType.TYPE)
14+
public @interface DeepLinkHandler {
15+
16+
/**
17+
* The name of the generated deep link handler class, by default this will be the name
18+
* of the class annotated with "Impl" appended at the end.
19+
*
20+
* @return the name to be used for the generated class.
21+
*/
22+
String value() default "";
23+
24+
}

flowr-compiler/build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
1+
import org.gradle.internal.jvm.Jvm
2+
13
apply plugin: 'java'
24
apply plugin: 'com.github.dcendents.android-maven'
5+
apply plugin: 'checkstyle'
6+
apply from: "../extra/checkstyle/checkstyle_java_library.gradle"
37

48
group = libraryGroup
59
version = libraryVersion
610

711
dependencies {
812
compile fileTree(dir: 'libs', include: ['*.jar'])
913
compile project(path: ':flowr-annotations')
14+
1015
compile libraries.javaPoet
16+
compile libraries.autoCommon
17+
compile libraries.autoService
18+
19+
testCompile project(':flowr-mock-classes')
20+
testCompile testLibraries.junit
1121
testCompile testLibraries.hamcrest
1222
testCompile testLibraries.junit
1323
testCompile testLibraries.mockito
24+
testCompile testLibraries.compileTesting
25+
testCompile testLibraries.googleTruth
26+
testCompile files(Jvm.current().getToolsJar())
1427
}
1528

1629

0 commit comments

Comments
 (0)