move windowInset check for bottom into extension

This commit is contained in:
CarlosEsco 2020-04-22 13:19:36 -04:00
parent f0cf0f4106
commit e5d3890ead
5 changed files with 27 additions and 14 deletions

View File

@ -4,8 +4,6 @@ import android.app.Dialog
import android.os.Bundle
import android.view.View
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.WhichButton
import com.afollestad.materialdialogs.actions.setActionButtonEnabled
import com.afollestad.materialdialogs.customview.customView
import com.jakewharton.rxbinding.widget.itemClicks
import com.jakewharton.rxbinding.widget.textChanges

View File

@ -183,7 +183,6 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>(),
false -> reader_layout.systemUiVisibility.rem(systemUiFlag)
}
if (presenter.needsInit()) {
val manga = intent.extras!!.getLong("manga", -1)
val chapter = intent.extras!!.getLong("chapter", -1)

View File

@ -7,7 +7,6 @@ import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.items.AbstractItem
import eu.kanade.tachiyomi.R

View File

@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.reader
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.os.Build
import android.util.AttributeSet
import android.view.View
import android.widget.LinearLayout
@ -16,6 +15,7 @@ import com.mikepenz.fastadapter.adapters.ItemAdapter
import com.mikepenz.fastadapter.listeners.ClickEventHook
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getBottomInsets
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets
@ -39,24 +39,28 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
fun setup(activity: ReaderActivity) {
presenter = activity.presenter
val fullPrimary = activity.getResourceColor(R.attr.colorSecondary)
val primary = ColorUtils.setAlphaComponent( fullPrimary, 200)
val primary = ColorUtils.setAlphaComponent(fullPrimary, 200)
sheetBehavior = BottomSheetBehavior.from(this)
chapters_button.setOnClickListener {
if (sheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED) sheetBehavior?.state =
BottomSheetBehavior.STATE_COLLAPSED
else sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED
if (sheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED) {
sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED
} else {
sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED
}
}
val peek = sheetBehavior?.peekHeight ?: 30.dpToPx
post {
chapter_recycler.alpha =
if (sheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED) 1f else 0f
chapter_recycler.alpha = when (sheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED) {
true -> 1f
false -> 0f
}
}
chapters_bottom_sheet.doOnApplyWindowInsets { _, insets, _ ->
sheetBehavior?.peekHeight =
peek + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) insets.mandatorySystemGestureInsets.bottom
else insets.systemWindowInsetBottom
sheetBehavior?.peekHeight = peek + insets.getBottomInsets()
chapters_bottom_sheet.updateLayoutParams<MarginLayoutParams> {
height = 280.dpToPx + insets.systemWindowInsetBottom
}

View File

@ -0,0 +1,13 @@
package eu.kanade.tachiyomi.util.system
import android.annotation.SuppressLint
import android.os.Build
import android.view.WindowInsets
@SuppressLint("NewApi")
fun WindowInsets.getBottomInsets(): Int {
return when (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
true -> mandatorySystemGestureInsets.bottom
false -> systemWindowInsetBottom
}
}