All Projects → IVIanuu → contributer

IVIanuu / contributer

Licence: other
Inject all types like views or a conductor controllers with @ContributesAndroidInjector

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to contributer

AndroidStarterAlt
A sample View-based Android app using the MVP architecture. It uses Mosby, Dagger2, RxJava, retrofit, LoganSquare, requery, EventBus, Conductor.
Stars: ✭ 27 (-30.77%)
Mutual labels:  dagger2, conductor
MultipleAppModules
An example how to use multiple application modules in one android project
Stars: ✭ 105 (+169.23%)
Mutual labels:  dagger2, dagger-android-injection
AndroidCleanArchitecture
Android Project with clean android architecture contain Dagger, Retrofit, Retrofit, Android archtecture components, LiveData with MVVM architecture
Stars: ✭ 22 (-43.59%)
Mutual labels:  dagger2, dagger-android-injection
TitleBar
🔥空祖家的标题栏组件
Stars: ✭ 36 (-7.69%)
Mutual labels:  view
MessagesView
view for displaying messages similarly to messages iOS system app
Stars: ✭ 16 (-58.97%)
Mutual labels:  view
dagger2-ktx
Kotlin extension bridge library for Dagger2 (proof-of-concept)
Stars: ✭ 41 (+5.13%)
Mutual labels:  dagger2
AndroidMVPArchitecture
Android MVP architecture sample project with or without RxJava and Dagger2 and Kotlin
Stars: ✭ 78 (+100%)
Mutual labels:  dagger2
VerifyBlocksView
Android view for providing blocks (Edit Texts) to achieve verification process.
Stars: ✭ 28 (-28.21%)
Mutual labels:  view
navigation-conductor
A Conductor integration for the Navigation Architecture Component.
Stars: ✭ 38 (-2.56%)
Mutual labels:  conductor
YoutubeVideoSample
YoutubeVideoSample
Stars: ✭ 176 (+351.28%)
Mutual labels:  view
kzmonitor
kafka zookeeper monitor
Stars: ✭ 34 (-12.82%)
Mutual labels:  view
react-native-PixelsCatcher
👀 Library for UI snapshot testing of React Native
Stars: ✭ 99 (+153.85%)
Mutual labels:  view
dagger2-kotlin
dagger2,querydsl kotlin 1.5.x annotation processor, gradle 7.x
Stars: ✭ 56 (+43.59%)
Mutual labels:  dagger2
Askme
Social media app to ask and answer user questions and interact with users
Stars: ✭ 16 (-58.97%)
Mutual labels:  dagger2
FastBanner
🔥快速轮播图,支持自定义布局和使用自有图片显示组件
Stars: ✭ 27 (-30.77%)
Mutual labels:  view
DaggerMultiFeature
Multi-feature app using dagger for learning purposes
Stars: ✭ 69 (+76.92%)
Mutual labels:  dagger2
recycler-adapter
RecyclerView-driven declarative UIs
Stars: ✭ 124 (+217.95%)
Mutual labels:  view
echo-template
golang template for echo framework!
Stars: ✭ 39 (+0%)
Mutual labels:  view
Dagger2-CYS
This code is part of a tutorial about Dagger2 on https://causeyourestuck.io
Stars: ✭ 19 (-51.28%)
Mutual labels:  dagger2
LocationAware
Set alarms for location in map
Stars: ✭ 34 (-12.82%)
Mutual labels:  dagger2

Contributer

Introduction

Dagger android injection is awesome right? But it only works for a limited number of types.. With contributer you can use the @ContributesAndroidInjector pattern for each type such as views or conductor controllers.

Download

// in your root gradle
allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}
dependencies {
         // for view
         implementation 'com.github.IVIanuu.Contributer:contributer-view:LATEST-VERSION'
         
         // for conductor
         implementation 'com.github.IVIanuu.Contributer:contributer-conductor:LATEST-VERSION'
         
         // for custom types
         implementation 'com.github.IVIanuu.Contributer:contributer-annotations:LATEST-VERSION'
         
         // Required
         annotationProcessor 'com.github.IVIanuu.Contributer:contributer-processor:LATEST-VERSION'
	 
	 // remove this line!!
         annotationProcessor 'com.google.dagger:dagger-android-processor:2.13'
}

Views

Assume that your project contains a basic dagger setup.

First add the @AndroidInjectorKeyRegistry annotation to a class in your project for example your app component. This the only extra step required compared to regular android injection. Here you have to add the @ViewKey.

@AndroidInjectorKeyRegistry(keys = arrayOf(ViewKey::class))
@Singleton
@Component(modules = {
      // modules
})
public interface AppComponent {
}

Next create your binding modules like you would with dagger android. If you're not familiar with dagger android read this. https://google.github.io/dagger/android.html

@Module abstract class ViewBindingModule {

    @SomeScope
    @ContributesAndroidInjector(modules = [LoginModule::class, UiModule::class])
    abstract fun bindLoginView(): LoginView
    
    @ContributesAndroidInjector
    abstract fun bindPlayPauseView(): PlayPauseView

}

Add your binding module and the ViewInjectionModule to your app component.

@Singleton
@Component(modules = [
        AppModule::class,
        ViewBindingModule::class,
        ViewInjectionModule::class
        ]
))
interface AppComponent {
    fun inject(app: App)

    @Component.Builder
    interface Builder {
        @BindsInstance
        fun application(application: Application): Builder

        fun build(): AppComponent
    }
}

Add the HasViewInjector interface to your app or base activity.

class App : Application(), HasViewInjector {

    @Inject lateinit var viewInjector: DispatchingAndroidInjector<View>

    override fun onCreate() {
        super.onCreate()

        DaggerAppComponent.builder()
                    .application(this)
                    .build()
                    .inject(this)
    }
    
    override fun viewInjector() = viewInjector
}

Now you're done you can now inject your views with ViewInjection.inject(view)

class MyView(context: Context, attrs: AttributeSet?) : View(context, attrs) {

    @Inject lateinit var audioManager: AudioManager
    @Inject lateinit var packageManager: PackageManager

    override fun onFinishInflate() {
        super.onFinishInflate()
        ViewInjection.inject(this)

        // todo use injected stuff
    }
}

Conductor

Absolutely the same as with views but replace the ViewKey with ControllerKey the HasViewInjector with HasControllerInjector and so on.

Custom types

  1. Create a annotation class annotated with @MapKey and a value with the supertype of the classes
  2. Replicate the HasSomeClassInjector, SomeClassInjection and SomeClassInjectionModule part
  3. Done:D

You can check out the view or conductor module to look how they are implemented.

Fun fact

Found out to late that contributer is a misspelling:DD

License

Copyright 2017 Manuel Wrage

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
 
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].