diff --git a/app/src/main/java/com/github/libretube/ui/sheets/BaseBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/BaseBottomSheet.kt index fc1f1ba43..2c432d355 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/BaseBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/BaseBottomSheet.kt @@ -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 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(R.id.design_bottom_sheet) as FrameLayout?)?.let { - BottomSheetBehavior.from(it).state = - BottomSheetBehavior.STATE_EXPANDED - } - } - } - - return dialog - } - fun setItems(items: List, listener: ((index: Int) -> Unit)?) = apply { this.items = items this.listener = { index -> diff --git a/app/src/main/java/com/github/libretube/ui/sheets/ExpandedBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/ExpandedBottomSheet.kt new file mode 100644 index 000000000..1f2379dde --- /dev/null +++ b/app/src/main/java/com/github/libretube/ui/sheets/ExpandedBottomSheet.kt @@ -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(R.id.design_bottom_sheet) as FrameLayout?)?.let { + BottomSheetBehavior.from(it).state = + BottomSheetBehavior.STATE_EXPANDED + } + } + } + + return dialog + } +} diff --git a/app/src/main/java/com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt index c0d19d559..33f8ac00f 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt @@ -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( diff --git a/app/src/main/java/com/github/libretube/ui/sheets/PlayingQueueSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/PlayingQueueSheet.kt index 8b89871e0..69f575469 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/PlayingQueueSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/PlayingQueueSheet.kt @@ -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(