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.extensions.BaseFragment
|
||||
import com.github.libretube.models.SubscriptionsViewModel
|
||||
import com.github.libretube.obj.BottomSheetItem
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
import com.github.libretube.views.BottomSheet
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class SubscriptionsFragment : BaseFragment() {
|
||||
@ -107,15 +109,22 @@ class SubscriptionsFragment : BaseFragment() {
|
||||
private fun showSortDialog() {
|
||||
val sortOptions = resources.getStringArray(R.array.sortOptions)
|
||||
val sortOptionValues = resources.getStringArray(R.array.sortOptionsValues)
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.sort)
|
||||
.setItems(sortOptions) { _, index ->
|
||||
val items = mutableListOf<BottomSheetItem>()
|
||||
sortOptions.forEach {
|
||||
items += BottomSheetItem(
|
||||
it, R.drawable.ic_arrow_down
|
||||
)
|
||||
}
|
||||
|
||||
val bottomSheet = BottomSheet().apply {
|
||||
setItems(items) { index ->
|
||||
binding.sortTV.text = sortOptions[index]
|
||||
sortOrder = sortOptionValues[index]
|
||||
showFeed()
|
||||
}
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
bottomSheet.show(childFragmentManager, null)
|
||||
}
|
||||
|
||||
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.ViewGroup
|
||||
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.PlayerOptionsInterface
|
||||
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
|
||||
*/
|
||||
class PlayerOptionsBottomSheet : BottomSheetDialogFragment() {
|
||||
lateinit var binding: BottomSheetBinding
|
||||
lateinit var binding: PlayerOptionsBottomSheetBinding
|
||||
private lateinit var playerOptionsInterface: PlayerOptionsInterface
|
||||
private var onlinePlayerOptionsInterface: OnlinePlayerOptionsInterface? = null
|
||||
|
||||
@ -44,7 +44,7 @@ class PlayerOptionsBottomSheet : BottomSheetDialogFragment() {
|
||||
BottomSheetBehavior.STATE_EXPANDED
|
||||
}
|
||||
|
||||
binding = BottomSheetBinding.inflate(layoutInflater, container, false)
|
||||
binding = PlayerOptionsBottomSheetBinding.inflate(layoutInflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
|
@ -1,46 +1,34 @@
|
||||
<?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"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="7dp"
|
||||
android:paddingVertical="10dp">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/quality"
|
||||
style="@style/BottomSheetItem"
|
||||
android:text="@string/quality"
|
||||
app:drawableStartCompat="@drawable/ic_hd" />
|
||||
<FrameLayout
|
||||
android:id="@+id/standard_bottom_sheet"
|
||||
style="@style/Widget.Material3.BottomSheet"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/playbackSpeed"
|
||||
style="@style/BottomSheetItem"
|
||||
android:text="@string/playback_speed"
|
||||
app:drawableStartCompat="@drawable/ic_speed" />
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/captions"
|
||||
style="@style/BottomSheetItem"
|
||||
android:text="@string/captions"
|
||||
app:drawableStartCompat="@drawable/ic_caption" />
|
||||
<!-- Drag handle for accessibility -->
|
||||
<com.google.android.material.bottomsheet.BottomSheetDragHandleView
|
||||
android:id="@+id/drag_handle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/autoplay"
|
||||
style="@style/BottomSheetItem"
|
||||
android:text="@string/player_autoplay"
|
||||
app:drawableStartCompat="@drawable/ic_play" />
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/options_recycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/repeatMode"
|
||||
style="@style/BottomSheetItem"
|
||||
android:text="@string/repeat_mode"
|
||||
app:drawableStartCompat="@drawable/ic_repeat" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/resizeMode"
|
||||
style="@style/BottomSheetItem"
|
||||
android:text="@string/player_resize_mode"
|
||||
app:drawableStartCompat="@drawable/ic_aspect_ratio" />
|
||||
</FrameLayout>
|
||||
|
||||
</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