do proper redirects in onBackedConnected if something goes wrong

This commit is contained in:
Daniel Gultsch 2018-10-31 10:24:47 +01:00
parent 3fab93bdd6
commit 3efb5b7f5c
3 changed files with 46 additions and 15 deletions

View file

@ -14,12 +14,16 @@ import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import java.util.concurrent.atomic.AtomicBoolean;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.ActivityEnterNumberBinding; import eu.siacs.conversations.databinding.ActivityEnterNumberBinding;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.QuickConversationsService; import eu.siacs.conversations.services.QuickConversationsService;
import eu.siacs.conversations.ui.drawable.TextDrawable; import eu.siacs.conversations.ui.drawable.TextDrawable;
import eu.siacs.conversations.ui.util.ApiDialogHelper; import eu.siacs.conversations.ui.util.ApiDialogHelper;
import eu.siacs.conversations.utils.AccountUtils;
import eu.siacs.conversations.utils.PhoneNumberUtilWrapper; import eu.siacs.conversations.utils.PhoneNumberUtilWrapper;
import io.michaelrocks.libphonenumber.android.NumberParseException; import io.michaelrocks.libphonenumber.android.NumberParseException;
import io.michaelrocks.libphonenumber.android.PhoneNumberUtil; import io.michaelrocks.libphonenumber.android.PhoneNumberUtil;
@ -31,6 +35,8 @@ public class EnterPhoneNumberActivity extends XmppActivity implements QuickConve
private ActivityEnterNumberBinding binding; private ActivityEnterNumberBinding binding;
private final AtomicBoolean redirectInProgress = new AtomicBoolean(false);
private String region = null; private String region = null;
private final TextWatcher countryCodeTextWatcher = new TextWatcher() { private final TextWatcher countryCodeTextWatcher = new TextWatcher() {
@Override @Override
@ -73,6 +79,10 @@ public class EnterPhoneNumberActivity extends XmppActivity implements QuickConve
@Override @Override
void onBackendConnected() { void onBackendConnected() {
xmppConnectionService.getQuickConversationsService().addOnVerificationRequestedListener(this); xmppConnectionService.getQuickConversationsService().addOnVerificationRequestedListener(this);
final Account account = AccountUtils.getFirst(xmppConnectionService);
if (account != null) {
runOnUiThread(this::performRedirectToVerificationActivity);
}
} }
@Override @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 @Override
public void onVerificationRequestFailed(int code) { public void onVerificationRequestFailed(int code) {
runOnUiThread(() -> { runOnUiThread(() -> {
@ -202,19 +228,11 @@ public class EnterPhoneNumberActivity extends XmppActivity implements QuickConve
@Override @Override
public void onVerificationRequested() { public void onVerificationRequested() {
runOnUiThread(() -> { runOnUiThread(this::performRedirectToVerificationActivity);
startActivity(new Intent(this, VerifyActivity.class));
finish();
});
} }
@Override @Override
public void onVerificationRequestedRetryAt(long timestamp) { public void onVerificationRequestedRetryAt(long timestamp) {
runOnUiThread(() -> { runOnUiThread(() -> performRedirectToVerificationActivity(timestamp));
Intent intent = new Intent(this, VerifyActivity.class);
intent.putExtra(VerifyActivity.EXTRA_RETRY_SMS_AFTER, timestamp);
startActivity(intent);
finish();
});
} }
} }

View file

@ -15,6 +15,8 @@ import android.support.v7.widget.Toolbar;
import android.text.Html; import android.text.Html;
import android.view.View; import android.view.View;
import java.util.concurrent.atomic.AtomicBoolean;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.ActivityVerifyBinding; import eu.siacs.conversations.databinding.ActivityVerifyBinding;
import eu.siacs.conversations.entities.Account; 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() { private boolean setTimeoutLabelInResendButton() {
if (retrySmsAfter != 0) { if (retrySmsAfter != 0) {
@ -191,6 +194,10 @@ public class VerifyActivity extends XmppActivity implements ClipboardManager.OnP
if (this.account == null) { if (this.account == null) {
return; 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())))); 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()); setVerifyingState(xmppConnectionService.getQuickConversationsService().isVerifying());
setRequestingVerificationState(xmppConnectionService.getQuickConversationsService().isRequestingVerification()); setRequestingVerificationState(xmppConnectionService.getQuickConversationsService().isRequestingVerification());
@ -261,11 +268,13 @@ public class VerifyActivity extends XmppActivity implements ClipboardManager.OnP
} }
private void performPostVerificationRedirect() { private void performPostVerificationRedirect() {
Intent intent = new Intent(this, PublishProfilePictureActivity.class); if (redirectInProgress.compareAndSet(false, true)) {
intent.putExtra(PublishProfilePictureActivity.EXTRA_ACCOUNT, account.getJid().asBareJid().toEscapedString()); Intent intent = new Intent(this, PublishProfilePictureActivity.class);
intent.putExtra("setup", true); intent.putExtra(PublishProfilePictureActivity.EXTRA_ACCOUNT, account.getJid().asBareJid().toEscapedString());
startActivity(intent); intent.putExtra("setup", true);
finish(); startActivity(intent);
finish();
}
} }
@Override @Override

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="notifications_from_strangers">true</bool>
</resources>