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 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
| 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
| 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 SearchShows searchShows; | |
| @Inject | |
| public QueryViewModelArc(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
| <?xml version="1.0" encoding="utf-8"?> | |
| <layout | |
| xmlns:android="http://schemas.android.com/apk/res/android"> | |
| <data> | |
| <variable | |
| name="viewModel" | |
| type="package.QueryViewModelArc"/> | |
| </data> | |
| <FrameLayout |
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 = {ViewModelSubComponent.class}) | |
| public class ApplicationModule { | |
| @Singleton | |
| @Provides | |
| ProjectViewModelFactory provideViewModelFactory( | |
| ViewModelSubComponent.Builder viewModelSubComponent) { | |
| return new 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 = { | |
| ApplicationModule.class, | |
| NetworkModule.class, | |
| ShowRepositoryModule.class, | |
| ResourceRepositoryModule.class | |
| }) | |
| public interface ApplicationComponent { | |
| // expose to sub graphs |
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 | |
| public interface ViewModelSubComponent { | |
| @Subcomponent.Builder | |
| interface Builder { | |
| ViewModelSubComponent build(); | |
| } | |
| HomeFragmentViewModel homeFragmentViewModel(); | |
| 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
| public class ProjectViewModelFactory implements ViewModelProvider.Factory { | |
| private final ArrayMap<Class, Callable<? extends ViewModel>> creators; | |
| public ProjectViewModelFactory(ViewModelSubComponent viewModelSubComponent) { | |
| creators = new ArrayMap<>(); | |
| creators.put(HomeFragmentViewModel.class, () -> viewModelSubComponent.homeFragmentViewModel()); | |
| creators.put(QueryViewModelArc.class, () -> viewModelSubComponent.queryViewModelArc()); | |
| } | |
| @Override |