ExtrasInjector Anotations

ButcherKnife

License

License

GroupId

GroupId

com.github.vicpinm
ArtifactId

ArtifactId

extrasinjector-annotations
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

ExtrasInjector Anotations
ButcherKnife
Project URL

Project URL

https://github.com/vicpinm/ExtrasInjector
Source Code Management

Source Code Management

https://github.com/vicpinm/ExtrasInjector

Download extrasinjector-annotations

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.vicpinm/extrasinjector-annotations/ -->
<dependency>
    <groupId>com.github.vicpinm</groupId>
    <artifactId>extrasinjector-annotations</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.vicpinm/extrasinjector-annotations/
implementation 'com.github.vicpinm:extrasinjector-annotations:1.0.0'
// https://jarcasting.com/artifacts/com.github.vicpinm/extrasinjector-annotations/
implementation ("com.github.vicpinm:extrasinjector-annotations:1.0.0")
'com.github.vicpinm:extrasinjector-annotations:jar:1.0.0'
<dependency org="com.github.vicpinm" name="extrasinjector-annotations" rev="1.0.0">
  <artifact name="extrasinjector-annotations" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.vicpinm', module='extrasinjector-annotations', version='1.0.0')
)
libraryDependencies += "com.github.vicpinm" % "extrasinjector-annotations" % "1.0.0"
[com.github.vicpinm/extrasinjector-annotations "1.0.0"]

Dependencies

runtime (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jre8 jar 1.2.0

Project Modules

There are no modules declared in this project.

Library written completely in Kotlin. It reduces boilerplate related with passing extras through activities and arguments through fragments. This library allows you to inject extras directly in the class you want, like your presenter if you use MVP, or your viewmodel if you use MVVM. See sample project for details.

Example with MVP

Presenter class

Use @InjectExtra in any class where you want to get your extras injected. If your extra is optional, you have to specify it with the argument optional = true in the annotation.

@ForActivity(ActivityPresenter::class)
class MyPresenter {

    @InjectExtra lateinit var userId: Long  //Mandatory extra
    @InjectExtra(optional = true) var userDetails : UserDetails? = null //Optional extra
}

These extras will be obtained from an activity called 'ActivityPresenter', so you have to specify that with the anotation @ForActivity(class)/@ForFragment(class)

View class

Inject your extras to the target class with ExtrasInjector.bind(activity/fragment instance, targetClass) If you have a ParentActivity which holds a reference to your presenter, you can inject your extras there.

class ParentActivity : Activity {

    var presenter : Presenter
    
    initPresenter() {
        ExtrasInjector.bind(this, presenter)
    }
}

Activity/fragment invocation

You can get a new intent for your activity with:

val myIntent = Activities.intentForDetailsActivity(context, extras...)

And for fragments:

val myFragment = Fragments.createDetailsFragment(extras...)

These generated methods allow you to pass only the arguments you have specified in your destination class (presenter, viewModel). Following this example, we have a class 'MyPresenter' with two annotated fields: userId: Long (mandatory) and userDetails: UserDetails? (optional). Therefore, these methods will expect a mandatory Long argument (userId), and an optional 'UserDetails' argument. You can check the sample project to see a real sample.

Proguard

If you are using proguard, you have to add this rules to your proguard-rules.pro:

-keep class com.vicpin.extrasinjector.**  { *; }

Download

Grab via Gradle:

repositories {
    mavenCentral()
}
//For androidX libraries compatibility:
implementation "com.github.vicpinm:extrasinjector:1.3.2"
kapt "com.github.vicpinm:extrasinjector-processor:1.3.1"

//If you use old appCompat libraries:
implementation "com.github.vicpinm:extrasinjector:1.2.0"
kapt "com.github.vicpinm:extrasinjector-processor:1.2.0"

Versions

Version
1.0.0