mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
Added the options dialog
Added a MaterialAlertDialog with the "background mode" option, needed to pass the childFragmentManager to display the alert.
This commit is contained in:
parent
9c906ee973
commit
9c72b5ac9c
@ -80,7 +80,7 @@ class Home : Fragment() {
|
|||||||
}
|
}
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
progressBar.visibility = View.GONE
|
progressBar.visibility = View.GONE
|
||||||
recyclerView.adapter = TrendingAdapter(response)
|
recyclerView.adapter = TrendingAdapter(response, childFragmentManager)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -476,7 +476,7 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
relatedRecView.adapter = TrendingAdapter(response.relatedStreams!!)
|
relatedRecView.adapter = TrendingAdapter(response.relatedStreams!!, childFragmentManager)
|
||||||
view.findViewById<TextView>(R.id.player_description).text =
|
view.findViewById<TextView>(R.id.player_description).text =
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
Html.fromHtml(response.description, Html.FROM_HTML_MODE_COMPACT)
|
Html.fromHtml(response.description, Html.FROM_HTML_MODE_COMPACT)
|
||||||
|
42
app/src/main/java/com/github/libretube/VideoOptionsDialog.kt
Normal file
42
app/src/main/java/com/github/libretube/VideoOptionsDialog.kt
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package com.github.libretube
|
||||||
|
|
||||||
|
import android.app.Dialog
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
|
import androidx.fragment.app.DialogFragment
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
|
||||||
|
class VideoOptionsDialog : DialogFragment() {
|
||||||
|
/**
|
||||||
|
* List that stores the different menu options.
|
||||||
|
*/
|
||||||
|
private val list = arrayListOf("Background mode")
|
||||||
|
|
||||||
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
|
return MaterialAlertDialogBuilder(requireContext())
|
||||||
|
.setAdapter(
|
||||||
|
ArrayAdapter(
|
||||||
|
requireContext(),
|
||||||
|
R.layout.video_options_dialog_item,
|
||||||
|
list
|
||||||
|
)
|
||||||
|
) { _, which ->
|
||||||
|
// For now, this checks the position of the option with the position that is in the
|
||||||
|
// list. I don't like it, but we will do like this for now.
|
||||||
|
when (which) {
|
||||||
|
// This for example will be the "Background mode" option
|
||||||
|
1 -> {
|
||||||
|
TODO("Implement the background mode option")
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
this.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TAG = "VideoOptionsDialog"
|
||||||
|
}
|
||||||
|
}
|
@ -10,15 +10,19 @@ import android.widget.TextView
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.constraintlayout.motion.widget.MotionLayout
|
import androidx.constraintlayout.motion.widget.MotionLayout
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.github.libretube.MainActivity
|
import com.github.libretube.*
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
import com.github.libretube.PlayerFragment
|
import com.github.libretube.PlayerFragment
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.obj.StreamItem
|
import com.github.libretube.obj.StreamItem
|
||||||
import com.github.libretube.formatShort
|
import com.github.libretube.formatShort
|
||||||
|
|
||||||
class TrendingAdapter(private val videoFeed: List<StreamItem>): RecyclerView.Adapter<CustomViewHolder>() {
|
class TrendingAdapter(
|
||||||
|
private val videoFeed: List<StreamItem>,
|
||||||
|
private val childFragmentManager: FragmentManager
|
||||||
|
) : RecyclerView.Adapter<CustomViewHolder>() {
|
||||||
override fun getItemCount(): Int {
|
override fun getItemCount(): Int {
|
||||||
return videoFeed.size
|
return videoFeed.size
|
||||||
}
|
}
|
||||||
@ -73,7 +77,10 @@ class TrendingAdapter(private val videoFeed: List<StreamItem>): RecyclerView.Ada
|
|||||||
.replace(R.id.container, frag)
|
.replace(R.id.container, frag)
|
||||||
.commitNow()
|
.commitNow()
|
||||||
}
|
}
|
||||||
holder.v.setOnLongClickListener { TODO("Not yet implemented") }
|
holder.v.setOnLongClickListener {
|
||||||
|
VideoOptionsDialog().show(childFragmentManager, VideoOptionsDialog.TAG)
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class CustomViewHolder(val v: View): RecyclerView.ViewHolder(v){
|
class CustomViewHolder(val v: View): RecyclerView.ViewHolder(v){
|
||||||
|
6
app/src/main/res/layout/video_options_dialog_item.xml
Normal file
6
app/src/main/res/layout/video_options_dialog_item.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
</TextView>
|
Loading…
Reference in New Issue
Block a user