From 08d3438dde59333327eb0d6c1ceccda4c41b9399 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Fri, 2 Oct 2020 21:12:12 +0200 Subject: [PATCH] improve layout of LoginActivity when keyboard is extended and animate changes --- app/src/main/AndroidManifest.xml | 3 +- .../components/login/LoginActivity.kt | 31 +++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a1911b7..c44f130 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -35,7 +35,8 @@ + android:theme="@style/AppTheme.Fullscreen" + android:windowSoftInputMode="adjustResize"> - val top = insets.getInsets(systemBars()).top + val insetTop = insets.getInsets(systemBars()).top val toolbarParams = binding.loginToolbar.layoutParams as ViewGroup.MarginLayoutParams - toolbarParams.topMargin = top + toolbarParams.topMargin = insetTop + + val insetBottom = insets.getInsets(ime()).bottom + val paddingBottom = binding.root.paddingBottom + + if (paddingBottom != insetBottom) { + // animate the bottom padding when the soft keyboard visibility changed + val animator = ValueAnimator.ofInt(paddingBottom, insetBottom) + animator.addUpdateListener { valueAnimator -> + binding.root.updatePadding(bottom = valueAnimator.animatedValue as Int) + } + animator.duration = 200 + animator.start() + } + WindowInsetsCompat.CONSUMED } @@ -155,7 +172,15 @@ class LoginActivity : BaseActivity() { } LoginState.SUCCESS -> { setLoading(true) - startActivityForResult(LoginWebViewActivity.newIntent(loginModel.domain!!, loginModel.clientId!!, loginModel.clientSecret!!, this), REQUEST_CODE) + startActivityForResult( + LoginWebViewActivity.newIntent( + loginModel.domain!!, + loginModel.clientId!!, + loginModel.clientSecret!!, + this + ), + REQUEST_CODE + ) } LoginState.SUCCESS_FINAL -> { setLoading(true)