From 4b5267f83d6007203befc96d3b9286d13ef694a4 Mon Sep 17 00:00:00 2001 From: lalilu <1248393538@qq.com> Date: Sun, 29 Dec 2024 14:05:41 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=E8=A7=A3=E5=86=B3=E5=AF=BC=E8=88=AA?= =?UTF-8?q?=E5=8A=A8=E7=94=BB=E7=9A=84=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F?= =?UTF-8?q?=E5=AF=BC=E8=87=B4viewModel=E5=BC=82=E5=B8=B8=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/lalilu/component/extension/ComposeExt.kt | 4 ++-- .../java/com/lalilu/lalbum/screen/AlbumDetailScreen.kt | 8 ++++++-- .../main/java/com/lalilu/lalbum/screen/AlbumsScreen.kt | 9 +++++++-- .../java/com/lalilu/lartist/screen/ArtistDetailScreen.kt | 8 ++++++-- .../lplaylist/screen/detail/PlaylistDetailScreen.kt | 2 ++ 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/component/src/main/java/com/lalilu/component/extension/ComposeExt.kt b/component/src/main/java/com/lalilu/component/extension/ComposeExt.kt index 2bae1f53..92abad65 100644 --- a/component/src/main/java/com/lalilu/component/extension/ComposeExt.kt +++ b/component/src/main/java/com/lalilu/component/extension/ComposeExt.kt @@ -276,9 +276,9 @@ inline fun Screen.screenVM( qualifier: Qualifier? = null, viewModelStoreOwner: ViewModelStoreOwner = checkNotNull( value = getScreenViewModelStoreOwner() ?: LocalViewModelStoreOwner.current, - lazyMessage = { "No Registered ViewModelStoreOwner was provided via registerMap for ${T::class.java}" } + lazyMessage = { "No ViewModelStoreOwner was provided for ${T::class.java}" } ), - key: String? = null, + key: String? = this.key, extras: CreationExtras = defaultExtras(viewModelStoreOwner), scope: Scope = currentKoinScope(), noinline parameters: ParametersDefinition? = null, diff --git a/lalbum/src/main/java/com/lalilu/lalbum/screen/AlbumDetailScreen.kt b/lalbum/src/main/java/com/lalilu/lalbum/screen/AlbumDetailScreen.kt index 3f2495f7..b17bbd01 100644 --- a/lalbum/src/main/java/com/lalilu/lalbum/screen/AlbumDetailScreen.kt +++ b/lalbum/src/main/java/com/lalilu/lalbum/screen/AlbumDetailScreen.kt @@ -51,7 +51,9 @@ data class AlbumDetailScreen( @Composable override fun provideScreenActions(): List { - val vm = screenVM() + val vm = screenVM( + parameters = { parametersOf(albumId) } + ) val state by vm.state return remember { @@ -97,7 +99,9 @@ data class AlbumDetailScreen( @Composable override fun Content() { - val vm = screenVM(parameters = { parametersOf(albumId) }) + val vm = screenVM( + parameters = { parametersOf(albumId) } + ) val songs by vm.songs val state by vm.state val album by vm.album diff --git a/lalbum/src/main/java/com/lalilu/lalbum/screen/AlbumsScreen.kt b/lalbum/src/main/java/com/lalilu/lalbum/screen/AlbumsScreen.kt index acd08c27..6f2ff740 100644 --- a/lalbum/src/main/java/com/lalilu/lalbum/screen/AlbumsScreen.kt +++ b/lalbum/src/main/java/com/lalilu/lalbum/screen/AlbumsScreen.kt @@ -28,6 +28,7 @@ import com.lalilu.remixicon.editor.text import com.lalilu.remixicon.media.albumFill import com.lalilu.remixicon.system.menuSearchLine import com.zhangke.krouter.annotation.Destination +import org.koin.core.parameter.parametersOf @Destination("/pages/albums") data class AlbumsScreen( @@ -43,7 +44,9 @@ data class AlbumsScreen( @Composable override fun provideScreenActions(): List { - val albumsVM = screenVM() + val albumsVM = screenVM( + parameters = { parametersOf(albumsId) } + ) val state by albumsVM.state return remember { @@ -83,7 +86,9 @@ data class AlbumsScreen( @Composable override fun Content() { - val vm = screenVM() + val vm = screenVM( + parameters = { parametersOf(albumsId) } + ) val state by vm.state val albums by vm.albums diff --git a/lartist/src/main/java/com/lalilu/lartist/screen/ArtistDetailScreen.kt b/lartist/src/main/java/com/lalilu/lartist/screen/ArtistDetailScreen.kt index db4b6009..a1d51e3d 100644 --- a/lartist/src/main/java/com/lalilu/lartist/screen/ArtistDetailScreen.kt +++ b/lartist/src/main/java/com/lalilu/lartist/screen/ArtistDetailScreen.kt @@ -53,7 +53,9 @@ data class ArtistDetailScreen( @Composable override fun provideScreenActions(): List { - val vm = screenVM() + val vm = screenVM( + parameters = { parametersOf(artistName) } + ) val state by vm.state return remember { @@ -99,7 +101,9 @@ data class ArtistDetailScreen( @Composable override fun Content() { - val vm = screenVM(parameters = { parametersOf(artistName) }) + val vm = screenVM( + parameters = { parametersOf(artistName) } + ) val songs by vm.songs val state by vm.state val artist by vm.artist diff --git a/lplaylist/src/main/java/com/lalilu/lplaylist/screen/detail/PlaylistDetailScreen.kt b/lplaylist/src/main/java/com/lalilu/lplaylist/screen/detail/PlaylistDetailScreen.kt index 26020b34..5ffe330f 100644 --- a/lplaylist/src/main/java/com/lalilu/lplaylist/screen/detail/PlaylistDetailScreen.kt +++ b/lplaylist/src/main/java/com/lalilu/lplaylist/screen/detail/PlaylistDetailScreen.kt @@ -6,6 +6,7 @@ import androidx.compose.runtime.remember import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource import cafe.adriel.voyager.core.screen.Screen +import cafe.adriel.voyager.core.screen.ScreenKey import com.lalilu.RemixIcon import com.lalilu.common.ext.requestFor import com.lalilu.component.base.screen.ScreenAction @@ -41,6 +42,7 @@ import org.koin.core.qualifier.named data class PlaylistDetailScreen( val playlistId: String ) : Screen, ScreenInfoFactory, ScreenActionFactory, ScreenBarFactory { + override val key: ScreenKey = "${super.key}:$playlistId" @Composable override fun provideScreenInfo(): ScreenInfo = remember {