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
public class QueryFragment extends BaseFragment { | |
private FragmentQueryMvvmBinding binding; | |
@Nullable | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
View view = inflater.inflate(R.layout.fragment_query_mvvm, container, false); | |
binding = DataBindingUtil.bind(view); | |
return view; | |
} |
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
public class QueryViewModelArc extends ViewModel { | |
private MutableLiveData<String> query = new MutableLiveData<>(); | |
private MutableLiveData<Boolean> searchEnabled = new MutableLiveData<>(); | |
private Observer<String> queryObserver; | |
private SearchShows searchShows; |
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() { | |
//your viewmodel stuff | |
} |
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() { | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
val queryViewModelArc = ViewModelProviders.of(this, viewModelFactory).get(QueryViewModelArc::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 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] |
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
@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
@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
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
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?) { |