-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #371 from 6QuizOnTheBlock/and/feat#366-organizatio…
…n_statistics And/feat#366 organization statistics
- Loading branch information
Showing
14 changed files
with
277 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
android/core/model/src/main/java/com/sixkids/model/ClassSummary.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package com.sixkids.model | ||
|
||
data class ClassSummary( | ||
val challengeCounts: List<MemberSimpleClassSummary>, | ||
val relayCounts: List<MemberSimpleClassSummary>, | ||
val postsCounts: List<MemberSimpleClassSummary>, | ||
val challengeCounts: List<MemberSimpleClassSummary> = emptyList(), | ||
val relayCounts: List<MemberSimpleClassSummary> = emptyList(), | ||
val postsCounts: List<MemberSimpleClassSummary> = emptyList(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...in/src/main/java/com/sixkids/domain/usecase/organization/GetOrganizationSummaryUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.sixkids.domain.usecase.organization | ||
|
||
import com.sixkids.domain.repository.OrganizationRepository | ||
import javax.inject.Inject | ||
|
||
class GetOrganizationSummaryUseCase @Inject constructor( | ||
private val organizationRepository: OrganizationRepository | ||
){ | ||
suspend operator fun invoke(organizationId: Int) = runCatching { | ||
organizationRepository.getOrganizationSummary(organizationId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...anageclass/src/main/java/com/sixkids/teacher/manageclass/statistics/StatisticsContract.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.sixkids.teacher.manageclass.statistics | ||
|
||
import com.sixkids.model.ClassSummary | ||
import com.sixkids.ui.base.SideEffect | ||
import com.sixkids.ui.base.UiState | ||
|
||
data class StatisticsState( | ||
val isLoading: Boolean = false, | ||
val organizationName: String = "", | ||
val statistics: ClassSummary = ClassSummary() | ||
) : UiState | ||
|
||
sealed interface StatisticsEffect : SideEffect{ | ||
data class HandleException(val throwable: Throwable, val retry: () -> Unit) : StatisticsEffect | ||
} |
171 changes: 171 additions & 0 deletions
171
.../manageclass/src/main/java/com/sixkids/teacher/manageclass/statistics/StatisticsScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
package com.sixkids.teacher.manageclass.statistics | ||
|
||
import androidx.annotation.DrawableRes | ||
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.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.derivedStateOf | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import coil.compose.AsyncImage | ||
import com.sixkids.designsystem.component.appbar.UlbanDetailAppBar | ||
import com.sixkids.designsystem.component.item.StudentSimpleCardItem | ||
import com.sixkids.designsystem.theme.Blue | ||
import com.sixkids.designsystem.theme.UlbanTypography | ||
import com.sixkids.model.MemberSimpleClassSummary | ||
import com.sixkids.teacher.manageclass.R | ||
import kotlin.math.max | ||
import kotlin.math.min | ||
import com.sixkids.designsystem.R as DesignSystemR | ||
|
||
@Composable | ||
fun StatisticsRoute( | ||
viewModel: StatisticsViewModel = hiltViewModel() | ||
) { | ||
val uiState by viewModel.uiState.collectAsStateWithLifecycle() | ||
|
||
LaunchedEffect(key1 = Unit) { | ||
viewModel.initData() | ||
} | ||
|
||
StatisticsScreen( | ||
uiState = uiState | ||
) | ||
} | ||
|
||
@Composable | ||
fun StatisticsScreen( | ||
modifier: Modifier = Modifier, | ||
uiState: StatisticsState = StatisticsState(), | ||
) { | ||
val scrollState = rememberScrollState() | ||
val isScrolled by remember { | ||
derivedStateOf { | ||
scrollState.value > 100 | ||
} | ||
} | ||
|
||
Column( | ||
modifier = modifier.fillMaxSize(), | ||
) { | ||
UlbanDetailAppBar( | ||
leftIcon = DesignSystemR.drawable.statistics, | ||
title = stringResource(id = R.string.manage_class_statistics), | ||
content = stringResource(id = R.string.manage_class_statistics), | ||
topDescription = "", | ||
bottomDescription = uiState.organizationName, | ||
color = Blue, | ||
expanded = !isScrolled, | ||
) | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(20.dp).verticalScroll(scrollState) | ||
) { | ||
BestWorstStudent( | ||
studentList = uiState.statistics.challengeCounts, | ||
title = stringResource(id = R.string.statistics_challenge), | ||
icon = DesignSystemR.drawable.hifive | ||
) | ||
|
||
BestWorstStudent( | ||
studentList = uiState.statistics.relayCounts, | ||
title = stringResource(id = R.string.statistics_relay), | ||
icon = DesignSystemR.drawable.relay | ||
) | ||
|
||
BestWorstStudent( | ||
studentList = uiState.statistics.postsCounts, | ||
title = stringResource(id = R.string.statistics_post), | ||
icon = DesignSystemR.drawable.board | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun BestWorstStudent( | ||
studentList: List<MemberSimpleClassSummary> = emptyList(), | ||
title: String = "", | ||
@DrawableRes icon: Int, | ||
|
||
){ | ||
Spacer(modifier = Modifier.height(20.dp)) | ||
Row(verticalAlignment = Alignment.CenterVertically) { | ||
AsyncImage( | ||
model = icon, | ||
contentDescription = "relay", | ||
modifier = Modifier | ||
.padding(end = 10.dp) | ||
.size(50.dp) | ||
) | ||
Text(text = title, style = UlbanTypography.titleSmall) | ||
} | ||
|
||
|
||
if (studentList.isNotEmpty()) { | ||
Text( | ||
text = "가장 많이 참여한 학생", | ||
style = UlbanTypography.bodyMedium, | ||
modifier = Modifier.padding(vertical = 10.dp) | ||
) | ||
|
||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { | ||
for (i in 0 until min(3,studentList.size )) { | ||
StudentSimpleCardItem( | ||
modifier = Modifier.weight(1f), | ||
id = studentList[i].member.id, | ||
name = studentList[i].member.name, | ||
photo = studentList[i].member.photo, | ||
score = studentList[i].count, | ||
isCount = true | ||
) | ||
} | ||
} | ||
|
||
Text( | ||
text = "가장 적게 참여한 학생", | ||
style = UlbanTypography.bodyMedium, | ||
modifier = Modifier.padding(vertical = 10.dp) | ||
) | ||
|
||
val startIdx = max(studentList.size - 1, 0) | ||
val endIdx = max(studentList.size - 3, 0) | ||
|
||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { | ||
for (i in startIdx downTo endIdx) { | ||
StudentSimpleCardItem( | ||
modifier = Modifier.weight(1f), | ||
id = studentList[i].member.id, | ||
name = studentList[i].member.name, | ||
photo = studentList[i].member.photo, | ||
score = studentList[i].count, | ||
isCount = true | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
@Preview(showBackground = true) | ||
fun StatisticsScreenPreview() { | ||
StatisticsScreen() | ||
} |
Oops, something went wrong.