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
liveData(context = viewModelScope.coroutineContext + Dispatcher.IO) { | |
emitSource(pagesRepository.getNextPageData(eventPageLiveData).asLiveData().map { | |
it.convertTo<MyUIModel>() | |
}) | |
} |
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 PageRepository( | |
private val simpleApi: ISimpleApi | |
) : IPageRepository { | |
override suspend fun getNextPageData(eventPageLiveData: LiveData<ViewEvent<Int>>): Flow<Result<List<MyUIModel>>> { | |
return flow { | |
// convert liveData to Flow | |
eventPageLiveData.asFlow().collect { viewEvent -> | |
val viewPage = viewEvent.data | |
// emit success state |
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 ISimpleApi { | |
@GET("data/list") | |
suspend fun getListData( | |
@Query("page") page: Int | |
): List<SomeRemoteModel> | |
} |
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 IPageRepository { | |
suspend fun getNextPageData(eventPageLiveData: LiveData<ViewEvent<Int>>): Flow<Result<List<MyUIModel>>> | |
} |
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 IPageRepository { | |
suspend fun getNextPageData(page: Int): Result<List<MyUIModel>> | |
} |
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 pagesRepository: IPagesRepository | |
) : ViewModel() { | |
val eventPageLiveData = MutableLiveData<ViewEvent<Int>>() | |
val resultLiveData: LiveData<Result<List<MyUIModel>>> by lazy { | |
// do some work on IO | |
liveData(context = viewModelScope.coroutineContext + Dispatcher.IO) { | |
emitSource(pagesRepository.getNextPageData(eventPageLiveData).asLiveData()) |
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 pagesRepository: IPagesRepository | |
) : ViewModel() { | |
val eventPageLiveData = MutableLiveData<ViewEvent<Int>>() | |
val resultLiveData: LiveData<Result<List<MyUIModel>>> by lazy { | |
eventPageLiveData.switchMap { pageEvent -> | |
liveData(context = viewModelScope.coroutineContext + Dispatchers.IO) { | |
emit(pagesRepository.getNextPageData(pageEvent.data)) |
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 MyClass { | |
} | |
class MyClassNeedAnother(val myclass: MyClass) { | |
} | |
val kodi = kodi { | |
bind<MyClass>() with provider { MyClass() } |
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
typealias UserAddressBuilderLambda = () -> UserAddress // 1 | |
class UserAddressBuilder( | |
addressInit: UserAddressBuilder.() -> Unit // 2 | |
) : UserAddressBuilderLambda { | |
init { | |
this.addressInit() // 3 | |
} | |
var userCity: String = "" | |
var userCountry: 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
typealias UserAddressBuilderLambda = () -> UserAddress // 1 | |
class UserAddressBuilder( | |
addressInit: UserAddressBuilder.() -> Unit // 2 | |
) : UserAddressBuilderLambda { | |
init { | |
this.addressInit() // 3 | |
} | |
var userCity: String = "" | |
var userCountry: String = "" |