Skip to content

Commit

Permalink
Merge pull request #363 from 6QuizOnTheBlock/and/feat#349-challenge_ui
Browse files Browse the repository at this point in the history
And/feat#349 challenge UI
  • Loading branch information
TRASALBY authored May 18, 2024
2 parents 72c262d + af1bf21 commit 49be093
Show file tree
Hide file tree
Showing 20 changed files with 269 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ data class Challenge(
val reward: Int = 0,
val startTime: LocalDateTime = LocalDateTime.now(),
val endTime: LocalDateTime = LocalDateTime.now(),
val totalCount: Int = 0
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.squareup.moshi.Json

data class ChallengeDetailResponse(
@Json(name = "challengeSimpleDTO")
val challenge: ChallengeResponse,
val challenge: ChallengeResponse,
val reports: List<ReportResponse>
)

Expand All @@ -15,7 +15,7 @@ internal fun ChallengeDetailResponse.toModel() = ChallengeDetail(
content = challenge.content,
startTime = challenge.startTime,
endTime = challenge.endTime,
headCount = challenge.headCount,
headCount = reports.fold(0) { headCount, report -> headCount + report.group.headCount },
teamCount = reports.size,
reportList = reports.map { it.toModel() }
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ data class ChallengeHistoryResponse(
val page: Int,
val size: Int,
val last: Boolean,
val totalCount : Int,
val challenges: List<ChallengeResponse>
)

Expand All @@ -19,11 +20,12 @@ data class ChallengeResponse(
val endTime: LocalDateTime = LocalDateTime.now(),
)

internal fun ChallengeResponse.toModel() = Challenge(
internal fun ChallengeResponse.toModel(totalCount: Int = 0) = Challenge(
id = id,
title = title,
content = content,
headCount = headCount,
startTime = startTime,
endTime = endTime
endTime = endTime,
totalCount = totalCount
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ data class RunningChallengeByStudentResponse(
@Json(name = "challengeSimpleDTO")
val challenge: ChallengeResponse,
val leaderStatus: Boolean?,
@Json(name = "memberList")
val memberNames: List<MemberSimpleResponse>?,
@Json(name = "memberNames")
val memberList: List<MemberSimpleResponse>?,
val type: String,
val createTime: LocalDateTime?,
val endStatus: Boolean?
)

internal fun RunningChallengeByStudentResponse.toModel() = RunningChallengeByStudent(
challenge = challenge.toModel(),
leaderStatus = leaderStatus,
memberNames = memberNames?.map { it.toModel() }?: emptyList(),
type = GroupType.valueOf(type),
createTime = createTime,
endStatus = endStatus
)
internal fun RunningChallengeByStudentResponse.toModel() =
RunningChallengeByStudent(
challenge = challenge.toModel(),
leaderStatus = leaderStatus,
memberNames = memberList?.map { it.toModel() } ?: emptyList(),
type = GroupType.valueOf(type),
createTime = createTime,
endStatus = endStatus
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sixkids.data.repository.challenge

import android.util.Log
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
Expand Down Expand Up @@ -42,8 +43,12 @@ class ChallengeRepositoryImpl @Inject constructor(

override suspend fun getRunningChallengesByStudent(
organizationId: Int
): RunningChallengeByStudent =
challengeRemoteDataSourceImpl.getRunningChallengesByStudent(organizationId).toModel()
): RunningChallengeByStudent {
val a = challengeRemoteDataSourceImpl.getRunningChallengesByStudent(organizationId)
Log.d("ttt", "getRunningChallengesByStudent: $a")
Log.d("ttt", "getRunningChallengesByStudent: ${a.toModel()}")
return a.toModel()
}

override suspend fun createChallenge(
organizationId: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sixkids.data.repository.challenge.remote

import android.util.Log
import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.sixkids.data.api.ChallengeService
Expand Down Expand Up @@ -29,7 +30,9 @@ class ChallengeHistoryPagingSource @Inject constructor(
page,
DEFAULT_SIZE
)
val challengeHistory = response.getOrThrow().data.challenges.map { it.toModel() }
val challengeHistory = response.getOrThrow().data.let { challengeResponse ->
challengeResponse.challenges.map { it.toModel(challengeResponse.totalCount) }
}

LoadResult.Page(
data = challengeHistory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fun ChallengeRoute(

ChallengeHistoryScreen(
uiState = uiState,
updateTotalCount = viewModel::updateTotalCount,
navigateToDetail = viewModel::navigateChallengeDetail,
showDialog = viewModel::showGroupDialog,
)
Expand All @@ -103,6 +104,7 @@ fun ChallengeRoute(
@Composable
fun ChallengeHistoryScreen(
uiState: ChallengeHistoryState = ChallengeHistoryState(),
updateTotalCount: (Int) -> Unit = {},
navigateToDetail: (Long) -> Unit = {},
showDialog: () -> Unit = {},
) {
Expand Down Expand Up @@ -136,15 +138,23 @@ fun ChallengeHistoryScreen(
topDescription = "${runningChallenge.startTime.formatToMonthDayTime()} ~ ${runningChallenge.endTime.formatToMonthDayTime()}",
bottomDescription = runningChallenge.content,
color = Red,
onClick = showDialog,
onReportEnable = uiState.runningChallenge.endStatus?.not() ?: false,
onClick = if (uiState.runningChallenge.createTime == null) {
showDialog
} else {
{}
},
onReportEnable = (uiState.runningChallenge.leaderStatus == true && uiState.runningChallenge.endStatus?.not() ?: false),
onReportClick = {
//TODO 과제 제출로 이동
},
teamDescription = if(uiState.runningChallenge.type == GroupType.DESIGN) {
teamDescription = if (uiState.runningChallenge.type == GroupType.DESIGN) {
uiState.runningChallenge.memberNames.joinToString(", ") { it.name }
} else {
stringResource(R.string.free_group_matching)
if (uiState.runningChallenge.memberNames.isNotEmpty()) {
uiState.runningChallenge.memberNames.joinToString(", ") { it.name }
} else {
stringResource(R.string.free_group_matching)
}
},
runningTimeDescription = "과제 참여 후 진행시간 표시하기",
expanded = !isScrolled
Expand All @@ -167,7 +177,7 @@ fun ChallengeHistoryScreen(
HorizontalDivider(modifier = Modifier.padding(vertical = 4.dp))


if (challengeItems == null) {
if (challengeItems == null || challengeItems.itemCount == 0) {
Spacer(modifier = Modifier.weight(1f))
Text(
modifier = Modifier
Expand All @@ -188,6 +198,9 @@ fun ChallengeHistoryScreen(
) {
items(challengeItems.itemCount) { index ->
challengeItems[index]?.let { challenge ->
if (index == 0) {
updateTotalCount(challenge.totalCount)
}
UlbanChallengeItem(
title = challenge.title,
description = challenge.content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ class ChallengeHistoryViewModel @Inject constructor(
fun navigateToJoinGroup() = postSideEffect(
ChallengeHistoryEffect.NavigateToJoinGroup(organizationId)
)

fun updateTotalCount(totalCount: Int) {
intent { copy(totalChallengeCount = totalCount) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fun GroupWaiting(
modifier = Modifier.fillMaxWidth(),
text = stringResource(R.string.done),
onClick = onDoneClick,
enabled = remainingMember == 0
enabled = remainingMember <= 0
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.sixkids.designsystem.theme.Cream
import com.sixkids.designsystem.theme.UlbanTypography
import com.sixkids.model.MemberSimple
import com.sixkids.designsystem.R as DesignSystemR
Expand Down Expand Up @@ -58,11 +60,14 @@ fun MemberIcon(
Box(
modifier = modifier.wrapContentSize(),
) {
AsyncImage(
model = memberIconItem.member.photo,
contentDescription = null,
modifier = modifier.size(48.dp)
)
Card {
AsyncImage(
model = memberIconItem.member.photo,
contentDescription = null,
modifier = modifier.size(48.dp),
contentScale = ContentScale.Crop
)
}
if (memberIconItem.showX) {
Icon(
imageVector = ImageVector.vectorResource(DesignSystemR.drawable.ic_close_filled),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data class CreateGroupState(
val isLoading: Boolean = false,
val isScanning: Boolean = false,
val foundMembers: List<MemberSimple> = emptyList(),
val showMembers: Array<MemberSimple?> = Array(5) { null },
val selectedMembers: List<MemberSimple> = emptyList(),
val waitingMembers: List<MemberSimple> = emptyList(),
val groupSize: Int = 0,
Expand Down
Loading

0 comments on commit 49be093

Please sign in to comment.