mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20: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
|
package com.github.libretube.api
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.core.text.isDigitsOnly
|
import androidx.core.text.isDigitsOnly
|
||||||
import com.github.libretube.api.obj.Playlist
|
import com.github.libretube.api.obj.Playlist
|
||||||
import com.github.libretube.api.obj.PlaylistId
|
import com.github.libretube.api.obj.PlaylistId
|
||||||
@ -179,8 +178,7 @@ object PlaylistsHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun clonePlaylist(context: Context, playlistId: String): String? {
|
suspend fun clonePlaylist(playlistId: String): String? {
|
||||||
val appContext = context.applicationContext
|
|
||||||
if (!loggedIn) {
|
if (!loggedIn) {
|
||||||
val playlist = RetrofitInstance.api.getPlaylist(playlistId)
|
val playlist = RetrofitInstance.api.getPlaylist(playlistId)
|
||||||
val newPlaylist = createPlaylist(playlist.name ?: "Unknown name") ?: return null
|
val newPlaylist = createPlaylist(playlist.name ?: "Unknown name") ?: return null
|
||||||
|
@ -30,7 +30,7 @@ class CreatePlaylistDialog(
|
|||||||
requireDialog().hide()
|
requireDialog().hide()
|
||||||
val playlistId = withContext(Dispatchers.IO) {
|
val playlistId = withContext(Dispatchers.IO) {
|
||||||
runCatching {
|
runCatching {
|
||||||
PlaylistsHelper.clonePlaylist(requireContext(), it)
|
PlaylistsHelper.clonePlaylist(it)
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
}
|
}
|
||||||
if (playlistId != null) {
|
if (playlistId != null) {
|
||||||
|
@ -237,30 +237,20 @@ class PlaylistFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun showPlaylistVideos(playlist: Playlist) {
|
private fun showPlaylistVideos(playlist: Playlist) {
|
||||||
val videos = if (playlistType == PlaylistType.PUBLIC) {
|
val videos = when {
|
||||||
playlistFeed
|
selectedSortOrder in listOf(0, 1) || playlistType == PlaylistType.PUBLIC -> {
|
||||||
} else {
|
|
||||||
when (selectedSortOrder) {
|
|
||||||
0, 1 -> {
|
|
||||||
if (playlistType == PlaylistType.LOCAL) {
|
|
||||||
playlistFeed.sortedBy {
|
|
||||||
it.url.orEmpty().toInt()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
playlistFeed
|
playlistFeed
|
||||||
}
|
}
|
||||||
}
|
selectedSortOrder in listOf(2, 3) -> {
|
||||||
2, 3 -> {
|
|
||||||
playlistFeed.sortedBy { it.duration }
|
playlistFeed.sortedBy { it.duration }
|
||||||
}
|
}
|
||||||
4, 5 -> {
|
selectedSortOrder in listOf(4, 5) -> {
|
||||||
playlistFeed.sortedBy { it.title }
|
playlistFeed.sortedBy { it.title }
|
||||||
}
|
}
|
||||||
else -> throw IllegalArgumentException()
|
else -> throw IllegalArgumentException()
|
||||||
}.let {
|
}.let {
|
||||||
if (selectedSortOrder % 2 == 0) it else it.reversed()
|
if (selectedSortOrder % 2 == 0) it else it.reversed()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
playlistAdapter = PlaylistAdapter(videos.toMutableList(), playlistId!!, playlistType)
|
playlistAdapter = PlaylistAdapter(videos.toMutableList(), playlistId!!, playlistType)
|
||||||
binding.playlistRecView.adapter = playlistAdapter
|
binding.playlistRecView.adapter = playlistAdapter
|
||||||
|
@ -69,7 +69,7 @@ class PlaylistOptionsBottomSheet(
|
|||||||
val context = requireContext()
|
val context = requireContext()
|
||||||
val playlistId = withContext(Dispatchers.IO) {
|
val playlistId = withContext(Dispatchers.IO) {
|
||||||
runCatching {
|
runCatching {
|
||||||
PlaylistsHelper.clonePlaylist(context, playlistId)
|
PlaylistsHelper.clonePlaylist(playlistId)
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
}
|
}
|
||||||
context.toastFromMainDispatcher(
|
context.toastFromMainDispatcher(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user