[Android] PlaylistViewModel: set proper context for provider

Duncan McNamara git at videolan.org
Tue May 9 10:30:24 UTC 2023


vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Tue Mar 14 18:56:32 2023 +0100| [a681eacb7e0a26424521e6fb0b572eae523d1298] | committer: Nicolas Pomepuy

PlaylistViewModel: set proper context for provider

The PlaylistsViewModel getter would use the activity and not the
fragment as context for the ViewModelProvider, so it would always return
the same view model instance for different fragments.

Fixes #2860

> https://code.videolan.org/videolan/vlc-android/commit/a681eacb7e0a26424521e6fb0b572eae523d1298
---

 .../src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt        | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt
index c8361d0d46..c64a1cda49 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt
@@ -49,4 +49,4 @@ class PlaylistsViewModel(context: Context, type: Playlist.Type) : MedialibraryVi
     }
 }
 
-internal fun PlaylistFragment.getViewModel(type: Playlist.Type) = ViewModelProvider(requireActivity(), PlaylistsViewModel.Factory(requireContext(), type)).get(PlaylistsViewModel::class.java)
\ No newline at end of file
+internal fun PlaylistFragment.getViewModel(type: Playlist.Type) =ViewModelProvider(this, PlaylistsViewModel.Factory(requireContext(), type)).get(PlaylistsViewModel::class.java)
\ No newline at end of file



More information about the Android mailing list