Skip to content

Instantly share code, notes, and snippets.

Rohan Kandwal rohankandwal

  • Bengaluru, Karnataka, India
Block or report user

Report or block rohankandwal

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rohankandwal
rohankandwal / RxSchedulersOverrideRule.java
Created May 20, 2018
RxSchedulersOverrideRule - subscriptions always subscribeOn and observeOn Schedulers.trampoline().
View RxSchedulersOverrideRule.java
package com.itcse.beerrecepies;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import java.util.concurrent.Callable;
import io.reactivex.Scheduler;
import io.reactivex.android.plugins.RxAndroidPlugins;
@rohankandwal
rohankandwal / AppModule.java
Created May 10, 2018
AppModule - Used to inject fragments, service, activities with other modules
View AppModule.java
@Module(includes = {
AndroidInjectionModule.class, RepositoryModule.class,
MySharedPreferencesModule.class
ViewModelModule.class, LocalRepositoryModule.class, MQTTModule.class
})
abstract class AppModule {
/*
* Singleton annotation isn't necessary since Application instance is unique but is here for
* convention. In general, providing Activity, Fragment, BroadcastReceiver, etc does not require
* them to be scoped since they are the components being injected and their instance is unique.
@rohankandwal
rohankandwal / ViewModelModule.java
Created May 10, 2018
ViewModelModule - Module to bind your ViewModels. We also bind our custom ViewModelFactory here.
View ViewModelModule.java
@Module
public abstract class ViewModelModule {
@Binds
@IntoMap
@ViewModelKey(SplashScreenViewModel.class)
abstract ViewModel bindSplashScreenViewModel(final SplashScreenViewModel splashScreenViewModel);
@Binds
@IntoMap
@ViewModelKey(LoginActivityViewModel.class)
@rohankandwal
rohankandwal / CustomViewModelFactory.java
Last active May 10, 2018
CustomViewModelFactory - Used to provide ViewModels with all injections available for that particular Activity/Fragment/Service
View CustomViewModelFactory.java
@Singleton
public class CustomViewModelFactory implements ViewModelProvider.Factory {
private final Map<Class<? extends ViewModel>, Provider<ViewModel>> creators;
@Inject
CustomViewModelFactory(Map<Class<? extends ViewModel>, Provider<ViewModel>> creators) {
this.creators = creators;
}
@NonNull
You can’t perform that action at this time.