Created
August 21, 2017 17:05
-
-
Save joecks/a0da0874165f69961a222e6c1e0ecc55 to your computer and use it in GitHub Desktop.
This file contains 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
// Definition of the provided dependencies of the MainActivity | |
class MainActivityDependencies(private val activity: FragmentActivity) : Dependencies { | |
override fun taskRepository(): TasksRepository { | |
return TasksRepository.getInstance(TasksRemoteDataSource.instance, TasksLocalDataSource.getInstance(activity)) | |
} | |
fun mainViewModel(): MainViewModel = ViewModelProviders.of(activity).get(MainViewModel::class.java) | |
fun tasksActions(): TasksActions = mainViewModel() | |
fun addEditActions(): AddEditActions = mainViewModel() | |
} | |
// TasksFragment when creating the view model, | |
// method will be called when the ViewModelFactory needs a ViewModel in the BaseReactFragment | |
override fun createViewModel() : TasksViewModel { | |
val dependencies = (activity as DependencyProvider<MainActivityDependencies>).dependencies | |
return TasksViewModel(dependencies.taskRepository(), dependencies.tasksActions()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment