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.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));
}
}

View file

@ -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

View file

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