From 72c96b03cfb8224496d942b7d5b3e9f73abbadb6 Mon Sep 17 00:00:00 2001 From: Lasta apps Date: Sun, 28 Jan 2024 18:36:46 +0200 Subject: [PATCH] refactor: Separate UI setting into a separate object --- .../menza/features/today/di/todayModule.kt | 4 +- .../today/domain/model/TodayUserSettings.kt | 34 +++++ .../domain/usecase/GetTodayUserSettingsUC.kt | 79 +++++++++++ .../today/ui/screen/DishListScreen.kt | 130 +++++++++--------- .../features/today/ui/vm/DishListViewModel.kt | 50 +------ .../features/today/ui/widget/TodayDishGrid.kt | 36 ++--- .../today/ui/widget/TodayDishHorizontal.kt | 47 +++---- .../features/today/ui/widget/TodayDishList.kt | 41 ++---- 8 files changed, 229 insertions(+), 192 deletions(-) create mode 100644 app/src/main/kotlin/cz/lastaapps/menza/features/today/domain/model/TodayUserSettings.kt create mode 100644 app/src/main/kotlin/cz/lastaapps/menza/features/today/domain/usecase/GetTodayUserSettingsUC.kt diff --git a/app/src/main/kotlin/cz/lastaapps/menza/features/today/di/todayModule.kt b/app/src/main/kotlin/cz/lastaapps/menza/features/today/di/todayModule.kt index 07f5c501..2099ee8a 100644 --- a/app/src/main/kotlin/cz/lastaapps/menza/features/today/di/todayModule.kt +++ b/app/src/main/kotlin/cz/lastaapps/menza/features/today/di/todayModule.kt @@ -19,13 +19,15 @@ package cz.lastaapps.menza.features.today.di +import cz.lastaapps.menza.features.today.domain.usecase.GetTodayUserSettingsUC import cz.lastaapps.menza.features.today.ui.vm.DishListViewModel import cz.lastaapps.menza.features.today.ui.vm.TodayViewModel import org.koin.core.module.dsl.factoryOf - import org.koin.dsl.module val todayModule = module { factoryOf(::DishListViewModel) factoryOf(::TodayViewModel) + + factoryOf(::GetTodayUserSettingsUC) } diff --git a/app/src/main/kotlin/cz/lastaapps/menza/features/today/domain/model/TodayUserSettings.kt b/app/src/main/kotlin/cz/lastaapps/menza/features/today/domain/model/TodayUserSettings.kt new file mode 100644 index 00000000..11df0272 --- /dev/null +++ b/app/src/main/kotlin/cz/lastaapps/menza/features/today/domain/model/TodayUserSettings.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved + * + * This file is part of Menza. + * + * Menza is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Menza is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Menza. If not, see . + */ + +package cz.lastaapps.menza.features.today.domain.model + +import cz.lastaapps.menza.features.settings.domain.model.DishLanguage +import cz.lastaapps.menza.features.settings.domain.model.DishListMode +import cz.lastaapps.menza.features.settings.domain.model.PriceType +import cz.lastaapps.menza.features.settings.domain.model.PriceType.Unset + +internal data class TodayUserSettings( + val dishListMode: DishListMode? = null, + val useOliverRow: Boolean = false, + val priceType: PriceType = Unset, + val downloadOnMetered: Boolean = false, + val language: DishLanguage = DishLanguage.Czech, + val imageScale: Float = 1f, +) diff --git a/app/src/main/kotlin/cz/lastaapps/menza/features/today/domain/usecase/GetTodayUserSettingsUC.kt b/app/src/main/kotlin/cz/lastaapps/menza/features/today/domain/usecase/GetTodayUserSettingsUC.kt new file mode 100644 index 00000000..75e8b999 --- /dev/null +++ b/app/src/main/kotlin/cz/lastaapps/menza/features/today/domain/usecase/GetTodayUserSettingsUC.kt @@ -0,0 +1,79 @@ +/* + * Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved + * + * This file is part of Menza. + * + * Menza is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Menza is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Menza. If not, see . + */ + +package cz.lastaapps.menza.features.today.domain.usecase + +import cz.lastaapps.core.domain.UCContext +import cz.lastaapps.core.domain.UseCase +import cz.lastaapps.menza.features.settings.domain.usecase.GetDishLanguageUC +import cz.lastaapps.menza.features.settings.domain.usecase.GetDishListModeUC +import cz.lastaapps.menza.features.settings.domain.usecase.GetImageScaleUC +import cz.lastaapps.menza.features.settings.domain.usecase.GetImagesOnMeteredUC +import cz.lastaapps.menza.features.settings.domain.usecase.GetOliverRow +import cz.lastaapps.menza.features.settings.domain.usecase.GetPriceTypeUC +import cz.lastaapps.menza.features.today.domain.model.TodayUserSettings +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.channelFlow +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.update + +internal class GetTodayUserSettingsUC( + context: UCContext, + private val getOliverRowUC: GetOliverRow, + private val getPriceTypeUC: GetPriceTypeUC, + private val getImagesOnMeteredUC: GetImagesOnMeteredUC, + private val getImageScaleUC: GetImageScaleUC, + private val getDishLanguageUC: GetDishLanguageUC, + private val getDishListModeUC: GetDishListModeUC, +) : UseCase(context) { + operator fun invoke(): Flow = channelFlow { + val state = MutableStateFlow(TodayUserSettings()) + + fun updateState(block: TodayUserSettings.() -> TodayUserSettings) = + state.update(block) + + getPriceTypeUC().onEach { + updateState { copy(priceType = it) } + }.launchIn(this) + + getImagesOnMeteredUC().onEach { + updateState { copy(downloadOnMetered = it) } + }.launchIn(this) + + getImageScaleUC().onEach { + updateState { copy(imageScale = it) } + }.launchIn(this) + + getDishLanguageUC().onEach { + updateState { copy(language = it) } + }.launchIn(this) + + getDishListModeUC().onEach { + updateState { copy(dishListMode = it) } + }.launchIn(this) + + getOliverRowUC().onEach { + updateState { copy(useOliverRow = it) } + }.launchIn(this) + + state.collect { send(it) } + } +} diff --git a/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/screen/DishListScreen.kt b/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/screen/DishListScreen.kt index db23b20a..5d2cc290 100644 --- a/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/screen/DishListScreen.kt +++ b/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/screen/DishListScreen.kt @@ -19,6 +19,7 @@ package cz.lastaapps.menza.features.today.ui.screen +import androidx.compose.animation.Crossfade import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -99,17 +100,19 @@ private fun DishListContent( scrollGridState: LazyStaggeredGridState, modifier: Modifier = Modifier, ) { + val userSettings = state.userSettings + Column { val gridSwitch: @Composable () -> Unit = { CompactViewSwitch( - currentMode = state.dishListMode, + currentMode = userSettings.dishListMode, onCompactChange = onViewMode, modifier = Modifier.fillMaxWidth(), ) } val imageSizeSetting: @Composable () -> Unit = { ImageSizeSetting( - progress = state.imageScale, + progress = userSettings.imageScale, onProgressChanged = onImageScale, modifier = Modifier.fillMaxWidth(), ) @@ -125,75 +128,72 @@ private fun DishListContent( } } - when (state.dishListMode) { - COMPACT -> - TodayDishList( - isLoading = state.isLoading, - onRefresh = onRefresh, - data = state.items, - onNoItems = onNoItems, - onDishSelected = onDishSelected, - priceType = state.priceType, - downloadOnMetered = state.downloadOnMetered, - language = state.language, - imageScale = state.imageScale, - isOnMetered = state.isOnMetered, - header = header, - footer = { - Column( - verticalArrangement = Arrangement.spacedBy(Padding.MidSmall), - modifier = Modifier.fillMaxWidth(), - ) { - gridSwitch() + Crossfade( + targetState = userSettings.dishListMode, + label = "dish_list_mode_router", + ) { dishListMode -> + when (dishListMode) { + COMPACT -> + TodayDishList( + isLoading = state.isLoading, + onRefresh = onRefresh, + data = state.items, + onNoItems = onNoItems, + onDishSelected = onDishSelected, + userSettings = userSettings, + isOnMetered = state.isOnMetered, + header = header, + footer = { + Column( + verticalArrangement = Arrangement.spacedBy(Padding.MidSmall), + modifier = Modifier.fillMaxWidth(), + ) { + gridSwitch() - OutlinedCard(modifier = Modifier.padding(horizontal = Padding.MidSmall)) { - Box(modifier = Modifier.padding(Padding.Medium)) { - imageSizeSetting() + OutlinedCard(modifier = Modifier.padding(horizontal = Padding.MidSmall)) { + Box(modifier = Modifier.padding(Padding.Medium)) { + imageSizeSetting() + } } } - } - }, - modifier = modifier.fillMaxSize(), - scroll = scrollListState, - ) + }, + modifier = modifier.fillMaxSize(), + scroll = scrollListState, + ) - GRID -> - TodayDishGrid( - isLoading = state.isLoading, - onRefresh = onRefresh, - data = state.items, - onNoItems = onNoItems, - onDishSelected = onDishSelected, - priceType = state.priceType, - downloadOnMetered = state.downloadOnMetered, - language = state.language, - isOnMetered = state.isOnMetered, - header = header, - footer = gridSwitch, - modifier = modifier.fillMaxSize(), - scrollGrid = scrollGridState, - ) + GRID -> + TodayDishGrid( + isLoading = state.isLoading, + onRefresh = onRefresh, + data = state.items, + onNoItems = onNoItems, + onDishSelected = onDishSelected, + userSettings = userSettings, + isOnMetered = state.isOnMetered, + header = header, + footer = gridSwitch, + modifier = modifier.fillMaxSize(), + scrollGrid = scrollGridState, + ) - HORIZONTAL -> - TodayDishHorizontal( - isLoading = state.isLoading, - onRefresh = onRefresh, - data = state.items, - onNoItems = onNoItems, - onDishSelected = onDishSelected, - useOliverRow = state.useOliverRow, - priceType = state.priceType, - downloadOnMetered = state.downloadOnMetered, - language = state.language, - isOnMetered = state.isOnMetered, - onOliverRow = onOliverRow, - header = header, - footer = gridSwitch, - modifier = modifier.fillMaxSize(), - scroll = scrollListState, - ) + HORIZONTAL -> + TodayDishHorizontal( + isLoading = state.isLoading, + onRefresh = onRefresh, + data = state.items, + onNoItems = onNoItems, + onDishSelected = onDishSelected, + userSettings = userSettings, + isOnMetered = state.isOnMetered, + onOliverRow = onOliverRow, + header = header, + footer = gridSwitch, + modifier = modifier.fillMaxSize(), + scroll = scrollListState, + ) - null -> {} + null -> {} + } } } } diff --git a/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/vm/DishListViewModel.kt b/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/vm/DishListViewModel.kt index a072ad21..32a2e772 100644 --- a/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/vm/DishListViewModel.kt +++ b/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/vm/DishListViewModel.kt @@ -39,19 +39,12 @@ import cz.lastaapps.core.ui.vm.VMContext import cz.lastaapps.core.ui.vm.VMState import cz.lastaapps.core.util.extensions.localLogger import cz.lastaapps.menza.features.main.domain.usecase.GetSelectedMenzaUC -import cz.lastaapps.menza.features.settings.domain.model.DishLanguage import cz.lastaapps.menza.features.settings.domain.model.DishListMode -import cz.lastaapps.menza.features.settings.domain.model.PriceType -import cz.lastaapps.menza.features.settings.domain.model.PriceType.Unset -import cz.lastaapps.menza.features.settings.domain.usecase.GetDishLanguageUC -import cz.lastaapps.menza.features.settings.domain.usecase.GetDishListModeUC -import cz.lastaapps.menza.features.settings.domain.usecase.GetImageScaleUC -import cz.lastaapps.menza.features.settings.domain.usecase.GetImagesOnMeteredUC -import cz.lastaapps.menza.features.settings.domain.usecase.GetOliverRow -import cz.lastaapps.menza.features.settings.domain.usecase.GetPriceTypeUC import cz.lastaapps.menza.features.settings.domain.usecase.SetDishListModeUC import cz.lastaapps.menza.features.settings.domain.usecase.SetImageScaleUC import cz.lastaapps.menza.features.settings.domain.usecase.SetOliverRow +import cz.lastaapps.menza.features.today.domain.model.TodayUserSettings +import cz.lastaapps.menza.features.today.domain.usecase.GetTodayUserSettingsUC import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import kotlinx.coroutines.Job @@ -65,16 +58,11 @@ internal class DishListViewModel( private val getSelectedMenzaUC: GetSelectedMenzaUC, private val getTodayDishListUC: GetTodayDishListUC, private val syncTodayDishListUC: SyncTodayDishListUC, - private val getOliverRowUC: GetOliverRow, private val setOliverRowUC: SetOliverRow, - private val getPriceTypeUC: GetPriceTypeUC, - private val getImagesOnMeteredUC: GetImagesOnMeteredUC, - private val getImageScaleUC: GetImageScaleUC, private val setImageScaleUC: SetImageScaleUC, - private val getDishLanguageUC: GetDishLanguageUC, - private val getDishListModeUC: GetDishListModeUC, private val setDishListModeUC: SetDishListModeUC, private val isOnMeteredUC: IsOnMeteredUC, + private val getUserSettingsUC: GetTodayUserSettingsUC, private val openMenuLinkUC: OpenMenuUC, ) : StateViewModel(DishListState(), context), Appearing, ErrorHolder { override var hasAppeared: Boolean = false @@ -106,33 +94,12 @@ internal class DishListViewModel( } } - getPriceTypeUC().onEach { - updateState { copy(priceType = it) } + getUserSettingsUC().onEach { + updateState { copy(userSettings = it) } }.launchInVM() - - getImagesOnMeteredUC().onEach { - updateState { copy(downloadOnMetered = it) } - }.launchInVM() - - getImageScaleUC().onEach { - updateState { copy(imageScale = it) } - }.launchInVM() - - getDishLanguageUC().onEach { - updateState { copy(language = it) } - }.launchInVM() - - getDishListModeUC().onEach { - updateState { copy(dishListMode = it) } - }.launchInVM() - isOnMeteredUC().onEach { updateState { copy(isOnMetered = it) } }.launchInVM() - - getOliverRowUC().onEach { - updateState { copy(useOliverRow = it) } - }.launchInVM() } private var syncJob: Job? = null @@ -177,15 +144,10 @@ internal class DishListViewModel( internal data class DishListState( val isLoading: Boolean = false, - val dishListMode: DishListMode? = null, val error: DomainError? = null, val selectedMenza: Option? = null, val items: ImmutableList = persistentListOf(), - val useOliverRow: Boolean = false, - val priceType: PriceType = Unset, - val downloadOnMetered: Boolean = false, - val language: DishLanguage = DishLanguage.Czech, - val imageScale: Float = 1f, + val userSettings: TodayUserSettings = TodayUserSettings(), val isOnMetered: Boolean = false, ) : VMState { val showExperimentalWarning: Boolean = diff --git a/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/widget/TodayDishGrid.kt b/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/widget/TodayDishGrid.kt index 90a706ab..3505434c 100644 --- a/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/widget/TodayDishGrid.kt +++ b/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/widget/TodayDishGrid.kt @@ -44,8 +44,8 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import cz.lastaapps.api.core.domain.model.Dish import cz.lastaapps.api.core.domain.model.DishCategory -import cz.lastaapps.menza.features.settings.domain.model.DishLanguage import cz.lastaapps.menza.features.settings.domain.model.PriceType +import cz.lastaapps.menza.features.today.domain.model.TodayUserSettings import cz.lastaapps.menza.ui.components.NoItems import cz.lastaapps.menza.ui.components.PullToRefreshWrapper import cz.lastaapps.menza.ui.locals.LocalWindowWidth @@ -54,15 +54,13 @@ import cz.lastaapps.menza.ui.util.appCardColors import kotlinx.collections.immutable.ImmutableList @Composable -fun TodayDishGrid( +internal fun TodayDishGrid( isLoading: Boolean, onRefresh: () -> Unit, data: ImmutableList, onNoItems: () -> Unit, onDishSelected: (Dish) -> Unit, - priceType: PriceType, - downloadOnMetered: Boolean, - language: DishLanguage, + userSettings: TodayUserSettings, isOnMetered: Boolean, header: @Composable () -> Unit, footer: @Composable () -> Unit, @@ -80,9 +78,7 @@ fun TodayDishGrid( data = data, onDishSelected = onDishSelected, onNoItems = onNoItems, - priceType = priceType, - downloadOnMetered = downloadOnMetered, - language = language, + userSettings = userSettings, isOnMetered = isOnMetered, scroll = scrollGrid, header = header, @@ -101,9 +97,7 @@ private fun DishContent( data: ImmutableList, onDishSelected: (Dish) -> Unit, onNoItems: () -> Unit, - priceType: PriceType, - downloadOnMetered: Boolean, - language: DishLanguage, + userSettings: TodayUserSettings, isOnMetered: Boolean, scroll: LazyStaggeredGridState, header: @Composable () -> Unit, @@ -148,15 +142,13 @@ private fun DishContent( if (index == 0) { DishHeader( courseType = category, - language = language, + language = userSettings.language, ) } DishItem( dish = dish, onDishSelected = onDishSelected, - priceType = priceType, - downloadOnMetered = downloadOnMetered, - language = language, + userSettings = userSettings, isOnMetered = isOnMetered, modifier = Modifier.fillMaxWidth(), ) @@ -175,9 +167,7 @@ private fun DishContent( private fun DishItem( dish: Dish, onDishSelected: (Dish) -> Unit, - priceType: PriceType, - downloadOnMetered: Boolean, - language: DishLanguage, + userSettings: TodayUserSettings, isOnMetered: Boolean, modifier: Modifier = Modifier, ) { @@ -195,8 +185,8 @@ private fun DishItem( if (dish.photoLink != null) { DishImageWithBadge( dish = dish, - priceType = priceType, - downloadOnMetered = downloadOnMetered, + priceType = userSettings.priceType, + downloadOnMetered = userSettings.downloadOnMetered, isOnMetered = isOnMetered, ) } @@ -210,15 +200,15 @@ private fun DishItem( ) { DishNameRow( dish = dish, - language = language, + language = userSettings.language, modifier = modifier.weight(1f), ) if (dish.photoLink == null) { - DishBadge(dish = dish, priceType = priceType) + DishBadge(dish = dish, priceType = userSettings.priceType) } } - DishInfoRow(dish, language) + DishInfoRow(dish, userSettings.language) } } } diff --git a/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/widget/TodayDishHorizontal.kt b/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/widget/TodayDishHorizontal.kt index 2a45eecc..88b2f6aa 100644 --- a/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/widget/TodayDishHorizontal.kt +++ b/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/widget/TodayDishHorizontal.kt @@ -48,8 +48,8 @@ import androidx.compose.ui.unit.dp import cz.lastaapps.api.core.domain.model.Dish import cz.lastaapps.api.core.domain.model.DishCategory import cz.lastaapps.menza.R -import cz.lastaapps.menza.features.settings.domain.model.DishLanguage import cz.lastaapps.menza.features.settings.domain.model.PriceType +import cz.lastaapps.menza.features.today.domain.model.TodayUserSettings import cz.lastaapps.menza.ui.components.NoItems import cz.lastaapps.menza.ui.components.PullToRefreshWrapper import cz.lastaapps.menza.ui.theme.Padding @@ -57,17 +57,14 @@ import cz.lastaapps.menza.ui.util.appCardColors import kotlinx.collections.immutable.ImmutableList @Composable -fun TodayDishHorizontal( +internal fun TodayDishHorizontal( isLoading: Boolean, onRefresh: () -> Unit, data: ImmutableList, onNoItems: () -> Unit, onDishSelected: (Dish) -> Unit, - priceType: PriceType, - downloadOnMetered: Boolean, - language: DishLanguage, + userSettings: TodayUserSettings, isOnMetered: Boolean, - useOliverRow: Boolean, onOliverRow: (Boolean) -> Unit, header: @Composable () -> Unit, footer: @Composable () -> Unit, @@ -84,11 +81,8 @@ fun TodayDishHorizontal( data = data, onDishSelected = onDishSelected, onNoItems = onNoItems, - priceType = priceType, - downloadOnMetered = downloadOnMetered, - language = language, + userSettings = userSettings, isOnMetered = isOnMetered, - useOliverRow = useOliverRow, onOliverRow = onOliverRow, scroll = scroll, header = header, @@ -106,11 +100,8 @@ private fun DishContent( data: ImmutableList, onDishSelected: (Dish) -> Unit, onNoItems: () -> Unit, - priceType: PriceType, - downloadOnMetered: Boolean, - language: DishLanguage, + userSettings: TodayUserSettings, isOnMetered: Boolean, - useOliverRow: Boolean, onOliverRow: (Boolean) -> Unit, scroll: LazyListState, header: @Composable () -> Unit, @@ -139,7 +130,7 @@ private fun DishContent( item { DishHeader( courseType = category, - language = language, + language = userSettings.language, modifier = Modifier.padding(bottom = Padding.Smaller), ) } @@ -150,9 +141,7 @@ private fun DishContent( DishItem( dish = category.dishList.first(), onDishSelected = onDishSelected, - priceType = priceType, - downloadOnMetered = downloadOnMetered, - language = language, + userSettings = userSettings, isOnMetered = isOnMetered, modifier = Modifier.fillMaxWidth(), ) @@ -163,9 +152,7 @@ private fun DishContent( DishItem( dish = dish, onDishSelected = onDishSelected, - priceType = priceType, - downloadOnMetered = downloadOnMetered, - language = language, + userSettings = userSettings, isOnMetered = isOnMetered, modifier = Modifier.sizeIn(maxWidth = 256.dp), ) @@ -175,7 +162,7 @@ private fun DishContent( Padding.MidLarge, Alignment.CenterHorizontally, ) - if (useOliverRow) { + if (userSettings.useOliverRow) { Row( verticalAlignment = Alignment.Top, horizontalArrangement = horizontalArrangement, @@ -207,7 +194,7 @@ private fun DishContent( item { OliverRowSwitch( - useOliverRow = useOliverRow, + useOliverRow = userSettings.useOliverRow, onOliverRow = onOliverRow, modifier = Modifier.fillMaxWidth(), ) @@ -224,9 +211,7 @@ private fun DishContent( private fun DishItem( dish: Dish, onDishSelected: (Dish) -> Unit, - priceType: PriceType, - downloadOnMetered: Boolean, - language: DishLanguage, + userSettings: TodayUserSettings, isOnMetered: Boolean, modifier: Modifier = Modifier, ) { @@ -245,8 +230,8 @@ private fun DishItem( if (dish.photoLink != null) { DishImageWithBadge( dish = dish, - priceType = priceType, - downloadOnMetered = downloadOnMetered, + priceType = userSettings.priceType, + downloadOnMetered = userSettings.downloadOnMetered, isOnMetered = isOnMetered, ) } @@ -260,18 +245,18 @@ private fun DishItem( ) { DishNameRow( dish = dish, - language = language, + language = userSettings.language, modifier = modifier.weight(1f), ) if (dish.photoLink == null) { DishBadge( dish = dish, - priceType = priceType, + priceType = userSettings.priceType, ) } } - DishInfoRow(dish, language) + DishInfoRow(dish, userSettings.language) } } } diff --git a/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/widget/TodayDishList.kt b/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/widget/TodayDishList.kt index 28357bae..8fa20795 100644 --- a/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/widget/TodayDishList.kt +++ b/app/src/main/kotlin/cz/lastaapps/menza/features/today/ui/widget/TodayDishList.kt @@ -45,8 +45,8 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import cz.lastaapps.api.core.domain.model.Dish import cz.lastaapps.api.core.domain.model.DishCategory -import cz.lastaapps.menza.features.settings.domain.model.DishLanguage import cz.lastaapps.menza.features.settings.domain.model.PriceType +import cz.lastaapps.menza.features.today.domain.model.TodayUserSettings import cz.lastaapps.menza.ui.components.NoItems import cz.lastaapps.menza.ui.components.PullToRefreshWrapper import cz.lastaapps.menza.ui.theme.Padding @@ -54,16 +54,13 @@ import cz.lastaapps.menza.ui.util.appCardColors import kotlinx.collections.immutable.ImmutableList @Composable -fun TodayDishList( +internal fun TodayDishList( isLoading: Boolean, onRefresh: () -> Unit, data: ImmutableList, onNoItems: () -> Unit, onDishSelected: (Dish) -> Unit, - priceType: PriceType, - downloadOnMetered: Boolean, - language: DishLanguage, - imageScale: Float, + userSettings: TodayUserSettings, isOnMetered: Boolean, header: @Composable () -> Unit, footer: @Composable () -> Unit, @@ -80,10 +77,7 @@ fun TodayDishList( data = data, onDishSelected = onDishSelected, onNoItems = onNoItems, - priceType = priceType, - downloadOnMetered = downloadOnMetered, - language = language, - imageScale = imageScale, + userSettings = userSettings, isOnMetered = isOnMetered, scroll = scroll, header = header, @@ -100,10 +94,7 @@ private fun DishContent( data: ImmutableList, onDishSelected: (Dish) -> Unit, onNoItems: () -> Unit, - priceType: PriceType, - downloadOnMetered: Boolean, - language: DishLanguage, - imageScale: Float, + userSettings: TodayUserSettings, isOnMetered: Boolean, scroll: LazyListState, header: @Composable () -> Unit, @@ -131,7 +122,7 @@ private fun DishContent( Surface(Modifier.fillMaxWidth()) { DishHeader( courseType = category, - language = language, + language = userSettings.language, modifier = Modifier.padding(bottom = Padding.Smaller), ) } @@ -140,10 +131,7 @@ private fun DishContent( DishItem( dish = dish, onDishSelected = onDishSelected, - priceType = priceType, - downloadOnMetered = downloadOnMetered, - language = language, - imageScale = imageScale, + userSettings = userSettings, isOnMetered = isOnMetered, modifier = Modifier.fillMaxWidth(), ) @@ -160,10 +148,7 @@ private fun DishContent( private fun DishItem( dish: Dish, onDishSelected: (Dish) -> Unit, - priceType: PriceType, - downloadOnMetered: Boolean, - language: DishLanguage, - imageScale: Float, + userSettings: TodayUserSettings, isOnMetered: Boolean, modifier: Modifier = Modifier, ) { @@ -180,14 +165,14 @@ private fun DishItem( DishImageWithBadge( dish = dish, - priceType = priceType, - downloadOnMetered = downloadOnMetered, - imageScale = imageScale, + priceType = userSettings.priceType, + downloadOnMetered = userSettings.downloadOnMetered, + imageScale = userSettings.imageScale, isOnMetered = isOnMetered, ) Column(verticalArrangement = Arrangement.spacedBy(Padding.Small)) { - DishNameRow(dish, language) - DishInfoRow(dish, language) + DishNameRow(dish, userSettings.language) + DishInfoRow(dish, userSettings.language) } } }