From 3efb5b7f5cee2130565a802bc7b909a609862617 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 31 Oct 2018 10:24:47 +0100 Subject: [PATCH] do proper redirects in onBackedConnected if something goes wrong --- .../ui/EnterPhoneNumberActivity.java | 38 ++++++++++++++----- .../conversations/ui/VerifyActivity.java | 19 +++++++--- src/quicksy/res/values/defaults.xml | 4 ++ 3 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 src/quicksy/res/values/defaults.xml diff --git a/src/quicksy/java/eu/siacs/conversations/ui/EnterPhoneNumberActivity.java b/src/quicksy/java/eu/siacs/conversations/ui/EnterPhoneNumberActivity.java index 200ca9e12..24d060d4e 100644 --- a/src/quicksy/java/eu/siacs/conversations/ui/EnterPhoneNumberActivity.java +++ b/src/quicksy/java/eu/siacs/conversations/ui/EnterPhoneNumberActivity.java @@ -14,12 +14,16 @@ import android.view.KeyEvent; import android.view.View; import android.widget.EditText; +import java.util.concurrent.atomic.AtomicBoolean; + import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.databinding.ActivityEnterNumberBinding; +import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.services.QuickConversationsService; import eu.siacs.conversations.ui.drawable.TextDrawable; import eu.siacs.conversations.ui.util.ApiDialogHelper; +import eu.siacs.conversations.utils.AccountUtils; import eu.siacs.conversations.utils.PhoneNumberUtilWrapper; import io.michaelrocks.libphonenumber.android.NumberParseException; import io.michaelrocks.libphonenumber.android.PhoneNumberUtil; @@ -31,6 +35,8 @@ public class EnterPhoneNumberActivity extends XmppActivity implements QuickConve private ActivityEnterNumberBinding binding; + private final AtomicBoolean redirectInProgress = new AtomicBoolean(false); + private String region = null; private final TextWatcher countryCodeTextWatcher = new TextWatcher() { @Override @@ -73,6 +79,10 @@ public class EnterPhoneNumberActivity extends XmppActivity implements QuickConve @Override void onBackendConnected() { xmppConnectionService.getQuickConversationsService().addOnVerificationRequestedListener(this); + final Account account = AccountUtils.getFirst(xmppConnectionService); + if (account != null) { + runOnUiThread(this::performRedirectToVerificationActivity); + } } @Override @@ -192,6 +202,22 @@ public class EnterPhoneNumberActivity extends XmppActivity implements QuickConve } } + private void performRedirectToVerificationActivity(long timestamp) { + if (redirectInProgress.compareAndSet(false, true)) { + Intent intent = new Intent(this, VerifyActivity.class); + intent.putExtra(VerifyActivity.EXTRA_RETRY_SMS_AFTER, timestamp); + startActivity(intent); + finish(); + } + } + + private void performRedirectToVerificationActivity() { + if (redirectInProgress.compareAndSet(false, true)) { + startActivity(new Intent(this, VerifyActivity.class)); + finish(); + } + } + @Override public void onVerificationRequestFailed(int code) { runOnUiThread(() -> { @@ -202,19 +228,11 @@ public class EnterPhoneNumberActivity extends XmppActivity implements QuickConve @Override public void onVerificationRequested() { - runOnUiThread(() -> { - startActivity(new Intent(this, VerifyActivity.class)); - finish(); - }); + runOnUiThread(this::performRedirectToVerificationActivity); } @Override public void onVerificationRequestedRetryAt(long timestamp) { - runOnUiThread(() -> { - Intent intent = new Intent(this, VerifyActivity.class); - intent.putExtra(VerifyActivity.EXTRA_RETRY_SMS_AFTER, timestamp); - startActivity(intent); - finish(); - }); + runOnUiThread(() -> performRedirectToVerificationActivity(timestamp)); } } diff --git a/src/quicksy/java/eu/siacs/conversations/ui/VerifyActivity.java b/src/quicksy/java/eu/siacs/conversations/ui/VerifyActivity.java index 80ef88335..9225a8be6 100644 --- a/src/quicksy/java/eu/siacs/conversations/ui/VerifyActivity.java +++ b/src/quicksy/java/eu/siacs/conversations/ui/VerifyActivity.java @@ -15,6 +15,8 @@ import android.support.v7.widget.Toolbar; import android.text.Html; import android.view.View; +import java.util.concurrent.atomic.AtomicBoolean; + import eu.siacs.conversations.R; import eu.siacs.conversations.databinding.ActivityVerifyBinding; import eu.siacs.conversations.entities.Account; @@ -58,6 +60,7 @@ public class VerifyActivity extends XmppActivity implements ClipboardManager.OnP } } }; + private final AtomicBoolean redirectInProgress = new AtomicBoolean(false); private boolean setTimeoutLabelInResendButton() { if (retrySmsAfter != 0) { @@ -191,6 +194,10 @@ public class VerifyActivity extends XmppActivity implements ClipboardManager.OnP if (this.account == null) { return; } + if (!account.isOptionSet(Account.OPTION_UNVERIFIED) && !account.isOptionSet(Account.OPTION_DISABLED)) { + runOnUiThread(this::performPostVerificationRedirect); + return; + } this.binding.weHaveSent.setText(Html.fromHtml(getString(R.string.we_have_sent_you_an_sms_to_x, PhoneNumberUtilWrapper.toFormattedPhoneNumber(this, this.account.getJid())))); setVerifyingState(xmppConnectionService.getQuickConversationsService().isVerifying()); setRequestingVerificationState(xmppConnectionService.getQuickConversationsService().isRequestingVerification()); @@ -261,11 +268,13 @@ public class VerifyActivity extends XmppActivity implements ClipboardManager.OnP } private void performPostVerificationRedirect() { - Intent intent = new Intent(this, PublishProfilePictureActivity.class); - intent.putExtra(PublishProfilePictureActivity.EXTRA_ACCOUNT, account.getJid().asBareJid().toEscapedString()); - intent.putExtra("setup", true); - startActivity(intent); - finish(); + if (redirectInProgress.compareAndSet(false, true)) { + Intent intent = new Intent(this, PublishProfilePictureActivity.class); + intent.putExtra(PublishProfilePictureActivity.EXTRA_ACCOUNT, account.getJid().asBareJid().toEscapedString()); + intent.putExtra("setup", true); + startActivity(intent); + finish(); + } } @Override diff --git a/src/quicksy/res/values/defaults.xml b/src/quicksy/res/values/defaults.xml new file mode 100644 index 000000000..0df07006b --- /dev/null +++ b/src/quicksy/res/values/defaults.xml @@ -0,0 +1,4 @@ + + + true + \ No newline at end of file