Skip to content

Commit

Permalink
feat: Added dish list mode chooser to header
Browse files Browse the repository at this point in the history
  • Loading branch information
Lastaapps committed Jan 21, 2025
1 parent 6321551 commit 1e8319b
Show file tree
Hide file tree
Showing 18 changed files with 204 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ internal class StravnikWalletApiImpl(
return@repeat
}
}
delay(420.milliseconds)
delay(690.milliseconds)
}
getData()
.bind()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand Down Expand Up @@ -57,6 +57,7 @@ internal class MainSettingsRepoImpl(
isOliverRow().distinctUntilChanged(),
getBalanceWarningThreshold().distinctUntilChanged(),
getAlternativeNavigation().distinctUntilChanged(),
isDishListModeChosen().distinctUntilChanged(),
) { arr ->
AppSettings(
initialMenzaMode = arr[0] as InitialSelectionBehaviour,
Expand All @@ -74,6 +75,7 @@ internal class MainSettingsRepoImpl(
useOliverRows = arr[12] as Boolean,
balanceWarningThreshold = arr[13] as Int,
alternativeNavigation = arr[14] as Boolean,
isDishListModeChosen = arr[15] as Boolean,
)
}.distinctUntilChanged()

Expand Down Expand Up @@ -119,34 +121,38 @@ internal class MainSettingsRepoImpl(

override suspend fun setDishLanguage(language: DataLanguage) = general.setDishLanguage(language)

override fun getDishLanguage(): Flow<DataLanguage> =
general.getDishLanguage().map { it ?: defaults.defaultDishLanguage() }
override fun getDishLanguage(): Flow<DataLanguage> = general.getDishLanguage().map { it ?: defaults.defaultDishLanguage() }

override suspend fun setCompactTodayView(mode: DishListMode) = general.setCompactTodayView(mode)

override fun isCompactTodayView(): Flow<DishListMode> =
general
.isCompactTodayView()
.map { it ?: DishListMode.CAROUSEL }
.map { it ?: AppSettings.default.todayViewMode }

override suspend fun setOliverRows(useOliverRows: Boolean) = general.setOliverRow(useOliverRows)

override fun isOliverRow(): Flow<Boolean> =
general
.isOliverRow()
.map { it ?: true }
.map { it ?: AppSettings.default.useOliverRows }

override suspend fun setBalanceWarningThreshold(threshold: Int) = general.setBalanceWarningThreshold(threshold)

override fun getBalanceWarningThreshold(): Flow<Int> =
general
.getBalanceWarningThreshold()
.map { it ?: 256 }
.map { it ?: AppSettings.default.balanceWarningThreshold }

override suspend fun setAlternativeNavigation(enabled: Boolean) = general.setAlternativeNavigation(enabled)

override fun getAlternativeNavigation(): Flow<Boolean> =
general
.getAlternativeNavigation()
.map { it ?: false }
.map { it ?: AppSettings.default.alternativeNavigation }

override suspend fun dismissDishListModeChosen() = general.setDishListModeChosen(true)

override fun isDishListModeChosen(): Flow<Boolean> =
general.getDishListModeChosen().map { it ?: AppSettings.default.isDishListModeChosen }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand Down Expand Up @@ -94,6 +94,10 @@ internal interface GeneralDataSource {
suspend fun setAlternativeNavigation(enabled: Boolean)

fun getAlternativeNavigation(): Flow<Boolean?>

suspend fun setDishListModeChosen(isChosen: Boolean)

fun getDishListModeChosen(): Flow<Boolean?>
}

@OptIn(ExperimentalSettingsApi::class)
Expand All @@ -116,6 +120,7 @@ internal class GeneralDataSourceImpl(
private const val oliverRowsKey = "oliver_row"
private const val balanceWarningThresholdKey = "balance_warning_threshold"
private const val alternativeNavigationKey = "alternative_navigation"
private const val dishListModeChosenKey = "dish_list_mode_chosen"
}

override suspend fun storeAppSetupFinished() = settings.putBoolean(appSetupFinishedKey, true)
Expand Down Expand Up @@ -159,8 +164,7 @@ internal class GeneralDataSourceImpl(

override fun getImagesOnMetered(): Flow<Boolean> = settings.getBooleanFlow(imagesOnMeteredKey, true)

override suspend fun setDishLanguage(language: DataLanguage) =
settings.putInt(dishLanguageKey, language.id)
override suspend fun setDishLanguage(language: DataLanguage) = settings.putInt(dishLanguageKey, language.id)

override fun getDishLanguage(): Flow<DataLanguage?> =
settings.getIntOrNullFlow(dishLanguageKey).map { id ->
Expand All @@ -187,4 +191,8 @@ internal class GeneralDataSourceImpl(
override suspend fun setAlternativeNavigation(enabled: Boolean) = settings.putBoolean(alternativeNavigationKey, enabled)

override fun getAlternativeNavigation(): Flow<Boolean?> = settings.getBooleanOrNullFlow(alternativeNavigationKey)

override suspend fun setDishListModeChosen(isChosen: Boolean) = settings.putBoolean(dishListModeChosenKey, isChosen)

override fun getDishListModeChosen(): Flow<Boolean?> = settings.getBooleanOrNullFlow(dishListModeChosenKey)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand Down Expand Up @@ -47,6 +47,7 @@ import cz.lastaapps.menza.features.settings.domain.usecase.menzaorder.IsMenzaOrd
import cz.lastaapps.menza.features.settings.domain.usecase.menzaorder.SetMenzaOrderFromTopUC
import cz.lastaapps.menza.features.settings.domain.usecase.menzaorder.ToggleMenzaVisibilityUC
import cz.lastaapps.menza.features.settings.domain.usecase.menzaorder.UpdateMenzaOrderUC
import cz.lastaapps.menza.features.settings.domain.usecase.settings.DismissDishListModeChooserUC
import cz.lastaapps.menza.features.settings.domain.usecase.settings.GetAppSettingsUC
import cz.lastaapps.menza.features.settings.domain.usecase.settings.GetBalanceWarningThresholdUC
import cz.lastaapps.menza.features.settings.domain.usecase.settings.GetDishLanguageUC
Expand Down Expand Up @@ -148,6 +149,7 @@ val settingsModule =
factoryOf(::SetDishLanguageUC)
factoryOf(::GetDishListModeUC)
factoryOf(::SetDishListModeUC)
factoryOf(::DismissDishListModeChooserUC)

// Menza order
factoryOf(::ReorderMenzaViewModel)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand Down Expand Up @@ -91,4 +91,8 @@ internal interface MainSettingsRepo {
suspend fun setAlternativeNavigation(enabled: Boolean)

fun getAlternativeNavigation(): Flow<Boolean>

suspend fun dismissDishListModeChosen()

fun isDishListModeChosen(): Flow<Boolean>
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand Down Expand Up @@ -40,10 +40,11 @@ internal data class AppSettings(
val useOliverRows: Boolean,
val balanceWarningThreshold: Int,
val alternativeNavigation: Boolean,
val isDishListModeChosen: Boolean,
) {
companion object {
// Used for previews
fun default() =
val default =
AppSettings(
initialMenzaMode = InitialSelectionBehaviour.Specific,
latestMenza = MenzaType.Testing.Kocourkov,
Expand All @@ -59,7 +60,8 @@ internal data class AppSettings(
todayViewMode = DishListMode.COMPACT,
useOliverRows = true,
balanceWarningThreshold = 256,
alternativeNavigation = false,
alternativeNavigation = true,
isDishListModeChosen = false,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2025, 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 <https://www.gnu.org/licenses/>.
*/

package cz.lastaapps.menza.features.settings.domain.usecase.settings

import cz.lastaapps.core.domain.UCContext
import cz.lastaapps.core.domain.UseCase
import cz.lastaapps.menza.features.settings.domain.MainSettingsRepo

class DismissDishListModeChooserUC internal constructor(
context: UCContext,
private val repo: MainSettingsRepo,
) : UseCase(context) {
suspend operator fun invoke() =
launch {
repo.dismissDishListModeChosen()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand All @@ -22,10 +22,12 @@ package cz.lastaapps.menza.features.settings.domain.usecase.settings
import cz.lastaapps.core.domain.UCContext
import cz.lastaapps.core.domain.UseCase
import cz.lastaapps.menza.features.settings.domain.MainSettingsRepo
import cz.lastaapps.menza.features.settings.domain.model.AppSettings
import kotlinx.coroutines.flow.Flow

internal class GetAppSettingsUC internal constructor(
context: UCContext,
private val repo: MainSettingsRepo,
) : UseCase(context) {
operator fun invoke() = repo.getAllSettings()
operator fun invoke(): Flow<AppSettings> = repo.getAllSettings()
}
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ private fun IconAndText(
private fun SettingsScreenPreview() =
PreviewWrapper {
SettingsScreen(
appSettings = AppSettings.default(),
appSettings = AppSettings.default,
appTheme = Agata,
onChooseTheme = {},
onChooseDishLanguage = {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand Down Expand Up @@ -31,4 +31,5 @@ internal data class TodayUserSettings(
val downloadOnMetered: Boolean = false,
val language: DataLanguage = DataLanguage.Czech,
val imageScale: Float = 1f,
val isDishListModeChosen: Boolean = true,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand All @@ -21,65 +21,27 @@ 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.settings.GetDishLanguageUC
import cz.lastaapps.menza.features.settings.domain.usecase.settings.GetDishListModeUC
import cz.lastaapps.menza.features.settings.domain.usecase.settings.GetImageScaleUC
import cz.lastaapps.menza.features.settings.domain.usecase.settings.GetImagesOnMeteredUC
import cz.lastaapps.menza.features.settings.domain.usecase.settings.GetOliverRowUC
import cz.lastaapps.menza.features.settings.domain.usecase.settings.GetPriceTypeUC
import cz.lastaapps.menza.features.settings.domain.usecase.settings.GetAppSettingsUC
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
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map

internal class GetTodayUserSettingsUC(
context: UCContext,
private val getOliverRowUC: GetOliverRowUC,
private val getPriceTypeUC: GetPriceTypeUC,
private val getImagesOnMeteredUC: GetImagesOnMeteredUC,
private val getImageScaleUC: GetImageScaleUC,
private val getDishLanguageUC: GetDishLanguageUC,
private val getDishListModeUC: GetDishListModeUC,
private val getAppSettingsUC: GetAppSettingsUC,
) : UseCase(context) {
operator fun invoke(): Flow<TodayUserSettings> =
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) }
}
getAppSettingsUC()
.map {
TodayUserSettings(
priceType = it.priceType,
downloadOnMetered = it.imagesOnMetered,
imageScale = it.imageScale,
language = it.dataLanguage,
dishListMode = it.todayViewMode,
useOliverRow = it.useOliverRows,
isDishListModeChosen = it.isDishListModeChosen,
)
}.distinctUntilChanged()
}
Loading

0 comments on commit 1e8319b

Please sign in to comment.