Skip to content

Commit

Permalink
Merge pull request #39 from 6QuizOnTheBlock/and/feat#31-challenge
Browse files Browse the repository at this point in the history
And/feat#31 challenge
  • Loading branch information
TRASALBY authored Apr 29, 2024
2 parents 04cb26d + e023400 commit 8039ef5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 34 deletions.
36 changes: 2 additions & 34 deletions android/core/ui/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,43 +1,11 @@
plugins {
alias(libs.plugins.androidLibrary)
alias(libs.plugins.jetbrainsKotlinAndroid)
alias(libs.plugins.sixkids.android.library)
alias(libs.plugins.sixkids.android.library.compose)
}

android {
namespace = "com.sixkids.ui"
compileSdk = 34

defaultConfig {
minSdk = 26

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
}

dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
}
35 changes: 35 additions & 0 deletions android/core/ui/src/main/java/com/sixkids/ui/base/BaseViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.sixkids.ui.base

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch

abstract class BaseViewModel<UI_STATE : UiState, SIDE_EFFECT : SideEffect>(
initialState: UI_STATE
) : ViewModel() {
private val _uiState = MutableStateFlow(initialState)
val uiState = _uiState.asStateFlow()

private val _sideEffect: Channel<SIDE_EFFECT> = Channel()
val sideEffect = _sideEffect.receiveAsFlow()

protected val currentState: UI_STATE
get() = _uiState.value

protected fun intent(reduce: UI_STATE.() -> UI_STATE) {
val state = currentState.reduce()
_uiState.value = state
}

protected fun postSideEffect(vararg builder: SIDE_EFFECT) {
for (effectValue in builder) {
viewModelScope.launch {
_sideEffect.send(effectValue)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.sixkids.ui.base

interface SideEffect
3 changes: 3 additions & 0 deletions android/core/ui/src/main/java/com/sixkids/ui/base/UiState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.sixkids.ui.base

interface UiState

0 comments on commit 8039ef5

Please sign in to comment.