Skip to content

Commit

Permalink
[MERGE] #221 -> develop
Browse files Browse the repository at this point in the history
[FEAT/#221] λ§ˆμ΄νŽ˜μ΄μ§€ λ·° / μ„œλ²„ν†΅μ‹  κ΅¬ν˜„
  • Loading branch information
leeeyubin authored Sep 8, 2024
2 parents b862c0e + 348b2a0 commit 8ddef8b
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 8ddef8b

Please sign in to comment.