Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private fun CertificationStatus(acquired: Boolean) {
} else {
stringResource(R.string.my_certification_pre)
},
style = CertiTheme.typography.caption.regular_10,
style = CertiTheme.typography.caption.semibold_10,
color = CertiTheme.colors.white
)
}
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/org/sopt/certi/core/util/StringExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.sopt.certi.core.util

import org.sopt.certi.domain.model.DateData
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import java.util.Locale
Expand Down Expand Up @@ -62,9 +61,8 @@ fun String.toLocalizedDate(): String {

fun String.splitDateTime(): Pair<String, String> {
return try {
val parsed = LocalDateTime.parse(this)
val date = parsed.format(DateFormatters.dotDate)
val time = parsed.toLocalTime().toString()
val date = this.split("T")[0]
val time = this.split("T")[1]
date to time
} catch (e: Exception) {
this to ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ fun PreCertDayItemResponseDto.toDomain(): CertificationData {
city = city,
state = state,
testDate = testDate,
testTime = testDate.splitDateTime().second,
isAcquired = isAcquired
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ fun CommentListPageableRequest.toDto(): CommentListPageableRequestDto {
return CommentListPageableRequestDto(
page = page,
size = size,
sort = sort
commentSortType = commentSortType.name
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class CertiPagingSource<T : Any>(
fun <T : Any> createPager(
limit: Int = 10,
initialLoadSize: Int = 20,
q: List<String>? = null,
q: String? = null,
startPage: Int? = null,
pagingSourceFactory: suspend (page: Int, limit: Int, sort: List<String>?) -> List<T>
pagingSourceFactory: suspend (page: Int, limit: Int, sort: String?) -> List<T>
): Pager<Int, T> {
return Pager(
config = PagingConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CommentRemoteDataSourceImpl @Inject constructor(
private val commentService: CommentService
) : CommentRemoteDataSource {
override suspend fun getCommentList(certificationId: Long, pageable: CommentListPageableRequestDto): ApiResponse<GetCommentListResponseDto> =
commentService.getCommentList(certificationId, page = pageable.page, size = pageable.size, sort = if (pageable.sort.isNotEmpty()) pageable.sort.toString() else null)
commentService.getCommentList(certificationId, page = pageable.page, size = pageable.size, commentSortType = pageable.commentSortType.ifEmpty { null })

override suspend fun registerComment(registerCommentRequest: RegisterCommentRequestDto): NullableApiResponse<Unit> =
commentService.registerComment(registerCommentRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ data class CommentListPageableRequestDto(
val page: Int,
@SerialName("size")
val size: Int,
@SerialName("sort")
val sort: List<String>
@SerialName("commentSortType")
val commentSortType: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface CommentService {
@Query("certificationId") certificationId: Long,
@Query("page") page: Int,
@Query("size") size: Int,
@Query("sort") sort: String? = null
@Query("commentSortType") commentSortType: String? = null
): ApiResponse<GetCommentListResponseDto>

@POST("api/v1/comments")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.sopt.certi.data.remote.util.HttpResponseHandler.handleNullableApiResp
import org.sopt.certi.domain.model.comment.CommentItemData
import org.sopt.certi.domain.model.comment.RegisterCommentRequest
import org.sopt.certi.domain.repository.CommentRepository
import org.sopt.certi.presentation.type.CommentSortType
import javax.inject.Inject

class CommentRepositoryImpl @Inject constructor(
Expand All @@ -20,18 +21,18 @@ class CommentRepositoryImpl @Inject constructor(

private var _totalCommentCount = MutableStateFlow(0)

override suspend fun getCommentList(certificationId: Long, sort: List<String>): Flow<PagingData<CommentItemData>> {
override suspend fun getCommentList(certificationId: Long, commentSortType: CommentSortType): Flow<PagingData<CommentItemData>> {
return createPager(
limit = 12,
initialLoadSize = 12,
q = sort
q = commentSortType.name
) { page, limit, sortParam ->
val response = commentRemoteDataSource.getCommentList(
certificationId,
CommentListPageableRequestDto(
page = page,
size = limit,
sort = sortParam ?: sort
commentSortType = sortParam ?: commentSortType.name
)
).data.toDomain()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.sopt.certi.domain.model.comment

import org.sopt.certi.presentation.type.CommentSortType

data class CommentListPageableRequest(
val page: Int,
val size: Int,
val sort: List<String>
val commentSortType: CommentSortType
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import androidx.paging.PagingData
import kotlinx.coroutines.flow.Flow
import org.sopt.certi.domain.model.comment.CommentItemData
import org.sopt.certi.domain.model.comment.RegisterCommentRequest
import org.sopt.certi.presentation.type.CommentSortType

interface CommentRepository {
suspend fun getCommentList(certificationId: Long, sort: List<String>): Flow<PagingData<CommentItemData>>
suspend fun getCommentList(certificationId: Long, commentSortType: CommentSortType): Flow<PagingData<CommentItemData>>
suspend fun registerComment(registerCommentRequest: RegisterCommentRequest): Result<Unit>
suspend fun likeComment(commentId: Long): Result<Unit>
suspend fun deleteComment(commentId: Long): Result<Unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import androidx.paging.PagingData
import kotlinx.coroutines.flow.Flow
import org.sopt.certi.domain.model.comment.CommentItemData
import org.sopt.certi.domain.repository.CommentRepository
import org.sopt.certi.presentation.type.CommentSortType
import javax.inject.Inject

class GetCommentListUseCase @Inject constructor(
private val commentRepository: CommentRepository
) {
suspend fun getCommentList(certificationId: Long, sort: List<String>): Flow<PagingData<CommentItemData>> {
return commentRepository.getCommentList(certificationId, sort)
suspend fun getCommentList(certificationId: Long, commentSortType: CommentSortType): Flow<PagingData<CommentItemData>> {
return commentRepository.getCommentList(certificationId, commentSortType)
}

fun getTotalCommentCount(): Flow<Int> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.sopt.certi.presentation.type

enum class CommentSortType {
Recent, Famous
LATEST, POPULAR
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,7 @@ class CertDetailViewModel @Inject constructor(
}

fun getCommentList(certId: Long, commentSortType: CommentSortType) = viewModelScope.launch {
val sortValue = if (commentSortType == CommentSortType.Famous) {
listOf("likeCount", "desc")
} else {
listOf()
}

getCommentListUseCase.getCommentList(certId, sortValue)
getCommentListUseCase.getCommentList(certId, commentSortType)
.distinctUntilChanged()
.cachedIn(viewModelScope)
.collect { pagingData ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ fun CommentArrayButton(
modifier: Modifier = Modifier
) {
val label = when (commentSortType) {
CommentSortType.Famous -> stringResource(R.string.comment_label_famous)
CommentSortType.Recent -> stringResource(R.string.comment_label_recent)
CommentSortType.POPULAR -> stringResource(R.string.comment_label_famous)
CommentSortType.LATEST -> stringResource(R.string.comment_label_recent)
}

Box(
Expand Down Expand Up @@ -53,7 +53,7 @@ fun CommentArrayButton(
@Composable
private fun PreviewCommentArrayButton() {
CommentArrayButton(
commentSortType = CommentSortType.Recent,
commentSortType = CommentSortType.LATEST,
isSelected = true,
selectOnClick = {}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ fun CommentItem(
when (commentData.state) {
CertStateType.ANTICIPATED -> {
acquireStateText = stringResource(R.string.comment_state_pre)
acquireStateTextColor = CertiTheme.colors.purpleBlue
acquireStateTextColor = CertiTheme.colors.gray300
}
CertStateType.ACQUISITION -> {
acquireStateText = stringResource(R.string.comment_state_acquired)
acquireStateTextColor = CertiTheme.colors.gray300
acquireStateTextColor = CertiTheme.colors.purpleBlue
}
CertStateType.NORMAL -> {
acquireStateText = "ERROR"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ fun ReportCommentDialog(
modifier = Modifier
.widthForScreenPercentage(24.dp)
.heightForScreenPercentage(24.dp)
.noRippleClickable {
onDismissClick()
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Brush
Expand All @@ -42,6 +45,7 @@ import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
Expand Down Expand Up @@ -77,7 +81,7 @@ fun CertDetailCommentRoute(
certStateType: CertStateType,
viewModel: CertDetailViewModel = hiltViewModel()
) {
var commentSortType by remember { mutableStateOf(CommentSortType.Famous) }
var commentSortType by remember { mutableStateOf(CommentSortType.POPULAR) }
val commentList = viewModel.commentPagingData.collectAsLazyPagingItems()
val totalCommentCount by viewModel.totalCommentCount.collectAsStateWithLifecycle()
val myUserId by viewModel.myUserId.collectAsStateWithLifecycle()
Expand Down Expand Up @@ -171,7 +175,7 @@ fun CertDetailCommentScreen(
reportOnClick: (commentId: Long) -> Unit = {},
deleteOnClick: (commentId: Long) -> Unit = {}
) {
var commentSortType by remember { mutableStateOf(CommentSortType.Famous) }
var commentSortType by remember { mutableStateOf(CommentSortType.POPULAR) }

var commentText by remember { mutableStateOf("") }

Expand Down Expand Up @@ -204,21 +208,21 @@ fun CertDetailCommentScreen(
verticalAlignment = Alignment.CenterVertically
) {
CommentArrayButton(
commentSortType = CommentSortType.Famous,
isSelected = commentSortType == CommentSortType.Famous,
commentSortType = CommentSortType.POPULAR,
isSelected = commentSortType == CommentSortType.POPULAR,
selectOnClick = {
commentSortType = CommentSortType.Famous
commentSortType = CommentSortType.POPULAR
changeSortType(commentSortType)
}
)

Spacer(Modifier.widthForScreenPercentage(8.dp))

CommentArrayButton(
commentSortType = CommentSortType.Recent,
isSelected = commentSortType == CommentSortType.Recent,
commentSortType = CommentSortType.LATEST,
isSelected = commentSortType == CommentSortType.LATEST,
selectOnClick = {
commentSortType = CommentSortType.Recent
commentSortType = CommentSortType.LATEST
changeSortType(commentSortType)
}
)
Expand Down Expand Up @@ -317,30 +321,53 @@ fun CertDetailCommentScreen(
color = CertiTheme.colors.gray300
)
} else {
BasicTextField(
value = commentText,
onValueChange = { commentText = it },
singleLine = true,
maxLines = 1,
textStyle = CertiTheme.typography.caption.regular_14.copy(
color = CertiTheme.colors.black
),
cursorBrush = SolidColor(CertiTheme.colors.black),
decorationBox = { innerTextField ->
if (commentText.isEmpty()) {
Text(
text = stringResource(R.string.comment_hint),
style = CertiTheme.typography.caption.semibold_14,
color = CertiTheme.colors.gray300
)
}
var isFocused by remember { mutableStateOf(false) }
val focusRequester = remember { FocusRequester() }

innerTextField()
},
modifier = Modifier
.weight(1f)
.padding(horizontal = screenWidthDp(10.dp))
)
if (!isFocused && commentText.isNotEmpty()) {
Text(
text = commentText,
style = CertiTheme.typography.caption.regular_14.copy(
color = CertiTheme.colors.black
),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier
.weight(1f)
.padding(horizontal = screenWidthDp(10.dp))
.noRippleClickable {
isFocused = true
focusRequester.requestFocus()
}
)
} else {
BasicTextField(
value = commentText,
onValueChange = { commentText = it },
singleLine = true,
maxLines = 1,
textStyle = CertiTheme.typography.caption.regular_14.copy(
color = CertiTheme.colors.black
),
cursorBrush = SolidColor(CertiTheme.colors.black),
decorationBox = { innerTextField ->
if (commentText.isEmpty()) {
Text(
text = stringResource(R.string.comment_hint),
style = CertiTheme.typography.caption.semibold_14,
color = CertiTheme.colors.gray300
)
}

innerTextField()
},
modifier = Modifier
.weight(1f)
.padding(horizontal = screenWidthDp(10.dp))
.focusRequester(focusRequester)
.onFocusChanged { isFocused = it.isFocused }
)
}

Spacer(Modifier.widthForScreenPercentage(12.dp))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ fun HomeScreen(
) {
DDayoTopBar(
logoutOnClick = {
navigateToLogin()
// TEST
// navigateToLogin()
},
modifier = Modifier.fillMaxWidth()
)
Expand Down
Loading