From a4e828aba5f3a85b27738b7f7956e8267a960245 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 16 Dec 2017 22:14:00 +0100 Subject: XmppConnection: refactor registration code. 'Open Website' on PAYMENT_REQUIRED failure --- .../de/pixart/messenger/ui/EditAccountActivity.java | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/main/java/de/pixart/messenger/ui/EditAccountActivity.java') diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index bb79bc67c..655f83514 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -38,6 +38,7 @@ import android.widget.Toast; import org.openintents.openpgp.util.OpenPgpUtils; +import java.net.URL; import java.util.Arrays; import java.util.List; import java.util.Set; @@ -153,10 +154,13 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } XmppConnection connection = mAccount == null ? null : mAccount.getXmppConnection(); - String url = connection != null && mAccount.getStatus() == Account.State.REGISTRATION_WEB ? connection.getWebRegistrationUrl() : null; - if (url != null && registerNewAccount && !wasDisabled) { + boolean openRegistrationUrl = registerNewAccount && mAccount != null && mAccount.getStatus() == Account.State.REGISTRATION_WEB; + boolean openPaymentUrl = mAccount != null && mAccount.getStatus() == Account.State.PAYMENT_REQUIRED; + final boolean redirectionWorthyStatus = openPaymentUrl || openRegistrationUrl; + URL url = connection != null && redirectionWorthyStatus ? connection.getRedirectionUrl() : null; + if (url != null && redirectionWorthyStatus && !wasDisabled) { try { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString()))); return; } catch (ActivityNotFoundException e) { Toast.makeText(EditAccountActivity.this, R.string.application_found_to_open_website, Toast.LENGTH_SHORT); @@ -455,11 +459,17 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.mSaveButton.setTextColor(getSecondaryTextColor()); } } else { - this.mSaveButton.setText(R.string.connect); + XmppConnection connection = mAccount == null ? null : mAccount.getXmppConnection(); + URL url = connection != null && mAccount.getStatus() == Account.State.PAYMENT_REQUIRED ? connection.getRedirectionUrl() : null; + if (url != null) { + this.mSaveButton.setText(R.string.open_website); + } else { + this.mSaveButton.setText(R.string.connect); + } } } else { XmppConnection connection = mAccount == null ? null : mAccount.getXmppConnection(); - String url = connection != null && mAccount.getStatus() == Account.State.REGISTRATION_WEB ? connection.getWebRegistrationUrl() : null; + URL url = connection != null && mAccount.getStatus() == Account.State.REGISTRATION_WEB ? connection.getRedirectionUrl() : null; if (url != null && mRegisterNew.isChecked()) { this.mSaveButton.setText(R.string.open_website); } else { -- cgit v1.2.3