mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
bottom sheet for sorting
This commit is contained in:
parent
bb16a5e823
commit
915795eaf0
@ -0,0 +1,41 @@
|
|||||||
|
package com.github.libretube.adapters
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.github.libretube.databinding.BottomSheetItemBinding
|
||||||
|
import com.github.libretube.obj.BottomSheetItem
|
||||||
|
|
||||||
|
class BottomSheetAdapter(
|
||||||
|
private val items: List<BottomSheetItem>,
|
||||||
|
private val listener: (index: Int) -> Unit
|
||||||
|
) : RecyclerView.Adapter<BottomSheetViewHolder>() {
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BottomSheetViewHolder {
|
||||||
|
val binding = BottomSheetItemBinding.inflate(
|
||||||
|
LayoutInflater.from(parent.context),
|
||||||
|
parent,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
return BottomSheetViewHolder(binding)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: BottomSheetViewHolder, position: Int) {
|
||||||
|
val item = items[position]
|
||||||
|
holder.binding.apply {
|
||||||
|
title.text = item.title
|
||||||
|
drawable.setImageResource(item.drawable)
|
||||||
|
|
||||||
|
root.setOnClickListener {
|
||||||
|
listener.invoke(position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int {
|
||||||
|
return items.size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class BottomSheetViewHolder(
|
||||||
|
val binding: BottomSheetItemBinding
|
||||||
|
) : RecyclerView.ViewHolder(binding.root)
|
@ -16,7 +16,9 @@ import com.github.libretube.constants.PreferenceKeys
|
|||||||
import com.github.libretube.databinding.FragmentSubscriptionsBinding
|
import com.github.libretube.databinding.FragmentSubscriptionsBinding
|
||||||
import com.github.libretube.extensions.BaseFragment
|
import com.github.libretube.extensions.BaseFragment
|
||||||
import com.github.libretube.models.SubscriptionsViewModel
|
import com.github.libretube.models.SubscriptionsViewModel
|
||||||
|
import com.github.libretube.obj.BottomSheetItem
|
||||||
import com.github.libretube.util.PreferenceHelper
|
import com.github.libretube.util.PreferenceHelper
|
||||||
|
import com.github.libretube.views.BottomSheet
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
|
||||||
class SubscriptionsFragment : BaseFragment() {
|
class SubscriptionsFragment : BaseFragment() {
|
||||||
@ -107,15 +109,22 @@ class SubscriptionsFragment : BaseFragment() {
|
|||||||
private fun showSortDialog() {
|
private fun showSortDialog() {
|
||||||
val sortOptions = resources.getStringArray(R.array.sortOptions)
|
val sortOptions = resources.getStringArray(R.array.sortOptions)
|
||||||
val sortOptionValues = resources.getStringArray(R.array.sortOptionsValues)
|
val sortOptionValues = resources.getStringArray(R.array.sortOptionsValues)
|
||||||
MaterialAlertDialogBuilder(requireContext())
|
val items = mutableListOf<BottomSheetItem>()
|
||||||
.setTitle(R.string.sort)
|
sortOptions.forEach {
|
||||||
.setItems(sortOptions) { _, index ->
|
items += BottomSheetItem(
|
||||||
|
it, R.drawable.ic_arrow_down
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val bottomSheet = BottomSheet().apply {
|
||||||
|
setItems(items) { index ->
|
||||||
binding.sortTV.text = sortOptions[index]
|
binding.sortTV.text = sortOptions[index]
|
||||||
sortOrder = sortOptionValues[index]
|
sortOrder = sortOptionValues[index]
|
||||||
showFeed()
|
showFeed()
|
||||||
}
|
}
|
||||||
.setNegativeButton(R.string.cancel, null)
|
}
|
||||||
.show()
|
|
||||||
|
bottomSheet.show(childFragmentManager, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showFeed() {
|
private fun showFeed() {
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
package com.github.libretube.obj
|
||||||
|
|
||||||
|
data class BottomSheetItem(
|
||||||
|
val title: String,
|
||||||
|
val drawable: Int
|
||||||
|
)
|
51
app/src/main/java/com/github/libretube/views/BottomSheet.kt
Normal file
51
app/src/main/java/com/github/libretube/views/BottomSheet.kt
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package com.github.libretube.views
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import com.github.libretube.adapters.BottomSheetAdapter
|
||||||
|
import com.github.libretube.databinding.BottomSheetBinding
|
||||||
|
import com.github.libretube.obj.BottomSheetItem
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||||
|
|
||||||
|
class BottomSheet : BottomSheetDialogFragment() {
|
||||||
|
private lateinit var items: List<BottomSheetItem>
|
||||||
|
private lateinit var listener: (index: Int) -> Unit
|
||||||
|
private lateinit var binding: BottomSheetBinding
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View {
|
||||||
|
dialog!!.setOnShowListener { dialog ->
|
||||||
|
val d = dialog as BottomSheetDialog
|
||||||
|
val bottomSheetInternal =
|
||||||
|
d.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)!!
|
||||||
|
BottomSheetBehavior.from(bottomSheetInternal).state =
|
||||||
|
BottomSheetBehavior.STATE_EXPANDED
|
||||||
|
}
|
||||||
|
|
||||||
|
binding = BottomSheetBinding.inflate(layoutInflater)
|
||||||
|
return binding.root
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
binding.optionsRecycler.layoutManager = LinearLayoutManager(requireContext())
|
||||||
|
binding.optionsRecycler.adapter = BottomSheetAdapter(items, listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setItems(items: List<BottomSheetItem>, listener: (index: Int) -> Unit) {
|
||||||
|
this.items = items
|
||||||
|
this.listener = { index ->
|
||||||
|
listener.invoke(index)
|
||||||
|
dialog?.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import com.github.libretube.databinding.BottomSheetBinding
|
import com.github.libretube.databinding.PlayerOptionsBottomSheetBinding
|
||||||
import com.github.libretube.interfaces.OnlinePlayerOptionsInterface
|
import com.github.libretube.interfaces.OnlinePlayerOptionsInterface
|
||||||
import com.github.libretube.interfaces.PlayerOptionsInterface
|
import com.github.libretube.interfaces.PlayerOptionsInterface
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
@ -16,7 +16,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
|||||||
* Bottom Sheet including all the player options
|
* Bottom Sheet including all the player options
|
||||||
*/
|
*/
|
||||||
class PlayerOptionsBottomSheet : BottomSheetDialogFragment() {
|
class PlayerOptionsBottomSheet : BottomSheetDialogFragment() {
|
||||||
lateinit var binding: BottomSheetBinding
|
lateinit var binding: PlayerOptionsBottomSheetBinding
|
||||||
private lateinit var playerOptionsInterface: PlayerOptionsInterface
|
private lateinit var playerOptionsInterface: PlayerOptionsInterface
|
||||||
private var onlinePlayerOptionsInterface: OnlinePlayerOptionsInterface? = null
|
private var onlinePlayerOptionsInterface: OnlinePlayerOptionsInterface? = null
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ class PlayerOptionsBottomSheet : BottomSheetDialogFragment() {
|
|||||||
BottomSheetBehavior.STATE_EXPANDED
|
BottomSheetBehavior.STATE_EXPANDED
|
||||||
}
|
}
|
||||||
|
|
||||||
binding = BottomSheetBinding.inflate(layoutInflater, container, false)
|
binding = PlayerOptionsBottomSheetBinding.inflate(layoutInflater, container, false)
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,46 +1,34 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
android:paddingHorizontal="7dp"
|
|
||||||
android:paddingVertical="10dp">
|
|
||||||
|
|
||||||
<TextView
|
<FrameLayout
|
||||||
android:id="@+id/quality"
|
android:id="@+id/standard_bottom_sheet"
|
||||||
style="@style/BottomSheetItem"
|
style="@style/Widget.Material3.BottomSheet"
|
||||||
android:text="@string/quality"
|
android:layout_width="match_parent"
|
||||||
app:drawableStartCompat="@drawable/ic_hd" />
|
android:layout_height="match_parent"
|
||||||
|
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:id="@+id/playbackSpeed"
|
android:orientation="vertical"
|
||||||
style="@style/BottomSheetItem"
|
android:layout_width="match_parent"
|
||||||
android:text="@string/playback_speed"
|
android:layout_height="wrap_content" >
|
||||||
app:drawableStartCompat="@drawable/ic_speed" />
|
|
||||||
|
|
||||||
<TextView
|
<!-- Drag handle for accessibility -->
|
||||||
android:id="@+id/captions"
|
<com.google.android.material.bottomsheet.BottomSheetDragHandleView
|
||||||
style="@style/BottomSheetItem"
|
android:id="@+id/drag_handle"
|
||||||
android:text="@string/captions"
|
android:layout_width="match_parent"
|
||||||
app:drawableStartCompat="@drawable/ic_caption" />
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
<TextView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/autoplay"
|
android:id="@+id/options_recycler"
|
||||||
style="@style/BottomSheetItem"
|
android:layout_width="match_parent"
|
||||||
android:text="@string/player_autoplay"
|
android:layout_height="wrap_content" />
|
||||||
app:drawableStartCompat="@drawable/ic_play" />
|
|
||||||
|
|
||||||
<TextView
|
</LinearLayout>
|
||||||
android:id="@+id/repeatMode"
|
|
||||||
style="@style/BottomSheetItem"
|
|
||||||
android:text="@string/repeat_mode"
|
|
||||||
app:drawableStartCompat="@drawable/ic_repeat" />
|
|
||||||
|
|
||||||
<TextView
|
</FrameLayout>
|
||||||
android:id="@+id/resizeMode"
|
|
||||||
style="@style/BottomSheetItem"
|
|
||||||
android:text="@string/player_resize_mode"
|
|
||||||
app:drawableStartCompat="@drawable/ic_aspect_ratio" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
23
app/src/main/res/layout/bottom_sheet_item.xml
Normal file
23
app/src/main/res/layout/bottom_sheet_item.xml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:padding="10dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/drawable"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
tools:src="@drawable/ic_download" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:text="Option" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
46
app/src/main/res/layout/player_options_bottom_sheet.xml
Normal file
46
app/src/main/res/layout/player_options_bottom_sheet.xml
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingHorizontal="7dp"
|
||||||
|
android:paddingVertical="10dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/quality"
|
||||||
|
style="@style/BottomSheetItem"
|
||||||
|
android:text="@string/quality"
|
||||||
|
app:drawableStartCompat="@drawable/ic_hd" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/playbackSpeed"
|
||||||
|
style="@style/BottomSheetItem"
|
||||||
|
android:text="@string/playback_speed"
|
||||||
|
app:drawableStartCompat="@drawable/ic_speed" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/captions"
|
||||||
|
style="@style/BottomSheetItem"
|
||||||
|
android:text="@string/captions"
|
||||||
|
app:drawableStartCompat="@drawable/ic_caption" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/autoplay"
|
||||||
|
style="@style/BottomSheetItem"
|
||||||
|
android:text="@string/player_autoplay"
|
||||||
|
app:drawableStartCompat="@drawable/ic_play" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/repeatMode"
|
||||||
|
style="@style/BottomSheetItem"
|
||||||
|
android:text="@string/repeat_mode"
|
||||||
|
app:drawableStartCompat="@drawable/ic_repeat" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/resizeMode"
|
||||||
|
style="@style/BottomSheetItem"
|
||||||
|
android:text="@string/player_resize_mode"
|
||||||
|
app:drawableStartCompat="@drawable/ic_aspect_ratio" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user