@@ -38,9 +38,7 @@ import androidx.compose.material3.MaterialTheme
3838import androidx.compose.material3.Text
3939import androidx.compose.runtime.Composable
4040import androidx.compose.runtime.MutableState
41- import androidx.compose.runtime.mutableStateOf
4241import androidx.compose.runtime.produceState
43- import androidx.compose.runtime.remember
4442import androidx.compose.ui.Alignment
4543import androidx.compose.ui.Modifier
4644import androidx.compose.ui.graphics.Color
@@ -54,11 +52,8 @@ import io.github.stefanoltmann.app.generated.resources.uiLeaderBoardExplainer
5452import io.github.stefanoltmann.app.generated.resources.uiLeaderBoardRank
5553import io.github.stefanoltmann.app.generated.resources.uiLeaderBoardUsername
5654import io.github.stefanoltmann.app.generated.resources.uiLoading
57- import kotlin.time.Clock
5855import kotlin.time.ExperimentalTime
5956import kotlinx.coroutines.CancellationException
60- import kotlinx.coroutines.delay
61- import kotlinx.coroutines.isActive
6257import org.jetbrains.compose.resources.stringResource
6358import service.DefaultWebClient
6459import ui.theme.DefaultSpacer
@@ -68,9 +63,6 @@ import ui.theme.defaultPadding
6863import ui.theme.defaultRoundedCornerShape
6964import ui.theme.doubleSpacing
7065import ui.theme.lightGray
71- import util.formatDate
72-
73- const val CONTRIBUTOR_LIST_UPDATE_INTERVAL_MS : Long = 60000
7466
7567private val contributorListFontSize = 20 .sp
7668
@@ -81,24 +73,15 @@ fun LeaderboardViewList(
8173 errorMessage : MutableState <String ?>
8274) {
8375
84- val lastRefreshTime = remember { mutableStateOf(0L ) }
85-
8676 val contributorsState = produceState(emptyList()) {
8777
8878 try {
8979
90- while (isActive) {
91-
92- lastRefreshTime.value = Clock .System .now().toEpochMilliseconds()
93-
94- value = DefaultWebClient .findContributors().map {
95- it.copy(
96- username = steamIdToUsernameMap[it.steamIdHash]
97- )
80+ value = DefaultWebClient .findContributors()
81+ .map {
82+ it.key to it.value
9883 }
99-
100- delay(CONTRIBUTOR_LIST_UPDATE_INTERVAL_MS )
101- }
84+ .sortedByDescending { it.second }
10285
10386 } catch (_: CancellationException ) {
10487
@@ -144,21 +127,6 @@ fun LeaderboardViewList(
144127
145128 DefaultSpacer ()
146129
147- Text (
148- text = formatDate(lastRefreshTime.value),
149- style = MaterialTheme .typography.bodyMedium,
150- color = lightGray,
151- textAlign = TextAlign .Center ,
152- modifier = Modifier
153- .background(
154- Color .Black ,
155- defaultRoundedCornerShape
156- )
157- .defaultPadding()
158- )
159-
160- DefaultSpacer ()
161-
162130 Row {
163131
164132 FillSpacer ()
@@ -215,7 +183,7 @@ fun LeaderboardViewList(
215183 modifier = Modifier .padding(doubleSpacing)
216184 ) {
217185
218- itemsIndexed(contributors) { index, contributor ->
186+ itemsIndexed(contributors) { index, entry ->
219187
220188 val rank = index + 1
221189
@@ -239,11 +207,13 @@ fun LeaderboardViewList(
239207
240208 DoubleSpacer ()
241209
210+ val name = steamIdToUsernameMap[entry.first] ? : " Anonymous"
211+
242212 Text (
243- text = contributor.username ? : " Anonymous " ,
213+ text = name ,
244214 style = MaterialTheme .typography.bodyLarge,
245215 fontSize = contributorListFontSize,
246- color = if (contributor.username == null )
216+ color = if (name == " Anonymous " )
247217 lightGray.copy(0.3F )
248218 else
249219 lightGray,
@@ -255,7 +225,7 @@ fun LeaderboardViewList(
255225 DoubleSpacer ()
256226
257227 Text (
258- text = contributor.mapCount .toString(),
228+ text = entry.second .toString(),
259229 style = MaterialTheme .typography.bodyLarge,
260230 fontSize = contributorListFontSize,
261231 color = lightGray,
0 commit comments