diff --git a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt index f6d5a05db..5f498bfdb 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt @@ -1,6 +1,7 @@ package com.github.libretube.ui.adapters import android.app.Activity +import android.content.Context import android.util.Log import android.view.LayoutInflater import android.view.View @@ -28,7 +29,6 @@ class PlaylistAdapter( private val videoFeed: MutableList, private val playlistId: String, private val isOwner: Boolean, - private val activity: Activity, private val childFragmentManager: FragmentManager ) : RecyclerView.Adapter() { @@ -69,16 +69,19 @@ class PlaylistAdapter( if (isOwner) { deletePlaylist.visibility = View.VISIBLE deletePlaylist.setOnClickListener { - removeFromPlaylist(position) + removeFromPlaylist(root.context, position) } } watchProgress.setWatchProgressLength(videoId, streamItem.duration!!) } } - fun removeFromPlaylist(position: Int) { + fun removeFromPlaylist(context: Context, position: Int) { videoFeed.removeAt(position) - activity.runOnUiThread { notifyDataSetChanged() } + (context as Activity).runOnUiThread { + notifyItemRemoved(position) + notifyItemRangeChanged(position, itemCount) + } CoroutineScope(Dispatchers.IO).launch { try { RetrofitInstance.authApi.removeFromPlaylist( diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt index e2bdb0c0f..580698e6a 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt @@ -1,5 +1,6 @@ package com.github.libretube.ui.fragments +import android.annotation.SuppressLint import android.os.Bundle import android.util.Log import android.view.LayoutInflater @@ -18,6 +19,8 @@ import com.github.libretube.extensions.toID import com.github.libretube.ui.adapters.PlaylistAdapter import com.github.libretube.ui.base.BaseFragment import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet +import com.github.libretube.util.ImageHelper +import com.github.libretube.util.NavigationHelper import retrofit2.HttpException import java.io.IOException @@ -58,6 +61,7 @@ class PlaylistFragment : BaseFragment() { fetchPlaylist() } + @SuppressLint("SetTextI18n") private fun fetchPlaylist() { lifecycleScope.launchWhenCreated { val response = try { @@ -79,27 +83,31 @@ class PlaylistFragment : BaseFragment() { playlistName = response.name isLoading = false runOnUiThread { + ImageHelper.loadImage(response.thumbnailUrl, binding.thumbnail) binding.playlistProgress.visibility = View.GONE binding.playlistName.text = response.name - binding.uploader.text = response.uploader - binding.videoCount.text = - getString(R.string.videoCount, response.videos.toString()) + binding.playlistInfo.text = response.uploader + " • " + getString(R.string.videoCount, response.videos.toString()) // show playlist options binding.optionsMenu.setOnClickListener { - val optionsDialog = - PlaylistOptionsBottomSheet(playlistId!!, playlistName!!, isOwner) - optionsDialog.show( + PlaylistOptionsBottomSheet(playlistId!!, playlistName!!, isOwner).show( childFragmentManager, PlaylistOptionsBottomSheet::class.java.name ) } + binding.playAll.setOnClickListener { + NavigationHelper.navigateVideo( + requireContext(), + response.relatedStreams?.first()?.toID(), + playlistId + ) + } + playlistAdapter = PlaylistAdapter( - response.relatedStreams!!.toMutableList(), + response.relatedStreams.orEmpty().toMutableList(), playlistId!!, isOwner, - requireActivity(), childFragmentManager ) @@ -107,11 +115,11 @@ class PlaylistFragment : BaseFragment() { playlistAdapter!!.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { override fun onChanged() { - binding.videoCount.text = - getString( - R.string.videoCount, - playlistAdapter!!.itemCount.toString() - ) + binding.playlistInfo.text = + binding.playlistInfo.text.split(" • ").first() + " • " + getString( + R.string.videoCount, + playlistAdapter!!.itemCount.toString() + ) } }) @@ -150,7 +158,7 @@ class PlaylistFragment : BaseFragment() { direction: Int ) { val position = viewHolder.absoluteAdapterPosition - playlistAdapter!!.removeFromPlaylist(position) + playlistAdapter!!.removeFromPlaylist(requireContext(), position) } } diff --git a/app/src/main/res/layout/fragment_playlist.xml b/app/src/main/res/layout/fragment_playlist.xml index c39957aa3..c3a7894e7 100644 --- a/app/src/main/res/layout/fragment_playlist.xml +++ b/app/src/main/res/layout/fragment_playlist.xml @@ -1,5 +1,6 @@ + + + android:paddingHorizontal="15dp" + android:layout_marginTop="8dp"> - + android:layout_marginVertical="10dp" + android:orientation="horizontal"> + + + + + + Are you sure you want to unsubscribe %1$s? Confirm unsubscribing Show a confirmation dialog before unsubscribing. + Shuffle + Play all Download Service diff --git a/app/src/main/res/values/style.xml b/app/src/main/res/values/style.xml index 265f3a9c4..a78db0a98 100644 --- a/app/src/main/res/values/style.xml +++ b/app/src/main/res/values/style.xml @@ -195,12 +195,12 @@ -