mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
Merge pull request #3655 from Bnyro/master
Fix crash when sorting playlists
This commit is contained in:
commit
96397abeae
@ -1,6 +1,5 @@
|
||||
package com.github.libretube.api
|
||||
|
||||
import android.content.Context
|
||||
import androidx.core.text.isDigitsOnly
|
||||
import com.github.libretube.api.obj.Playlist
|
||||
import com.github.libretube.api.obj.PlaylistId
|
||||
@ -179,8 +178,7 @@ object PlaylistsHelper {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun clonePlaylist(context: Context, playlistId: String): String? {
|
||||
val appContext = context.applicationContext
|
||||
suspend fun clonePlaylist(playlistId: String): String? {
|
||||
if (!loggedIn) {
|
||||
val playlist = RetrofitInstance.api.getPlaylist(playlistId)
|
||||
val newPlaylist = createPlaylist(playlist.name ?: "Unknown name") ?: return null
|
||||
|
@ -30,7 +30,7 @@ class CreatePlaylistDialog(
|
||||
requireDialog().hide()
|
||||
val playlistId = withContext(Dispatchers.IO) {
|
||||
runCatching {
|
||||
PlaylistsHelper.clonePlaylist(requireContext(), it)
|
||||
PlaylistsHelper.clonePlaylist(it)
|
||||
}.getOrNull()
|
||||
}
|
||||
if (playlistId != null) {
|
||||
|
@ -237,29 +237,19 @@ class PlaylistFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun showPlaylistVideos(playlist: Playlist) {
|
||||
val videos = if (playlistType == PlaylistType.PUBLIC) {
|
||||
playlistFeed
|
||||
} else {
|
||||
when (selectedSortOrder) {
|
||||
0, 1 -> {
|
||||
if (playlistType == PlaylistType.LOCAL) {
|
||||
playlistFeed.sortedBy {
|
||||
it.url.orEmpty().toInt()
|
||||
}
|
||||
} else {
|
||||
playlistFeed
|
||||
}
|
||||
}
|
||||
2, 3 -> {
|
||||
playlistFeed.sortedBy { it.duration }
|
||||
}
|
||||
4, 5 -> {
|
||||
playlistFeed.sortedBy { it.title }
|
||||
}
|
||||
else -> throw IllegalArgumentException()
|
||||
}.let {
|
||||
if (selectedSortOrder % 2 == 0) it else it.reversed()
|
||||
val videos = when {
|
||||
selectedSortOrder in listOf(0, 1) || playlistType == PlaylistType.PUBLIC -> {
|
||||
playlistFeed
|
||||
}
|
||||
selectedSortOrder in listOf(2, 3) -> {
|
||||
playlistFeed.sortedBy { it.duration }
|
||||
}
|
||||
selectedSortOrder in listOf(4, 5) -> {
|
||||
playlistFeed.sortedBy { it.title }
|
||||
}
|
||||
else -> throw IllegalArgumentException()
|
||||
}.let {
|
||||
if (selectedSortOrder % 2 == 0) it else it.reversed()
|
||||
}
|
||||
|
||||
playlistAdapter = PlaylistAdapter(videos.toMutableList(), playlistId!!, playlistType)
|
||||
|
@ -69,7 +69,7 @@ class PlaylistOptionsBottomSheet(
|
||||
val context = requireContext()
|
||||
val playlistId = withContext(Dispatchers.IO) {
|
||||
runCatching {
|
||||
PlaylistsHelper.clonePlaylist(context, playlistId)
|
||||
PlaylistsHelper.clonePlaylist(playlistId)
|
||||
}.getOrNull()
|
||||
}
|
||||
context.toastFromMainDispatcher(
|
||||
|
Loading…
x
Reference in New Issue
Block a user