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 SearchShows @Inject | |
constructor(private val showRepository: ShowRepository, private val resourceRepository: ResourceRepository) : | |
UseCase<Show>() { | |
var id: String? = null | |
override suspend fun executeOnBackground(): Show { | |
id?.let { | |
val showDetail = background{ | |
showRepository.showDetail(it) |
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 SearchShows @Inject | |
constructor(private val showRepository: ShowRepository, private val resourceRepository: ResourceRepository) : | |
UseCase<String>() { | |
var query: String? = null | |
override suspend fun executeOnBackground(): String { | |
query?.let { | |
val showsInfo = showRepository.searchShow(it) | |
val showName: String? = showsInfo?.getOrNull(0)?.show?.title |
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
/** | |
* (C) Copyright 2018 Paulo Vitor Sato Open Source Project | |
* | |
* 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 |
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 QueryViewModelArc @Inject | |
constructor(private val searchShows: SearchShows?) : ViewModel() { | |
val result = MutableLiveData<String>() | |
val query = MutableLiveData<String>() | |
val showLoading = MutableLiveData<Boolean>() | |
val searchEnabled = MutableLiveData<Boolean>() |
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 QueryFragment : BaseFragment() { | |
private var binding: FragmentQueryMvvmBinding? = null | |
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | |
val view = inflater.inflate(R.layout.fragment_query_mvvm, container, false) | |
binding = DataBindingUtil.bind(view) | |
return view | |
} | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
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 QueryViewModelArc @Inject | |
constructor(private val mSearchShows: SearchShows?) : ViewModel() { | |
val query = MutableLiveData<String>() | |
val searchEnabled = MutableLiveData<Boolean>() | |
init { | |
searchEnabled.value = false | |
query.value = "" |
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(subcomponents = arrayOf(ViewModelSubComponent::class)) | |
class ApplicationModule() { | |
@Singleton | |
@Provides | |
internal fun provideViewModelFactory( | |
viewModelSubComponent: ViewModelSubComponent.Builder): ProjectViewModelFactory { | |
return ProjectViewModelFactory(viewModelSubComponent.build()) | |
} |
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
@Singleton | |
@Component(modules = arrayOf(ApplicationModule::class, NetworkModule::class, ShowRepositoryModule::class, ResourceRepositoryModule::class)) | |
interface ApplicationComponent { | |
// expose to sub graphs | |
fun showRepository(): ShowRepository | |
fun resourceRepository(): ResourceRepository | |
fun viewModelFactory(): ProjectViewModelFactory |
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
@Subcomponent | |
interface ViewModelSubComponent { | |
@Subcomponent.Builder | |
interface Builder { | |
fun build(): ViewModelSubComponent | |
} | |
fun homeFragmentViewModel(): HomeFragmentViewModel | |
fun queryViewModelArc(): QueryViewModelArc | |
} |
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 ProjectViewModelFactory(viewModelSubComponent: ViewModelSubComponent) : ViewModelProvider.Factory { | |
private val creators: ArrayMap<Class<*>,() ->ViewModel> = ArrayMap() | |
init { | |
creators[HomeFragmentViewModel::class.java] = { viewModelSubComponent.homeFragmentViewModel() } | |
creators[QueryViewModelArc::class.java] = { viewModelSubComponent.queryViewModelArc() } | |
} | |
override fun <T : ViewModel> create(modelClass: Class<T>): T { | |
var creator: (() ->ViewModel)? = creators[modelClass] |