Skip to content

Commit

Permalink
feat(RecipeDifficult): 레시피 추천 난이도 화면을 그린다
Browse files Browse the repository at this point in the history
  • Loading branch information
SeongHoonC committed Jun 25, 2024
1 parent 90345c6 commit 617585d
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ data class RecipeRecommendResponse(
val need: List<String>,
val servings: Int,
val cookingTime: Int,
val isBookmarked: Boolean,
val difficulty: String
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sundaegukbap.banchango.core.data.di

import com.sundaegukbap.banchango.core.data.repository.DefaultRecipeRepository
import com.sundaegukbap.banchango.core.data.repository.FakeRecipeRepository
import com.sundaegukbap.banchango.core.data.repository.api.RecipeRepository
import dagger.Binds
Expand All @@ -12,5 +13,5 @@ import dagger.hilt.components.SingletonComponent
internal abstract class RepositoryModule {

@Binds
abstract fun bindsRecipeRepository(recipeRepository: FakeRecipeRepository): RecipeRepository
abstract fun bindsRecipeRepository(recipeRepository: DefaultRecipeRepository): RecipeRepository
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package com.sundaegukbap.banchango.core.data.mapper

import com.sundaegukbap.banchango.Recipe
import com.sundaegukbap.banchango.RecipeDifficulty
import com.sundaegukbap.banchango.core.data.api.model.RecipeRecommendResponse

internal fun List<RecipeRecommendResponse>.toData(): List<Recipe> = map { it.toData() }

internal fun RecipeRecommendResponse.toData(): Recipe {
val difficulty = when (difficulty) {
"아무나" -> RecipeDifficulty.ANYONE
"초보" -> RecipeDifficulty.BEGINNER
"중급" -> RecipeDifficulty.INTERMEDIATE
"고급" -> RecipeDifficulty.ADVANCED
"신의경지" -> RecipeDifficulty.GODLIKE
else -> RecipeDifficulty.ANYONE
}
return Recipe(
id = id,
name = name,
Expand All @@ -16,7 +25,6 @@ internal fun RecipeRecommendResponse.toData(): Recipe {
need = need,
servings = servings,
cookingTime = cookingTime,
isBookmarked = isBookmarked,
difficulty = difficulty,
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sundaegukbap.banchango.core.data.repository

import com.sundaegukbap.banchango.Recipe
import com.sundaegukbap.banchango.RecipeDifficulty
import com.sundaegukbap.banchango.core.data.repository.api.RecipeRepository
import javax.inject.Inject

Expand All @@ -16,10 +17,9 @@ class FakeRecipeRepository @Inject constructor() : RecipeRepository {
link = "https://www.10000recipe.com/recipe/6889616",
cookingTime = 10,
servings = 2,
difficulty = "Easy",
difficulty = RecipeDifficulty.BEGINNER,
have = listOf("계란", "간장"),
need = listOf("식초", "당근", "감자"),
isBookmarked = false,
)
}
)
Expand All @@ -35,10 +35,9 @@ class FakeRecipeRepository @Inject constructor() : RecipeRepository {
link = "https://www.10000recipe.com/recipe/6889616",
cookingTime = 10,
servings = 2,
difficulty = "Easy",
difficulty = RecipeDifficulty.BEGINNER,
have = listOf("계란", "간장"),
need = listOf("식초", "당근", "감자"),
isBookmarked = false,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ val PurpleGrey40 = Color(0xFF625b71)
val Pink40 = Color(0xFF7D5260)

val Orange = Color(0xFFFF7A00)
val LightBeige = Color(0xFFF5EB)
val LightOrange = Color(0xFFFFC085)
val White = Color(0xFFFFFFFF)
val Black = Color(0xFF000000)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.sundaegukbap.banchango.feature.recipe.detail

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material3.Text
import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight.Companion.Bold
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.sundaegukbap.banchango.RecipeDifficulty
import com.sundaegukbap.banchango.core.designsystem.theme.BanchangoTheme
import com.sundaegukbap.banchango.core.designsystem.theme.LightOrange
import com.sundaegukbap.banchango.core.designsystem.theme.Orange
import com.sundaegukbap.banchango.feature.recipe.difficulty.Stars

@Composable
fun RecipeDetailInfo(
difficulty: RecipeDifficulty,
serving: Int,
cookingTime: Int,
paddingHorizontal: Int,
modifier: Modifier = Modifier
) {
Row(modifier = modifier.fillMaxWidth()) {
RecipeDetailDifficulty(
modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterVertically)
.padding(horizontal = paddingHorizontal.dp),
difficulty = difficulty
)

RecipeLine(alignment = Alignment.CenterVertically)

DetailText(
modifier = Modifier.align(Alignment.CenterVertically),
text = "${serving}인분",
paddingHorizontal = paddingHorizontal
)

RecipeLine(alignment = Alignment.CenterVertically)

DetailText(
modifier = Modifier.align(Alignment.CenterVertically),
text = "${cookingTime}m",
paddingHorizontal = paddingHorizontal
)
}
}

@Composable
private fun RecipeDetailDifficulty(
modifier: Modifier = Modifier,
difficulty: RecipeDifficulty
) {
Column(modifier = modifier) {
Stars(
modifier = Modifier.wrapContentSize(),
starSize = 14,
filledCount = difficulty.level
)
Text(
modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally),
text = difficulty.explain,
fontSize = 12.sp,
fontWeight = Bold,
color = Orange,
)
}
}

@Composable
private fun RowScope.RecipeLine(alignment: Alignment.Vertical) {
VerticalDivider(
modifier = Modifier
.height(52.dp)
.align(alignment),
color = LightOrange,
thickness = 2.dp
)
}

@Composable
private fun RowScope.DetailText(
modifier: Modifier = Modifier,
paddingHorizontal: Int,
text: String
) {
Text(
modifier = modifier
.wrapContentSize()
.padding(horizontal = paddingHorizontal.dp)
.align(Alignment.CenterVertically),
text = text,
fontSize = 12.sp,
fontWeight = Bold,
color = Orange,
textAlign = TextAlign.Center
)
}

@Preview(showBackground = true)
@Composable
fun RecipeDetailInfoPreview() {
BanchangoTheme {
RecipeDetailInfo(
difficulty = RecipeDifficulty.ADVANCED,
serving = 2,
cookingTime = 30,
20,
)
}
}

Loading

0 comments on commit 617585d

Please sign in to comment.