From 11467cdb01a907a9b3b1c4a60128ede6bcde99f8 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Thu, 27 May 2021 15:51:31 -0400 Subject: [PATCH] Using adjust nothing softinput mode for Android 11 Setting category controller to auto adjust itself --- app/src/main/AndroidManifest.xml | 2 +- .../ui/category/CategoryController.kt | 2 +- .../kanade/tachiyomi/ui/main/MainActivity.kt | 3 +++ .../util/view/ControllerExtensions.kt | 17 +++++++++++------ .../tachiyomi/util/view/ViewExtensions.kt | 18 +++++++++++------- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index be21bcf56c..241f331a98 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -39,7 +39,7 @@ android:networkSecurityConfig="@xml/network_security_config"> diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt index fe83205e9c..8205bc457c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt @@ -58,7 +58,7 @@ class CategoryController(bundle: Bundle? = null) : */ override fun onViewCreated(view: View) { super.onViewCreated(view) - liftAppbarWith(binding.recycler) + liftAppbarWith(binding.recycler, true) adapter = CategoryAdapter(this@CategoryController) binding.recycler.layoutManager = LinearLayoutManager(view.context) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 5d394166df..efb1972e62 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -169,6 +169,9 @@ open class MainActivity : BaseActivity(), DownloadServiceLi R.drawable.ic_close_24dp ) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + } var continueSwitchingTabs = false nav.getItemView(R.id.nav_library)?.setOnLongClickListener { if (!LibraryUpdateService.isRunning()) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt index 8afaa5283a..04c3bdbf9a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt @@ -109,16 +109,21 @@ fun Controller.liftAppbarWith(recycler: RecyclerView, padView: Boolean = false) recycler.updatePaddingRelative( top = activityBinding!!.toolbar.y.toInt() + appBarHeight ) + recycler.applyBottomAnimatedInsets(setPadding = true) recycler.doOnApplyWindowInsets { view, insets, _ -> val headerHeight = insets.systemWindowInsetTop + appBarHeight view.updatePaddingRelative( - top = headerHeight, - bottom = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - insets.getInsets(WindowInsets.Type.ime() or WindowInsets.Type.systemBars()).bottom - } else { - insets.systemWindowInsetBottom - } + top = headerHeight ) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + view.updatePaddingRelative( + bottom = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + insets.getInsets(WindowInsets.Type.ime() or WindowInsets.Type.systemBars()).bottom + } else { + insets.systemWindowInsetBottom + } + ) + } } } else { view?.applyWindowInsetsForController() diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt index 3e42580767..4e0f7964b2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt @@ -123,16 +123,20 @@ object RecyclerWindowInsetsListener : View.OnApplyWindowInsetsListener { } } -fun View.applyBottomAnimatedInsets(bottomMargin: Int = 0) { +fun View.applyBottomAnimatedInsets(bottomMargin: Int = 0, setPadding: Boolean = false) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) return val setInsets: ((WindowInsets) -> Unit) = { insets -> - updateLayoutParams { - val bottom = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - insets.getInsets(WindowInsets.Type.systemBars() or WindowInsets.Type.ime()).bottom - } else { - insets.systemWindowInsetBottom + val bottom = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + insets.getInsets(WindowInsets.Type.systemBars() or WindowInsets.Type.ime()).bottom + } else { + insets.systemWindowInsetBottom + } + if (setPadding) { + updatePaddingRelative(bottom = bottomMargin + bottom) + } else { + updateLayoutParams { + this.bottomMargin = bottom + bottomMargin } - this.bottomMargin = bottom + bottomMargin } } var handleInsets = true