From 0dc32774ec14b15508a9182b9552305fb701bb0a Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Thu, 17 Mar 2022 21:50:14 +0100 Subject: [PATCH] handle screen rotation in LoginWebViewActivity (#2390) --- .../components/login/LoginWebViewActivity.kt | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/login/LoginWebViewActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/login/LoginWebViewActivity.kt index 16e07f99d..fbe4519d4 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/login/LoginWebViewActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/login/LoginWebViewActivity.kt @@ -127,19 +127,29 @@ class LoginWebViewActivity : BaseActivity(), Injectable { } } webView.setBackgroundColor(Color.TRANSPARENT) - webView.loadUrl(data.url.toString()) + + if (savedInstanceState == null) { + webView.loadUrl(data.url.toString()) + } else { + webView.restoreState(savedInstanceState) + } + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + binding.loginWebView.saveState(outState) } override fun onDestroy() { - // We don't want to keep user session in WebView, we just want our own accessToken - WebStorage.getInstance().deleteAllData() - CookieManager.getInstance().removeAllCookies(null) + if (isFinishing) { + // We don't want to keep user session in WebView, we just want our own accessToken + WebStorage.getInstance().deleteAllData() + CookieManager.getInstance().removeAllCookies(null) + } super.onDestroy() } - override fun requiresLogin(): Boolean { - return false - } + override fun requiresLogin() = false private fun sendResult(result: LoginResult) { setResult(Activity.RESULT_OK, OauthLogin.makeResultIntent(result))