Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into refactor/#220-anno…
Browse files Browse the repository at this point in the history
…uncement
  • Loading branch information
arinming committed Sep 8, 2024
2 parents 2e3023e + 8ddef8b commit 6babcdf
Show file tree
Hide file tree
Showing 80 changed files with 1,353 additions and 1,457 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 @@ -23,13 +23,11 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.terning.core.R
import com.terning.core.designsystem.theme.Grey400
import com.terning.core.designsystem.theme.Grey150
import com.terning.core.designsystem.theme.Grey200
import com.terning.core.designsystem.theme.Grey375
import com.terning.core.designsystem.theme.TerningMain
import com.terning.core.designsystem.theme.TerningPointTheme
import com.terning.core.designsystem.theme.TerningSub1
import com.terning.core.designsystem.theme.TerningSub3
import com.terning.core.designsystem.theme.TerningSub4
import com.terning.core.designsystem.theme.TerningSub5
import com.terning.core.designsystem.theme.TerningTheme
import com.terning.core.designsystem.theme.White
import com.terning.core.util.NoRippleTheme
Expand Down Expand Up @@ -58,19 +56,16 @@ fun FilteringButton(
) {
val interactionSource = remember { MutableInteractionSource() }
val isPressed by interactionSource.collectIsPressedAsState()
val backgroundColor = when {
!isSelected && !isPressed -> White
!isSelected && isPressed -> TerningSub5
isSelected && !isPressed -> TerningSub4
else -> TerningSub3
}
val backgroundColor = White
val textColor = when {
!isSelected -> Grey400
!isSelected -> Grey375
isPressed -> Grey375
else -> TerningMain
}
val borderColor = when {
!isSelected -> TerningMain
else -> TerningSub1
!isSelected && !isPressed -> Grey150
isPressed -> Grey200
else -> TerningMain
}

CompositionLocalProvider(LocalRippleTheme provides NoRippleTheme) {
Expand All @@ -87,7 +82,7 @@ fun FilteringButton(
color = borderColor
),
shape = RoundedCornerShape(cornerRadius),
onClick = { onButtonClick() }
onClick = onButtonClick
) {
Text(
text = stringResource(id = text),
Expand All @@ -104,14 +99,14 @@ fun FilteringButtonPreview() {
TerningPointTheme {
Column {
FilteringButton(
isSelected = true,
isSelected = false,
text = R.string.button_preview,
cornerRadius = 15.dp,
paddingVertical = 10.dp,
onButtonClick = {}
)
FilteringButton(
isSelected = false,
isSelected = true,
text = R.string.button_preview,
cornerRadius = 15.dp,
paddingVertical = 10.dp,
Expand Down
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()
}
}
7 changes: 7 additions & 0 deletions core/src/main/java/com/terning/core/extension/CalendarExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.terning.core.extension

import java.util.Calendar

val Calendar.currentYear: Int get() = get(Calendar.YEAR)

val Calendar.currentMonth: Int get() = get(Calendar.MONTH) + 1
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)
}
}
8 changes: 8 additions & 0 deletions core/src/main/java/com/terning/core/util/CalendarDefaults.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.terning.core.util

object CalendarDefaults {
const val START_YEAR = 2010
const val END_YEAR = 2030
const val START_MONTH = 1
const val END_MONTH = 12
}
Loading

0 comments on commit 6babcdf

Please sign in to comment.