From ce801498d0719f912d5de9ab6f35f5201a10a558 Mon Sep 17 00:00:00 2001 From: iliano101 Date: Sun, 3 Nov 2024 11:27:48 -0500 Subject: [PATCH] Small attempt at fixing HomePage Lag --- .../com/maxrave/simpmusic/data/db/entities/SongEntity.kt | 5 ++--- .../maxrave/simpmusic/data/model/browse/album/AlbumBrowse.kt | 2 ++ .../com/maxrave/simpmusic/data/model/browse/album/Track.kt | 2 ++ .../java/com/maxrave/simpmusic/data/model/home/HomeItem.kt | 2 ++ .../java/com/maxrave/simpmusic/ui/screen/home/HomeScreen.kt | 4 ++-- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/maxrave/simpmusic/data/db/entities/SongEntity.kt b/app/src/main/java/com/maxrave/simpmusic/data/db/entities/SongEntity.kt index ebfb196a..58cb2505 100644 --- a/app/src/main/java/com/maxrave/simpmusic/data/db/entities/SongEntity.kt +++ b/app/src/main/java/com/maxrave/simpmusic/data/db/entities/SongEntity.kt @@ -6,7 +6,7 @@ import com.maxrave.simpmusic.common.DownloadState.STATE_NOT_DOWNLOADED import java.time.LocalDateTime @Entity(tableName = "song") -data class SongEntity ( +data class SongEntity( @PrimaryKey(autoGenerate = false) val videoId: String = "", val albumId: String? = null, val albumName: String? = null, @@ -26,8 +26,7 @@ data class SongEntity ( val totalPlayTime: Long = 0, // in milliseconds val downloadState: Int = STATE_NOT_DOWNLOADED, val inLibrary: LocalDateTime = LocalDateTime.now(), - ) -{ +) { fun toggleLike() = copy(liked = !liked) } \ No newline at end of file diff --git a/app/src/main/java/com/maxrave/simpmusic/data/model/browse/album/AlbumBrowse.kt b/app/src/main/java/com/maxrave/simpmusic/data/model/browse/album/AlbumBrowse.kt index 02a29466..aed8c481 100644 --- a/app/src/main/java/com/maxrave/simpmusic/data/model/browse/album/AlbumBrowse.kt +++ b/app/src/main/java/com/maxrave/simpmusic/data/model/browse/album/AlbumBrowse.kt @@ -1,10 +1,12 @@ package com.maxrave.simpmusic.data.model.browse.album +import androidx.compose.runtime.Immutable import com.google.gson.annotations.SerializedName import com.maxrave.simpmusic.data.model.searchResult.songs.Artist import com.maxrave.simpmusic.data.model.searchResult.songs.Thumbnail +@Immutable data class AlbumBrowse( @SerializedName("artists") val artists: List, diff --git a/app/src/main/java/com/maxrave/simpmusic/data/model/browse/album/Track.kt b/app/src/main/java/com/maxrave/simpmusic/data/model/browse/album/Track.kt index c84cd642..a226f32a 100644 --- a/app/src/main/java/com/maxrave/simpmusic/data/model/browse/album/Track.kt +++ b/app/src/main/java/com/maxrave/simpmusic/data/model/browse/album/Track.kt @@ -1,12 +1,14 @@ package com.maxrave.simpmusic.data.model.browse.album +import androidx.compose.runtime.Immutable import com.google.gson.annotations.SerializedName import com.maxrave.simpmusic.data.model.searchResult.songs.Album import com.maxrave.simpmusic.data.model.searchResult.songs.Artist import com.maxrave.simpmusic.data.model.searchResult.songs.FeedbackTokens import com.maxrave.simpmusic.data.model.searchResult.songs.Thumbnail +@Immutable data class Track( @SerializedName("album") val album: Album?, diff --git a/app/src/main/java/com/maxrave/simpmusic/data/model/home/HomeItem.kt b/app/src/main/java/com/maxrave/simpmusic/data/model/home/HomeItem.kt index 404a09a0..7b28d48f 100644 --- a/app/src/main/java/com/maxrave/simpmusic/data/model/home/HomeItem.kt +++ b/app/src/main/java/com/maxrave/simpmusic/data/model/home/HomeItem.kt @@ -1,9 +1,11 @@ package com.maxrave.simpmusic.data.model.home +import androidx.compose.runtime.Immutable import com.google.gson.annotations.SerializedName import com.maxrave.simpmusic.data.model.searchResult.songs.Thumbnail +@Immutable data class HomeItem( @SerializedName("contents") val contents: List, diff --git a/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/HomeScreen.kt b/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/HomeScreen.kt index 450a7ba7..65241a1e 100644 --- a/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/HomeScreen.kt +++ b/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/HomeScreen.kt @@ -286,7 +286,7 @@ fun HomeScreen( ) } } - items(homeData) { + items(homeData, key = { it.title + it.channelId }) { if (it.title != context.getString(R.string.quick_picks)) { HomeItem( homeViewModel = viewModel, @@ -296,7 +296,7 @@ fun HomeScreen( ) } } - items(newRelease) { + items(newRelease, key = { it.title + it.channelId }) { androidx.compose.animation.AnimatedVisibility( visible = newRelease.isNotEmpty(), ) {