Refactor BaseBottomSheetDialog to set maxWidth with newer API

This commit is contained in:
arkon 2021-05-19 22:20:32 -04:00
parent 17c321286d
commit 940c5b3838
7 changed files with 55 additions and 39 deletions

View File

@ -4,6 +4,7 @@ import android.app.Activity
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
@ -14,23 +15,20 @@ import eu.kanade.tachiyomi.widget.sheet.BaseBottomSheetDialog
class SourceFilterSheet( class SourceFilterSheet(
activity: Activity, activity: Activity,
onFilterClicked: () -> Unit, private val onFilterClicked: () -> Unit,
onResetClicked: () -> Unit private val onResetClicked: () -> Unit
) : BaseBottomSheetDialog(activity) { ) : BaseBottomSheetDialog(activity) {
private var filterNavView: FilterNavigationView = FilterNavigationView(activity) private var filterNavView: FilterNavigationView = FilterNavigationView(activity)
private val sheetBehavior: BottomSheetBehavior<*>
init { override fun createView(inflater: LayoutInflater): View {
filterNavView.onFilterClicked = { filterNavView.onFilterClicked = {
onFilterClicked() onFilterClicked()
this.dismiss() this.dismiss()
} }
filterNavView.onResetClicked = onResetClicked filterNavView.onResetClicked = onResetClicked
setContentView(filterNavView) return filterNavView
sheetBehavior = BottomSheetBehavior.from(filterNavView.parent as ViewGroup)
} }
override fun show() { override fun show() {

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.ui.manga.chapter package eu.kanade.tachiyomi.ui.manga.chapter
import android.content.Context import android.content.Context
import android.os.Bundle
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import androidx.core.view.isVisible import androidx.core.view.isVisible
@ -16,21 +17,18 @@ import eu.kanade.tachiyomi.widget.sheet.TabbedBottomSheetDialog
class ChaptersSettingsSheet( class ChaptersSettingsSheet(
private val router: Router, private val router: Router,
private val presenter: MangaPresenter, private val presenter: MangaPresenter,
onGroupClickListener: (ExtendedNavigationView.Group) -> Unit private val onGroupClickListener: (ExtendedNavigationView.Group) -> Unit
) : TabbedBottomSheetDialog(router.activity!!) { ) : TabbedBottomSheetDialog(router.activity!!) {
val filters: Filter val filters = Filter(router.activity!!)
private val sort: Sort private val sort = Sort(router.activity!!)
private val display: Display private val display = Display(router.activity!!)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
init {
filters = Filter(router.activity!!)
filters.onGroupClicked = onGroupClickListener filters.onGroupClicked = onGroupClickListener
sort = Sort(router.activity!!)
sort.onGroupClicked = onGroupClickListener sort.onGroupClicked = onGroupClickListener
display = Display(router.activity!!)
display.onGroupClicked = onGroupClickListener display.onGroupClicked = onGroupClickListener
binding.menu.isVisible = true binding.menu.isVisible = true

View File

@ -1,7 +1,8 @@
package eu.kanade.tachiyomi.ui.manga.track package eu.kanade.tachiyomi.ui.manga.track
import android.os.Bundle import android.os.Bundle
import android.view.ViewGroup import android.view.LayoutInflater
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
@ -23,22 +24,20 @@ class TrackSheet(
private lateinit var binding: TrackControllerBinding private lateinit var binding: TrackControllerBinding
private lateinit var sheetBehavior: BottomSheetBehavior<*>
private lateinit var adapter: TrackAdapter private lateinit var adapter: TrackAdapter
override fun createView(inflater: LayoutInflater): View {
binding = TrackControllerBinding.inflate(layoutInflater)
return binding.root
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = TrackControllerBinding.inflate(layoutInflater)
setContentView(binding.root)
adapter = TrackAdapter(this) adapter = TrackAdapter(this)
binding.trackRecycler.layoutManager = LinearLayoutManager(context) binding.trackRecycler.layoutManager = LinearLayoutManager(context)
binding.trackRecycler.adapter = adapter binding.trackRecycler.adapter = adapter
sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup)
adapter.items = controller.presenter.trackList adapter.items = controller.presenter.trackList
} }

View File

@ -1,5 +1,7 @@
package eu.kanade.tachiyomi.ui.reader package eu.kanade.tachiyomi.ui.reader
import android.view.LayoutInflater
import android.view.View
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.ReaderPageSheetBinding import eu.kanade.tachiyomi.databinding.ReaderPageSheetBinding
@ -15,14 +17,16 @@ class ReaderPageSheet(
private val page: ReaderPage private val page: ReaderPage
) : BaseBottomSheetDialog(activity) { ) : BaseBottomSheetDialog(activity) {
private val binding = ReaderPageSheetBinding.inflate(activity.layoutInflater, null, false) private lateinit var binding: ReaderPageSheetBinding
init { override fun createView(inflater: LayoutInflater): View {
setContentView(binding.root) binding = ReaderPageSheetBinding.inflate(activity.layoutInflater, null, false)
binding.setAsCoverLayout.setOnClickListener { setAsCover() } binding.setAsCoverLayout.setOnClickListener { setAsCover() }
binding.shareLayout.setOnClickListener { share() } binding.shareLayout.setOnClickListener { share() }
binding.saveLayout.setOnClickListener { save() } binding.saveLayout.setOnClickListener { save() }
return binding.root
} }
/** /**

View File

@ -1,7 +1,6 @@
package eu.kanade.tachiyomi.ui.reader.setting package eu.kanade.tachiyomi.ui.reader.setting
import android.view.ViewGroup import android.os.Bundle
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.ReaderActivity
@ -10,20 +9,21 @@ import eu.kanade.tachiyomi.widget.sheet.TabbedBottomSheetDialog
class ReaderSettingsSheet( class ReaderSettingsSheet(
private val activity: ReaderActivity, private val activity: ReaderActivity,
showColorFilterSettings: Boolean = false, private val showColorFilterSettings: Boolean = false,
) : TabbedBottomSheetDialog(activity) { ) : TabbedBottomSheetDialog(activity) {
private val readingModeSettings = ReaderReadingModeSettings(activity) private val readingModeSettings = ReaderReadingModeSettings(activity)
private val generalSettings = ReaderGeneralSettings(activity) private val generalSettings = ReaderGeneralSettings(activity)
private val colorFilterSettings = ReaderColorFilterSettings(activity) private val colorFilterSettings = ReaderColorFilterSettings(activity)
private val sheetBackgroundDim = window?.attributes?.dimAmount ?: 0.25f override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
init {
val sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup)
sheetBehavior.isFitToContents = false sheetBehavior.isFitToContents = false
sheetBehavior.halfExpandedRatio = 0.25f sheetBehavior.halfExpandedRatio = 0.25f
val sheetBackgroundDim = window?.attributes?.dimAmount ?: 0.25f
val filterTabIndex = getTabViews().indexOf(colorFilterSettings) val filterTabIndex = getTabViews().indexOf(colorFilterSettings)
binding.tabs.addOnTabSelectedListener(object : SimpleTabSelectedListener() { binding.tabs.addOnTabSelectedListener(object : SimpleTabSelectedListener() {
override fun onTabSelected(tab: TabLayout.Tab?) { override fun onTabSelected(tab: TabLayout.Tab?) {

View File

@ -2,17 +2,31 @@ package eu.kanade.tachiyomi.widget.sheet
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
open class BaseBottomSheetDialog(context: Context) : BottomSheetDialog(context) { abstract class BaseBottomSheetDialog(context: Context) : BottomSheetDialog(context) {
internal lateinit var sheetBehavior: BottomSheetBehavior<*>
abstract fun createView(inflater: LayoutInflater): View
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
val rootView = createView(layoutInflater)
setContentView(rootView)
sheetBehavior = BottomSheetBehavior.from(rootView.parent as ViewGroup)
// Enforce max width for tablets
val width = context.resources.getDimensionPixelSize(R.dimen.bottom_sheet_width) val width = context.resources.getDimensionPixelSize(R.dimen.bottom_sheet_width)
if (width > 0) { if (width > 0) {
window?.setLayout(width, ViewGroup.LayoutParams.MATCH_PARENT) sheetBehavior.maxWidth = width
} }
} }
} }

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.widget.sheet package eu.kanade.tachiyomi.widget.sheet
import android.app.Activity import android.app.Activity
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import eu.kanade.tachiyomi.databinding.CommonTabbedSheetBinding import eu.kanade.tachiyomi.databinding.CommonTabbedSheetBinding
@ -8,15 +9,17 @@ import eu.kanade.tachiyomi.widget.ViewPagerAdapter
abstract class TabbedBottomSheetDialog(private val activity: Activity) : BaseBottomSheetDialog(activity) { abstract class TabbedBottomSheetDialog(private val activity: Activity) : BaseBottomSheetDialog(activity) {
val binding = CommonTabbedSheetBinding.inflate(activity.layoutInflater) lateinit var binding: CommonTabbedSheetBinding
override fun createView(inflater: LayoutInflater): View {
binding = CommonTabbedSheetBinding.inflate(activity.layoutInflater)
init {
val adapter = LibrarySettingsSheetAdapter() val adapter = LibrarySettingsSheetAdapter()
binding.pager.offscreenPageLimit = 2 binding.pager.offscreenPageLimit = 2
binding.pager.adapter = adapter binding.pager.adapter = adapter
binding.tabs.setupWithViewPager(binding.pager) binding.tabs.setupWithViewPager(binding.pager)
setContentView(binding.root) return binding.root
} }
abstract fun getTabViews(): List<View> abstract fun getTabViews(): List<View>