diff --git a/app/src/main/java/com/github/libretube/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/PlaylistFragment.kt index 16ed078ad..f31dffb7b 100644 --- a/app/src/main/java/com/github/libretube/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/PlaylistFragment.kt @@ -13,8 +13,8 @@ import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.github.libretube.adapters.PlaylistAdapter -import java.io.IOException import retrofit2.HttpException +import java.io.IOException class PlaylistFragment : Fragment() { private var playlist_id: String? = null @@ -80,7 +80,8 @@ class PlaylistFragment : Fragment() { response.relatedStreams!!.toMutableList(), playlist_id!!, isOwner, - requireActivity() + requireActivity(), + childFragmentManager ) view.findViewById(R.id.playlist_recView).adapter = playlistAdapter val scrollView = view.findViewById(R.id.playlist_scrollview) diff --git a/app/src/main/java/com/github/libretube/VideoOptionsDialog.kt b/app/src/main/java/com/github/libretube/VideoOptionsDialog.kt index 8675f137b..eb0c3a9f6 100644 --- a/app/src/main/java/com/github/libretube/VideoOptionsDialog.kt +++ b/app/src/main/java/com/github/libretube/VideoOptionsDialog.kt @@ -7,7 +7,6 @@ import android.os.Bundle import android.widget.ArrayAdapter import android.widget.Toast import androidx.fragment.app.DialogFragment -import androidx.preference.PreferenceManager import com.google.android.material.dialog.MaterialAlertDialogBuilder /** @@ -51,9 +50,8 @@ class VideoOptionsDialog(private val videoId: String, context: Context) : Dialog } // Add Video to Playlist Dialog 1 -> { - val sharedPreferences = PreferenceManager - .getDefaultSharedPreferences(requireContext()) - val token = sharedPreferences.getString("token", "") + val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE) + val token = sharedPref?.getString("token", "") if (token != "") { val newFragment = AddtoPlaylistDialog() val bundle = Bundle() diff --git a/app/src/main/java/com/github/libretube/adapters/PlaylistAdapter.kt b/app/src/main/java/com/github/libretube/adapters/PlaylistAdapter.kt index bbf6e79b2..403979413 100644 --- a/app/src/main/java/com/github/libretube/adapters/PlaylistAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/PlaylistAdapter.kt @@ -11,23 +11,26 @@ import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView import androidx.appcompat.app.AppCompatActivity +import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.RecyclerView import com.github.libretube.PlayerFragment import com.github.libretube.R import com.github.libretube.RetrofitInstance +import com.github.libretube.VideoOptionsDialog import com.github.libretube.obj.PlaylistId import com.github.libretube.obj.StreamItem import com.squareup.picasso.Picasso -import java.io.IOException import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import retrofit2.HttpException +import java.io.IOException class PlaylistAdapter( private val videoFeed: MutableList, private val playlistId: String, private val isOwner: Boolean, - private val activity: Activity + private val activity: Activity, + private val childFragmentManager: FragmentManager ) : RecyclerView.Adapter() { private val TAG = "PlaylistAdapter" override fun getItemCount(): Int { @@ -66,6 +69,13 @@ class PlaylistAdapter( .replace(R.id.container, frag) .commitNow() } + holder.v.setOnLongClickListener { + val videoId = streamItem.url!!.replace("/watch?v=", "") + VideoOptionsDialog(videoId, holder.v.context) + .show(childFragmentManager, VideoOptionsDialog.TAG) + true + } + if (isOwner) { val delete = holder.v.findViewById(R.id.delete_playlist) delete.visibility = View.VISIBLE