All Projects → alexfacciorusso → DaggerViewModel

alexfacciorusso / DaggerViewModel

Licence: Apache-2.0 license
An integration Module for injecting Google Architecture Components' ViewModel into Dagger2-injected Android components.

Programming Languages

kotlin
9241 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to DaggerViewModel

Aacomponents
基于google Android Architecture Components 封装实现组件式MVP快速开发框架
Stars: ✭ 66 (-1.49%)
Mutual labels:  viewmodel, architecture-components
Popularmovies
🎥 Movie discovery app showcasing Android best practices with Google's recommended architecture: MVVM + Repository + Offline support + Android Architecture Components + Paging library & Retrofit2.
Stars: ✭ 142 (+111.94%)
Mutual labels:  viewmodel, architecture-components
Kotlin Pokedex
🌀 A Pokedex app using ViewModel, LiveData, Room and Navigation
Stars: ✭ 1,156 (+1625.37%)
Mutual labels:  viewmodel, architecture-components
Retrokotlin
Simple Android app to show how unit testing with MockWebServer and Architecture Components (ViewModel + LiveData)
Stars: ✭ 55 (-17.91%)
Mutual labels:  viewmodel, architecture-components
Galwaybus
Galway Bus Kotlin Multiplatform project using Jetpack Compose and SwiftUI
Stars: ✭ 220 (+228.36%)
Mutual labels:  viewmodel, architecture-components
Tdcapp
Sample app which access the TDC (The Developer's Conference) REST API.
Stars: ✭ 55 (-17.91%)
Mutual labels:  viewmodel, architecture-components
Movieapp Clean Architecture
Learning Project (Movie App) For Applying Android Architecture Components And Clean Architecture Using MVVM With Kotlin
Stars: ✭ 123 (+83.58%)
Mutual labels:  viewmodel, architecture-components
News
A sample News 🗞 app built using Modern Android Development [Architecture Components, Coroutines, Retrofit, Room, Kotlin, Dagger]
Stars: ✭ 774 (+1055.22%)
Mutual labels:  viewmodel, architecture-components
KTAndroidArchitecture
A Kotlin android architecture with Google Architecture Components
Stars: ✭ 33 (-50.75%)
Mutual labels:  viewmodel, architecture-components
Mvvmframe
🏰 MVVMFrame for Android 是一个基于Google官方推出的Architecture Components dependencies(现在叫JetPack){ Lifecycle,LiveData,ViewModel,Room } 构建的快速开发框架。有了MVVMFrame的加持,从此构建一个MVVM模式的项目变得快捷简单。
Stars: ✭ 218 (+225.37%)
Mutual labels:  viewmodel, architecture-components
Readhubclient
Readhub客户端
Stars: ✭ 44 (-34.33%)
Mutual labels:  viewmodel, architecture-components
TeamManagerApp
A sample app structure using the MVVM architecture LiveData, RxJava, ViewModel, Room and the Navigation Arch Components.
Stars: ✭ 36 (-46.27%)
Mutual labels:  viewmodel, architecture-components
Kodein Mvvm
Example app using Kodein for dependency injection with MVVM and Architecture Components
Stars: ✭ 26 (-61.19%)
Mutual labels:  viewmodel, architecture-components
Githubprojectbrowser
This is a sample Android Project that is based on Clean Architecture
Stars: ✭ 64 (-4.48%)
Mutual labels:  viewmodel, architecture-components
Base Mvvm
App built to showcase basic Android View components like ViewPager, RecyclerView(homogeneous and heterogeneous items), NavigationDrawer, Animated Vector Drawables, Collapsing Toolbar Layout etc. housed in a MVVM architecture
Stars: ✭ 18 (-73.13%)
Mutual labels:  viewmodel, architecture-components
Cleanarchitecture
Android Kotlin Clean Architecture
Stars: ✭ 94 (+40.3%)
Mutual labels:  viewmodel, architecture-components
Changedetection
Automatically track websites changes on Android in background.
Stars: ✭ 563 (+740.3%)
Mutual labels:  viewmodel, architecture-components
Reactive Mvvm Android
My way to MVVM using KotlinX Coroutines and Android data-binding
Stars: ✭ 626 (+834.33%)
Mutual labels:  viewmodel, architecture-components
Coolweather
Weather App that uses Android best practices. Android Jetpack, clean architecture. Written in Kotlin
Stars: ✭ 154 (+129.85%)
Mutual labels:  viewmodel, architecture-components
Restaurants
Restaurants sample app built with the new architecture components (LiveData, Room, ViewModel) and Dagger 2
Stars: ✭ 47 (-29.85%)
Mutual labels:  viewmodel, architecture-components

Download

DaggerViewModel

An integration Module for injecting Google Architecture Components' ViewModel into Dagger2-injected Android activities and fragments.

This library was inspired by the official GithubBrowserSample example.

Installation

Add one of the following lines in the dependencies section of your Android build.gradle file:

implementation 'com.alexfacciorusso:daggerviewmodel:0.2.0'

Usage

Install the library, then bind your ViewModel into an abstract @Module class, annotating your binding method with @IntoMap and @ViewModelKey with your custom ViewModel class as parameter.

For example:

 @Module
 abstract class ViewModelModule {
     @Binds
     @IntoMap
     @ViewModelKey(MyViewModel::class)
     abstract fun bindsMainViewModel(myViewModel: MyViewModel): ViewModel
     
     // other binds...
 }

Then add the DaggerViewModelModule and the module containing your ViewModels (in our example, ViewModelModule) to your Application component:

Kotlin

@Singleton
@Component(modules = arrayOf(AndroidSupportInjectionModule::class, DaggerViewModelInjectionModule::class,
        your other modules...))
interface ApplicationComponent {
    // your component definitions ...
}

Java

@Singleton
@Component(modules = {AndroidSupportInjectionModule.class, DaggerViewModelInjectionModule.class, 
    your other modules...})
public interface ApplicationComponent {
    // your component definitions ...
}

And finally @Inject a ViewModelProvider.Factory into your Activity/Fragment and use it to create your ViewModel.

Kotlin

class MainActivity : AppCompatActivity() {
    @Inject
    lateinit var viewModelFactory: ViewModelProvider.Factory
    
    private lateinit var viewModel: MyViewModel
    
    override fun onCreate(savedInstanceState: Bundle?) {
        AndroidInjection.inject(this)
        super.onCreate(savedInstanceState)
        
        setContentView(R.layout.activity_main)
        viewModel = ViewModelProviders.of(this, viewModelFactory).get(MyViewModel::class.java)
        
        // ...
    }
    
    // ...
}

Java

public class MainActivity extends AppCompatActivity {
    @Inject
    ViewModelProvider.Factory viewModelFactory;
        
    private MyViewModel viewModel;
    
    
    void onCreate(Bundle savedInstanceState) {
        AndroidInjection.inject(this);
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.activity_main);
        viewModel = ViewModelProviders.of(this, viewModelFactory).get(MyViewModel.class);
        
        // ...
    }
    
    // ...
}

License

Copyright 2017-2019 Alex Facciorusso.

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].