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 TestRepository { | |
@Inject | |
public TestRepository() {} | |
… | |
} | |
public class MainActivity extends DaggerActivity { | |
@Inject |
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 TestRepository { | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
@Inject String name; |
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 | |
public class RepoModule { | |
@Provides | |
TestRepository provideTestRepository() { | |
return new TestRepository("blah"); | |
} | |
} |
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 | |
public abstract class AndroidBindingModule { | |
@ContributesAndroidInjector | |
abstract MainActivity bindMainActivity(); | |
} | |
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 TestApplication extends DaggerApplication { | |
@Override | |
protected AndroidInjector<? extends DaggerApplication> applicationInjector() { | |
return DaggerAppComponent.builder().application(this).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
public int salaryCap(int[] salaries, int target) { | |
int a = target / salaries.length; | |
int sum = 0, count=0; | |
for (int s: salaries) { | |
if (s <= a) { | |
sum += s; | |
} else { | |
count++; | |
} | |
} |
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 Rover { | |
public static int roverMove(int matrixSize, List<String> cmds) { | |
int result = 0; | |
for (int i = 0; i < cmds.size(); i++) { | |
result = process(cmds.get(i), matrixSize, result); | |
} | |
return result; | |
} | |
static int process(String cmd, int n, int current) { |
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 | |
class ViewModelFactory @Inject constructor(private val viewModels: MutableMap<Class<out ViewModel>, Provider<ViewModel>>) : ViewModelProvider.Factory { | |
override fun <T : ViewModel> create(modelClass: Class<T>): T = viewModels[modelClass]?.get() as T } | |
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) | |
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME) | |
@MapKey | |
internal annotation class ViewModelKey(val value: KClass<out ViewModel>) |
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 | |
abstract class ViewModelModule { | |
@Binds | |
internal abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory | |
@Binds | |
@IntoMap | |
@ViewModelKey(LoginViewModel::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
@Module | |
abstract class ViewModelModule { | |
@Binds | |
internal abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory | |
@Binds | |
@IntoMap | |
@ViewModelKey(LoginViewModel::class) |