Using adjust nothing softinput mode for Android 11

Setting category controller to auto adjust itself
This commit is contained in:
Jays2Kings 2021-05-27 15:51:31 -04:00
parent a7c01684bf
commit 11467cdb01
5 changed files with 27 additions and 15 deletions

View File

@ -39,7 +39,7 @@
android:networkSecurityConfig="@xml/network_security_config">
<activity
android:name=".ui.main.MainActivity"
android:windowSoftInputMode="adjustPan"
android:windowSoftInputMode="adjustNothing"
android:label="@string/app_short_name"
android:theme="@style/Theme.Splash">
<intent-filter>

View File

@ -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)

View File

@ -169,6 +169,9 @@ open class MainActivity : BaseActivity<MainActivityBinding>(), 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()) {

View File

@ -109,10 +109,14 @@ 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,
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 {
@ -120,6 +124,7 @@ fun Controller.liftAppbarWith(recycler: RecyclerView, padView: Boolean = false)
}
)
}
}
} else {
view?.applyWindowInsetsForController()
recycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener)

View File

@ -123,18 +123,22 @@ 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<ViewGroup.MarginLayoutParams> {
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<ViewGroup.MarginLayoutParams> {
this.bottomMargin = bottom + bottomMargin
}
}
}
var handleInsets = true
doOnApplyWindowInsets { _, insets, _ ->
if (handleInsets) {