mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
add playlist deletion
This commit is contained in:
parent
3a63e3c546
commit
9c207d2e80
@ -146,6 +146,32 @@ object PlaylistsHelper {
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun removeFromPlaylist(playlistId: String, index: Int) {
|
||||
if (!loggedIn()) {
|
||||
val transaction = awaitQuery {
|
||||
DatabaseHolder.Database.localPlaylistsDao().getAll()
|
||||
}.first { it.playlist.id.toString() == playlistId }
|
||||
awaitQuery {
|
||||
DatabaseHolder.Database.localPlaylistsDao().removePlaylistVideo(transaction.videos[index])
|
||||
}
|
||||
if (transaction.videos.size > 1) return
|
||||
// remove thumbnail if playlist now empty
|
||||
awaitQuery {
|
||||
transaction.playlist.thumbnailUrl = ""
|
||||
DatabaseHolder.Database.localPlaylistsDao().updatePlaylist(transaction.playlist)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
RetrofitInstance.authApi.removeFromPlaylist(
|
||||
PreferenceHelper.getToken(),
|
||||
PlaylistId(
|
||||
playlistId = playlistId,
|
||||
index = index
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun getType(): PlaylistType {
|
||||
return if (PreferenceHelper.getToken() != "") {
|
||||
PlaylistType.PUBLIC
|
||||
|
@ -7,6 +7,7 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.api.PlaylistsHelper
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.api.obj.PlaylistId
|
||||
import com.github.libretube.api.obj.StreamItem
|
||||
@ -89,19 +90,9 @@ class PlaylistAdapter(
|
||||
}
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
RetrofitInstance.authApi.removeFromPlaylist(
|
||||
PreferenceHelper.getToken(),
|
||||
PlaylistId(
|
||||
playlistId = playlistId,
|
||||
index = position
|
||||
)
|
||||
)
|
||||
PlaylistsHelper.removeFromPlaylist(playlistId, position)
|
||||
} catch (e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG(), "IOException, you might not have internet connection")
|
||||
return@launch
|
||||
} catch (e: HttpException) {
|
||||
Log.e(TAG(), "HttpException, unexpected response")
|
||||
Log.e(TAG(), e.toString())
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user