-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c067790
commit 597ee88
Showing
7 changed files
with
172 additions
and
150 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...go/presentation/reciperecommend/Recipe.kt → ...om/sundaegukbap/banchango/model/Recipe.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...d/app/src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipeCard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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), | ||
) | ||
) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipeRecommendViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
...src/main/java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipeRepository.kt
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
...in/java/com/sundaegukbap/banchango/presentation/reciperecommend/RecipesRecommendScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) } | ||
}, | ||
) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
Android/app/src/main/java/com/sundaegukbap/banchango/repository/RecipeRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.sundaegukbap.banchango.repository | ||
|
||
import com.sundaegukbap.banchango.model.Recipe | ||
|
||
interface RecipeRepository { | ||
fun getRecipeRecommendation(): List<Recipe> | ||
} |