mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Merge pull request #4328 from 0x24D/local-playlist-order
fix: Sort local playlists based on selected preference
This commit is contained in:
commit
c24c147ae6
@ -6,6 +6,7 @@ import com.github.libretube.api.obj.Message
|
||||
import com.github.libretube.api.obj.Playlist
|
||||
import com.github.libretube.api.obj.Playlists
|
||||
import com.github.libretube.api.obj.StreamItem
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.constants.YOUTUBE_FRONTEND_URL
|
||||
import com.github.libretube.db.DatabaseHolder
|
||||
import com.github.libretube.db.obj.LocalPlaylist
|
||||
@ -31,10 +32,10 @@ object PlaylistsHelper {
|
||||
private fun Message.isOk() = this.message == "ok"
|
||||
|
||||
suspend fun getPlaylists(): List<Playlists> = withContext(Dispatchers.IO) {
|
||||
if (loggedIn) {
|
||||
val playlists = if (loggedIn) {
|
||||
RetrofitInstance.authApi.getUserPlaylists(token)
|
||||
} else {
|
||||
DatabaseHolder.Database.localPlaylistsDao().getAll().reversed()
|
||||
DatabaseHolder.Database.localPlaylistsDao().getAll()
|
||||
.map {
|
||||
Playlists(
|
||||
id = it.playlist.id.toString(),
|
||||
@ -45,6 +46,18 @@ object PlaylistsHelper {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
when (
|
||||
PreferenceHelper.getString(PreferenceKeys.PLAYLISTS_ORDER, "creation_date")
|
||||
) {
|
||||
"creation_date" -> playlists
|
||||
"creation_date_reversed" -> playlists.reversed()
|
||||
"alphabetic" -> playlists.sortedBy { it.name?.lowercase() }
|
||||
"alphabetic_reversed" -> playlists.sortedBy { it.name?.lowercase() }
|
||||
.reversed()
|
||||
|
||||
else -> playlists
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getPlaylist(playlistId: String): Playlist {
|
||||
|
@ -128,7 +128,7 @@ class LibraryFragment : Fragment() {
|
||||
_binding?.playlistRefresh?.isRefreshing = true
|
||||
lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
||||
var playlists = try {
|
||||
val playlists = try {
|
||||
withContext(Dispatchers.IO) {
|
||||
PlaylistsHelper.getPlaylists()
|
||||
}
|
||||
@ -142,18 +142,6 @@ class LibraryFragment : Fragment() {
|
||||
binding.playlistRefresh.isRefreshing = false
|
||||
|
||||
if (playlists.isNotEmpty()) {
|
||||
playlists = when (
|
||||
PreferenceHelper.getString(PreferenceKeys.PLAYLISTS_ORDER, "creation_date")
|
||||
) {
|
||||
"creation_date" -> playlists
|
||||
"creation_date_reversed" -> playlists.reversed()
|
||||
"alphabetic" -> playlists.sortedBy { it.name?.lowercase() }
|
||||
"alphabetic_reversed" -> playlists.sortedBy { it.name?.lowercase() }
|
||||
.reversed()
|
||||
|
||||
else -> playlists
|
||||
}
|
||||
|
||||
val playlistsAdapter = PlaylistsAdapter(
|
||||
playlists.toMutableList(),
|
||||
PlaylistsHelper.getPrivatePlaylistType()
|
||||
|
Loading…
Reference in New Issue
Block a user