mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Fix warnings in Library controller
This commit is contained in:
parent
e5ab5c220e
commit
818bf2f1da
2 changed files with 33 additions and 35 deletions
|
@ -10,7 +10,6 @@ import android.content.DialogInterface
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
@ -21,7 +20,6 @@ import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.ViewPropertyAnimator
|
import android.view.ViewPropertyAnimator
|
||||||
import android.view.WindowInsets
|
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
@ -32,6 +30,7 @@ import androidx.core.view.GestureDetectorCompat
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowInsetsAnimationCompat
|
import androidx.core.view.WindowInsetsAnimationCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import androidx.core.view.WindowInsetsCompat.Type.ime
|
||||||
import androidx.core.view.WindowInsetsCompat.Type.systemBars
|
import androidx.core.view.WindowInsetsCompat.Type.systemBars
|
||||||
import androidx.core.view.isInvisible
|
import androidx.core.view.isInvisible
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
@ -89,6 +88,7 @@ import eu.kanade.tachiyomi.util.system.isImeVisible
|
||||||
import eu.kanade.tachiyomi.util.system.launchUI
|
import eu.kanade.tachiyomi.util.system.launchUI
|
||||||
import eu.kanade.tachiyomi.util.system.materialAlertDialog
|
import eu.kanade.tachiyomi.util.system.materialAlertDialog
|
||||||
import eu.kanade.tachiyomi.util.system.openInBrowser
|
import eu.kanade.tachiyomi.util.system.openInBrowser
|
||||||
|
import eu.kanade.tachiyomi.util.system.rootWindowInsetsCompat
|
||||||
import eu.kanade.tachiyomi.util.view.activityBinding
|
import eu.kanade.tachiyomi.util.view.activityBinding
|
||||||
import eu.kanade.tachiyomi.util.view.collapse
|
import eu.kanade.tachiyomi.util.view.collapse
|
||||||
import eu.kanade.tachiyomi.util.view.expand
|
import eu.kanade.tachiyomi.util.view.expand
|
||||||
|
@ -211,9 +211,14 @@ class LibraryController(
|
||||||
private lateinit var elevateAppBar: ((Boolean) -> Unit)
|
private lateinit var elevateAppBar: ((Boolean) -> Unit)
|
||||||
private var hopperOffset = 0f
|
private var hopperOffset = 0f
|
||||||
private val maxHopperOffset: Float
|
private val maxHopperOffset: Float
|
||||||
get() =
|
get() = if (activityBinding?.bottomNav != null) {
|
||||||
if (activityBinding?.bottomNav != null) 55f.dpToPx
|
55f.dpToPx
|
||||||
else (view?.rootWindowInsets?.systemWindowInsetBottom?.toFloat() ?: 0f) + 55f.dpToPx
|
} else {
|
||||||
|
(
|
||||||
|
view?.rootWindowInsetsCompat?.getInsets(systemBars())?.bottom?.toFloat()
|
||||||
|
?: 0f
|
||||||
|
) + 55f.dpToPx
|
||||||
|
}
|
||||||
|
|
||||||
override fun getTitle(): String? {
|
override fun getTitle(): String? {
|
||||||
setSubtitle()
|
setSubtitle()
|
||||||
|
@ -242,7 +247,7 @@ class LibraryController(
|
||||||
insets: WindowInsetsCompat,
|
insets: WindowInsetsCompat,
|
||||||
runningAnimations: List<WindowInsetsAnimationCompat>
|
runningAnimations: List<WindowInsetsAnimationCompat>
|
||||||
): WindowInsetsCompat {
|
): WindowInsetsCompat {
|
||||||
updateHopperY(insets.toWindowInsets())
|
updateHopperY(insets)
|
||||||
return insets
|
return insets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,37 +307,27 @@ class LibraryController(
|
||||||
|
|
||||||
fun updateFilterSheetY() {
|
fun updateFilterSheetY() {
|
||||||
val bottomBar = activityBinding?.bottomNav
|
val bottomBar = activityBinding?.bottomNav
|
||||||
|
val systemInsets = view?.rootWindowInsetsCompat?.getInsets(systemBars())
|
||||||
|
val bottomSheet = binding.filterBottomSheet.filterBottomSheet
|
||||||
if (bottomBar != null) {
|
if (bottomBar != null) {
|
||||||
if (binding.filterBottomSheet.filterBottomSheet.sheetBehavior.isHidden()) {
|
bottomSheet.translationY = if (bottomSheet.sheetBehavior.isHidden()) {
|
||||||
val pad = bottomBar.translationY - bottomBar.height
|
bottomBar.translationY - bottomBar.height
|
||||||
binding.filterBottomSheet.filterBottomSheet.translationY = pad
|
|
||||||
} else {
|
} else {
|
||||||
binding.filterBottomSheet.filterBottomSheet.translationY = 0f
|
0f
|
||||||
}
|
}
|
||||||
val pad = bottomBar.translationY - bottomBar.height
|
val pad = bottomBar.translationY - bottomBar.height
|
||||||
binding.filterBottomSheet.filterBottomSheet.updatePaddingRelative(
|
val padding = max((-pad).toInt(), systemInsets?.bottom ?: 0)
|
||||||
bottom = max(
|
bottomSheet.updatePaddingRelative(bottom = padding)
|
||||||
(-pad).toInt(),
|
|
||||||
view?.rootWindowInsets?.systemWindowInsetBottom ?: 0
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
val padding = max(
|
bottomSheet.sheetBehavior?.peekHeight = 60.dpToPx + padding
|
||||||
(-pad).toInt(),
|
|
||||||
view?.rootWindowInsets?.systemWindowInsetBottom ?: 0
|
|
||||||
)
|
|
||||||
binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.peekHeight = 60.dpToPx + padding
|
|
||||||
updateHopperY()
|
updateHopperY()
|
||||||
binding.fastScroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
binding.fastScroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||||
bottomMargin = -pad.toInt()
|
bottomMargin = -pad.toInt()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
binding.filterBottomSheet.filterBottomSheet.updatePaddingRelative(
|
bottomSheet.updatePaddingRelative(bottom = systemInsets?.bottom ?: 0)
|
||||||
bottom = view?.rootWindowInsets?.systemWindowInsetBottom ?: 0
|
|
||||||
)
|
|
||||||
updateHopperY()
|
updateHopperY()
|
||||||
binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.peekHeight = 60.dpToPx +
|
bottomSheet.sheetBehavior?.peekHeight = 60.dpToPx + (systemInsets?.bottom ?: 0)
|
||||||
(view?.rootWindowInsets?.systemWindowInsetBottom ?: 0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -756,19 +751,19 @@ class LibraryController(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateHopperY(windowInsets: WindowInsets? = null) {
|
fun updateHopperY(windowInsets: WindowInsetsCompat? = null) {
|
||||||
val view = view ?: return
|
val view = view ?: return
|
||||||
val insets = windowInsets ?: view.rootWindowInsets
|
val insets = windowInsets ?: view.rootWindowInsetsCompat
|
||||||
val listOfYs = mutableListOf(
|
val listOfYs = mutableListOf(
|
||||||
binding.filterBottomSheet.filterBottomSheet.y,
|
binding.filterBottomSheet.filterBottomSheet.y,
|
||||||
activityBinding?.bottomNav?.y ?: binding.filterBottomSheet.filterBottomSheet.y
|
activityBinding?.bottomNav?.y ?: binding.filterBottomSheet.filterBottomSheet.y
|
||||||
)
|
)
|
||||||
val insetBottom = insets?.systemWindowInsetBottom ?: 0
|
val insetBottom = insets?.getInsets(systemBars())?.bottom ?: 0
|
||||||
if (!preferences.autohideHopper().get() || activityBinding?.bottomNav == null) {
|
if (!preferences.autohideHopper().get() || activityBinding?.bottomNav == null) {
|
||||||
listOfYs.add(view.height - (insetBottom).toFloat())
|
listOfYs.add(view.height - (insetBottom).toFloat())
|
||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && insets?.isImeVisible() == true) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && insets?.isImeVisible() == true) {
|
||||||
val insetKey = insets.getInsets(WindowInsets.Type.ime() or WindowInsets.Type.systemBars()).bottom
|
val insetKey = insets.getInsets(ime() or systemBars()).bottom
|
||||||
listOfYs.add(view.height - (insetKey).toFloat())
|
listOfYs.add(view.height - (insetKey).toFloat())
|
||||||
}
|
}
|
||||||
binding.categoryHopperFrame.y = -binding.categoryHopperFrame.height +
|
binding.categoryHopperFrame.y = -binding.categoryHopperFrame.height +
|
||||||
|
@ -879,7 +874,7 @@ class LibraryController(
|
||||||
view.elevation = 15f.dpToPx
|
view.elevation = 15f.dpToPx
|
||||||
setAction(R.string.cancel) {
|
setAction(R.string.cancel) {
|
||||||
LibraryUpdateService.stop(context)
|
LibraryUpdateService.stop(context)
|
||||||
Handler().post {
|
viewScope.launchUI {
|
||||||
NotificationReceiver.dismissNotification(
|
NotificationReceiver.dismissNotification(
|
||||||
context,
|
context,
|
||||||
Notifications.ID_LIBRARY_PROGRESS
|
Notifications.ID_LIBRARY_PROGRESS
|
||||||
|
@ -891,7 +886,7 @@ class LibraryController(
|
||||||
|
|
||||||
private fun setRecyclerLayout() {
|
private fun setRecyclerLayout() {
|
||||||
with(binding.libraryGridRecycler.recycler) {
|
with(binding.libraryGridRecycler.recycler) {
|
||||||
post {
|
viewScope.launchUI {
|
||||||
updatePaddingRelative(
|
updatePaddingRelative(
|
||||||
bottom = 50.dpToPx + (activityBinding?.bottomNav?.height ?: 0)
|
bottom = 50.dpToPx + (activityBinding?.bottomNav?.height ?: 0)
|
||||||
)
|
)
|
||||||
|
@ -912,6 +907,7 @@ class LibraryController(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private fun setPreferenceFlows() {
|
private fun setPreferenceFlows() {
|
||||||
listOf(
|
listOf(
|
||||||
preferences.libraryLayout(),
|
preferences.libraryLayout(),
|
||||||
|
@ -1152,7 +1148,7 @@ class LibraryController(
|
||||||
binding.libraryGridRecycler.recycler.suppressLayout(true)
|
binding.libraryGridRecycler.recycler.suppressLayout(true)
|
||||||
val appbarOffset = if (appbar?.y ?: 0f > -20) 0 else (
|
val appbarOffset = if (appbar?.y ?: 0f > -20) 0 else (
|
||||||
appbar?.y?.plus(
|
appbar?.y?.plus(
|
||||||
view?.rootWindowInsets?.systemWindowInsetTop ?: 0
|
view?.rootWindowInsetsCompat?.getInsets(systemBars())?.top ?: 0
|
||||||
) ?: 0f
|
) ?: 0f
|
||||||
).roundToInt() + 30.dpToPx
|
).roundToInt() + 30.dpToPx
|
||||||
val previousHeader = adapter.getItem(adapter.indexOf(pos - 1)) as? LibraryHeaderItem
|
val previousHeader = adapter.getItem(adapter.indexOf(pos - 1)) as? LibraryHeaderItem
|
||||||
|
@ -1227,6 +1223,7 @@ class LibraryController(
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
override fun onDestroyActionMode(mode: ActionMode?) {
|
override fun onDestroyActionMode(mode: ActionMode?) {
|
||||||
selectedMangas.clear()
|
selectedMangas.clear()
|
||||||
actionMode = null
|
actionMode = null
|
||||||
|
@ -1378,6 +1375,7 @@ class LibraryController(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
override fun onUpdateManga(manga: Manga?) {
|
override fun onUpdateManga(manga: Manga?) {
|
||||||
if (manga == null) adapter.notifyDataSetChanged()
|
if (manga == null) adapter.notifyDataSetChanged()
|
||||||
else presenter.updateManga()
|
else presenter.updateManga()
|
||||||
|
@ -1496,7 +1494,7 @@ class LibraryController(
|
||||||
view.elevation = 15f.dpToPx
|
view.elevation = 15f.dpToPx
|
||||||
setAction(R.string.cancel) {
|
setAction(R.string.cancel) {
|
||||||
LibraryUpdateService.stop(context)
|
LibraryUpdateService.stop(context)
|
||||||
Handler().post {
|
viewScope.launchUI {
|
||||||
NotificationReceiver.dismissNotification(
|
NotificationReceiver.dismissNotification(
|
||||||
context,
|
context,
|
||||||
Notifications.ID_LIBRARY_PROGRESS
|
Notifications.ID_LIBRARY_PROGRESS
|
||||||
|
|
|
@ -41,7 +41,7 @@ fun WindowInsetsCompat.hasSideNavBar() =
|
||||||
getInsets(systemBars()).bottom == 0
|
getInsets(systemBars()).bottom == 0
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.R)
|
@RequiresApi(Build.VERSION_CODES.R)
|
||||||
fun WindowInsets.isImeVisible() = isVisible(WindowInsets.Type.ime())
|
fun WindowInsetsCompat.isImeVisible() = isVisible(WindowInsetsCompat.Type.ime())
|
||||||
|
|
||||||
fun WindowInsets.topCutoutInset() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
fun WindowInsets.topCutoutInset() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
displayCutout?.safeInsetTop ?: 0
|
displayCutout?.safeInsetTop ?: 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue