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