mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +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 {
|
fun getType(): PlaylistType {
|
||||||
return if (PreferenceHelper.getToken() != "") {
|
return if (PreferenceHelper.getToken() != "") {
|
||||||
PlaylistType.PUBLIC
|
PlaylistType.PUBLIC
|
||||||
|
@ -7,6 +7,7 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.github.libretube.api.PlaylistsHelper
|
||||||
import com.github.libretube.api.RetrofitInstance
|
import com.github.libretube.api.RetrofitInstance
|
||||||
import com.github.libretube.api.obj.PlaylistId
|
import com.github.libretube.api.obj.PlaylistId
|
||||||
import com.github.libretube.api.obj.StreamItem
|
import com.github.libretube.api.obj.StreamItem
|
||||||
@ -89,19 +90,9 @@ class PlaylistAdapter(
|
|||||||
}
|
}
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
try {
|
try {
|
||||||
RetrofitInstance.authApi.removeFromPlaylist(
|
PlaylistsHelper.removeFromPlaylist(playlistId, position)
|
||||||
PreferenceHelper.getToken(),
|
|
||||||
PlaylistId(
|
|
||||||
playlistId = playlistId,
|
|
||||||
index = position
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
println(e)
|
Log.e(TAG(), e.toString())
|
||||||
Log.e(TAG(), "IOException, you might not have internet connection")
|
|
||||||
return@launch
|
|
||||||
} catch (e: HttpException) {
|
|
||||||
Log.e(TAG(), "HttpException, unexpected response")
|
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user