{"id":25632045,"url":"https://github.com/ivianuu/contributer","last_synced_at":"2025-04-14T17:12:30.440Z","repository":{"id":94685657,"uuid":"115832458","full_name":"IVIanuu/contributer","owner":"IVIanuu","description":"Inject all types like views or a conductor controllers with @ContributesAndroidInjector","archived":false,"fork":false,"pushed_at":"2018-03-26T13:05:00.000Z","size":180,"stargazers_count":38,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T17:12:23.462Z","etag":null,"topics":["conductor","contributesandroidinjector","dagger-android-injection","dagger2","view"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IVIanuu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-31T00:06:43.000Z","updated_at":"2022-07-12T07:25:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"c2103378-8517-4380-8b86-12b88d56fa32","html_url":"https://github.com/IVIanuu/contributer","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IVIanuu%2Fcontributer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IVIanuu%2Fcontributer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IVIanuu%2Fcontributer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IVIanuu%2Fcontributer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IVIanuu","download_url":"https://codeload.github.com/IVIanuu/contributer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248923765,"owners_count":21183953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["conductor","contributesandroidinjector","dagger-android-injection","dagger2","view"],"created_at":"2025-02-22T20:32:15.706Z","updated_at":"2025-04-14T17:12:30.434Z","avatar_url":"https://github.com/IVIanuu.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Contributer\n\n\n## Introduction\nDagger android injection is awesome right? But it only works for a limited number of types..\nWith contributer you can use the @ContributesAndroidInjector pattern for each type such as views or conductor controllers.\n\n## Download\n```groovy\n// in your root gradle\nallprojects {\n\trepositories {\n\t\t...\n\t\tmaven { url 'https://jitpack.io' }\n\t}\n}\n```\n\n```groovy\ndependencies {\n         // for view\n         implementation 'com.github.IVIanuu.Contributer:contributer-view:LATEST-VERSION'\n         \n         // for conductor\n         implementation 'com.github.IVIanuu.Contributer:contributer-conductor:LATEST-VERSION'\n         \n         // for custom types\n         implementation 'com.github.IVIanuu.Contributer:contributer-annotations:LATEST-VERSION'\n         \n         // Required\n         annotationProcessor 'com.github.IVIanuu.Contributer:contributer-processor:LATEST-VERSION'\n\t \n\t // remove this line!!\n         annotationProcessor 'com.google.dagger:dagger-android-processor:2.13'\n}\n```\n\n## Views\n\nAssume that your project contains a basic dagger setup.\n\nFirst add the @AndroidInjectorKeyRegistry annotation to a class in your project for example your app component.\nThis the only extra step required compared to regular android injection.\nHere you have to add the @ViewKey.\n\n```kotlin\n@AndroidInjectorKeyRegistry(keys = arrayOf(ViewKey::class))\n@Singleton\n@Component(modules = {\n      // modules\n})\npublic interface AppComponent {\n}\n```\n\nNext create your binding modules like you would with dagger android.\nIf you're not familiar with dagger android read this. https://google.github.io/dagger/android.html\n\n```kotlin\n@Module abstract class ViewBindingModule {\n\n    @SomeScope\n    @ContributesAndroidInjector(modules = [LoginModule::class, UiModule::class])\n    abstract fun bindLoginView(): LoginView\n    \n    @ContributesAndroidInjector\n    abstract fun bindPlayPauseView(): PlayPauseView\n\n}\n```\n\nAdd your binding module and the ViewInjectionModule to your app component.\n\n```kotlin\n@Singleton\n@Component(modules = [\n        AppModule::class,\n        ViewBindingModule::class,\n        ViewInjectionModule::class\n        ]\n))\ninterface AppComponent {\n    fun inject(app: App)\n\n    @Component.Builder\n    interface Builder {\n        @BindsInstance\n        fun application(application: Application): Builder\n\n        fun build(): AppComponent\n    }\n}\n```\n\nAdd the HasViewInjector interface to your app or base activity.\n\n```kotlin\nclass App : Application(), HasViewInjector {\n\n    @Inject lateinit var viewInjector: DispatchingAndroidInjector\u003cView\u003e\n\n    override fun onCreate() {\n        super.onCreate()\n\n        DaggerAppComponent.builder()\n                    .application(this)\n                    .build()\n                    .inject(this)\n    }\n    \n    override fun viewInjector() = viewInjector\n}\n```\n\nNow you're done you can now inject your views with ViewInjection.inject(view)\n\n```kotlin\nclass MyView(context: Context, attrs: AttributeSet?) : View(context, attrs) {\n\n    @Inject lateinit var audioManager: AudioManager\n    @Inject lateinit var packageManager: PackageManager\n\n    override fun onFinishInflate() {\n        super.onFinishInflate()\n        ViewInjection.inject(this)\n\n        // todo use injected stuff\n    }\n}\n```\n\n## Conductor\n\nAbsolutely the same as with views but replace the ViewKey with ControllerKey\nthe HasViewInjector with HasControllerInjector and so on.\n\n## Custom types\n\n1. Create a annotation class annotated with @MapKey and a value with the supertype of the classes\n2. Replicate the HasSomeClassInjector, SomeClassInjection and SomeClassInjectionModule part\n3. Done:D\n\nYou can check out the view or conductor module to look how they are implemented.\n\n## Fun fact\n\nFound out to late that contributer is a misspelling:DD\n\n## License\n\n```\nCopyright 2017 Manuel Wrage\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n \nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivianuu%2Fcontributer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivianuu%2Fcontributer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivianuu%2Fcontributer/lists"}