diff --git a/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/Recipe.kt b/Android/app/src/main/java/com/sundaegukbap/banchango/model/Recipe.kt similarity index 80% rename from Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/Recipe.kt rename to Android/app/src/main/java/com/sundaegukbap/banchango/model/Recipe.kt index 3e82b34..adb62e5 100644 --- a/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/Recipe.kt +++ b/Android/app/src/main/java/com/sundaegukbap/banchango/model/Recipe.kt @@ -1,4 +1,4 @@ -package com.sundaegukbap.banchango.presentation.reciperecommend +package com.sundaegukbap.banchango.model data class Recipe( val id: Long, diff --git a/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/MainActivity.kt b/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/MainActivity.kt index 813ded6..bfbfe82 100644 --- a/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/MainActivity.kt +++ b/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/MainActivity.kt @@ -5,42 +5,10 @@ import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.activity.viewModels -import androidx.compose.foundation.ExperimentalFoundationApi -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.pager.PagerState -import androidx.compose.foundation.pager.VerticalPager -import androidx.compose.foundation.pager.rememberPagerState -import androidx.compose.material3.Button -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.layout.ContentScale -import androidx.compose.ui.text.TextStyle -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 androidx.hilt.navigation.compose.hiltViewModel -import androidx.lifecycle.compose.LocalLifecycleOwner -import androidx.lifecycle.compose.collectAsStateWithLifecycle -import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi -import com.bumptech.glide.integration.compose.GlideImage import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.sundaegukbap.banchango.ui.theme.BanchangoTheme import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch @AndroidEntryPoint class MainActivity : ComponentActivity() { @@ -63,115 +31,3 @@ class MainActivity : ComponentActivity() { } } } - -@OptIn(ExperimentalFoundationApi::class) -@Composable -fun RecipesRecommendScreen( - modifier: Modifier = Modifier, - viewModel: RecipeRecommendViewModel = hiltViewModel(), -) { - val recipesUiState by viewModel.recipes.collectAsStateWithLifecycle() - - val pagerState = rememberPagerState( - pageCount = { - recipesUiState.size - } - ) - VerticalPager( - modifier = modifier, - state = pagerState, - contentPadding = PaddingValues(vertical = 200.dp, horizontal = 40.dp), - pageSpacing = 40.dp, - ) { page -> - RecipeScreen( - pagerState = pagerState, - page = page, - recipesUiState[page], - ) - } -} - - -@OptIn(ExperimentalFoundationApi::class) -@Composable -private fun RecipeScreen( - pagerState: PagerState, - page: Int, - recipe: Recipe, -) { - Box( - modifier = Modifier - .fillMaxSize() - .background(Color.Black), - contentAlignment = Alignment.Center, - ) { - NetworkImage( - modifier = Modifier - .fillMaxSize(), - url = recipe.image, - ) - Box { - Column { - Text( - recipe.name, - color = Color.White, - fontSize = 24.sp, - style = TextStyle(fontWeight = Bold), - textAlign = TextAlign.Center, - modifier = Modifier.fillMaxWidth(), - ) - Text( - text = page.toString(), - textAlign = TextAlign.Center, - modifier = Modifier.fillMaxWidth(), - color = Color.White, - fontSize = 60.sp - ) - val coroutineScope = rememberCoroutineScope() - Row( - modifier = Modifier - .align(Alignment.CenterHorizontally) - ) { - Button( - modifier = Modifier.padding(end = 16.dp), - onClick = { - coroutineScope.launch { - pagerState.animateScrollToPage(page + 1) - } - } - ) { - Text("싫어요") - } - Button( - onClick = { - coroutineScope.launch { - pagerState.animateScrollToPage(page + 1) - } - }, - ) { - Text("좋아요") - } - } - } - } - } -} - -@Preview(showBackground = true) -@Composable -fun GreetingPreview() { - BanchangoTheme { - RecipesRecommendScreen() - } -} - -@OptIn(ExperimentalGlideComposeApi::class) -@Composable -fun NetworkImage(modifier: Modifier, url: String) { - GlideImage( - model = url, - contentScale = ContentScale.Crop, - contentDescription = null, - modifier = modifier.fillMaxSize(), - ) -} diff --git a/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipeCard.kt b/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipeCard.kt new file mode 100644 index 0000000..10f5e24 --- /dev/null +++ b/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipeCard.kt @@ -0,0 +1,116 @@ +package com.sundaegukbap.banchango.presentation.reciperecommend + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Button +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.TextStyle +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.core.designsystem.NetworkImage +import com.sundaegukbap.banchango.model.Recipe +import com.sundaegukbap.banchango.ui.theme.BanchangoTheme + +@Composable +fun RecipeCard( + page: Int, + recipe: Recipe, + onHateClick: (page: Int) -> Unit = {}, + onLikeClick: (page: Int) -> Unit = {}, +) { + Box( + modifier = Modifier + .fillMaxSize() + .background(Color.Black), + contentAlignment = Alignment.Center, + ) { + NetworkImage( + modifier = Modifier + .fillMaxSize(), + url = recipe.image, + ) + RecipeInfo(recipe, page, onHateClick, onLikeClick) + } +} + +@Composable +private fun RecipeInfo( + recipe: Recipe, + page: Int, + onHateClick: (page: Int) -> Unit, + onLikeClick: (page: Int) -> Unit +) { + Box { + Column { + Text( + recipe.name, + color = Color.White, + fontSize = 24.sp, + style = TextStyle(fontWeight = Bold), + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth(), + ) + Text( + text = page.toString(), + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth(), + color = Color.White, + fontSize = 60.sp + ) + Row( + modifier = Modifier + .align(Alignment.CenterHorizontally) + ) { + Button( + modifier = Modifier.padding(end = 16.dp), + onClick = { + onHateClick(page + 1) + } + ) { + Text("싫어요") + } + Button( + onClick = { + onLikeClick(page + 1) + }, + ) { + Text("좋아요") + } + } + } + } +} + + +@Preview(showBackground = true) +@Composable +fun RecipeCardPreview() { + BanchangoTheme { + RecipeCard( + page = 1, recipe = Recipe( + id = 1, + name = "간장계란볶음밥", + introduction = "아주 간단하면서 맛있는 계란간장볶음밥으로 한끼식사 만들어보세요. 아이들이 더 좋아할거예요.", + image = "https://recipe1.ezmember.co.kr/cache/recipe/2018/05/26/d0c6701bc673ac5c18183b47212a58571.jpg", + link = "https://www.10000recipe.com/recipe/6889616", + cookingTime = 10, + servings = 2, + difficulty = "Easy", + have = listOf(1, 2, 3, 4, 5), + need = listOf(6, 7, 8, 9, 10), + ) + ) + } +} diff --git a/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipeRecommendViewModel.kt b/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipeRecommendViewModel.kt index b9fb5c3..1e33384 100644 --- a/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipeRecommendViewModel.kt +++ b/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipeRecommendViewModel.kt @@ -1,6 +1,7 @@ package com.sundaegukbap.banchango.presentation.reciperecommend import androidx.lifecycle.ViewModel +import com.sundaegukbap.banchango.model.Recipe import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow diff --git a/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipeRepository.kt b/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipeRepository.kt deleted file mode 100644 index c8b2c6c..0000000 --- a/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipeRepository.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.sundaegukbap.banchango.presentation.reciperecommend - -interface RecipeRepository { - fun getRecipeRecommendation(): List -} diff --git a/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipesRecommendScreen.kt b/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipesRecommendScreen.kt new file mode 100644 index 0000000..9de4207 --- /dev/null +++ b/Android/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipesRecommendScreen.kt @@ -0,0 +1,47 @@ +package com.sundaegukbap.banchango.presentation.reciperecommend + +import androidx.compose.foundation.ExperimentalFoundationApi +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.pager.VerticalPager +import androidx.compose.foundation.pager.rememberPagerState +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import kotlinx.coroutines.launch + +@OptIn(ExperimentalFoundationApi::class) +@Composable +fun RecipesRecommendScreen( + modifier: Modifier = Modifier, + viewModel: RecipeRecommendViewModel = hiltViewModel(), +) { + val recipesUiState by viewModel.recipes.collectAsStateWithLifecycle() + + val pagerState = rememberPagerState( + pageCount = { + recipesUiState.size + } + ) + val coroutineScope = rememberCoroutineScope() + VerticalPager( + modifier = modifier, + state = pagerState, + contentPadding = PaddingValues(vertical = 200.dp, horizontal = 40.dp), + pageSpacing = 40.dp, + ) { page -> + RecipeCard( + page = page, + recipe = recipesUiState[page], + onLikeClick = { + coroutineScope.launch { pagerState.animateScrollToPage(it) } + }, + onHateClick = { + coroutineScope.launch { pagerState.animateScrollToPage(it) } + }, + ) + } +} diff --git a/Android/app/src/main/java/com/sundaegukbap/banchango/repository/RecipeRepository.kt b/Android/app/src/main/java/com/sundaegukbap/banchango/repository/RecipeRepository.kt new file mode 100644 index 0000000..c1769e4 --- /dev/null +++ b/Android/app/src/main/java/com/sundaegukbap/banchango/repository/RecipeRepository.kt @@ -0,0 +1,7 @@ +package com.sundaegukbap.banchango.repository + +import com.sundaegukbap.banchango.model.Recipe + +interface RecipeRepository { + fun getRecipeRecommendation(): List +}