From a383a4bf3d562bbc469cd640120df65d345c6452 Mon Sep 17 00:00:00 2001 From: Inwoo Date: Wed, 27 Nov 2024 19:08:26 +0900 Subject: [PATCH] Feat : apply DeleteDialog - #53 --- .../data/datasource/remote/PostDataSource.kt | 1 - feature/my/build.gradle.kts | 1 + .../src/main/java/com/kolown/my/MyScreen.kt | 4 +- .../main/java/com/kolown/my/MyViewModel.kt | 3 +- .../com/kolown/my/component/DeleteDialog.kt | 89 +++++++++++++++++++ .../com/kolown/my/component/GalleryItem.kt | 39 +++++++- 6 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 feature/my/src/main/java/com/kolown/my/component/DeleteDialog.kt diff --git a/core/data/src/main/java/com/kolown/data/datasource/remote/PostDataSource.kt b/core/data/src/main/java/com/kolown/data/datasource/remote/PostDataSource.kt index 5fe2fa8b..2afa47a6 100644 --- a/core/data/src/main/java/com/kolown/data/datasource/remote/PostDataSource.kt +++ b/core/data/src/main/java/com/kolown/data/datasource/remote/PostDataSource.kt @@ -156,7 +156,6 @@ class PostDataSourceImpl @Inject constructor( override suspend fun deletePost(postId: String): Result { return runCatching { - throw Exception("Test") val documentId = postId.substringAfter("-") postCollection.document(documentId).delete().await() } diff --git a/feature/my/build.gradle.kts b/feature/my/build.gradle.kts index 5dca1040..6b1aa374 100644 --- a/feature/my/build.gradle.kts +++ b/feature/my/build.gradle.kts @@ -66,4 +66,5 @@ dependencies { implementation(libs.androidx.foundation) implementation(projects.core.data) + implementation(projects.core.designsystem) } diff --git a/feature/my/src/main/java/com/kolown/my/MyScreen.kt b/feature/my/src/main/java/com/kolown/my/MyScreen.kt index 5bd00d84..3f86b5b2 100644 --- a/feature/my/src/main/java/com/kolown/my/MyScreen.kt +++ b/feature/my/src/main/java/com/kolown/my/MyScreen.kt @@ -11,6 +11,8 @@ import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridItemSpan import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.tooling.preview.Preview @@ -18,6 +20,7 @@ import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.paging.LoadState import androidx.paging.compose.collectAsLazyPagingItems +import com.kolown.my.component.DeleteDialog import com.kolown.my.component.GalleryItem import com.kolown.my.component.MyAppBar import com.kolown.my.component.PageItemFooter @@ -46,7 +49,6 @@ fun MyScreen( padding: PaddingValues = PaddingValues(), viewModel: MyViewModel = hiltViewModel(), ) { - val width = LocalConfiguration.current.screenWidthDp.dp / 2 val pagingItems = viewModel.galleryFlow.collectAsLazyPagingItems() val listState = rememberLazyStaggeredGridState() diff --git a/feature/my/src/main/java/com/kolown/my/MyViewModel.kt b/feature/my/src/main/java/com/kolown/my/MyViewModel.kt index de3a7550..f92ebe03 100644 --- a/feature/my/src/main/java/com/kolown/my/MyViewModel.kt +++ b/feature/my/src/main/java/com/kolown/my/MyViewModel.kt @@ -23,11 +23,10 @@ class MyViewModel @Inject constructor( val galleryFlow = postRepository.getUserPosts().cachedIn(viewModelScope) fun deletePost(postId: String) { - Log.e("GalleryItem", "postId: $postId") viewModelScope.launch { postRepository.deletePost(postId) .onEach { - Log.e("GalleryItem", "deletePost: $it") + } .catch { Log.e("GalleryItem", "deletePost error: $it") diff --git a/feature/my/src/main/java/com/kolown/my/component/DeleteDialog.kt b/feature/my/src/main/java/com/kolown/my/component/DeleteDialog.kt new file mode 100644 index 00000000..fe30afb2 --- /dev/null +++ b/feature/my/src/main/java/com/kolown/my/component/DeleteDialog.kt @@ -0,0 +1,89 @@ +package com.kolown.my.component + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.Dialog +import androidx.compose.ui.window.DialogProperties +import com.kolown.designsystem.Error +import com.kolown.designsystem.Primary + +@Composable +fun DeleteDialog( + modifier: Modifier = Modifier, + onClickCancel: () -> Unit = {}, + onClickConfirm: (String) -> Unit = {} +) { + val textValue = remember { mutableStateOf("") } + Dialog( + onDismissRequest = { onClickCancel() }, + properties = DialogProperties( + dismissOnBackPress = true, + dismissOnClickOutside = true, + ) + ) { + Card( + modifier = modifier.size( + width = 380.dp, + height = 100.dp + ), + shape = RoundedCornerShape(10.dp), + colors = CardDefaults.cardColors(containerColor = Color.White), + elevation = CardDefaults.cardElevation(defaultElevation = 4.dp) + ) { + Column( + modifier = Modifier + .fillMaxSize() + .padding(horizontal = 20.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center + ) { + Text(text = "이 게시물을 삭제하시겠어요?", style = MaterialTheme.typography.titleMedium) + Spacer(modifier = Modifier.height(20.dp)) + Row { + TextButton( + onClick = onClickCancel, + colors = ButtonDefaults.buttonColors(containerColor = Color.White) + ) { + Text(text = "취소", color = Error) + } + TextButton( + onClick = { + onClickConfirm(textValue.value) + onClickCancel() + }, + colors = ButtonDefaults.buttonColors(containerColor = Color.White) + ) { + Text(text = "삭제", color = Primary) + } + } + } + } + } +} + +@Preview +@Composable +private fun DeleteDialogPreview() { + DeleteDialog() +} \ No newline at end of file diff --git a/feature/my/src/main/java/com/kolown/my/component/GalleryItem.kt b/feature/my/src/main/java/com/kolown/my/component/GalleryItem.kt index 85e89461..07e8775b 100644 --- a/feature/my/src/main/java/com/kolown/my/component/GalleryItem.kt +++ b/feature/my/src/main/java/com/kolown/my/component/GalleryItem.kt @@ -2,21 +2,47 @@ package com.kolown.my.component import android.util.Log import androidx.compose.foundation.ExperimentalFoundationApi +import androidx.compose.foundation.clickable import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.gestures.detectTapGestures +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.material3.TextField +import androidx.compose.material3.TextFieldDefaults import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +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.input.pointer.pointerInput import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.Dialog +import androidx.compose.ui.window.DialogProperties import coil3.compose.AsyncImage import com.kolown.data.mock.MockDataProvider +import com.kolown.designsystem.Error +import com.kolown.designsystem.Primary import com.kolown.model.PostContentModel import kotlin.random.Random @@ -29,6 +55,7 @@ fun GalleryItem( ) { //비율은 그냥 테스트 val height = if (Random.nextBoolean()) (width.value * 1.4).dp else width + 20.dp + val isDialogVisible = remember { mutableStateOf(false) } AsyncImage( modifier = Modifier @@ -40,7 +67,7 @@ fun GalleryItem( // todo navigateToDetail }, onLongClick = { - onLongClickImage() + isDialogVisible.value = true Log.d("GalleryItem", "GalleryItem: LongClick") } ), @@ -49,6 +76,16 @@ fun GalleryItem( contentScale = ContentScale.Crop ) + if(isDialogVisible.value) { + DeleteDialog( + onClickCancel = { isDialogVisible.value = false }, + onClickConfirm = { + onLongClickImage() + isDialogVisible.value = false + } + ) + } + } @Preview