Browse Source

Make the button to send problem enable, but show an error if the decription is too short to prevent users from being blocked.

pull/2350/head
Benoit Marty 8 months ago
parent
commit
87f14d8bab
  1. 21
      features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportFormError.kt
  2. 8
      features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportPresenter.kt
  3. 5
      features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportState.kt
  4. 1
      features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportStateProvider.kt
  5. 8
      features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportView.kt
  6. 1
      features/rageshake/impl/src/main/res/values/localazy.xml

21
features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportFormError.kt

@ -0,0 +1,21 @@ @@ -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()
}

8
features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportPresenter.kt

@ -91,7 +91,13 @@ class BugReportPresenter @Inject constructor( @@ -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)

5
features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportState.kt

@ -28,8 +28,9 @@ data class BugReportState( @@ -28,8 +28,9 @@ data class BugReportState(
val sending: AsyncAction<Unit>,
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

1
features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportStateProvider.kt

@ -33,6 +33,7 @@ open class BugReportStateProvider : PreviewParameterProvider<BugReportState> { @@ -33,6 +33,7 @@ open class BugReportStateProvider : PreviewParameterProvider<BugReportState> {
),
aBugReportState().copy(sending = AsyncAction.Loading),
aBugReportState().copy(sending = AsyncAction.Success(Unit)),
aBugReportState().copy(sending = AsyncAction.Failure(BugReportFormError.DescriptionTooShort)),
)
}

8
features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportView.kt

@ -96,7 +96,7 @@ fun BugReportView( @@ -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( @@ -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) },
)
}

1
features/rageshake/impl/src/main/res/values/localazy.xml

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
<string name="screen_bug_report_editor_description">"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."</string>
<string name="screen_bug_report_editor_placeholder">"Describe the problem…"</string>
<string name="screen_bug_report_editor_supporting">"If possible, please write the description in English."</string>
<string name="screen_bug_report_error_description_too_short">"The description is too short, please provide more details about what happened. Thanks!"</string>
<string name="screen_bug_report_include_crash_logs">"Send crash logs"</string>
<string name="screen_bug_report_include_logs">"Allow logs"</string>
<string name="screen_bug_report_include_screenshot">"Send screenshot"</string>

Loading…
Cancel
Save