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 YourViewModel extends ViewModel { | |
//YOUR VIEWMODEL CODE | |
} |
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 SearchShows searchShows; | |
@Inject | |
public QueryViewModelArc(SearchShows searchShows) { | |
this.searchShows = searchShows; | |
} | |
//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 QueryFragment extends BaseFragment { | |
@Override | |
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | |
super.onViewCreated(view, savedInstanceState); | |
QueryViewModelArc queryViewModelArc = | |
ViewModelProviders.of(this, getViewModelFactory()).get(QueryViewModelArc.class); | |
} | |
} |
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 abstract class BaseFragment extends Fragment { | |
@Inject | |
ProjectViewModelFactory viewModelFactory; | |
@Override | |
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | |
super.onViewCreated(view, savedInstanceState); | |
DevCampApplication app = (DevCampApplication) getActivity().getApplication(); |
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 |
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
@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
@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
<?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
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) { |
OlderNewer