This file contains 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
private fun updateImageWithImageDecoder(assetFileName: String, imageView: ImageView) { | |
val context = requireContext() | |
viewLifecycleOwner.lifecycleScope.launch { | |
val d = withContext(Dispatchers.Default) { | |
val source = ImageDecoder.createSource(context.assets, assetFileName) | |
val drawable = ImageDecoder.decodeDrawable(source) | |
return@withContext drawable | |
} | |
withContext(Dispatchers.Main) { |
This file contains 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
//1) inject a datasource and repository, which is passed to the constructor of the ViewModel | |
@Singleton | |
class LoginDataSource @Inject constructor(){ | |
private var mAuth: FirebaseAuth. ...// | |
class LoginRepository @Inject constructor(val dataSource: LoginDataSource) { ... | |
//2) use the Executor overload from the DataSource: | |
var executor: ThreadPoolExecutor = ThreadPoolExecutor( | |
numCores * 2, numCores * 2, |
This file contains 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 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 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 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 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 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 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 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"); | |
} | |
} |
NewerOlder