Skip to content

Commit

Permalink
fix: Images not updating when last played order changed on home screen
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Mar 16, 2024
1 parent ab34cf3 commit e66166e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.mineinabyss.launchy.data.config

import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.res.loadImageBitmap
import com.charleskorn.kaml.encodeToStream
Expand Down Expand Up @@ -65,19 +63,15 @@ data class GameInstanceConfig(
}.onFailure { it.printStackTrace() }
}

@Composable
fun getBackground() = remember {
fun getBackgroundAsState() =
cachedBackground.also {
if (it.value == null) downloadScope.launch { loadBackground() }
}
}

@Composable
fun getLogo() = remember {
fun getLogoAsState() =
cachedLogo.also {
if (it.value == null) downloadScope.launch { loadLogo() }
}
}

fun saveTo(path: Path) = runCatching {
Formats.yaml.encodeToStream(this, path.outputStream())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ fun HomeScreen() {
Spacer(Modifier.height(16.dp))
}
item {
InstanceList("Instances", state.gameInstances)
InstanceList(
"Instances",
state.gameInstances.sortedByDescending { state.lastPlayed[it.config.name] })
}
// item {
// ModpackGroup("Find more", state.downloadedModpacks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -52,7 +53,7 @@ fun InstanceCard(
) {
val state = LocalLaunchyState
val coroutineScope = rememberCoroutineScope()
val background by config.getBackground()
val background by remember(config) { config.getBackgroundAsState() }
Card(
onClick = {
instance ?: return@Card
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fun InstanceList(title: String, packs: List<GameInstance>) {
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
items(visiblePacks.sortedByDescending { state.lastPlayed[it.config.name] }) { pack ->
items(visiblePacks) { pack ->
InstanceCard(pack.config, pack)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.window.WindowDraggableArea
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
Expand All @@ -24,7 +25,7 @@ import com.mineinabyss.launchy.ui.screens.LocalGameInstanceState
@Composable
fun BoxScope.BackgroundImage(windowScope: WindowScope) {
val pack = LocalGameInstanceState
val background by pack.instance.config.getBackground()
val background by remember { pack.instance.config.getBackgroundAsState() }
AnimatedVisibility(background != null, enter = fadeIn(), exit = fadeOut()) {
if (background == null) return@AnimatedVisibility
windowScope.WindowDraggableArea {
Expand Down Expand Up @@ -75,9 +76,9 @@ fun BoxScope.SlightBackgroundTint(modifier: Modifier = Modifier) {

@Composable
fun LogoLarge(modifier: Modifier) {
val state = LocalLaunchyState
LocalLaunchyState
val pack = LocalGameInstanceState
val painter by pack.instance.config.getLogo()
val painter by remember { pack.instance.config.getLogoAsState() }
AnimatedVisibility(
painter != null,
enter = fadeIn() + expandVertically(clip = false) + fadeIn(),
Expand Down

0 comments on commit e66166e

Please sign in to comment.