ExtrasInjector

ButcherKnife

License

License

GroupId

GroupId

com.github.vicpinm
ArtifactId

ArtifactId

extrasinjector
Last Version

Last Version

1.3.2
Release Date

Release Date

Type

Type

aar
Description

Description

ExtrasInjector
ButcherKnife
Project URL

Project URL

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

Source Code Management

https://github.com/vicpinm/ExtrasInjector

Download extrasinjector

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
androidx.appcompat » appcompat jar 1.0.2
com.github.vicpinm : extrasinjector-annotations jar 1.0.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.3.2
1.3.1
1.2.0
1.1.0
1.0.10
1.0.9
1.0.8
1.0.0