Skip to content

Commit

Permalink
[MERGE/#223] develop -> #223
Browse files Browse the repository at this point in the history
  • Loading branch information
boiledEgg-s committed Sep 8, 2024
2 parents acd21db + 8ddef8b commit 7768a33
Show file tree
Hide file tree
Showing 47 changed files with 706 additions and 1,251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.terning.core.R
import com.terning.core.designsystem.theme.TerningMain
import com.terning.core.designsystem.theme.TerningTheme
import com.terning.core.extension.noRippleClickable
import com.terning.core.type.ProfileImage
import kotlinx.coroutines.launch

/**
Expand All @@ -38,15 +39,15 @@ import kotlinx.coroutines.launch
* @param modifier ๋ฐ”ํ…€์‹œํŠธ์— ์ ์šฉํ•  Modifier์ž…๋‹ˆ๋‹ค.
* @param onDismiss ๋ฐ”ํ…€์‹œํŠธ๊ฐ€ ๋‹ซํž ๋•Œ ํ˜ธ์ถœ๋˜๋Š” ์ฝœ๋ฐฑ ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
* @param onSaveClick ์ €์žฅํ•˜๊ธฐ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ, ํ˜ธ์ถœ๋˜๋Š” ์ฝœ๋ฐฑ ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
* @param initialSelectedOption ์ดˆ๊ธฐ์— ์„ ํƒ๋œ ์ด๋ฏธ์ง€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์ธ๋ฑ์Šค ๊ฐ’์ž…๋‹ˆ๋‹ค.
* @param initialSelectedOption ์ดˆ๊ธฐ์— ์„ ํƒ๋œ ์ด๋ฏธ์ง€์˜ ์ด๋ฆ„์„ ๋‚˜ํƒ€๋‚ด๋Š” string ๊ฐ’์ž…๋‹ˆ๋‹ค.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ProfileBottomSheet(
modifier: Modifier = Modifier,
onDismiss: () -> Unit,
onSaveClick: (Int) -> Unit,
initialSelectedOption: Int
onSaveClick: (ProfileImage) -> Unit,
initialSelectedOption: String
) {
val scope = rememberCoroutineScope()
val sheetState = rememberModalBottomSheetState()
Expand All @@ -64,11 +65,11 @@ fun ProfileBottomSheet(
),
)
RadioButtonGroup(
onOptionSelected = { index ->
onOptionSelected = { selectedProfile ->
scope.launch { sheetState.hide() }
.invokeOnCompletion {
if (!sheetState.isVisible) {
onSaveClick(index)
onSaveClick(selectedProfile)
}
}
},
Expand All @@ -82,38 +83,34 @@ fun ProfileBottomSheet(
)
}


/**
* 6๊ฐœ์˜ ํ”„๋กœํ•„ ์ด๋ฏธ์ง€ ์ค‘, ํ•˜๋‚˜์˜ ์ด๋ฏธ์ง€๋งŒ ์„ ํƒํ•  ์ˆ˜ ์žˆ๋Š” ๋ผ๋””์˜ค ๋ฒ„ํŠผ์ž…๋‹ˆ๋‹ค.
*
* @param onOptionSelected ์„ ํƒ๋œ ์ด๋ฏธ์ง€์˜ ์ธ๋ฑ์Šค ๊ฐ’์„ ๋‚˜ํƒ€๋‚ด๋Š” ์ฝœ๋ฐฑ ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
* @param initialSelectedOption ์ดˆ๊ธฐ์— ์„ ํƒ๋œ ์ด๋ฏธ์ง€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์ธ๋ฑ์Šค ๊ฐ’์ž…๋‹ˆ๋‹ค.
* @param onOptionSelected ์„ ํƒ๋œ ์ด๋ฏธ์ง€์˜ ์ด๋ฆ„์„ ๋‚˜ํƒ€๋‚ด๋Š” ์ฝœ๋ฐฑ ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
* @param initialSelectedOption ์ดˆ๊ธฐ์— ์„ ํƒ๋œ ์ด๋ฏธ์ง€์˜ ์ด๋ฆ„์„ ๋‚˜ํƒ€๋‚ด๋Š” string ๊ฐ’์ž…๋‹ˆ๋‹ค.
* @param modifier ๋ผ๋””์˜ค ๋ฒ„ํŠผ์— ์ ์šฉํ•  Modifier์ž…๋‹ˆ๋‹ค.
*/
@Composable
fun RadioButtonGroup(
onOptionSelected: (Int) -> Unit,
initialSelectedOption: Int,
onOptionSelected: (ProfileImage) -> Unit,
initialSelectedOption: String,
modifier: Modifier = Modifier,
) {
val options = listOf(
R.drawable.ic_terning_profile_00,
R.drawable.ic_terning_profile_01,
R.drawable.ic_terning_profile_02,
R.drawable.ic_terning_profile_03,
R.drawable.ic_terning_profile_04,
R.drawable.ic_terning_profile_05
)
val options = ProfileImage.entries

var selectedOption by rememberSaveable { mutableIntStateOf(options[initialSelectedOption]) }
var selectedOptionIndex by rememberSaveable {
mutableIntStateOf(ProfileImage.toIndex(ProfileImage.fromString(initialSelectedOption)))
}

LazyVerticalGrid(
columns = GridCells.Fixed(3),
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalArrangement = Arrangement.spacedBy(20.dp),
modifier = modifier.padding(horizontal = 34.dp)
) {
itemsIndexed(options) { index, option ->
val imageModifier = if (selectedOption == options[index]) {
itemsIndexed(options.take(6)) { index, option ->
val imageModifier = if (selectedOptionIndex == index) {
Modifier
.border(
color = TerningMain,
Expand All @@ -126,19 +123,17 @@ fun RadioButtonGroup(
}

Image(
painter = painterResource(
id = option
),
painter = painterResource(id = option.drawableResId),
contentDescription = "profile image",
modifier = imageModifier
.noRippleClickable {
onOptionSelected(index)
selectedOption = option
onOptionSelected(option)
selectedOptionIndex = index
}
.clip(shape = CircleShape)
.size(76.dp)
.aspectRatio(1f)
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,20 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.terning.core.R
import com.terning.core.type.ProfileImage

@Composable
fun ProfileWithPlusButton(
index: Int,
profileImage: String,
modifier: Modifier = Modifier,
) {
val grade = when (index) {
0 -> R.drawable.ic_terning_profile_00
1 -> R.drawable.ic_terning_profile_01
2 -> R.drawable.ic_terning_profile_02
3 -> R.drawable.ic_terning_profile_03
4 -> R.drawable.ic_terning_profile_04
else -> R.drawable.ic_terning_profile_05
}
val userProfile = ProfileImage.fromString(profileImage)

Box(
modifier = modifier.wrapContentWidth()
) {
Image(
painterResource(id = grade),
painterResource(id = userProfile.drawableResId),
contentDescription = "profile image",
modifier = modifier
.clip(shape = CircleShape)
Expand All @@ -51,5 +45,5 @@ fun ProfileWithPlusButton(
@Preview(showBackground = true)
@Composable
fun ProfileWithPlusButtonPreview() {
ProfileWithPlusButton(index = 1)
ProfileWithPlusButton(profileImage = "basic")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.terning.core.designsystem.component.snackbar

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import com.terning.core.designsystem.theme.Grey500

@Composable
fun TerningBasicSnackBar(content: @Composable () -> Unit) {
Box(
modifier = Modifier
.clip(CircleShape)
.background(Grey500)
.padding(vertical = 7.dp, horizontal = 20.dp)
) {
content()
}
}
33 changes: 33 additions & 0 deletions core/src/main/java/com/terning/core/type/ProfileImage.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.terning.core.type

import androidx.annotation.DrawableRes
import com.terning.core.R

enum class ProfileImage(
@DrawableRes val drawableResId: Int,
val stringValue: String
) {

BASIC(drawableResId = R.drawable.ic_terning_profile_00, stringValue = "basic"),
LUCKY(drawableResId = R.drawable.ic_terning_profile_01, stringValue = "lucky"),
SMART(drawableResId = R.drawable.ic_terning_profile_02, stringValue = "smart"),
GLASS(drawableResId = R.drawable.ic_terning_profile_03, stringValue = "glass"),
CALENDAR(drawableResId = R.drawable.ic_terning_profile_04, stringValue = "calendar"),
PASSION(drawableResId = R.drawable.ic_terning_profile_05, stringValue = "passion"),
DEFAULT(drawableResId = R.drawable.ic_terning_profile_default, stringValue = "default");

companion object {
fun fromString(value: String): ProfileImage = when (value) {
"basic" -> BASIC
"lucky" -> LUCKY
"smart" -> SMART
"glass" -> GLASS
"calendar" -> CALENDAR
"passion" -> PASSION
else -> BASIC
}

fun toIndex(profileImage: ProfileImage): Int =
entries.indexOf(profileImage)
}
}
Loading

0 comments on commit 7768a33

Please sign in to comment.