Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
.externalNativeBuild
.cxx
local.properties
.omc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package khs.onmi.core.designsystem.component

import androidx.annotation.DrawableRes
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.LinearOutSlowInEasing
Expand All @@ -21,6 +22,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand All @@ -31,23 +33,24 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import khs.onmi.core.designsystem.icon.AllergiesEggIcon
import khs.onmi.core.designsystem.icon.InfoCardMealIcon
import khs.onmi.core.designsystem.icon.InfoCardTimeTableIcon
import khs.onmi.core.designsystem.modifier.addBounceEffect
import khs.onmi.core.designsystem.modifier.onmiClickable
import khs.onmi.core.designsystem.theme.ONMITheme
import khs.onmi.core.designsystem.R as DR

@Composable
fun AllergiesCard(
modifier: Modifier = Modifier,
id: Int,
name: String,
@DrawableRes iconId: Int,
isSelected: Boolean,
itemNumber: Int,
allergyName: String,
allergyIcon: @Composable () -> Unit,
onItemClick: () -> Unit,
) {
ONMITheme { color, typography ->
Expand All @@ -73,10 +76,22 @@ fun AllergiesCard(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(start = 20.dp)
) {
allergyIcon()
Box(
modifier = Modifier
.size(56.dp)
.clip(RoundedCornerShape(8.dp))
.background(color.BackgroundSecondary)
) {
Icon(
painter = painterResource(id = iconId),
contentDescription = "Allergies Icon",
modifier = Modifier.align(Alignment.Center),
tint = if (isSelected) color.Black else color.UnselectedPrimary
)
Comment thread
khs3994 marked this conversation as resolved.
}
RowSpacer(dp = 8.dp)
Text(
text = allergyName,
text = name,
style = typography.Body3,
color = if (isSelected) color.TextPrimary else color.UnselectedPrimary
)
Expand All @@ -89,7 +104,7 @@ fun AllergiesCard(
.offset(x = (-8).dp, y = 8.dp)
) {
Text(
text = itemNumber.toString(),
text = id.toString(),
style = typography.Body3,
color = if (isSelected) color.TextPrimary else color.UnselectedPrimary,
modifier = Modifier.align(Alignment.Center)
Expand Down Expand Up @@ -171,23 +186,15 @@ fun InfoCard(
@Preview
@Composable
fun AllergiesCardPre() {
var isSelected by remember {
mutableStateOf(false)
}

AllergiesCard(
modifier = Modifier
.width(167.dp)
.height(96.dp),
isSelected = isSelected,
itemNumber = 1,
allergyName = "난류",
allergyIcon = {
AllergiesEggIcon(isItemSelected = isSelected)
},
onItemClick = {
isSelected = !isSelected
}
isSelected = true,
id = 1,
name = "난류",
iconId = DR.drawable.ic_allergies_egg,
onItemClick = {}
)
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.onmi.data.datasource

import kotlinx.coroutines.flow.Flow

interface LocalAllergyDataSource {
fun getSelectedAllergyIds(): Flow<List<Int>>
suspend fun saveSelectedAllergyIds(ids: List<Int>)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.onmi.data.datasourceimpl

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringSetPreferencesKey
import com.onmi.data.datasource.LocalAllergyDataSource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject

class LocalAllergyDataSourceImpl @Inject constructor(
private val dataStore: DataStore<Preferences>,
) : LocalAllergyDataSource {

companion object {
private val SELECTED_ALLERGY_IDS = stringSetPreferencesKey("selected_allergy_ids")
}

override fun getSelectedAllergyIds(): Flow<List<Int>> {
return dataStore.data.map { prefs ->
prefs[SELECTED_ALLERGY_IDS]?.map { it.toInt() } ?: emptyList()
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

override suspend fun saveSelectedAllergyIds(ids: List<Int>) {
dataStore.edit { prefs ->
prefs[SELECTED_ALLERGY_IDS] = ids.map { it.toString() }.toSet()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.onmi.data.dto.meal.response.GetTodayMealsResponse
import com.onmi.data.dto.meal.response.SchoolMealInfo
import com.onmi.data.datasource.MealDataSource
import com.onmi.data.utils.bodyOrThrow
import com.onmi.domain.model.meal.MealMenuItem
import io.ktor.client.HttpClient
import io.ktor.client.request.get
import io.ktor.client.request.parameter
Expand Down Expand Up @@ -34,15 +35,24 @@ class MealDataSourceImpl @Inject constructor(
)
}

private fun String.removeDetailInfo(): String {
val regex = Regex("\\([^)]*\\)")
return this.replace(regex, "")
private fun String.parseMealMenuItem(): MealMenuItem {
val regex = Regex("\\(([^)]*?)\\)\\s*$")
val match = regex.find(this.trim())
return if (match != null) {
val name = this.substring(0, match.range.first).trim()
val allergyIds = match.groupValues[1]
.split(".")
.mapNotNull { it.trim().toIntOrNull() }
MealMenuItem(name = name, allergyIds = allergyIds)
} else {
MealMenuItem(name = this.trim(), allergyIds = emptyList())
}
}

private fun List<SchoolMealInfo>.findMealInfo(type: String): Pair<List<String>, String> {
private fun List<SchoolMealInfo>.findMealInfo(type: String): Pair<List<MealMenuItem>, String> {
return this.find { findData -> findData.type == type }?.let { schoolMealInfo ->
Pair(
schoolMealInfo.meal.split("<br/>").map { it.removeDetailInfo() },
schoolMealInfo.meal.split("<br/>").map { it.parseMealMenuItem() },
schoolMealInfo.kcal
)
} ?: Pair(emptyList(), "")
Expand Down
Loading
Loading