Skip to content

Commit

Permalink
Merge pull request #220 from hellokitty-coding-club/feat/suggestion-d…
Browse files Browse the repository at this point in the history
…etail

[FEAT] 미션 제안 상세 화면 기능 구현 마무리 (#219)
  • Loading branch information
915dbfl authored Mar 12, 2024
2 parents 8d16ba5 + 3d74830 commit 16001c7
Show file tree
Hide file tree
Showing 20 changed files with 598 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.lgtm.android.common_ui.R
import com.lgtm.android.common_ui.theme.LGTMTheme
import com.lgtm.android.common_ui.util.throttleClickable

@Composable
fun LikeButton(
modifier: Modifier = Modifier,
likeNum: String,
isLiked: Boolean,
modifier: Modifier = Modifier
onClick: () -> Unit
) {
Row(
verticalAlignment = Alignment.CenterVertically,
Expand All @@ -41,6 +43,10 @@ fun LikeButton(
horizontal = 6.dp,
vertical = 9.dp
)
.throttleClickable(
enabled = true,
onClick = onClick
)
) {

Text(
Expand All @@ -53,7 +59,7 @@ fun LikeButton(

Image(
modifier = Modifier.padding(start = 2.dp),
imageVector = ImageVector.vectorResource(id = R.drawable.ic_like_selected),
imageVector = if (isLiked) ImageVector.vectorResource(id = R.drawable.ic_like_selected) else ImageVector.vectorResource(id = R.drawable.ic_like_unselected),
contentDescription = null
)
}
Expand All @@ -65,7 +71,8 @@ fun LikeButtonPreview() {
LGTMTheme {
LikeButton(
likeNum = "22",
isLiked = true
isLiked = true,
onClick = {}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,56 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.lgtm.android.common_ui.R
import com.lgtm.android.common_ui.theme.LGTMTheme
import com.lgtm.android.common_ui.util.throttleClickable

@Composable
fun MenuButton(
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
dropDownContent: @Composable (expanded: Boolean, onDismissRequest: () -> Unit) -> Unit
) {
var dropDownExpanded by remember { mutableStateOf(false) }

Box(
modifier = modifier
.wrapContentSize()
.border(
width = 1.dp,
color = LGTMTheme.colors.gray_3,
color = if (!dropDownExpanded) LGTMTheme.colors.gray_3 else LGTMTheme.colors.black,
shape = RoundedCornerShape(10.dp)
)
.background(
color = LGTMTheme.colors.white,
color = if (!dropDownExpanded) LGTMTheme.colors.white else LGTMTheme.colors.black,
shape = RoundedCornerShape(10.dp)
)
.padding(3.dp)
.throttleClickable(enabled = true) {
dropDownExpanded = !dropDownExpanded
}
) {
Image(
painter = painterResource(id = R.drawable.ic_menu_black),
painter = if (!dropDownExpanded) painterResource(id = R.drawable.ic_menu_black) else painterResource(id = R.drawable.ic_menu_green),
contentDescription = null
)
dropDownContent(dropDownExpanded) {
dropDownExpanded = false
}
}
}

@Preview
@Composable
fun MenuButtonPreview() {
LGTMTheme {
MenuButton {_, _ -> }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ModalBottomSheetLayout
import androidx.compose.material.ModalBottomSheetState
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
Expand All @@ -18,9 +23,51 @@ import com.lgtm.android.common_ui.R
import com.lgtm.android.common_ui.components.buttons.ConfirmButtonBackgroundColor
import com.lgtm.android.common_ui.components.buttons.DialogConfirmationButton
import com.lgtm.android.common_ui.theme.LGTMTheme
import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun LgtmConfirmationDialog(
bottomSheetState: ModalBottomSheetState,
dialogTitle: String,
dialogDescription: String? = null,
onClickConfirm: () -> Unit,
confirmBtnBackground: ConfirmButtonBackgroundColor,
content: @Composable () -> Unit
) {
val coroutineScope = rememberCoroutineScope()

ModalBottomSheetLayout(
sheetState = bottomSheetState,
sheetShape = RoundedCornerShape(
topStart = 20.dp,
topEnd = 20.dp
),
scrimColor = LGTMTheme.colors.transparent_black,
sheetContent = {
LgtmConfirmationDialogContent(
dialogTitle = dialogTitle,
dialogDescription = dialogDescription,
onClickCancel = {
coroutineScope.launch {
bottomSheetState.hide()
}
},
onClickConfirm = {
coroutineScope.launch {
bottomSheetState.hide()
onClickConfirm()
}
},
confirmBtnBackground = confirmBtnBackground
)
},
content = content
)
}

@Composable
fun LgtmConfirmationDialogContent(
dialogTitle: String,
dialogDescription: String? = null,
onClickCancel: () -> Unit,
Expand Down Expand Up @@ -91,7 +138,7 @@ fun DialogButtons(
@Preview
fun LGTMBottomSheetDialogContentPreview() {
LGTMTheme {
LgtmConfirmationDialog(
LgtmConfirmationDialogContent(
dialogTitle = "작성을 중단할까요?",
dialogDescription = "작성한 내용은 저장되지 않아요.",
onClickCancel = {},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.lgtm.android.common_ui.components.dropdown

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.lgtm.android.common_ui.theme.LGTMTheme

@Composable
fun SuggestionDropDownOneMenu(
isExpanded: Boolean,
text: String,
onDismissRequest: () -> Unit,
onMenuClick: () -> Unit
) {
MaterialTheme(shapes = MaterialTheme.shapes.copy(medium = RoundedCornerShape(10.dp))) {
DropdownMenu(
modifier = Modifier
.background(
color = LGTMTheme.colors.white
)
.border(
width = 1.dp,
color = LGTMTheme.colors.gray_2,
shape = RoundedCornerShape(10.dp)
),
expanded = isExpanded,
onDismissRequest = onDismissRequest
) {
DropdownMenuItem(
onClick = {
onDismissRequest()
onMenuClick()
}
) {
Text(
text = text,
style = LGTMTheme.typography.body2,
color = LGTMTheme.colors.black
)
}
}
}
}
4 changes: 4 additions & 0 deletions common-ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@

<!-- 미션 제안 디테일 -->
<string name="want_this_mission">저도 이 미션 원해요!</string>
<string name="delete_suggestion">삭제하기</string>
<string name="report_suggestion">신고하기</string>
<string name="want_to_delete_suggestion">게시글을 삭제하시겠어요?</string>
<string name="cannot_cancel_the_deletion">삭제 후에는 되돌릴 수 없어요.</string>

<!-- 미션 제안 생성 -->
<string name="mission_suggestion_title">제목</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package com.lgtm.android.data.datasource

import com.lgtm.android.data.model.response.BaseDTO
import com.lgtm.android.data.model.response.CreateSuggestionResponseDTO
import com.lgtm.android.data.model.response.DeleteSuggestionDTO
import com.lgtm.android.data.model.response.MissionSuggestionDTO
import com.lgtm.android.data.model.response.SuggestionDTO
import com.lgtm.android.data.model.response.SuggestionLikeDTO
import com.lgtm.android.data.service.SuggestionService
import com.lgtm.domain.entity.request.CreateSuggestionRequestVO
import javax.inject.Inject
Expand All @@ -22,4 +24,16 @@ class SuggestionDataSource @Inject constructor(
suspend fun createSuggestion(createSuggestionRequest: CreateSuggestionRequestVO): BaseDTO<CreateSuggestionResponseDTO> {
return checkResponse(suggestionService.createSuggestion(createSuggestionRequest))
}

suspend fun likeSuggestion(suggestionId: Int): BaseDTO<SuggestionLikeDTO> {
return checkResponse(suggestionService.likeSuggestion(suggestionId))
}

suspend fun cancelLikeSuggestion(suggestionId: Int): BaseDTO<SuggestionLikeDTO> {
return checkResponse(suggestionService.cancelLikeSuggestion(suggestionId))
}

suspend fun deleteSuggestion(suggestionId: Int): BaseDTO<DeleteSuggestionDTO> {
return checkResponse(suggestionService.deleteSuggestion(suggestionId))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.lgtm.android.data.model.response

import com.lgtm.domain.entity.response.DeleteSuggestionVO

data class DeleteSuggestionDTO(
val suggestionId: Int?,
val success: Boolean?
) {
fun toVO() = DeleteSuggestionVO(
suggestionId = suggestionId ?: 0,
success = success ?: false
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.lgtm.android.data.model.response

import com.lgtm.domain.entity.response.SuggestionLikeVO

data class SuggestionLikeDTO(
val isLiked: Boolean?,
val likeNum: String?
) {
fun toVO() = SuggestionLikeVO(
isLiked = requireNotNull(isLiked),
likeNum = requireNotNull(likeNum)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.util.Log
import com.lgtm.android.data.datasource.SuggestionDataSource
import com.lgtm.domain.entity.request.CreateSuggestionRequestVO
import com.lgtm.domain.entity.response.CreateSuggestionResponseVO
import com.lgtm.domain.entity.response.DeleteSuggestionVO
import com.lgtm.domain.entity.response.SuggestionLikeVO
import com.lgtm.domain.mission_suggestion.MissionSuggestionVO
import com.lgtm.domain.mission_suggestion.SuggestionVO
import com.lgtm.domain.repository.SuggestionRepository
Expand Down Expand Up @@ -42,4 +44,34 @@ class SuggestionRepositoryImpl @Inject constructor(
Result.failure(e)
}
}

override suspend fun likeSuggestion(suggestionId: Int): Result<SuggestionLikeVO> {
return try {
val response = suggestionDataSource.likeSuggestion(suggestionId)
Result.success(response.data.toVO())
} catch (e: Exception) {
Log.e(TAG, "likeSuggestion: ${this.javaClass} ${e.message}")
Result.failure(e)
}
}

override suspend fun cancelLikeSuggestion(suggestionId: Int): Result<SuggestionLikeVO> {
return try {
val response = suggestionDataSource.cancelLikeSuggestion(suggestionId)
Result.success(response.data.toVO())
} catch (e: Exception) {
Log.e(TAG, "cancelLikeSuggestion: ${this.javaClass} ${e.message}")
Result.failure(e)
}
}

override suspend fun deleteSuggestion(suggestionId: Int): Result<DeleteSuggestionVO> {
return try {
val response = suggestionDataSource.deleteSuggestion(suggestionId)
Result.success(response.data.toVO())
} catch (e: Exception) {
Log.e(TAG, "deleteSuggestion: ${this.javaClass} ${e.message}")
Result.failure(e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package com.lgtm.android.data.service

import com.lgtm.android.data.model.response.BaseDTO
import com.lgtm.android.data.model.response.CreateSuggestionResponseDTO
import com.lgtm.android.data.model.response.DeleteSuggestionDTO
import com.lgtm.android.data.model.response.MissionSuggestionDTO
import com.lgtm.android.data.model.response.SuggestionDTO
import com.lgtm.android.data.model.response.SuggestionLikeDTO
import com.lgtm.domain.entity.request.CreateSuggestionRequestVO
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
Expand All @@ -24,4 +27,19 @@ interface SuggestionService {
suspend fun createSuggestion(
@Body createSuggestionRequestVO: CreateSuggestionRequestVO
): Response<BaseDTO<CreateSuggestionResponseDTO>>

@POST("v1/suggestion/{suggestionId}/like")
suspend fun likeSuggestion(
@Path("suggestionId") suggestionId: Int
): Response<BaseDTO<SuggestionLikeDTO>>

@DELETE("v1/suggestion/{suggestionId}/like")
suspend fun cancelLikeSuggestion(
@Path("suggestionId") suggestionId: Int
): Response<BaseDTO<SuggestionLikeDTO>>

@DELETE("v1/suggestion/{suggestionId}")
suspend fun deleteSuggestion(
@Path("suggestionId") suggestionId: Int
): Response<BaseDTO<DeleteSuggestionDTO>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.lgtm.domain.entity.response

data class DeleteSuggestionVO(
val suggestionId: Int,
val success: Boolean
)
Loading

0 comments on commit 16001c7

Please sign in to comment.