diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-12-16 22:14:00 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-12-16 22:14:00 +0100 |
commit | a4e828aba5f3a85b27738b7f7956e8267a960245 (patch) | |
tree | 2055b1fb70da02fe68b91eea0afb257d85c3e99a /src/main/java/de/pixart/messenger/ui/EditAccountActivity.java | |
parent | 6d0fb4d9b77bad4496179b1b8dcf43e2d19b0cef (diff) |
XmppConnection: refactor registration code. 'Open Website' on PAYMENT_REQUIRED failure
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/EditAccountActivity.java | 20 |
1 files changed, 15 insertions, 5 deletions
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 { |