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
data class SomeModel(val id: String, val name: String) | |
interface SomeModelRepository { | |
suspend fun getSomeModels(): Answer<List<SomeModel>, String> | |
} | |
fun interface GetSomeModelUseCase : suspend () -> Answer<List<SomeModel>, String> | |
class SomeViewModel(private val getSomeModelUseCase: GetSomeModelUseCase) : ViewModel() { | |
fun load() { |
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
data class SomeModel(val id: String, val name: String) | |
interface SomeModelRepository { | |
suspend fun getSomeModels(): Answer<List<SomeModel>, String> | |
} | |
typealias GetSomeModelUseCase = suspend () -> Answer<List<SomeModel>, String> | |
class SomeViewModel(private val getSomeModelUseCase: GetSomeModelUseCase) : ViewModel() { | |
fun load() { |
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
data class SomeModel(val id: String, val name: String) | |
interface SomeModelRepository { | |
suspend fun getSomeModels(): Answer<List<SomeModel>, String> | |
} | |
interface GetSomeModelUseCase { | |
suspend operator fun invoke(): Answer<List<SomeModel>, String> | |
} |
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
data class SomeModel(val id: String, val name: String) | |
interface SomeModelRepository { | |
suspend fun getSomeModels(): Answer<List<SomeModel>, String> | |
} | |
class SomeViewModel(private val someModelRepository: SomeModelRepository) : ViewModel() { | |
fun load() { | |
viewModelScope.launch { | |
val result = someModelRepository.getSomeModels() |
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
abstract class Employee { | |
abstract fun getSalary(): String | |
abstract fun getLineManager(): Employee | |
} | |
class SeniorAndroidDeveloper( | |
private val leadAndroidDeveloper: LeadAndroidDeveloper |
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
class FakePreferences : SharedPreferences { | |
private val map: MutableMap<String, Any?> = mutableMapOf() | |
private val listeners: MutableList<SharedPreferences.OnSharedPreferenceChangeListener> = mutableListOf() | |
override fun getAll(): MutableMap<String, *> = map | |
override fun getString(key: String, default: String?): String? = map[key] as String? ?: default | |
@Suppress("UNCHECKED_CAST") | |
override fun getStringSet(key: String, default: MutableSet<String>?): MutableSet<String>? = |
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
interface GetTransactionsUseCase { | |
fun execute(): Single<SimpleResult<List<Transaction>>> | |
} |
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
interface GetTransactionsUseCase { | |
operator fun invoke(): Single<SimpleResult<List<Transaction>>> | |
} | |
class MyViewModel( | |
private val getTransactionUseCase: GetTransactionUseCase | |
) { | |
fun doSomething() { | |
//No need for invoke | |
getTransactionUseCase().subscribeBy { |
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
class MyViewModel( | |
private val getTransactionUseCase: GetTransactionUseCase | |
) { | |
fun doSomething() { | |
getTransactionUseCase.execute().subscribeBy { | |
//do something with the result | |
} | |
} | |
} |
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
interface GetTransactionsUseCase { | |
operator fun invoke(): Single<SimpleResult<List<Transaction>>> | |
} |
NewerOlder