mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
add option to rename a playlist
This commit is contained in:
parent
63911442bb
commit
206b560eb4
@ -140,6 +140,12 @@ interface PipedApi {
|
|||||||
@GET("user/playlists")
|
@GET("user/playlists")
|
||||||
suspend fun playlists(@Header("Authorization") token: String): List<Playlists>
|
suspend fun playlists(@Header("Authorization") token: String): List<Playlists>
|
||||||
|
|
||||||
|
@POST("user/playlists/rename")
|
||||||
|
suspend fun renamePlaylist(
|
||||||
|
@Header("Authorization") token: String,
|
||||||
|
@Body playlistId: PlaylistId
|
||||||
|
)
|
||||||
|
|
||||||
@POST("user/playlists/delete")
|
@POST("user/playlists/delete")
|
||||||
suspend fun deletePlaylist(
|
suspend fun deletePlaylist(
|
||||||
@Header("Authorization") token: String,
|
@Header("Authorization") token: String,
|
||||||
|
@ -8,6 +8,7 @@ import android.widget.Toast
|
|||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.api.RetrofitInstance
|
import com.github.libretube.api.RetrofitInstance
|
||||||
|
import com.github.libretube.databinding.DialogTextPreferenceBinding
|
||||||
import com.github.libretube.extensions.TAG
|
import com.github.libretube.extensions.TAG
|
||||||
import com.github.libretube.extensions.toID
|
import com.github.libretube.extensions.toID
|
||||||
import com.github.libretube.obj.PlaylistId
|
import com.github.libretube.obj.PlaylistId
|
||||||
@ -36,6 +37,7 @@ class PlaylistOptionsDialog(
|
|||||||
|
|
||||||
if (isOwner) {
|
if (isOwner) {
|
||||||
optionsList = optionsList +
|
optionsList = optionsList +
|
||||||
|
context?.getString(R.string.renamePlaylist)!! +
|
||||||
context?.getString(R.string.deletePlaylist)!! -
|
context?.getString(R.string.deletePlaylist)!! -
|
||||||
context?.getString(R.string.clonePlaylist)!!
|
context?.getString(R.string.clonePlaylist)!!
|
||||||
}
|
}
|
||||||
@ -88,8 +90,21 @@ class PlaylistOptionsDialog(
|
|||||||
shareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
|
shareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
|
||||||
}
|
}
|
||||||
context?.getString(R.string.deletePlaylist) -> {
|
context?.getString(R.string.deletePlaylist) -> {
|
||||||
val token = PreferenceHelper.getToken()
|
deletePlaylist(
|
||||||
deletePlaylist(playlistId, token)
|
playlistId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
context?.getString(R.string.renamePlaylist) -> {
|
||||||
|
val binding = DialogTextPreferenceBinding.inflate(layoutInflater)
|
||||||
|
binding.input.hint = context?.getString(R.string.playlistName)
|
||||||
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
|
.setTitle(R.string.renamePlaylist)
|
||||||
|
.setView(binding.root)
|
||||||
|
.setPositiveButton(R.string.okay) { _, _ ->
|
||||||
|
renamePlaylist(playlistId, binding.input.text.toString())
|
||||||
|
}
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,21 +128,32 @@ class PlaylistOptionsDialog(
|
|||||||
run()
|
run()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deletePlaylist(id: String, token: String) {
|
private fun renamePlaylist(id: String, newName: String) {
|
||||||
fun run() {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
try {
|
||||||
try {
|
RetrofitInstance.authApi.renamePlaylist(
|
||||||
RetrofitInstance.authApi.deletePlaylist(token, PlaylistId(id))
|
PreferenceHelper.getToken(),
|
||||||
} catch (e: IOException) {
|
PlaylistId(
|
||||||
println(e)
|
playlistId = id,
|
||||||
Log.e(TAG(), "IOException, you might not have internet connection")
|
newName = newName
|
||||||
return@launch
|
)
|
||||||
} catch (e: HttpException) {
|
)
|
||||||
Log.e(TAG(), "HttpException, unexpected response")
|
} catch (e: Exception) {
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun deletePlaylist(id: String) {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
try {
|
||||||
|
RetrofitInstance.authApi.deletePlaylist(
|
||||||
|
PreferenceHelper.getToken(),
|
||||||
|
PlaylistId(id)
|
||||||
|
)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
return@launch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
run()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,6 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
|||||||
data class PlaylistId(
|
data class PlaylistId(
|
||||||
var playlistId: String? = null,
|
var playlistId: String? = null,
|
||||||
var videoId: String? = null,
|
var videoId: String? = null,
|
||||||
|
var newName: String? = null,
|
||||||
var index: Int = -1
|
var index: Int = -1
|
||||||
)
|
)
|
||||||
|
@ -316,4 +316,5 @@
|
|||||||
<string name="audio_video_summary">Quality and format</string>
|
<string name="audio_video_summary">Quality and format</string>
|
||||||
<string name="delete">Delete</string>
|
<string name="delete">Delete</string>
|
||||||
<string name="trending_layout">Alternative trending layout</string>
|
<string name="trending_layout">Alternative trending layout</string>
|
||||||
|
<string name="renamePlaylist">Rename playlist</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user