Pirate is a multi-module Activity
collecting library.
The annotation processor will generate a class below:
public final class PirateTreasureMap implements TreasureMap {
private static final Map<String, Treasure> ISLANDS;
static {
ISLANDS = new java.util.HashMap<>();
ISLANDS.put("/main", new Treasure("/main", MainActivity.class, false));
ISLANDS.putAll(SecretPirateMap.ISLANDS);
}
@Override
@Nullable
public Treasure sail(String key) {
return ISLANDS.get(key);
}
@Override
public Map<String, Treasure> islands() {
return ISLANDS;
}
}
- add dependencies
// Java
dependencies {
...
implementation 'com.crookk.pirate:pirate:{latest-version}'
annotationProcessor 'com.crookk.pirate:pirate-compiler:{latest-version}'
}
// Kotlin
dependencies {
...
implementation 'com.crookk.pirate:pirate:{latest-version}'
kapt 'com.crookk.pirate:pirate-compiler:{latest-version}'
}
- config your sub-module gradle file by adding, you can ignore this step if you only have one module:
// Java
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = [ piratePackage : '{replaceWithSubModulePackageName}', pirateModule : true ]
}
}
}
...
}
// Kotlin
kapt {
arguments {
arg("piratePackage", "{replaceWithSubModulePackageName}")
arg("pirateModule", true)
}
}
- mark your
Activity
classes with@PirateIsland
description | default | example | |
---|---|---|---|
key | the name/id/key of the activity | - | "/main" |
auth | showing if the activity is protected or not | false | false |
@PirateIsland(key = "/main", auth = false)
class MainActivity : AppCompatActivity() {
...
}
- mark your
App
class with@Pirate
, you should also pass in the allpiratePackage
tovalue
. You can ignore this step if you only have one module.
@Pirate(value = ["com.crookk.pirate2"])
class App : Application() {
override fun onCreate() {
super.onCreate()
// let the pirates study the generated map
Pirates.study(PirateTreasureMap())
}
}
- Let
Pirates
study thePirateTreasureMap
class App : Application() {
override fun onCreate() {
super.onCreate()
// let the pirates study the generated map
Pirates.study(PirateTreasureMap())
}
}
- call
Pirates
anywhere tosails()
to the treasure islands.
Pirates.sails("/main")