@@ -38,6 +38,7 @@ import com.github.libretube.extensions.toastFromMainDispatcher
3838import com.github.libretube.helpers.ImageHelper
3939import com.github.libretube.helpers.NavigationHelper
4040import com.github.libretube.helpers.PreferenceHelper
41+ import com.github.libretube.repo.UserDataRepositoryHelper
4142import com.github.libretube.ui.adapters.PlaylistAdapter
4243import com.github.libretube.ui.adapters.PlaylistItem
4344import com.github.libretube.ui.base.BaseActivity
@@ -54,7 +55,6 @@ import kotlinx.coroutines.Dispatchers
5455import kotlinx.coroutines.launch
5556import kotlinx.coroutines.runBlocking
5657import kotlinx.coroutines.withContext
57- import org.schabi.newpipe.extractor.timeago.patterns.it
5858
5959class PlaylistFragment : DynamicLayoutManagerFragment (R .layout.fragment_playlist) {
6060 private var _binding : FragmentPlaylistBinding ? = null
@@ -100,10 +100,14 @@ class PlaylistFragment : DynamicLayoutManagerFragment(R.layout.fragment_playlist
100100
101101 binding.playlistProgress.isVisible = true
102102
103- isBookmarked = runBlocking(Dispatchers .IO ) {
104- DatabaseHolder .Database .playlistBookmarkDao().includes(playlistId)
103+ lifecycleScope.launch(Dispatchers .IO ) {
104+ isBookmarked =
105+ UserDataRepositoryHelper .userDataRepository.getPlaylistBookmark(playlistId) != null
106+
107+ withContext(Dispatchers .Main ) {
108+ updateBookmarkRes()
109+ }
105110 }
106- updateBookmarkRes()
107111
108112 commonPlayerViewModel.isMiniPlayerVisible.observe(viewLifecycleOwner) {
109113 binding.playlistRecView.updatePadding(bottom = if (it) 64f .dpToPx() else 0 )
@@ -185,7 +189,8 @@ class PlaylistFragment : DynamicLayoutManagerFragment(R.layout.fragment_playlist
185189 )
186190 }
187191
188- binding.playlistInfo.text = getChannelAndVideoString(response, playlistFeed.size)
192+ binding.playlistInfo.text =
193+ getChannelAndVideoString(response, playlistFeed.size)
189194 }
190195 })
191196
@@ -266,11 +271,12 @@ class PlaylistFragment : DynamicLayoutManagerFragment(R.layout.fragment_playlist
266271 updateBookmarkRes()
267272 lifecycleScope.launch(Dispatchers .IO ) {
268273 if (! isBookmarked) {
269- DatabaseHolder . Database .playlistBookmarkDao()
270- .deleteById (playlistId)
274+ UserDataRepositoryHelper .userDataRepository
275+ .deletePlaylistBookmark (playlistId)
271276 } else {
272- DatabaseHolder .Database .playlistBookmarkDao()
273- .insert(response.toPlaylistBookmark(playlistId))
277+ val bookmark = response.toPlaylistBookmark(playlistId)
278+ UserDataRepositoryHelper .userDataRepository
279+ .createPlaylistBookmark(bookmark)
274280 }
275281 }
276282 }
@@ -339,14 +345,14 @@ class PlaylistFragment : DynamicLayoutManagerFragment(R.layout.fragment_playlist
339345 withContext(Dispatchers .IO ) {
340346 // update the playlist thumbnail and title if bookmarked
341347 val playlistBookmark =
342- DatabaseHolder . Database .playlistBookmarkDao().findById (playlistId)
348+ UserDataRepositoryHelper .userDataRepository.getPlaylistBookmark (playlistId)
343349 ? : return @withContext
344350 if (playlistBookmark.thumbnailUrl != playlist.thumbnailUrl ||
345351 playlistBookmark.playlistName != playlist.name ||
346352 playlistBookmark.videos != playlist.videos
347353 ) {
348- DatabaseHolder . Database .playlistBookmarkDao( )
349- .update(playlist.toPlaylistBookmark(playlistBookmark.playlistId) )
354+ val bookmark = playlist.toPlaylistBookmark(playlistBookmark.playlistId )
355+ UserDataRepositoryHelper .userDataRepository.createPlaylistBookmark(bookmark )
350356 }
351357 }
352358 }
@@ -402,7 +408,11 @@ class PlaylistFragment : DynamicLayoutManagerFragment(R.layout.fragment_playlist
402408 // try to remove the video from the playlist and show an undo snackbar if successful
403409 lifecycleScope.launch(Dispatchers .IO ) {
404410 try {
405- PlaylistsHelper .removeFromPlaylist(playlistId, video.url!! .toID(), originalPlaylistPosition)
411+ PlaylistsHelper .removeFromPlaylist(
412+ playlistId,
413+ video.url!! .toID(),
414+ originalPlaylistPosition
415+ )
406416
407417 val shortTitle = TextUtils .limitTextToLength(video.title.orEmpty(), 50 )
408418 val snackBarText = getString(
@@ -462,7 +472,11 @@ class PlaylistFragment : DynamicLayoutManagerFragment(R.layout.fragment_playlist
462472 *
463473 * I.e., this method adds the given offset to all videos with an originalPlaylistIndex > modifiedPosition.
464474 */
465- private fun fixItemIndices (items : List <PlaylistItem >, modifiedPosition : Int , offset : Int ): List <PlaylistItem > {
475+ private fun fixItemIndices (
476+ items : List <PlaylistItem >,
477+ modifiedPosition : Int ,
478+ offset : Int
479+ ): List <PlaylistItem > {
466480 return items.map {
467481 if (it.originalPlaylistIndex > modifiedPosition) {
468482 it.copy(originalPlaylistIndex = it.originalPlaylistIndex + offset)
0 commit comments