Skip to content

Commit

Permalink
feat: Rating badge added
Browse files Browse the repository at this point in the history
  • Loading branch information
Lastaapps committed Sep 5, 2024
1 parent e56bae1 commit 1890c3f
Show file tree
Hide file tree
Showing 23 changed files with 331 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ import io.ktor.client.request.post
import io.ktor.client.statement.bodyAsText
import io.ktor.http.HttpStatusCode
import io.ktor.http.parameters
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.delay
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlin.time.Duration.Companion.milliseconds

interface StravnikWalletApi : WalletApi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ internal class SyncJobHash<T, R, Params>(
fetchApi,
convert,
store,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ fun List<OpenTimeEntity>.toDomain() =
)
}.sortedBy { it.startDay }
.toImmutableList(),
)
}.toImmutableList(),
)
}.toImmutableList(),
)
}

Expand All @@ -223,8 +223,8 @@ internal fun List<StrahovEntity>.toDomain() =
dishList =
values
.sortedBy { it.itemOrder }
.map { it.toDomain() }
.toImmutableList(),
.map { it.toDomain() }
.toImmutableList(),
)
}.toImmutableList()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ import cz.lastaapps.menza.api.agata.data.model.HashType
import cz.lastaapps.menza.api.agata.data.model.toDB
import cz.lastaapps.menza.api.agata.data.model.toDto
import cz.lastaapps.menza.api.agata.domain.HashStore
import kotlin.time.Duration.Companion.days
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onStart
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import org.koin.core.parameter.parametersOf
import kotlin.time.Duration.Companion.days

internal class InfoRepoImpl(
private val subsystemId: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ internal class MenzaSubsystemRepoImpl(
"https://agata.suz.cvut.cz/jidelnicky/sd-cam-img.php",
),
)
MenzaType.Agata.Subsystem(3) ->
it.copy(
videoLinks =
persistentListOf(
"https://agata.suz.cvut.cz/jidelnicky/tm-cam-img.php",
),
)

else -> it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package cz.lastaapps.api.core.domain.model

import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentMapOf

data class DishCategory(
val nameShort: String?,
Expand All @@ -44,7 +45,9 @@ data class Dish(
val servingPlaces: ImmutableList<ServingPlace>,
val ingredients: ImmutableList<String>,
val isActive: Boolean,
)
) {
val rating: Rating = Rating("", 4.321f, 420, persistentMapOf())
}

