From 87f14d8babb36b6ca9c99140968c88992808dc3a Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 5 Feb 2024 16:00:29 +0100 Subject: [PATCH] Make the button to send problem enable, but show an error if the decription is too short to prevent users from being blocked. --- .../impl/bugreport/BugReportFormError.kt | 21 +++++++++++++++++++ .../impl/bugreport/BugReportPresenter.kt | 8 ++++++- .../impl/bugreport/BugReportState.kt | 5 +++-- .../impl/bugreport/BugReportStateProvider.kt | 1 + .../rageshake/impl/bugreport/BugReportView.kt | 8 ++++++- .../impl/src/main/res/values/localazy.xml | 1 + 6 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportFormError.kt diff --git a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportFormError.kt b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportFormError.kt new file mode 100644 index 0000000000..fdaebc376e --- /dev/null +++ b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportFormError.kt @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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 io.element.android.features.rageshake.impl.bugreport + +sealed class BugReportFormError: Exception() { + data object DescriptionTooShort : BugReportFormError() +} diff --git a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportPresenter.kt b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportPresenter.kt index fea6bc95b1..5e3b3cfeb1 100644 --- a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportPresenter.kt +++ b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportPresenter.kt @@ -91,7 +91,13 @@ class BugReportPresenter @Inject constructor( fun handleEvents(event: BugReportEvents) { when (event) { - BugReportEvents.SendBugReport -> appCoroutineScope.sendBugReport(formState.value, crashInfo.isNotEmpty(), uploadListener) + BugReportEvents.SendBugReport -> { + if (formState.value.description.length < 10) { + sendingAction.value = AsyncAction.Failure(BugReportFormError.DescriptionTooShort) + } else { + appCoroutineScope.sendBugReport(formState.value, crashInfo.isNotEmpty(), uploadListener) + } + } BugReportEvents.ResetAll -> appCoroutineScope.resetAll() is BugReportEvents.SetDescription -> updateFormState(formState) { copy(description = event.description) diff --git a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportState.kt b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportState.kt index c3bfbec888..16edae46c4 100644 --- a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportState.kt +++ b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportState.kt @@ -28,8 +28,9 @@ data class BugReportState( val sending: AsyncAction, val eventSink: (BugReportEvents) -> Unit ) { - val submitEnabled = - formState.description.length > 10 && sending !is AsyncAction.Loading + val submitEnabled = sending !is AsyncAction.Loading + val isDescriptionInError = sending is AsyncAction.Failure && + sending.error is BugReportFormError.DescriptionTooShort } @Parcelize diff --git a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportStateProvider.kt b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportStateProvider.kt index bb0d273de4..8bda648c4c 100644 --- a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportStateProvider.kt +++ b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportStateProvider.kt @@ -33,6 +33,7 @@ open class BugReportStateProvider : PreviewParameterProvider { ), aBugReportState().copy(sending = AsyncAction.Loading), aBugReportState().copy(sending = AsyncAction.Success(Unit)), + aBugReportState().copy(sending = AsyncAction.Failure(BugReportFormError.DescriptionTooShort)), ) } diff --git a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportView.kt b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportView.kt index e10e9250e3..86f351ea00 100644 --- a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportView.kt +++ b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportView.kt @@ -96,7 +96,7 @@ fun BugReportView( imeAction = ImeAction.Next ), minLines = 3, - // TODO Error text too short + isError = state.isDescriptionInError, ) } Spacer(modifier = Modifier.height(16.dp)) @@ -167,6 +167,12 @@ fun BugReportView( eventSink(BugReportEvents.ResetAll) onDone() }, + errorMessage = { error -> + when (error) { + BugReportFormError.DescriptionTooShort -> stringResource(id = R.string.screen_bug_report_error_description_too_short) + else -> error.message ?: error.toString() + } + }, onErrorDismiss = { eventSink(BugReportEvents.ClearError) }, ) } diff --git a/features/rageshake/impl/src/main/res/values/localazy.xml b/features/rageshake/impl/src/main/res/values/localazy.xml index 83413c3919..1d1805a386 100644 --- a/features/rageshake/impl/src/main/res/values/localazy.xml +++ b/features/rageshake/impl/src/main/res/values/localazy.xml @@ -7,6 +7,7 @@ "Please describe the problem. What did you do? What did you expect to happen? What actually happened. Please go into as much detail as you can." "Describe the problem…" "If possible, please write the description in English." + "The description is too short, please provide more details about what happened. Thanks!" "Send crash logs" "Allow logs" "Send screenshot"