Merge remote-tracking branch 'origin/develop' into feature/eric/new-layout-navigation

This commit is contained in:
ericdecanini 2022-08-23 10:00:55 +02:00
commit ace2c672ed
16 changed files with 134 additions and 49 deletions

1
changelog.d/6836.bugfix Normal file
View File

@ -0,0 +1 @@
Fixes uncaught exceptions in the SyncWorker to cause the worker to become stuck in the failure state

1
changelog.d/6855.bugfix Normal file
View File

@ -0,0 +1 @@
Fixes onboarding captcha crashing when no WebView is available by showing an error with information instead

1
changelog.d/6859.wip Normal file
View File

@ -0,0 +1 @@
[New Layout] Adds space settings accessible through clicking the toolbar

1
changelog.d/6860.bugfix Normal file
View File

@ -0,0 +1 @@
Removes ability to continue registration after the app has been destroyed, fixes the next steps crashing due to missing information from the previous steps

1
changelog.d/6861.bugfix Normal file
View File

@ -0,0 +1 @@
Fixes crash when exiting the login or registration entry screens whilst they're loading

View File

@ -53,7 +53,7 @@ internal class MultipleEventSendingDispatcherWorker(context: Context, params: Wo
@Inject lateinit var timelineSendEventWorkCommon: TimelineSendEventWorkCommon
@Inject lateinit var localEchoRepository: LocalEchoRepository
override fun doOnError(params: Params): Result {
override fun doOnError(params: Params, failureMessage: String): Result {
params.localEchoIds.forEach { localEchoIds ->
localEchoRepository.updateSendState(
eventId = localEchoIds.eventId,
@ -63,7 +63,7 @@ internal class MultipleEventSendingDispatcherWorker(context: Context, params: Wo
)
}
return super.doOnError(params)
return super.doOnError(params, failureMessage)
}
override fun injectWith(injector: SessionComponent) {

View File

@ -30,6 +30,7 @@ import org.matrix.android.sdk.internal.session.sync.SyncTask
import org.matrix.android.sdk.internal.worker.SessionSafeCoroutineWorker
import org.matrix.android.sdk.internal.worker.SessionWorkerParams
import org.matrix.android.sdk.internal.worker.WorkerParamsFactory
import org.matrix.android.sdk.internal.worker.startChain
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
@ -136,6 +137,7 @@ internal class SyncWorker(context: Context, workerParameters: WorkerParameters,
.setConstraints(WorkManagerProvider.workConstraints)
.setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS)
.setInputData(data)
.startChain(true)
.build()
workManagerProvider.workManager
.enqueueUniqueWork(BG_SYNC_WORK_NAME, ExistingWorkPolicy.APPEND_OR_REPLACE, workRequest)

View File

@ -55,14 +55,16 @@ internal abstract class SessionSafeCoroutineWorker<PARAM : SessionWorkerParams>(
// Make sure to inject before handling error as you may need some dependencies to process them.
injectWith(sessionComponent)
if (params.lastFailureMessage != null) {
// Forward error to the next workers
doOnError(params)
} else {
doSafeWork(params)
when (val lastFailureMessage = params.lastFailureMessage) {
null -> doSafeWork(params)
else -> {
// Forward error to the next workers
doOnError(params, lastFailureMessage)
}
}
} catch (throwable: Throwable) {
buildErrorResult(params, throwable.localizedMessage ?: "error")
buildErrorResult(params, "${throwable::class.java.name}: ${throwable.localizedMessage ?: "N/A error message"}")
}
}
@ -89,10 +91,10 @@ internal abstract class SessionSafeCoroutineWorker<PARAM : SessionWorkerParams>(
* This is called when the input parameters are correct, but contain an error from the previous worker.
*/
@CallSuper
open fun doOnError(params: PARAM): Result {
open fun doOnError(params: PARAM, failureMessage: String): Result {
// Forward the error
return Result.success(inputData)
.also { Timber.e("Work cancelled due to input error from parent") }
.also { Timber.e("Work cancelled due to input error from parent: $failureMessage") }
}
companion object {

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.core.extensions
/**
* Recursive through the throwable and its causes for the given predicate.
*
* @return true when the predicate finds a match.
*/
tailrec fun Throwable?.crawlCausesFor(predicate: (Throwable) -> Boolean): Boolean {
return when {
this == null -> false
else -> {
when (predicate(this)) {
true -> true
else -> this.cause.crawlCausesFor(predicate)
}
}
}
}

View File

@ -303,11 +303,20 @@ class NewHomeDetailFragment @Inject constructor(
}
}
views.collapsingToolbar.debouncedClicks(::openSpaceSettings)
views.toolbar.debouncedClicks(::openSpaceSettings)
views.avatar.debouncedClicks {
navigator.openSettings(requireContext())
}
}
private fun openSpaceSettings() = withState(viewModel) { viewState ->
viewState.selectedSpace?.let {
sharedActionViewModel.post(HomeActivitySharedAction.ShowSpaceSettings(it.roomId))
}
}
private fun setupBottomNavigationView() {
views.bottomNavigationView.menu.findItem(R.id.bottom_action_notification).isVisible = vectorPreferences.labAddNotificationTab()
views.bottomNavigationView.setOnItemSelectedListener {

View File

@ -122,9 +122,6 @@ class OnboardingViewModel @AssistedInject constructor(
private val registrationWizard: RegistrationWizard
get() = authenticationService.getRegistrationWizard()
val currentThreePid: String?
get() = registrationWizard.getCurrentThreePid()
// True when login and password has been sent with success to the homeserver
val isRegistrationStarted: Boolean
get() = authenticationService.isRegistrationStarted()
@ -479,17 +476,6 @@ class OnboardingViewModel @AssistedInject constructor(
private fun handleInitWith(action: OnboardingAction.InitWith) {
loginConfig = action.loginConfig
// If there is a pending email validation continue on this step
try {
if (registrationWizard.isRegistrationStarted()) {
currentThreePid?.let {
handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.OnSendEmailSuccess(it, isRestoredSession = true)))
}
}
} catch (e: Throwable) {
// NOOP. API is designed to use wizards in a login/registration flow,
// but we need to check the state anyway.
}
}
private fun handleResetPassword(action: OnboardingAction.ResetPassword) {

View File

@ -16,15 +16,23 @@
package im.vector.app.features.onboarding.ftueauth
import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewStub
import com.airbnb.mvrx.args
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
import im.vector.app.core.extensions.crawlCausesFor
import im.vector.app.databinding.FragmentFtueLoginCaptchaBinding
import im.vector.app.databinding.ViewStubWebviewBinding
import im.vector.app.features.onboarding.OnboardingAction
import im.vector.app.features.onboarding.OnboardingViewState
import im.vector.app.features.onboarding.RegisterAction
import kotlinx.parcelize.Parcelize
import org.matrix.android.sdk.api.extensions.orFalse
import javax.inject.Inject
@Parcelize
@ -40,10 +48,32 @@ class FtueAuthCaptchaFragment @Inject constructor(
) : AbstractFtueAuthFragment<FragmentFtueLoginCaptchaBinding>() {
private val params: FtueAuthCaptchaFragmentArgument by args()
private var webViewBinding: ViewStubWebviewBinding? = null
private var isWebViewLoaded = false
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueLoginCaptchaBinding {
return FragmentFtueLoginCaptchaBinding.inflate(inflater, container, false)
return FragmentFtueLoginCaptchaBinding.inflate(inflater, container, false).also {
it.loginCaptchaWebViewStub.setOnInflateListener { _, inflated ->
webViewBinding = ViewStubWebviewBinding.bind(inflated)
}
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
inflateWebViewOrShowError()
}
private fun inflateWebViewOrShowError() {
views.loginCaptchaWebViewStub.inflateWebView(onError = {
MaterialAlertDialogBuilder(requireActivity())
.setTitle(R.string.dialog_title_error)
.setMessage(it.localizedMessage)
.setPositiveButton(R.string.ok) { _, _ ->
requireActivity().recreate()
}
.show()
})
}
override fun resetViewModel() {
@ -51,11 +81,26 @@ class FtueAuthCaptchaFragment @Inject constructor(
}
override fun updateWithState(state: OnboardingViewState) {
if (!isWebViewLoaded) {
captchaWebview.setupWebView(this, views.loginCaptchaWevView, views.loginCaptchaProgress, params.siteKey, state) {
if (!isWebViewLoaded && webViewBinding != null) {
captchaWebview.setupWebView(this, webViewBinding!!.root, views.loginCaptchaProgress, params.siteKey, state) {
viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.CaptchaDone(it)))
}
isWebViewLoaded = true
}
}
}
private fun ViewStub.inflateWebView(onError: (Throwable) -> Unit) {
try {
inflate()
} catch (e: Exception) {
val isMissingWebView = e.crawlCausesFor { it.message?.contains("MissingWebViewPackageException").orFalse() }
if (isMissingWebView) {
onError(MissingWebViewException(e))
} else {
onError(e)
}
}
}
private class MissingWebViewException(cause: Throwable) : IllegalStateException("Failed to load WebView provider: No WebView installed", cause)

View File

@ -261,11 +261,11 @@ class FtueAuthVariant(
}
private fun onStartCombinedLogin() {
addRegistrationStageFragmentToBackstack(FtueAuthCombinedLoginFragment::class.java)
addRegistrationStageFragmentToBackstack(FtueAuthCombinedLoginFragment::class.java, allowStateLoss = true)
}
private fun openStartCombinedRegister() {
addRegistrationStageFragmentToBackstack(FtueAuthCombinedRegisterFragment::class.java)
addRegistrationStageFragmentToBackstack(FtueAuthCombinedRegisterFragment::class.java, allowStateLoss = true)
}
private fun displayFallbackWebDialog() {
@ -520,13 +520,14 @@ class FtueAuthVariant(
)
}
private fun addRegistrationStageFragmentToBackstack(fragmentClass: Class<out Fragment>, params: Parcelable? = null) {
private fun addRegistrationStageFragmentToBackstack(fragmentClass: Class<out Fragment>, params: Parcelable? = null, allowStateLoss: Boolean = false) {
activity.addFragmentToBackstack(
views.loginFragmentContainer,
fragmentClass,
params,
tag = FRAGMENT_REGISTRATION_STAGE_TAG,
option = commonOption
option = commonOption,
allowStateLoss = allowStateLoss,
)
}

View File

@ -64,15 +64,27 @@
android:id="@+id/titleContentSpacing"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/loginCaptchaWevView"
app:layout_constraintBottom_toTopOf="@id/loginWebViewBarrier"
app:layout_constraintHeight_percent="0.03"
app:layout_constraintTop_toBottomOf="@id/captchaHeaderTitle" />
<WebView
android:id="@+id/loginCaptchaWevView"
<androidx.constraintlayout.widget.Barrier
android:id="@+id/loginWebViewBarrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="loginCaptchaWebViewStub,loginCaptchaWebView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/captchaGutterEnd"
app:layout_constraintStart_toStartOf="@id/captchaGutterStart"
app:layout_constraintTop_toBottomOf="@id/titleContentSpacing"/>
<ViewStub
android:id="@+id/loginCaptchaWebViewStub"
android:layout_width="0dp"
android:layout_height="0dp"
android:contentDescription="@string/login_a11y_captcha_container"
android:layout="@layout/view_stub_webview"
android:inflatedId="@+id/loginCaptchaWebView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/captchaGutterEnd"
app:layout_constraintStart_toStartOf="@id/captchaGutterStart"

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@ -195,21 +195,6 @@ class OnboardingViewModelTest {
.finish()
}
@Test
fun `given registration started with currentThreePid, when handling InitWith, then emits restored session OnSendEmailSuccess`() = runTest {
val test = viewModel.test()
fakeAuthenticationService.givenRegistrationWizard(FakeRegistrationWizard().also {
it.givenRegistrationStarted(hasStarted = true)
it.givenCurrentThreePid(AN_EMAIL)
})
viewModel.handle(OnboardingAction.InitWith(LoginConfig(A_HOMESERVER_URL, identityServerUrl = null)))
test
.assertEvents(OnboardingViewEvents.OnSendEmailSuccess(AN_EMAIL, isRestoredSession = true))
.finish()
}
@Test
fun `given registration not started, when handling InitWith, then does nothing`() = runTest {
val test = viewModel.test()