-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Creating CategoryScreen * Filter Category * CategoryCardTest * Creating EventManeger and emit event the Category to NewOperationScreen * Creating CategoryScreen * Filter Category * CategoryCardTest * Creating EventManeger and emit event the Category to NewOperationScreen * Resolve conflicts The EventManager class was deleted due to it is functionally being really similar to the UiState sealed interface. --------- Co-authored-by: Lise <[email protected]>
- Loading branch information
1 parent
e2895e7
commit 12b2f1b
Showing
14 changed files
with
383 additions
and
114 deletions.
There are no files selected for viewing
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
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
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
71 changes: 71 additions & 0 deletions
71
composeApp/src/commonMain/kotlin/presentation/designsystem/CategoryCard.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package presentation.designsystem | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.defaultMinSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.shape.CornerSize | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.Card | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.ColorFilter | ||
import domain.model.Category | ||
import org.jetbrains.compose.resources.ExperimentalResourceApi | ||
import org.jetbrains.compose.resources.painterResource | ||
import presentation.theme.* | ||
|
||
@OptIn(ExperimentalResourceApi::class) | ||
@Composable | ||
fun CategoryCard( | ||
modifier: Modifier = Modifier, | ||
category: Category, | ||
onClick: (Category) -> Unit, | ||
) { | ||
Card( | ||
modifier = modifier then Modifier | ||
.padding(vertical = PADDING_4) | ||
.fillMaxWidth() | ||
.defaultMinSize(minHeight = MEDIUM_INPUT_HEIGHT) | ||
.clickable { onClick(category) }, | ||
backgroundColor = MaterialTheme.colors.surface, | ||
shape = RoundedCornerShape(corner = CornerSize(CORNER_RADIUS_4)), | ||
) { | ||
Row( | ||
modifier = Modifier.padding(PADDING_8), | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
|
||
Box( | ||
modifier = Modifier | ||
.width(MIN_INPUT_WIDTH) | ||
.height(MIN_INPUT_HEIGHT) | ||
.background( | ||
category.secondaryColor.copy(alpha = 0.2f), | ||
RoundedCornerShape(CORNER_RADIUS_4) | ||
), | ||
contentAlignment = Alignment.Center, | ||
) { | ||
Image( | ||
painter = painterResource(category.icon), | ||
contentDescription = category.categoryName, | ||
colorFilter = ColorFilter.tint(category.primaryColor), | ||
) | ||
} | ||
|
||
Text( | ||
modifier = Modifier.padding(PADDING_8), | ||
text = category.categoryName, | ||
) | ||
} | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
composeApp/src/commonMain/kotlin/presentation/event/EventManager.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package presentation.event | ||
|
||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
|
||
class EventManager<T>(initialEvent: T) { | ||
private val _events = MutableStateFlow(initialEvent) | ||
val events: StateFlow<T> = _events.asStateFlow() | ||
|
||
fun emitEvent(event: T) { | ||
_events.value = event | ||
} | ||
} |
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
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
99 changes: 99 additions & 0 deletions
99
composeApp/src/commonMain/kotlin/presentation/screen/category/CategoryScreen.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package presentation.screen.category | ||
|
||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Scaffold | ||
import androidx.compose.material.Surface | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Modifier | ||
import domain.model.Category | ||
import domain.model.UIState | ||
import moe.tlaster.precompose.flow.collectAsStateWithLifecycle | ||
import moe.tlaster.precompose.koin.koinViewModel | ||
import org.jetbrains.compose.ui.tooling.preview.Preview | ||
import presentation.designsystem.CategoryCard | ||
import presentation.designsystem.SearchInputText | ||
import presentation.designsystem.TopAppBar | ||
import presentation.theme.MoneyMateTheme | ||
import presentation.theme.PADDING_16 | ||
import presentation.theme.PADDING_24 | ||
import presentation.theme.PADDING_8 | ||
|
||
|
||
@Composable | ||
fun CategoryRoute( | ||
modifier: Modifier = Modifier, | ||
onCategory: (category: Category) -> Unit, | ||
onBack: () -> Unit, | ||
) { | ||
val viewModel = koinViewModel(CategoryViewModel::class) | ||
val categories by viewModel.categories.collectAsStateWithLifecycle() | ||
|
||
CategoryScreen( | ||
modifier = modifier.fillMaxSize().padding(horizontal = PADDING_24), | ||
uiState = categories, | ||
onQuery = viewModel::queryCategories, | ||
onCategory = onCategory, | ||
onBack = onBack, | ||
) | ||
} | ||
|
||
@Composable | ||
internal fun CategoryScreen( | ||
modifier: Modifier = Modifier, | ||
uiState: UIState<Array<Category>>, | ||
onQuery: (String) -> Unit, | ||
onCategory: (category: Category) -> Unit, | ||
onBack: () -> Unit, | ||
) { | ||
var query by remember { mutableStateOf("") } | ||
|
||
Scaffold( | ||
topBar = { | ||
TopAppBar(title = "Categories", onBack = onBack) | ||
}, | ||
) { paddingValues -> | ||
LazyColumn(modifier = modifier then Modifier.padding(paddingValues)) { | ||
item { | ||
SearchInputText( | ||
modifier = Modifier.padding(top = PADDING_8, bottom = PADDING_16), | ||
value = query, | ||
label = "Search category...", | ||
onValueChange = { query = it; onQuery(it) }, | ||
) | ||
} | ||
|
||
when (uiState) { | ||
is UIState.Success -> { | ||
items(items = uiState.result) { category -> | ||
CategoryCard( | ||
category = category, | ||
onClick = { onCategory(category) }, | ||
) | ||
} | ||
} | ||
else -> Unit | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
@Composable | ||
@Preview | ||
private fun PreviewCategoryScreen() { | ||
MoneyMateTheme { | ||
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colors.background) { | ||
CategoryScreen( | ||
modifier = Modifier.fillMaxSize().padding(horizontal = PADDING_24), | ||
uiState = UIState.Empty, | ||
onQuery = { }, | ||
onCategory = { }, | ||
onBack = { }, | ||
) | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
composeApp/src/commonMain/kotlin/presentation/screen/category/CategoryViewModel.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package presentation.screen.category | ||
|
||
import domain.model.Category | ||
import domain.model.UIState | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import presentation.base.BaseViewModel | ||
|
||
class CategoryViewModel : BaseViewModel() { | ||
private val _categories = MutableStateFlow<UIState<Array<Category>>>(UIState.Success(Category.all())) | ||
val categories: StateFlow<UIState<Array<Category>>> = _categories.asStateFlow() | ||
|
||
fun queryCategories(query: String) { | ||
_categories.value = UIState.Success(Category.filterCategory(query)) | ||
} | ||
} |
Oops, something went wrong.