improve LoginWebViewActivityUX (#2465)

This commit is contained in:
Konrad Pozniak 2022-04-28 20:38:51 +02:00 committed by GitHub
parent 28ac190212
commit e5b58770ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 3 deletions

View File

@ -19,8 +19,10 @@ import androidx.activity.result.contract.ActivityResultContract
import androidx.core.net.toUri import androidx.core.net.toUri
import com.keylesspalace.tusky.BaseActivity import com.keylesspalace.tusky.BaseActivity
import com.keylesspalace.tusky.BuildConfig import com.keylesspalace.tusky.BuildConfig
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.databinding.LoginWebviewBinding import com.keylesspalace.tusky.databinding.LoginWebviewBinding
import com.keylesspalace.tusky.di.Injectable import com.keylesspalace.tusky.di.Injectable
import com.keylesspalace.tusky.util.hide
import com.keylesspalace.tusky.util.viewBinding import com.keylesspalace.tusky.util.viewBinding
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
@ -87,7 +89,9 @@ class LoginWebViewActivity : BaseActivity(), Injectable {
setSupportActionBar(binding.loginToolbar) setSupportActionBar(binding.loginToolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowTitleEnabled(false) supportActionBar?.setDisplayShowTitleEnabled(true)
setTitle(R.string.title_login)
val webView = binding.loginWebView val webView = binding.loginWebView
webView.settings.allowContentAccess = false webView.settings.allowContentAccess = false
@ -103,13 +107,17 @@ class LoginWebViewActivity : BaseActivity(), Injectable {
val oauthUrl = data.oauthRedirectUrl val oauthUrl = data.oauthRedirectUrl
webView.webViewClient = object : WebViewClient() { webView.webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView?, url: String?) {
binding.loginProgress.hide()
}
override fun onReceivedError( override fun onReceivedError(
view: WebView, view: WebView,
request: WebResourceRequest, request: WebResourceRequest,
error: WebResourceError error: WebResourceError
) { ) {
Log.d("LoginWeb", "Failed to load ${data.url}: $error") Log.d("LoginWeb", "Failed to load ${data.url}: $error")
finish() finishWithoutSlideOutAnimation()
} }
override fun shouldOverrideUrlLoading( override fun shouldOverrideUrlLoading(
@ -165,10 +173,14 @@ class LoginWebViewActivity : BaseActivity(), Injectable {
super.onDestroy() super.onDestroy()
} }
override fun finish() {
super.finishWithoutSlideOutAnimation()
}
override fun requiresLogin() = false override fun requiresLogin() = false
private fun sendResult(result: LoginResult) { private fun sendResult(result: LoginResult) {
setResult(Activity.RESULT_OK, OauthLogin.makeResultIntent(result)) setResult(Activity.RESULT_OK, OauthLogin.makeResultIntent(result))
finish() finishWithoutSlideOutAnimation()
} }
} }

View File

@ -16,6 +16,12 @@
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<ProgressBar
android:id="@+id/loginProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<WebView <WebView
android:id="@+id/loginWebView" android:id="@+id/loginWebView"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -21,6 +21,7 @@
<string name="error_media_upload_sending">The upload failed.</string> <string name="error_media_upload_sending">The upload failed.</string>
<string name="error_sender_account_gone">Error sending post.</string> <string name="error_sender_account_gone">Error sending post.</string>
<string name="title_login">Login</string>
<string name="title_home">Home</string> <string name="title_home">Home</string>
<string name="title_notifications">Notifications</string> <string name="title_notifications">Notifications</string>
<string name="title_public_local">Local</string> <string name="title_public_local">Local</string>