data class ServingPlace(
val name: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/

package cz.lastaapps.api.core.domain.model

import kotlinx.collections.immutable.ImmutableMap

data class Rating(
val dishID: String,
val overallRating: Float,
val ratingCount: Int,
val ratingCategories: ImmutableMap<RatingCategory, Float>,
)

enum class RatingCategory {
TASTE,
PORTION_SIZE,
WORTHINESS,
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ class SyncJobNoCache<T, R, Params>(
fetchApi,
convert,
store,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ private fun AgataLoginDialogContent(
SubtitleWidget(
indexSelected = selectedIndex,
modifier =
Modifier
.padding(vertical = Padding.Tiny)
.animateContentSize(),
Modifier
.padding(vertical = Padding.Tiny)
.animateContentSize(),
)

val modeType =
Expand Down Expand Up @@ -301,7 +301,7 @@ private fun LoginForm(
) {
OutlinedTextField(
modifier =
Modifier.withAutofill(
Modifier.withAutofill(
autofillTypes = persistentListOf(AutofillType.Username),
onFill = onUsername,
),
Expand All @@ -313,7 +313,7 @@ private fun LoginForm(
KeyboardOptions(
keyboardType = KeyboardType.Ascii,
imeAction = ImeAction.Next,
),
),
)

var showPasswordInfo by rememberSaveable { mutableStateOf(false) }
Expand All @@ -323,23 +323,23 @@ private fun LoginForm(
Modifier.withAutofill(
autofillTypes = persistentListOf(AutofillType.Password),
onFill = onPassword,
),
),
enabled = !isLoading,
value = password,
onValueChange = onPassword,
label = { Text(stringResource(R.string.wallet_login_password)) },
visualTransformation = PasswordVisualTransformation(),
keyboardActions =
KeyboardActions {
if (loginEnabled) {
onLogin(balanceType)
}
},
KeyboardActions {
if (loginEnabled) {
onLogin(balanceType)
}
},
keyboardOptions =
KeyboardOptions(
keyboardType = KeyboardType.Password,
imeAction = ImeAction.Go,
),
KeyboardOptions(
keyboardType = KeyboardType.Password,
imeAction = ImeAction.Go,
),
trailingIcon = {
IconButton(onClick = { showPasswordInfo = !showPasswordInfo }) {
Icon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ private fun MenzaSelectionListContent(
lazyState = lazyState,
accountBalance = accountBalance,
modifier =
Modifier
.fillMaxWidth()
.animateContentSize(),
Modifier
.fillMaxWidth()
.animateContentSize(),
)
}
}
Expand Down Expand Up @@ -151,9 +151,9 @@ private fun MenzaList(
text = stringResource(R.string.app_name_long),
style = MaterialTheme.typography.headlineMedium,
modifier =
Modifier
.padding(vertical = Padding.Smaller)
.padding(start = Padding.Medium),
Modifier
.padding(vertical = Padding.Smaller)
.padding(start = Padding.Medium),
)
}

Expand Down Expand Up @@ -224,8 +224,8 @@ internal fun MenzaItem(
} else {
addRect(Rect(size.width, 0f, size.height / 2, size.height))
addOval(Rect(size.height, 0f, 0f, size.height))
}
},
}
},
modifier = modifier.alpha(openedAlpha),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,15 @@ internal class MainSettingsRepoImpl(

override suspend fun setImageScale(scale: Float) = general.setImageScale(scale)

override fun getImageScale(): Flow<Float> = general.getImageScale()
override fun getImageScale(): Flow<Float> = general.getImageScale().map { it ?: 1.3f }

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

override fun getImagesOnMetered(): Flow<Boolean> = general.getImagesOnMetered()

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

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

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

Expand All @@ -136,16 +135,14 @@ internal class MainSettingsRepoImpl(
.isOliverRow()
.map { it ?: true }

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

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

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

override fun getAlternativeNavigation(): Flow<Boolean> =
general
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ internal interface GeneralDataSource {

suspend fun setImageScale(scale: Float)

fun getImageScale(): Flow<Float>
fun getImageScale(): Flow<Float?>

suspend fun setImagesOnMetered(enabled: Boolean)

Expand Down Expand Up @@ -124,8 +124,7 @@ internal class GeneralDataSourceImpl(

override suspend fun storeSettingsEverOpened() = settings.putBoolean(settingsEverOpenedKey, true)

override fun isSettingsEverOpened(): Flow<Boolean> =
settings.getBooleanFlow(settingsEverOpenedKey, false)
override fun isSettingsEverOpened(): Flow<Boolean> = settings.getBooleanFlow(settingsEverOpenedKey, false)

override suspend fun setPriceType(type: PriceType) = settings.putInt(priceTypeKey, type.id)

Expand Down Expand Up @@ -154,24 +153,20 @@ internal class GeneralDataSourceImpl(

override suspend fun setImageScale(scale: Float) = settings.putFloat(imageScaleKey, scale)

override fun getImageScale(): Flow<Float> = settings.getFloatFlow(imageScaleKey, 1f)
override fun getImageScale(): Flow<Float?> = settings.getFloatOrNullFlow(imageScaleKey)

override suspend fun setImagesOnMetered(enabled: Boolean) =
settings.putBoolean(imagesOnMeteredKey, enabled)
override suspend fun setImagesOnMetered(enabled: Boolean) = settings.putBoolean(imagesOnMeteredKey, enabled)

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

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

override fun getDishLanguage(): Flow<DishLanguage?> =
settings.getIntOrNullFlow(dishLanguageKey).map { id ->
DishLanguage.entries.firstOrNull { it.id == id }
}

override suspend fun setCompactTodayView(mode: DishListMode) =
settings.putInt(compactTodayViewKey, mode.id)
override suspend fun setCompactTodayView(mode: DishListMode) = settings.putInt(compactTodayViewKey, mode.id)

override fun isCompactTodayView(): Flow<DishListMode?> =
settings
Expand All @@ -184,15 +179,11 @@ internal class GeneralDataSourceImpl(

override fun isOliverRow(): Flow<Boolean?> = settings.getBooleanOrNullFlow(oliverRowsKey)

override suspend fun setBalanceWarningThreshold(threshold: Int) =
settings.putInt(balanceWarningThresholdKey, threshold)
override suspend fun setBalanceWarningThreshold(threshold: Int) = settings.putInt(balanceWarningThresholdKey, threshold)

override fun getBalanceWarningThreshold(): Flow<Int?> =
settings.getIntOrNullFlow(balanceWarningThresholdKey)
override fun getBalanceWarningThreshold(): Flow<Int?> = settings.getIntOrNullFlow(balanceWarningThresholdKey)

override suspend fun setAlternativeNavigation(enabled: Boolean) =
settings.putBoolean(alternativeNavigationKey, enabled)
override suspend fun setAlternativeNavigation(enabled: Boolean) = settings.putBoolean(alternativeNavigationKey, enabled)

override fun getAlternativeNavigation(): Flow<Boolean?> =
settings.getBooleanOrNullFlow(alternativeNavigationKey)
override fun getAlternativeNavigation(): Flow<Boolean?> = settings.getBooleanOrNullFlow(alternativeNavigationKey)
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ private fun ReorderMenzaContent(

Column(
modifier =
modifier
.padding(Padding.MidLarge)
.fillMaxSize(),
modifier
.padding(Padding.MidLarge)
.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(Padding.Medium),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Expand Down Expand Up @@ -205,7 +205,7 @@ private fun MenzaItem(
horizontalArrangement = Arrangement.spacedBy(Padding.Small),
verticalAlignment = Alignment.CenterVertically,
modifier =
Modifier.padding(
Modifier.padding(
horizontal = Padding.Medium,
vertical = Padding.Small,
),
Expand Down Expand Up @@ -253,7 +253,7 @@ private fun MenzaItemPreview() {
supportsWeekly = true,
isExperimental = false,
videoLinks = persistentListOf(),
),
),
visible = true,
onVisibilityClick = {},
)
Expand All @@ -268,7 +268,7 @@ private fun MenzaItemPreview() {
supportsWeekly = true,
isExperimental = false,
videoLinks = persistentListOf(),
),
),
visible = false,
onVisibilityClick = {},
)
Expand Down
Loading

0 comments on commit 1890c3f

Please sign in to comment.