Skip to content

Commit

Permalink
Feat : apply DeleteDialog
Browse files Browse the repository at this point in the history
- #53
  • Loading branch information
inwoo13 committed Nov 28, 2024
1 parent 2922c0a commit a383a4b
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ class PostDataSourceImpl @Inject constructor(

override suspend fun deletePost(postId: String): Result<Unit> {
return runCatching {
throw Exception("Test")
val documentId = postId.substringAfter("-")
postCollection.document(documentId).delete().await()
}
Expand Down
1 change: 1 addition & 0 deletions feature/my/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ dependencies {
implementation(libs.androidx.foundation)

implementation(projects.core.data)
implementation(projects.core.designsystem)
}
4 changes: 3 additions & 1 deletion feature/my/src/main/java/com/kolown/my/MyScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ 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
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
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions feature/my/src/main/java/com/kolown/my/MyViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
89 changes: 89 additions & 0 deletions feature/my/src/main/java/com/kolown/my/component/DeleteDialog.kt
Original file line number Diff line number Diff line change
@@ -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()
}
39 changes: 38 additions & 1 deletion feature/my/src/main/java/com/kolown/my/component/GalleryItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -40,7 +67,7 @@ fun GalleryItem(
// todo navigateToDetail
},
onLongClick = {
onLongClickImage()
isDialogVisible.value = true
Log.d("GalleryItem", "GalleryItem: LongClick")
}
),
Expand All @@ -49,6 +76,16 @@ fun GalleryItem(
contentScale = ContentScale.Crop
)

if(isDialogVisible.value) {
DeleteDialog(
onClickCancel = { isDialogVisible.value = false },
onClickConfirm = {
onLongClickImage()
isDialogVisible.value = false
}
)
}

}

@Preview
Expand Down

0 comments on commit a383a4b

Please sign in to comment.