Make change number error notifications more prominent.

This commit is contained in:
Nicholas
2023-05-10 15:48:26 -04:00
committed by Cody Henthorne
parent e4f70fa4fe
commit 208147db9e
4 changed files with 18 additions and 5 deletions
@@ -1,11 +1,15 @@
package org.thoughtcrime.securesms.components.settings.app.changenumber
import android.content.Context
import android.content.DialogInterface.OnClickListener
import android.os.Bundle
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.appcompat.widget.Toolbar
import androidx.navigation.fragment.findNavController
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Single
import org.signal.core.util.concurrent.LifecycleDisposable
@@ -46,6 +50,7 @@ class ChangeNumberVerifyFragment : LoggingFragment(R.layout.fragment_change_phon
if (!requestingCaptcha || viewModel.hasCaptchaToken()) {
requestCode()
} else {
Log.d(TAG, "Captcha required.")
Toast.makeText(requireContext(), R.string.ChangeNumberVerifyFragment__captcha_required, Toast.LENGTH_SHORT).show()
findNavController().navigateUp()
}
@@ -60,6 +65,7 @@ class ChangeNumberVerifyFragment : LoggingFragment(R.layout.fragment_change_phon
.andThen(viewModel.changeNumberWithRecoveryPassword())
.flatMap { changed ->
if (changed) {
Log.d(TAG, "Successfully changed number using recovery password.")
Single.just(RequestCodeResult.RecoveryPasswordWorked)
} else {
viewModel.requestVerificationCode(mode, mccMncProducer.mcc, mccMncProducer.mnc)
@@ -83,16 +89,18 @@ class ChangeNumberVerifyFragment : LoggingFragment(R.layout.fragment_change_phon
requestingCaptcha = true
} else if (processor.rateLimit()) {
Log.i(TAG, "Unable to request sms code due to rate limit")
Toast.makeText(requireContext(), R.string.RegistrationActivity_rate_limited_to_service, Toast.LENGTH_LONG).show()
findNavController().navigateUp()
showErrorDialog(requireContext(), R.string.RegistrationActivity_rate_limited_to_service) { _, _ -> findNavController().navigateUp() }
} else {
Log.w(TAG, "Unable to request sms code", processor.error)
Toast.makeText(requireContext(), R.string.RegistrationActivity_unable_to_connect_to_service, Toast.LENGTH_LONG).show()
findNavController().navigateUp()
showErrorDialog(requireContext(), R.string.RegistrationActivity_unable_to_request_verification_code) { _, _ -> findNavController().navigateUp() }
}
}
}
private fun showErrorDialog(context: Context, @StringRes message: Int, onPositiveButtonClickListener: OnClickListener?) {
MaterialAlertDialogBuilder(context).setMessage(message).setPositiveButton(R.string.ok, onPositiveButtonClickListener).show()
}
private sealed interface RequestCodeResult {
object RecoveryPasswordWorked : RequestCodeResult
class RequestedVerificationCode(val processor: RegistrationSessionProcessor) : RequestCodeResult
@@ -53,6 +53,7 @@ class VerifyAccountRepository(private val context: Application) {
mcc: String?,
mnc: String?
): Single<ServiceResponse<RegistrationSessionMetadataResponse>> {
Log.d(TAG, "Initializing registration session.")
return Single.fromCallable {
val fcmToken: String? = FcmUtil.getToken(context).orElse(null)
val accountManager: SignalServiceAccountManager = AccountManagerFactory.getInstance().createUnauthenticated(context, e164, SignalServiceAddress.DEFAULT_DEVICE_ID, password)
@@ -34,7 +34,7 @@ import io.reactivex.rxjava3.core.Single;
/**
* Base view model used in registration and change number flow. Handles the storage of all data
* shared between the two flows, orchestrating verification, and calling to subclasses to peform
* shared between the two flows, orchestrating verification, and calling to subclasses to perform
* the specific verify operations for each flow.
*/
public abstract class BaseRegistrationViewModel extends ViewModel {
@@ -287,6 +287,7 @@ public abstract class BaseRegistrationViewModel extends ViewModel {
.map(RegistrationSessionProcessor.RegistrationSessionProcessorForSession::new)
.doOnSuccess(createSessionProcessor -> {
if (createSessionProcessor.pushChallengeTimedOut()) {
Log.w(TAG, "Registration push challenge timed out.");
markPushChallengeTimedOut();
}
});
@@ -300,6 +301,7 @@ public abstract class BaseRegistrationViewModel extends ViewModel {
final String sessionId = processor.getSessionId();
if (processor.isAllowedToRequestCode()) {
Log.d(TAG, "All challenges satisfied.");
return Single.just(processor);
}
+2
View File
@@ -1830,6 +1830,8 @@
<!-- During registration, if the user attempts (and fails) to register, we display this error message with a number of minutes timer they are allowed to try again.-->
<string name="RegistrationActivity_rate_limited_to_try_again">You\'ve made too many attempts to register this number. Please try again in %s.</string>
<string name="RegistrationActivity_unable_to_connect_to_service">Unable to connect to service. Please check network connection and try again.</string>
<!-- Generic error when the app is unable to request an SMS code for an unknown reason. -->
<string name="RegistrationActivity_unable_to_request_verification_code">Unable to request a verification code. Please check network connection and try again.</string>
<string name="RegistrationActivity_non_standard_number_format">Non-standard number format</string>
<string name="RegistrationActivity_the_number_you_entered_appears_to_be_a_non_standard">The number you entered (%1$s) appears to be a non-standard format.\n\nDid you mean %2$s?</string>
<string name="RegistrationActivity_signal_android_phone_number_format">Signal Android - Phone Number Format</string>