From 03686dd4ff4c4c6e1710619ff7161f1cf077575a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 26 Jul 2022 07:40:21 +0200 Subject: [PATCH] fix playlists --- .../github/libretube/fragments/PlaylistFragment.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt index 6c35edcd9..c39217a16 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt @@ -56,7 +56,9 @@ class PlaylistFragment : Fragment() { fun run() { lifecycleScope.launchWhenCreated { val response = try { - RetrofitInstance.api.getPlaylist(playlistId!!) + // load locally stored playlists with the auth api + if (isPipedPlaylist()) RetrofitInstance.authApi.getPlaylist(playlistId!!) + else RetrofitInstance.api.getPlaylist(playlistId!!) } catch (e: IOException) { println(e) Log.e(TAG, "IOException, you might not have internet connection") @@ -118,6 +120,8 @@ class PlaylistFragment : Fragment() { fun run() { lifecycleScope.launchWhenCreated { val response = try { + // load locally stored playlists with the auth api + if (isPipedPlaylist()) RetrofitInstance.authApi.getPlaylistNextPage(playlistId!!, nextPage!!) RetrofitInstance.api.getPlaylistNextPage(playlistId!!, nextPage!!) } catch (e: IOException) { println(e) @@ -135,6 +139,11 @@ class PlaylistFragment : Fragment() { run() } + private fun isPipedPlaylist(): Boolean { + val regex = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}" + return playlistId?.contains(regex) == true + } + private fun Fragment?.runOnUiThread(action: () -> Unit) { this ?: return if (!isAdded) return // Fragment not attached to an Activity