mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
fix auth api playlists
This commit is contained in:
parent
212152cef2
commit
077d5728fa
@ -4,9 +4,11 @@ import android.app.Activity
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.databinding.PlaylistsRowBinding
|
||||
import com.github.libretube.dialogs.PlaylistOptionsDialog
|
||||
import com.github.libretube.obj.PlaylistId
|
||||
import com.github.libretube.obj.Playlists
|
||||
import com.github.libretube.preferences.PreferenceHelper
|
||||
@ -22,6 +24,7 @@ import java.io.IOException
|
||||
|
||||
class PlaylistsAdapter(
|
||||
private val playlists: MutableList<Playlists>,
|
||||
private val childFragmentManager: FragmentManager,
|
||||
private val activity: Activity
|
||||
) : RecyclerView.Adapter<PlaylistsViewHolder>() {
|
||||
val TAG = "PlaylistsAdapter"
|
||||
@ -67,6 +70,18 @@ class PlaylistsAdapter(
|
||||
root.setOnClickListener {
|
||||
NavigationHelper.navigatePlaylist(root.context, playlist.id)
|
||||
}
|
||||
|
||||
root.setOnLongClickListener {
|
||||
val playlistOptionsDialog = PlaylistOptionsDialog(
|
||||
playlistId = playlist.id!!,
|
||||
isOwner = true
|
||||
)
|
||||
playlistOptionsDialog.show(
|
||||
childFragmentManager,
|
||||
PlaylistOptionsDialog::class.java.name
|
||||
)
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,6 +109,7 @@ class LibraryFragment : Fragment() {
|
||||
}
|
||||
val playlistsAdapter = PlaylistsAdapter(
|
||||
response.toMutableList(),
|
||||
childFragmentManager,
|
||||
requireActivity()
|
||||
)
|
||||
binding.playlistRecView.adapter = playlistsAdapter
|
||||
|
@ -61,8 +61,7 @@ class PlaylistFragment : Fragment() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
// load locally stored playlists with the auth api
|
||||
if (isPipedPlaylist()) RetrofitInstance.authApi.getPlaylist(playlistId!!)
|
||||
else RetrofitInstance.api.getPlaylist(playlistId!!)
|
||||
RetrofitInstance.authApi.getPlaylist(playlistId!!)
|
||||
} catch (e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
@ -82,8 +81,7 @@ class PlaylistFragment : Fragment() {
|
||||
|
||||
val user = PreferenceHelper.getUsername()
|
||||
// check whether the user owns the playlist
|
||||
isOwner = response.uploaderUrl == null &&
|
||||
response.uploader.equals(user, true)
|
||||
isOwner = response.uploaderUrl == null && response.uploader.equals(user, true)
|
||||
|
||||
// show playlist options
|
||||
binding.optionsMenu.setOnClickListener {
|
||||
@ -121,7 +119,7 @@ class PlaylistFragment : Fragment() {
|
||||
if (isOwner) {
|
||||
val itemTouchCallback = object : ItemTouchHelper.SimpleCallback(
|
||||
0,
|
||||
ItemTouchHelper.RIGHT
|
||||
ItemTouchHelper.LEFT
|
||||
) {
|
||||
override fun onMove(
|
||||
recyclerView: RecyclerView,
|
||||
@ -154,11 +152,10 @@ class PlaylistFragment : Fragment() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
// load locally stored playlists with the auth api
|
||||
if (isPipedPlaylist()) RetrofitInstance.authApi.getPlaylistNextPage(
|
||||
RetrofitInstance.authApi.getPlaylistNextPage(
|
||||
playlistId!!,
|
||||
nextPage!!
|
||||
)
|
||||
RetrofitInstance.api.getPlaylistNextPage(playlistId!!, nextPage!!)
|
||||
} catch (e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
@ -175,11 +172,6 @@ class PlaylistFragment : Fragment() {
|
||||
run()
|
||||
}
|
||||
|
||||
private fun isPipedPlaylist(): Boolean {
|
||||
val regex = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"
|
||||
return playlistId?.contains(regex) == true || isOwner
|
||||
}
|
||||
|
||||
private fun Fragment?.runOnUiThread(action: () -> Unit) {
|
||||
this ?: return
|
||||
if (!isAdded) return // Fragment not attached to an Activity
|
||||
|
@ -205,6 +205,7 @@ class BackgroundMode : Service() {
|
||||
nextStreamId = streams?.relatedStreams!![0].url.toID()
|
||||
}
|
||||
|
||||
return
|
||||
if (playlistId == null) return
|
||||
if (!this::autoPlayHelper.isInitialized) autoPlayHelper = AutoPlayHelper(playlistId!!)
|
||||
// search for the next videoId in the playlist
|
||||
|
@ -23,8 +23,8 @@ class AutoPlayHelper(
|
||||
return withContext(Dispatchers.IO) {
|
||||
// fetch the playlists or its nextPage's videos
|
||||
val playlist =
|
||||
if (playlistNextPage == null) RetrofitInstance.api.getPlaylist(playlistId)
|
||||
else RetrofitInstance.api.getPlaylistNextPage(playlistId, playlistNextPage!!)
|
||||
if (playlistNextPage == null) RetrofitInstance.authApi.getPlaylist(playlistId)
|
||||
else RetrofitInstance.authApi.getPlaylistNextPage(playlistId, playlistNextPage!!)
|
||||
// save the playlist urls to the list
|
||||
playlistStreamIds += playlist.relatedStreams!!.map { it.url.toID() }
|
||||
// save playlistNextPage for usage if video is not contained
|
||||
|
@ -77,6 +77,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:maxLines="2"
|
||||
app:layout_constraintEnd_toStartOf="@+id/delete_playlist"
|
||||
app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
@ -87,6 +88,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:maxLines="2"
|
||||
app:layout_constraintEnd_toStartOf="@+id/delete_playlist"
|
||||
app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail"
|
||||
app:layout_constraintTop_toBottomOf="@+id/playlist_title"
|
||||
|
Loading…
Reference in New Issue
Block a user