expand all sheets

This commit is contained in:
Bnyro 2022-11-05 15:46:02 +01:00
parent 7704b8f40b
commit b78b8a8bb6
4 changed files with 30 additions and 26 deletions

View File

@ -1,22 +1,16 @@
package com.github.libretube.ui.sheets
import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.libretube.databinding.BottomSheetBinding
import com.github.libretube.obj.BottomSheetItem
import com.github.libretube.ui.adapters.BottomSheetAdapter
import com.google.android.material.R
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
open class BaseBottomSheet : BottomSheetDialogFragment() {
open class BaseBottomSheet : ExpandedBottomSheet() {
private lateinit var items: List<BottomSheetItem>
private lateinit var listener: (index: Int) -> Unit
private lateinit var binding: BottomSheetBinding
@ -37,21 +31,6 @@ open class BaseBottomSheet : BottomSheetDialogFragment() {
binding.optionsRecycler.adapter = BottomSheetAdapter(items, listener)
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
dialog.setOnShowListener {
(it as BottomSheetDialog).let { d ->
(d.findViewById<View>(R.id.design_bottom_sheet) as FrameLayout?)?.let {
BottomSheetBehavior.from(it).state =
BottomSheetBehavior.STATE_EXPANDED
}
}
}
return dialog
}
fun setItems(items: List<BottomSheetItem>, listener: ((index: Int) -> Unit)?) = apply {
this.items = items
this.listener = { index ->

View File

@ -0,0 +1,27 @@
package com.github.libretube.ui.sheets
import android.app.Dialog
import android.os.Bundle
import android.view.View
import android.widget.FrameLayout
import com.google.android.material.R
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
open class ExpandedBottomSheet : BottomSheetDialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
dialog.setOnShowListener {
(it as BottomSheetDialog).let { d ->
(d.findViewById<View>(R.id.design_bottom_sheet) as FrameLayout?)?.let {
BottomSheetBehavior.from(it).state =
BottomSheetBehavior.STATE_EXPANDED
}
}
}
return dialog
}
}

View File

@ -9,11 +9,10 @@ import com.github.libretube.databinding.PlaybackBottomSheetBinding
import com.github.libretube.extensions.round
import com.google.android.exoplayer2.PlaybackParameters
import com.google.android.exoplayer2.Player
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
class PlaybackSpeedSheet(
private val player: Player
) : BottomSheetDialogFragment() {
) : ExpandedBottomSheet() {
private lateinit var binding: PlaybackBottomSheetBinding
override fun onCreateView(

View File

@ -11,9 +11,8 @@ import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.QueueBottomSheetBinding
import com.github.libretube.ui.adapters.PlayingQueueAdapter
import com.github.libretube.util.PlayingQueue
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
class PlayingQueueSheet : BottomSheetDialogFragment() {
class PlayingQueueSheet : ExpandedBottomSheet() {
private lateinit var binding: QueueBottomSheetBinding
override fun onCreateView(