Skip to content

Commit

Permalink
Merge pull request #204 from Project-Unifest/feat/star-image-dialog
Browse files Browse the repository at this point in the history
[feat] [#205] 연예인 이미지 롱클릭 확대 기능 구현
  • Loading branch information
easyhooon authored May 27, 2024
2 parents e06caff + ab913f5 commit b69c4fa
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.unifest.android.core.ui.component

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
Expand All @@ -15,10 +16,12 @@ import com.unifest.android.core.designsystem.component.NetworkImage
import com.unifest.android.core.designsystem.theme.Content9
import com.unifest.android.core.designsystem.theme.UnifestTheme

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun StarImage(
imgUrl: String?,
onClick: () -> Unit,
onLongClick: () -> Unit,
isClicked: Boolean,
label: String,
modifier: Modifier = Modifier,
Expand All @@ -28,7 +31,10 @@ fun StarImage(
) {
Box(
modifier = modifier
.clickable(onClick = onClick),
.combinedClickable(
onLongClick = onLongClick,
onClick = onClick,
),
contentAlignment = Alignment.Center,
) {
NetworkImage(
Expand Down Expand Up @@ -60,6 +66,7 @@ fun StarImagePreview() {
StarImage(
imgUrl = "",
onClick = {},
onLongClick = {},
isClicked = false,
label = "",
)
Expand All @@ -73,6 +80,7 @@ fun StarImageClickedPreview() {
StarImage(
imgUrl = "",
onClick = {},
onLongClick = {},
isClicked = true,
label = "키스오브라이프",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ internal fun HomeScreen(
onFestivalUiAction = onFestivalUiAction,
)
}
if (homeUiState.isStarImageDialogVisible && homeUiState.selectedStar != null) {
StarImageDialog(
onDismissRequest = { onHomeUiAction(HomeUiAction.OnStarImageDialogDismiss) },
star = homeUiState.selectedStar,
)
}
}
}

Expand Down Expand Up @@ -322,6 +328,9 @@ fun FestivalScheduleItem(
onClick = {
onHomeUiAction(HomeUiAction.OnToggleStarImageClick(scheduleIndex, starIndex, !isStarImageClicked[starIndex]))
},
onLongClick = {
onHomeUiAction(HomeUiAction.OnStarImageLongClick(scheduleIndex, starIndex))
},
isClicked = isStarImageClicked[starIndex],
label = starInfo.name,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.unifest.android.feature.home

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.BasicAlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.min
import androidx.compose.ui.window.DialogProperties
import com.unifest.android.core.designsystem.component.NetworkImage
import com.unifest.android.core.designsystem.theme.Title2
import com.unifest.android.core.model.StarInfoModel

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun StarImageDialog(
onDismissRequest: () -> Unit,
star: StarInfoModel,
modifier: Modifier = Modifier,
) {
val configuration = LocalConfiguration.current
val dialogSize = remember(configuration) {
val screenWidth = configuration.screenWidthDp.dp
val screenHeight = configuration.screenHeightDp.dp
min(screenWidth, screenHeight) - 128.dp
}

BasicAlertDialog(
onDismissRequest = onDismissRequest,
modifier = modifier
.width(dialogSize)
.height(dialogSize + 96.dp)
.clip(RoundedCornerShape(16.dp))
.background(Color.Transparent),
properties = DialogProperties(
usePlatformDefaultWidth = false,
),
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
NetworkImage(
imgUrl = star.imgUrl,
contentDescription = null,
modifier = Modifier
.size(dialogSize)
.clip(CircleShape),
)
Spacer(modifier = Modifier.height(16.dp))
Text(
text = star.name,
color = Color.White,
textAlign = TextAlign.Center,
style = Title2,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ sealed interface HomeUiAction {
data class OnDateSelected(val date: LocalDate) : HomeUiAction
data class OnAddAsLikedFestivalClick(val festivalTodayModel: FestivalTodayModel) : HomeUiAction
data class OnToggleStarImageClick(val scheduleIndex: Int, val starIndex: Int, val flag: Boolean) : HomeUiAction
data class OnStarImageLongClick(val scheduleIndex: Int, val starIndex: Int) : HomeUiAction
data object OnStarImageDialogDismiss : HomeUiAction
data object OnClickWeekMode : HomeUiAction
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.unifest.android.feature.home.viewmodel
import androidx.compose.ui.text.input.TextFieldValue
import com.unifest.android.core.model.FestivalModel
import com.unifest.android.core.model.FestivalTodayModel
import com.unifest.android.core.model.StarInfoModel
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import java.time.LocalDate
Expand All @@ -21,4 +22,6 @@ data class HomeUiState(
val isStarImageClicked: ImmutableList<ImmutableList<Boolean>> = persistentListOf(persistentListOf()),
val isWeekMode: Boolean = false,
val isDataReady: Boolean = true,
val isStarImageDialogVisible: Boolean = false,
val selectedStar: StarInfoModel? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class HomeViewModel @Inject constructor(
}
is HomeUiAction.OnAddAsLikedFestivalClick -> addLikeFestival(action.festivalTodayModel)
is HomeUiAction.OnToggleStarImageClick -> toggleStarImageClicked(action.scheduleIndex, action.starIndex, action.flag)
is HomeUiAction.OnStarImageLongClick -> showStarImageDialog(action.scheduleIndex, action.starIndex)
is HomeUiAction.OnStarImageDialogDismiss -> hideStarImageDialog()
is HomeUiAction.OnClickWeekMode -> setWeekMode(!_uiState.value.isWeekMode)
}
}
Expand Down Expand Up @@ -157,6 +159,24 @@ class HomeViewModel @Inject constructor(
}
}

private fun showStarImageDialog(scheduleIndex: Int, starIndex: Int) {
_uiState.update {
it.copy(
isStarImageDialogVisible = true,
selectedStar = it.todayFestivals[scheduleIndex].starInfo[starIndex],
)
}
}

private fun hideStarImageDialog() {
_uiState.update {
it.copy(
isStarImageDialogVisible = false,
selectedStar = null,
)
}
}

private fun setWeekMode(flag: Boolean) {
_uiState.update {
it.copy(isWeekMode = flag)
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
minSdk = "26"
targetSdk = "34"
compileSdk = "34"
versionCode = "16"
versionName = "1.0.6"
versionCode = "17"
versionName = "1.0.7"
packageName = "com.unifest.android"

android-gradle-plugin = "8.2.2"
Expand Down

0 comments on commit b69c4fa

Please sign in to comment.