added video options dialog to search

This commit is contained in:
Bnyro 2022-05-30 15:43:55 +02:00
parent cc0219c61f
commit a42d5f64e2
3 changed files with 33 additions and 14 deletions

View File

@ -27,11 +27,11 @@ import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.adapters.SearchAdapter
import com.github.libretube.adapters.SearchHistoryAdapter
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.io.IOException
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import retrofit2.HttpException
import java.io.IOException
class SearchFragment : Fragment() {
private val TAG = "SearchFragment"
@ -229,7 +229,7 @@ class SearchFragment : Fragment() {
nextPage = response.nextpage
if (response.items!!.isNotEmpty()) {
runOnUiThread {
searchAdapter = SearchAdapter(response.items)
searchAdapter = SearchAdapter(response.items, childFragmentManager)
searchRecView.adapter = searchAdapter
}
}

View File

@ -4,7 +4,9 @@ import android.app.Dialog
import android.content.Context
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
/**
@ -47,11 +49,17 @@ class VideoOptionsDialog(private val videoId: String, context: Context) : Dialog
}
// Add Video to Playlist Dialog
1 -> {
val newFragment = AddtoPlaylistDialog()
var bundle = Bundle()
bundle.putString("videoId", videoId)
newFragment.arguments = bundle
newFragment.show(parentFragmentManager, "AddToPlaylist")
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
val token = sharedPreferences.getString("token", "")
if (token != "") {
val newFragment = AddtoPlaylistDialog()
var bundle = Bundle()
bundle.putString("videoId", videoId)
newFragment.arguments = bundle
newFragment.show(parentFragmentManager, "AddToPlaylist")
} else {
Toast.makeText(context, R.string.login_first, Toast.LENGTH_SHORT).show()
}
}
else -> {
dialog.dismiss()

View File

@ -9,15 +9,17 @@ import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.MainActivity
import com.github.libretube.PlayerFragment
import com.github.libretube.R
import com.github.libretube.formatShort
import com.github.libretube.*
import com.github.libretube.obj.SearchItem
import com.squareup.picasso.Picasso
import kotlinx.coroutines.NonDisposableHandle.parent
class SearchAdapter(private val searchItems: MutableList<SearchItem>) :
class SearchAdapter(
private val searchItems: MutableList<SearchItem>,
private val childFragmentManager: FragmentManager
) :
RecyclerView.Adapter<CustomViewHolder1>() {
fun updateItems(newItems: List<SearchItem>) {
@ -39,7 +41,7 @@ class SearchAdapter(private val searchItems: MutableList<SearchItem>) :
}
val layoutInflater = LayoutInflater.from(parent.context)
val cell = layoutInflater.inflate(layout, parent, false)
return CustomViewHolder1(cell)
return CustomViewHolder1(cell, childFragmentManager)
}
override fun onBindViewHolder(holder: CustomViewHolder1, position: Int) {
@ -56,7 +58,10 @@ class SearchAdapter(private val searchItems: MutableList<SearchItem>) :
}
}
class CustomViewHolder1(private val v: View) : RecyclerView.ViewHolder(v) {
class CustomViewHolder1(
private val v: View,
private val childFragmentManager: FragmentManager
) : RecyclerView.ViewHolder(v) {
private fun bindWatch(item: SearchItem) {
val thumbnailImage = v.findViewById<ImageView>(R.id.search_thumbnail)
@ -90,6 +95,12 @@ class CustomViewHolder1(private val v: View) : RecyclerView.ViewHolder(v) {
.replace(R.id.container, frag)
.commitNow()
}
v.setOnLongClickListener {
val videoId = item.url!!.replace("/watch?v=", "")
VideoOptionsDialog(videoId, v.context)
.show(childFragmentManager, VideoOptionsDialog.TAG)
true
}
channelImage.setOnClickListener {
val activity = v.context as MainActivity
val bundle = bundleOf("channel_id" to item.uploaderUrl)