kaiyan910 / Pirate

Pirate is a multi-module Activity collecting library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Download

Pirate

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;
  }
}

How to use

  1. 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}'
}
  1. 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)
    }
}
  1. 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() {
    ...
}
  1. mark your App class with @Pirate, you should also pass in the all piratePackage to value. 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())
    }
}
  1. Let Pirates study the PirateTreasureMap
class App : Application() {

    override fun onCreate() {
        super.onCreate()
        // let the pirates study the generated map
        Pirates.study(PirateTreasureMap())
    }
}
  1. call Pirates anywhere to sails() to the treasure islands.
Pirates.sails("/main")

About

Pirate is a multi-module Activity collecting library.

License:Apache License 2.0


Languages

Language:Java 92.8%Language:Kotlin 7.2%