Setup Presentation Module
This commit is contained in:
@@ -32,10 +32,16 @@ dependencies {
|
||||
|
||||
api(project(":i18n"))
|
||||
implementation(Libs.core_ktx)
|
||||
api(Libs.androidx_lifecycle_viewmodel_ktx)
|
||||
|
||||
api(Libs.room_runtime)
|
||||
api(Libs.room_ktx)
|
||||
|
||||
api(platform(Libs.kotlin_coroutine_bom))
|
||||
api(Libs.kotlin_coroutine_core)
|
||||
|
||||
api(Libs.orbit_mvi_core)
|
||||
|
||||
testImplementation(Libs.junit_jupiter_api)
|
||||
testImplementation(Libs.junit_jupiter_engine)
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.ericampire.android.androidstudycase.util.mvi
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import org.orbitmvi.orbit.ContainerHost
|
||||
|
||||
abstract class BaseViewModel<S: Any, E: Any, A> : ContainerHost<S, E>, ViewModel() {
|
||||
protected val pendingAction = MutableSharedFlow<A>()
|
||||
|
||||
protected fun submitAction(action: A) {
|
||||
viewModelScope.launch {
|
||||
pendingAction.emit(action)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.ericampire.android.androidstudycase.util.room
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import java.util.*
|
||||
|
||||
|
||||
object DateConverter {
|
||||
|
||||
@TypeConverter
|
||||
fun fromTimestamp(value: Long): Date {
|
||||
return Date(value)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun dateToTimestamp(date: Date): Long {
|
||||
return date.time
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
|
||||
/**
|
||||
* Executes business logic in its execute method and keep posting updates to the result as
|
||||
@@ -13,6 +14,7 @@ import kotlinx.coroutines.flow.flowOn
|
||||
*/
|
||||
abstract class FlowUseCase<in P, R>(private val coroutineDispatcher: CoroutineDispatcher) {
|
||||
operator fun invoke(parameters: P): Flow<Result<R>> = execute(parameters)
|
||||
.onStart { emit(Result.Loading) }
|
||||
.catch { e -> emit(Result.Error(Exception(e))) }
|
||||
.flowOn(coroutineDispatcher)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user