diff --git a/app/src/main/java/com/github/libretube/adapters/PlaylistsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/PlaylistsAdapter.kt index de7d31e79..1e53cbaf6 100644 --- a/app/src/main/java/com/github/libretube/adapters/PlaylistsAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/PlaylistsAdapter.kt @@ -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, + private val childFragmentManager: FragmentManager, private val activity: Activity ) : RecyclerView.Adapter() { 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 + } } } diff --git a/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt b/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt index 67b348a2a..b1cc76c99 100644 --- a/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt @@ -109,6 +109,7 @@ class LibraryFragment : Fragment() { } val playlistsAdapter = PlaylistsAdapter( response.toMutableList(), + childFragmentManager, requireActivity() ) binding.playlistRecView.adapter = playlistsAdapter diff --git a/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt index c1f435021..a11098bd5 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt @@ -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 diff --git a/app/src/main/java/com/github/libretube/services/BackgroundMode.kt b/app/src/main/java/com/github/libretube/services/BackgroundMode.kt index 0a70a285e..6c0e9dc17 100644 --- a/app/src/main/java/com/github/libretube/services/BackgroundMode.kt +++ b/app/src/main/java/com/github/libretube/services/BackgroundMode.kt @@ -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 diff --git a/app/src/main/java/com/github/libretube/util/AutoPlayHelper.kt b/app/src/main/java/com/github/libretube/util/AutoPlayHelper.kt index d89a146ac..87d416d40 100644 --- a/app/src/main/java/com/github/libretube/util/AutoPlayHelper.kt +++ b/app/src/main/java/com/github/libretube/util/AutoPlayHelper.kt @@ -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 diff --git a/app/src/main/res/layout/playlist_row.xml b/app/src/main/res/layout/playlist_row.xml index 1846bb9d7..9a69f8594 100644 --- a/app/src/main/res/layout/playlist_row.xml +++ b/app/src/main/res/layout/playlist_row.xml @@ -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"