This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="me.mladenrakonjac.modernandroidapp"> | |
... | |
<application | |
android:name=".ModernApplication" | |
...> | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ModernApplication : DaggerApplication(){ | |
override fun applicationInjector(): AndroidInjector<out DaggerApplication> { | |
TODO("not implemented") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
class AppModule{ | |
@Provides | |
fun providesContext(application: ModernApplication): Context { | |
return application.applicationContext | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
dependencies { | |
... | |
implementation "com.google.dagger:dagger:2.14.1" | |
implementation "com.google.dagger:dagger-android:2.14.1" | |
implementation "com.google.dagger:dagger-android-support:2.14.1" | |
kapt "com.google.dagger:dagger-compiler:2.14.1" | |
kapt "com.google.dagger:dagger-android-processor:2.14.1" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Injection { | |
private var NET_MANAGER: NetManager? = null | |
private fun provideNetManager(context: Context): NetManager { | |
if (NET_MANAGER == null) { | |
NET_MANAGER = NetManager(context) | |
} | |
return NET_MANAGER!! | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Injection { | |
private fun provideNetManager(context: Context) : NetManager { | |
return NetManager(context) | |
} | |
private fun gitRepoRepository(netManager: NetManager) :GitRepoRepository { | |
return GitRepoRepository(netManager) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity(), RepositoryRecyclerViewAdapter.OnItemClickListener { | |
private lateinit var mainViewModelFactory: MainViewModelFactory | |
override fun onCreate(savedInstanceState: Bundle?) { | |
... | |
mainViewModelFactory = Injection.provideMainViewModelFactory(applicationContext) | |
val viewModel = ViewModelProviders.of(this, mainViewModelFactory) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Injection { | |
fun provideMainViewModelFactory(context: Context) : MainViewModelFactory{ | |
val netManager = NetManager(context) | |
val repository = GitRepoRepository(netManager) | |
return MainViewModelFactory(repository) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity(), RepositoryRecyclerViewAdapter.OnItemClickListener { | |
.... | |
override fun onCreate(savedInstanceState: Bundle?) { | |
... | |
val repository = GitRepoRepository(NetManager(applicationContext)) | |
val mainViewModelFactory = MainViewModelFactory(repository) | |
val viewModel = ViewModelProviders.of(this, mainViewModelFactory) | |
.get(MainViewModel::class.java) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainViewModelFactory(private val repository: GitRepoRepository) | |
: ViewModelProvider.Factory { | |
override fun <T : ViewModel?> create(modelClass: Class<T>): T { | |
if (modelClass.isAssignableFrom(MainViewModel::class.java)) { | |
return MainViewModel(repository) as T | |
} | |
throw IllegalArgumentException("Unknown ViewModel Class") | |
} |