-
Notifications
You must be signed in to change notification settings - Fork 4
Build Extra
Simple way to construct your extras(bundle) and start activities, services, fragments. OmegaIntentBuilder uses annotation processing to bind intent's extras to pojo fields, and to generate intent builders via a fluent API.
To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.Omega-R.OmegaIntentBuilder:core:1.1.2'
// For extras
implementation 'com.github.Omega-R.OmegaIntentBuilder:annotations:1.1.2'
annotationProcessor 'com.github.Omega-R.OmegaIntentBuilder:processor:1.1.2'
}
If you use Kotlin or Java with Kotlin, please use kapt instead java annotationProcessor. Main build.gradle file should look like this
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
kapt {
generateStubs = true
}
android {
......
}
dependencies {
implementation 'com.github.Omega-R.OmegaIntentBuilder:core:1.1.2'
// For extras
implementation 'com.github.Omega-R.OmegaIntentBuilder:annotations:1.1.2'
kapt 'com.github.Omega-R.OmegaIntentBuilder:processor:1.1.2'
}
Step 3. Usage
This is supported annotations type. Choose one for particular classes.
- @OmegaActivity - annotation for activities
- @OmegaFragment - annotation for fragments.
- @OmegaService - annotation for services.
Annotate your fields with @OmegaExtra. If you want to annotate some object (not simple classes like - String, int, double...) this class should implement Serializable interface.
@OmegaExtra("your name") // You can use your owner name for generated method and key extras.
protected String url1;
@OmegaExtra // Or method name will be generated with the same value name "url1".
protected String url2;
@OmegaExtra("your name")
lateinit var url1 : String
Annotate your fields with @OmegaExtraModel. Inside this object use @OmegaExtra annotation for fields. "OmegaExtraModel" also supports prefix for generated method. For each "OmegaExtra" fields inside "OmegaExtraModel" will be generated method with prefix.
@OmegaExtraModel(prefix = "model")
Model model = new Model(); // You should create instance of your class, because we don't know constructor type.
@OmegaExtraModel(prefix = "model")
var model : Model()
public class Model {
@OmegaExtra("Var2")
String url;
public String getUrl() {
return url;
}
}
AppOmegaIntentBuilder.from(this)
.appActivities()
.shareFilesActivity()
.modelVar2("https://avatars1.githubusercontent.com/u/28600571?s=200&v=4")
.startActivity();
Important. If you want to put whole "Model" object to your new activity, you could annotate it with @OmegaExtra and implement Serializable interface. It's not necessary to use @OmegaExtraModel in this case.