Creating a base class for the edge2edge bottomsheets

This commit is contained in:
Jays2Kings 2021-04-26 03:15:59 -04:00
parent 5ca4e8ade0
commit 8523dba27b
11 changed files with 99 additions and 125 deletions

View File

@ -5,6 +5,7 @@ import android.animation.ValueAnimator
import android.annotation.SuppressLint
import android.app.Activity
import android.os.Build
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.DrawableRes
@ -12,17 +13,15 @@ import androidx.annotation.StringRes
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.BottomMenuSheetBinding
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.hasSideNavBar
import eu.kanade.tachiyomi.util.system.isInNightMode
import eu.kanade.tachiyomi.util.view.expand
import eu.kanade.tachiyomi.util.view.setBottomEdge
import eu.kanade.tachiyomi.util.view.setEdgeToEdge
import eu.kanade.tachiyomi.util.view.updateLayoutParams
import eu.kanade.tachiyomi.widget.EdgeToEdgeBottomSheetDialog
import eu.kanade.tachiyomi.widget.MenuSheetItemView
@SuppressLint("InflateParams")
@ -34,16 +33,11 @@ open class MaterialMenuSheet(
maxHeight: Int? = null,
showDivider: Boolean = false,
onMenuItemClicked: (MaterialMenuSheet, Int) -> Boolean
) :
BottomSheetDialog
(activity, R.style.BottomSheetDialogTheme) {
) : EdgeToEdgeBottomSheetDialog<BottomMenuSheetBinding>(activity) {
private val primaryColor = activity.getResourceColor(android.R.attr.textColorPrimary)
private val binding = BottomMenuSheetBinding.inflate(activity.layoutInflater)
override fun createBinding(inflater: LayoutInflater) = BottomMenuSheetBinding.inflate(inflater)
init {
setContentView(binding.root)
setEdgeToEdge(activity, binding.root)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !context.isInNightMode() && !activity.window.decorView.rootWindowInsets.hasSideNavBar()) {
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
}

View File

@ -2,13 +2,12 @@ package eu.kanade.tachiyomi.ui.category.addtolibrary
import android.app.Activity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.ISelectionListener
import com.mikepenz.fastadapter.adapters.ItemAdapter
@ -23,9 +22,9 @@ import eu.kanade.tachiyomi.databinding.SetCategoriesSheetBinding
import eu.kanade.tachiyomi.ui.category.ManageCategoryDialog
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.view.expand
import eu.kanade.tachiyomi.util.view.setEdgeToEdge
import eu.kanade.tachiyomi.util.view.updateLayoutParams
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
import eu.kanade.tachiyomi.widget.EdgeToEdgeBottomSheetDialog
import uy.kohesive.injekt.injectLazy
import java.util.ArrayList
import java.util.Date
@ -39,27 +38,19 @@ class SetCategoriesSheet(
var preselected: Array<Int>,
private val addingToLibrary: Boolean,
val onMangaAdded: (() -> Unit) = { }
) : BottomSheetDialog
(activity, R.style.BottomSheetDialogTheme) {
) : EdgeToEdgeBottomSheetDialog<SetCategoriesSheetBinding>(activity) {
constructor(activity: Activity, manga: Manga, categories: MutableList<Category>, preselected: Array<Int>, addingToLibrary: Boolean, onMangaAdded: () -> Unit) :
this(activity, listOf(manga), categories, preselected, addingToLibrary, onMangaAdded)
private var sheetBehavior: BottomSheetBehavior<*>
private val fastAdapter: FastAdapter<AddCategoryItem>
private val itemAdapter = ItemAdapter<AddCategoryItem>()
private val selectExtension: SelectExtension<AddCategoryItem>
private val db: DatabaseHelper by injectLazy()
private val binding = SetCategoriesSheetBinding.inflate(activity.layoutInflater)
override fun createBinding(inflater: LayoutInflater) =
SetCategoriesSheetBinding.inflate(inflater)
init {
// Use activity theme for this layout
setContentView(binding.root)
sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup)
setEdgeToEdge(activity, binding.root)
binding.toolbarTitle.text = context.getString(
if (addingToLibrary) {
R.string.add_x_to

View File

@ -1,37 +1,29 @@
package eu.kanade.tachiyomi.ui.manga.chapter
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.databinding.ChapterSortBottomSheetBinding
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.view.setBottomEdge
import eu.kanade.tachiyomi.util.view.setEdgeToEdge
import eu.kanade.tachiyomi.widget.EdgeToEdgeBottomSheetDialog
import kotlin.math.max
class ChaptersSortBottomSheet(controller: MangaDetailsController) : BottomSheetDialog
(controller.activity!!, R.style.BottomSheetDialogTheme) {
class ChaptersSortBottomSheet(controller: MangaDetailsController) :
EdgeToEdgeBottomSheetDialog<ChapterSortBottomSheetBinding>(controller.activity!!) {
val activity = controller.activity!!
private var sheetBehavior: BottomSheetBehavior<*>
private val presenter = controller.presenter
private val binding = ChapterSortBottomSheetBinding.inflate(activity.layoutInflater)
override fun createBinding(inflater: LayoutInflater) = ChapterSortBottomSheetBinding.inflate(inflater)
init {
// Use activity theme for this layout
setContentView(binding.root)
sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup)
setEdgeToEdge(activity, binding.root)
val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
sheetBehavior.peekHeight = 415.dpToPx + height

View File

@ -2,12 +2,12 @@ package eu.kanade.tachiyomi.ui.manga.track
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.net.toUri
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.track.TrackService
import eu.kanade.tachiyomi.data.track.model.TrackSearch
@ -16,12 +16,13 @@ import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener
import eu.kanade.tachiyomi.util.view.setEdgeToEdge
import eu.kanade.tachiyomi.util.view.checkHeightThen
import eu.kanade.tachiyomi.util.view.updateLayoutParams
import eu.kanade.tachiyomi.widget.EdgeToEdgeBottomSheetDialog
import timber.log.Timber
class TrackingBottomSheet(private val controller: MangaDetailsController) :
BottomSheetDialog
(controller.activity!!, R.style.BottomSheetDialogTheme),
EdgeToEdgeBottomSheetDialog<TrackingBottomSheetBinding>(controller.activity!!),
TrackAdapter.OnClickListener,
SetTrackStatusDialog.Listener,
SetTrackChaptersDialog.Listener,
@ -31,20 +32,14 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) :
val activity = controller.activity!!
private var sheetBehavior: BottomSheetBehavior<*>
val presenter = controller.presenter
private var adapter: TrackAdapter? = null
private val binding = TrackingBottomSheetBinding.inflate(activity.layoutInflater)
override fun createBinding(inflater: LayoutInflater) =
TrackingBottomSheetBinding.inflate(inflater)
init {
// Use activity theme for this layout
setContentView(binding.root)
sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup)
setEdgeToEdge(activity, binding.root, 0)
val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
sheetBehavior.peekHeight = 500.dpToPx + height
@ -59,6 +54,14 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) :
}
}
)
binding.displayBottomSheet.checkHeightThen {
val fullHeight = activity.window.decorView.height
val insets = activity.window.decorView.rootWindowInsets
binding.trackRecycler.updateLayoutParams<ConstraintLayout.LayoutParams> {
matchConstraintMaxHeight =
fullHeight - (insets?.systemWindowInsetTop ?: 0) - 30.dpToPx
}
}
}
override fun onStart() {

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.migration.manga.design
import android.app.Activity
import android.content.res.Configuration
import android.os.Bundle
import android.view.LayoutInflater
import android.widget.CompoundButton
import android.widget.LinearLayout
import android.widget.RadioButton
@ -12,7 +13,6 @@ import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible
import com.bluelinelabs.conductor.Controller
import com.f2prateek.rx.preferences.Preference
import com.google.android.material.bottomsheet.BottomSheetDialog
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
@ -22,23 +22,21 @@ import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.toInt
import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.setBottomEdge
import eu.kanade.tachiyomi.util.view.setEdgeToEdge
import eu.kanade.tachiyomi.widget.EdgeToEdgeBottomSheetDialog
import uy.kohesive.injekt.injectLazy
class MigrationBottomSheetDialog(
activity: Activity,
private val listener: StartMigrationListener
) : BottomSheetDialog(activity, R.style.BottomSheetDialogTheme) {
) : EdgeToEdgeBottomSheetDialog<MigrationBottomSheetBinding>(activity) {
/**
* Preferences helper.
*/
private val preferences by injectLazy<PreferencesHelper>()
private val binding = MigrationBottomSheetBinding.inflate(activity.layoutInflater)
override fun createBinding(inflater: LayoutInflater) = MigrationBottomSheetBinding.inflate(inflater)
init {
// Use activity theme for this layout
setContentView(binding.root)
if (activity.resources.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE) {
binding.sourceGroup.orientation = LinearLayout.HORIZONTAL
val params = binding.skipStep.layoutParams as ConstraintLayout.LayoutParams
@ -61,7 +59,6 @@ class MigrationBottomSheetDialog(
params3.endToEnd = -1
binding.extraSearchParam.layoutParams = params3
}
setEdgeToEdge(activity, binding.root)
setBottomEdge(
if (activity.resources.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE) binding.extraSearchParamText
else binding.skipStep,

View File

@ -1,12 +1,10 @@
package eu.kanade.tachiyomi.ui.reader.settings
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.core.content.ContextCompat
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.tabs.TabLayout
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.ReaderColorFilterBinding
@ -57,7 +55,6 @@ class TabbedReaderSettingsSheet(
R.string.filter
)
var sheetBehavior: BottomSheetBehavior<*>
init {
generalView.activity = readerActivity
pagedView.activity = readerActivity
@ -66,8 +63,6 @@ class TabbedReaderSettingsSheet(
filterView.window = window
generalView.sheet = this
sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup)
ReaderColorFilterBinding.bind(filterView).swipeDown.setOnClickListener {
if (sheetBehavior.isCollapsed()) {
sheetBehavior.expand()

View File

@ -2,27 +2,24 @@ package eu.kanade.tachiyomi.ui.source.browse
import android.app.Activity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver.OnGlobalLayoutListener
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.SourceFilterSheetBinding
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.view.collapse
import eu.kanade.tachiyomi.util.view.setEdgeToEdge
import eu.kanade.tachiyomi.util.view.updateLayoutParams
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
import eu.kanade.tachiyomi.widget.EdgeToEdgeBottomSheetDialog
class SourceFilterSheet(val activity: Activity) :
BottomSheetDialog(activity, R.style.BottomSheetDialogTheme) {
private val sheetBehavior: BottomSheetBehavior<*>
EdgeToEdgeBottomSheetDialog<SourceFilterSheetBinding>(activity) {
private var filterChanged = true
@ -33,16 +30,13 @@ class SourceFilterSheet(val activity: Activity) :
var onResetClicked = {}
private val binding = SourceFilterSheetBinding.inflate(activity.layoutInflater)
override fun createBinding(inflater: LayoutInflater) = SourceFilterSheetBinding.inflate(inflater)
init {
setContentView(binding.root)
binding.searchBtn.setOnClickListener { dismiss() }
binding.resetBtn.setOnClickListener { onResetClicked() }
sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup)
sheetBehavior.peekHeight = 450.dpToPx
sheetBehavior.collapse()
setEdgeToEdge(activity, binding.root)
binding.titleLayout.viewTreeObserver.addOnGlobalLayoutListener(object : OnGlobalLayoutListener {
override fun onGlobalLayout() {

View File

@ -34,7 +34,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.material.bottomnavigation.BottomNavigationItemView
import com.google.android.material.bottomnavigation.BottomNavigationMenuView
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.button.MaterialButton
import com.google.android.material.snackbar.Snackbar
import eu.kanade.tachiyomi.R
@ -232,43 +231,6 @@ inline fun View.updatePaddingRelative(
setPaddingRelative(start, top, end, bottom)
}
fun BottomSheetDialog.setEdgeToEdge(
activity: Activity,
contentView: View,
setTopMargin: Int = -1
) {
window?.setBackgroundDrawable(null)
window?.navigationBarColor = activity.window.navigationBarColor
val isLight = (activity.window?.decorView?.systemUiVisibility ?: 0) and View
.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR == View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isLight) {
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
}
window?.findViewById<View>(com.google.android.material.R.id.container)?.fitsSystemWindows =
false
window?.findViewById<View>(com.google.android.material.R.id.coordinator)?.fitsSystemWindows =
false
contentView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View
.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
val insets = activity.window.decorView.rootWindowInsets
(contentView.parent as View).background = null
contentView.post {
(contentView.parent as View).background = null
}
contentView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
leftMargin = insets.systemWindowInsetLeft
rightMargin = insets.systemWindowInsetRight
}
if (setTopMargin > 0) (contentView.parent as View).updateLayoutParams<ViewGroup.MarginLayoutParams> {
height = activity.window.decorView.height - insets.systemWindowInsetTop - setTopMargin
}
else if (setTopMargin == 0) contentView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = insets.systemWindowInsetTop
}
contentView.requestLayout()
}
fun setBottomEdge(view: View, activity: Activity) {
val marginB = view.marginBottom
view.updateLayoutParams<ViewGroup.MarginLayoutParams> {

View File

@ -0,0 +1,56 @@
package eu.kanade.tachiyomi.widget
import android.app.Activity
import android.os.Build
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.view.updateLayoutParams
@Suppress("LeakingThis")
abstract class EdgeToEdgeBottomSheetDialog<VB : ViewBinding>(activity: Activity) :
BottomSheetDialog(activity, R.style.BottomSheetDialogTheme) {
protected val binding: VB
protected val sheetBehavior: BottomSheetBehavior<*>
init {
binding = createBinding(activity.layoutInflater)
setContentView(binding.root)
sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup)
val contentView = binding.root
window?.setBackgroundDrawable(null)
window?.navigationBarColor = activity.window.navigationBarColor
val isLight = (activity.window?.decorView?.systemUiVisibility ?: 0) and View
.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR == View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isLight) {
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
}
window?.findViewById<View>(com.google.android.material.R.id.container)?.fitsSystemWindows =
false
window?.findViewById<View>(com.google.android.material.R.id.coordinator)?.fitsSystemWindows =
false
contentView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View
.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
val insets = activity.window.decorView.rootWindowInsets
(contentView.parent as View).background = null
contentView.post {
(contentView.parent as View).background = null
}
contentView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
leftMargin = insets.systemWindowInsetLeft
rightMargin = insets.systemWindowInsetRight
}
contentView.requestLayout()
}
abstract fun createBinding(inflater: LayoutInflater): VB
}

View File

@ -3,34 +3,24 @@ package eu.kanade.tachiyomi.widget
import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.widget.NestedScrollView
import androidx.viewpager.widget.ViewPager
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.tabs.TabLayout
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.TabbedBottomSheetBinding
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.view.expand
import eu.kanade.tachiyomi.util.view.setEdgeToEdge
import kotlin.math.max
abstract class TabbedBottomSheetDialog(private val activity: Activity) :
BottomSheetDialog
(activity, R.style.BottomSheetDialogTheme) {
EdgeToEdgeBottomSheetDialog<TabbedBottomSheetBinding>(activity) {
private var sheetBehavior: BottomSheetBehavior<*>
protected val binding = TabbedBottomSheetBinding.inflate(activity.layoutInflater)
override fun createBinding(inflater: LayoutInflater) = TabbedBottomSheetBinding.inflate(inflater)
open var offset = -1
init {
// Use activity theme for this layout
setContentView(binding.root)
sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup)
setEdgeToEdge(activity, binding.root)
val height = activity.window.decorView.rootWindowInsets.systemWindowInsetTop
binding.pager.maxHeight = activity.window.decorView.height - height - 125.dpToPx

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/display_bottom_sheet"
android:layout_width="match_parent"
@ -13,4 +13,4 @@
android:paddingTop="5dp"
android:clipToPadding="false"
tools:listitem="@layout/track_item" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>