M src/main/res/values/strings.xml => src/main/res/values/strings.xml +11 -1
@@ 761,10 761,11 @@
<string name="search_countries">Search countries</string>
<string name="verify_x">Verify %s</string>
<string name="we_have_sent_you_an_sms_to_x"><![CDATA[We have sent you an SMS to <b>%s</b>.]]></string>
- <string name="we_have_sent_you_the_sms_again">We have sent you the SMS again.</string>
+ <string name="we_have_sent_you_another_sms">We have sent you another SMS with a 6 digit code.</string>
<string name="please_enter_pin_below">Please enter the 6 digit pin below.</string>
<string name="resend_sms">Resend SMS</string>
<string name="resend_sms_in">Resend SMS (%s)</string>
+ <string name="wait_x">Please wait (%s)</string>
<string name="back">back</string>
<string name="possible_pin">Automatically pasted possible pin from clipboard.</string>
<string name="please_enter_pin">Please enter your 6 digit pin.</string>
@@ 773,4 774,13 @@
<string name="no">No</string>
<string name="verifying">Verifying…</string>
<string name="requesting_sms">Requesting SMS…</string>
+ <string name="incorrect_pin">The pin you have entered is incorrect.</string>
+ <string name="unknown_api_error_network">Unknown network error.</string>
+ <string name="unknown_api_error_response">Unknown response from server.</string>
+ <string name="unable_to_connect_to_server">Unable to connect to server.</string>
+ <string name="unable_to_establish_secure_connection">Unable to establish secure connection.</string>
+ <string name="unable_to_find_server">Unable to find server.</string>
+ <string name="invalid_user_input">Invalid user input</string>
+ <string name="temporarily_unavailable">Temporarily unavailable. Try again later.</string>
+ <string name="no_network_connection">No network connection.</string>
</resources>
M src/quick/java/eu/siacs/conversations/services/QuickConversationsService.java => src/quick/java/eu/siacs/conversations/services/QuickConversationsService.java +15 -4
@@ 18,6 18,8 @@ import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
+import javax.net.ssl.SSLHandshakeException;
+
import eu.siacs.conversations.Config;
import eu.siacs.conversations.crypto.sasl.Plain;
import eu.siacs.conversations.entities.Account;
@@ 33,8 35,10 @@ public class QuickConversationsService {
public static final int API_ERROR_OTHER = -1;
public static final int API_ERROR_UNKNOWN_HOST = -2;
public static final int API_ERROR_CONNECT = -3;
+ public static final int API_ERROR_SSL_HANDSHAKE = -4;
+ public static final int API_ERROR_AIRPLANE_MODE = -5;
- private static final String BASE_URL = "https://venus.fritz.box:4567";
+ private static final String BASE_URL = "http://venus.fritz.box:4567";
private final XmppConnectionService service;
@@ 145,7 149,7 @@ public class QuickConversationsService {
}
}
- public void verify(Account account, String pin) {
+ public void verify(final Account account, String pin) {
/**
* POST /password
* authentication gesetzt mit telephone nummber und verification code
@@ 177,6 181,9 @@ public class QuickConversationsService {
connection.connect();
final int code = connection.getResponseCode();
if (code == 200) {
+ account.setOption(Account.OPTION_UNVERIFIED, false);
+ account.setOption(Account.OPTION_DISABLED, false);
+ service.updateAccount(account);
synchronized (mOnVerification) {
for (OnVerification onVerification : mOnVerification) {
onVerification.onVerificationSucceeded();
@@ 210,11 217,15 @@ public class QuickConversationsService {
}
}
- private static int getApiErrorCode(Exception e) {
- if (e instanceof UnknownHostException) {
+ private int getApiErrorCode(Exception e) {
+ if (!service.hasInternetConnection()) {
+ return API_ERROR_AIRPLANE_MODE;
+ } else if (e instanceof UnknownHostException) {
return API_ERROR_UNKNOWN_HOST;
} else if (e instanceof ConnectException) {
return API_ERROR_CONNECT;
+ } else if (e instanceof SSLHandshakeException) {
+ return API_ERROR_SSL_HANDSHAKE;
} else {
Log.d(Config.LOGTAG,e.getClass().getName());
return API_ERROR_OTHER;
M src/quick/java/eu/siacs/conversations/ui/EnterPhoneNumberActivity.java => src/quick/java/eu/siacs/conversations/ui/EnterPhoneNumberActivity.java +6 -3
@@ 20,6 20,7 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.ActivityEnterNumberBinding;
import eu.siacs.conversations.services.QuickConversationsService;
import eu.siacs.conversations.ui.drawable.TextDrawable;
+import eu.siacs.conversations.ui.util.ApiErrorDialogHelper;
import eu.siacs.conversations.utils.PhoneNumberUtilWrapper;
import io.michaelrocks.libphonenumber.android.NumberParseException;
import io.michaelrocks.libphonenumber.android.PhoneNumberUtil;
@@ 32,8 33,6 @@ public class EnterPhoneNumberActivity extends XmppActivity implements QuickConve
private ActivityEnterNumberBinding binding;
private String region = null;
- private boolean requestingVerification = false;
-
private final TextWatcher countryCodeTextWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@@ 65,6 64,7 @@ public class EnterPhoneNumberActivity extends XmppActivity implements QuickConve
}
}
};
+ private boolean requestingVerification = false;
@Override
protected void refreshUiReal() {
@@ 159,6 159,8 @@ public class EnterPhoneNumberActivity extends XmppActivity implements QuickConve
this.binding.number.setEnabled(!requesting);
this.binding.next.setEnabled(!requesting);
this.binding.next.setText(requesting ? R.string.requesting_sms : R.string.next);
+ this.binding.progressBar.setVisibility(requesting ? View.VISIBLE : View.GONE);
+ this.binding.progressBar.setIndeterminate(requesting);
}
@Override
@@ 176,8 178,9 @@ public class EnterPhoneNumberActivity extends XmppActivity implements QuickConve
@Override
public void onVerificationRequestFailed(int code) {
- runOnUiThread(()->{
+ runOnUiThread(() -> {
setRequestingVerificationState(false);
+ ApiErrorDialogHelper.create(this, code).show();
});
}
M src/quick/java/eu/siacs/conversations/ui/VerifyActivity.java => src/quick/java/eu/siacs/conversations/ui/VerifyActivity.java +64 -19
@@ 13,14 13,13 @@ import android.os.SystemClock;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.Toolbar;
import android.text.Html;
-import android.util.Log;
import android.view.View;
-import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.ActivityVerifyBinding;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.QuickConversationsService;
+import eu.siacs.conversations.ui.util.ApiErrorDialogHelper;
import eu.siacs.conversations.ui.util.PinEntryWrapper;
import eu.siacs.conversations.utils.AccountUtils;
import eu.siacs.conversations.utils.PhoneNumberUtilWrapper;
@@ 32,7 31,8 @@ import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;
public class VerifyActivity extends XmppActivity implements ClipboardManager.OnPrimaryClipChangedListener, QuickConversationsService.OnVerification, QuickConversationsService.OnVerificationRequested {
public static final String EXTRA_RETRY_SMS_AFTER = "retry_sms_after";
-
+ private static final String EXTRA_RETRY_VERIFICATION_AFTER = "retry_verification_after";
+ private final Handler mHandler = new Handler();
private ActivityVerifyBinding binding;
private Account account;
private PinEntryWrapper pinEntryWrapper;
@@ 41,15 41,20 @@ public class VerifyActivity extends XmppActivity implements ClipboardManager.OnP
private boolean verifying = false;
private boolean requestingVerification = false;
private long retrySmsAfter = 0;
-
- private final Handler mHandler = new Handler();
-
-
private final Runnable SMS_TIMEOUT_UPDATER = new Runnable() {
@Override
public void run() {
if (setTimeoutLabelInResendButton()) {
- mHandler.postDelayed(this,300);
+ mHandler.postDelayed(this, 300);
+ }
+ }
+ };
+ private long retryVerificationAfter = 0;
+ private final Runnable VERIFICATION_TIMEOUT_UPDATER = new Runnable() {
+ @Override
+ public void run() {
+ if (setTimeoutLabelInNextButton()) {
+ mHandler.postDelayed(this, 300);
}
}
};
@@ 59,7 64,7 @@ public class VerifyActivity extends XmppActivity implements ClipboardManager.OnP
long remaining = retrySmsAfter - SystemClock.elapsedRealtime();
if (remaining >= 0) {
binding.resendSms.setEnabled(false);
- binding.resendSms.setText(getString(R.string.resend_sms_in, TimeframeUtils.resolve(VerifyActivity.this,remaining)));
+ binding.resendSms.setText(getString(R.string.resend_sms_in, TimeframeUtils.resolve(VerifyActivity.this, remaining)));
return true;
}
}
@@ 68,6 73,20 @@ public class VerifyActivity extends XmppActivity implements ClipboardManager.OnP
return false;
}
+ private boolean setTimeoutLabelInNextButton() {
+ if (retryVerificationAfter != 0) {
+ long remaining = retryVerificationAfter - SystemClock.elapsedRealtime();
+ if (remaining >= 0) {
+ binding.next.setEnabled(false);
+ binding.next.setText(getString(R.string.wait_x, TimeframeUtils.resolve(VerifyActivity.this, remaining)));
+ return true;
+ }
+ }
+ this.binding.next.setEnabled(!verifying);
+ this.binding.next.setText(verifying ? R.string.verifying : R.string.next);
+ return false;
+ }
+
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ 75,7 94,8 @@ public class VerifyActivity extends XmppActivity implements ClipboardManager.OnP
boolean verifying = savedInstanceState != null && savedInstanceState.getBoolean("verifying");
boolean requestingVerification = savedInstanceState != null && savedInstanceState.getBoolean("requesting_verification", false);
this.pasted = savedInstanceState != null ? savedInstanceState.getString("pasted") : null;
- this.retrySmsAfter = savedInstanceState != null ? savedInstanceState.getLong(EXTRA_RETRY_SMS_AFTER,0L) : 0L;
+ this.retrySmsAfter = savedInstanceState != null ? savedInstanceState.getLong(EXTRA_RETRY_SMS_AFTER, 0L) : 0L;
+ this.retryVerificationAfter = savedInstanceState != null ? savedInstanceState.getLong(EXTRA_RETRY_VERIFICATION_AFTER, 0L) : 0L;
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_verify);
setSupportActionBar((Toolbar) this.binding.toolbar);
this.pinEntryWrapper = new PinEntryWrapper(binding.pinBox);
@@ 182,6 202,7 @@ public class VerifyActivity extends XmppActivity implements ClipboardManager.OnP
savedInstanceState.putBoolean("verifying", this.verifying);
savedInstanceState.putBoolean("requesting_verification", this.requestingVerification);
savedInstanceState.putLong(EXTRA_RETRY_SMS_AFTER, this.retrySmsAfter);
+ savedInstanceState.putLong(EXTRA_RETRY_VERIFICATION_AFTER, this.retryVerificationAfter);
if (this.pasted != null) {
savedInstanceState.putString("pasted", this.pasted);
}
@@ 192,15 213,21 @@ public class VerifyActivity extends XmppActivity implements ClipboardManager.OnP
public void onStart() {
super.onStart();
clipboardManager.addPrimaryClipChangedListener(this);
+ final Intent intent = getIntent();
+ this.retrySmsAfter = intent != null ? intent.getLongExtra(EXTRA_RETRY_SMS_AFTER, this.retrySmsAfter) : this.retrySmsAfter;
if (this.retrySmsAfter > 0) {
mHandler.post(SMS_TIMEOUT_UPDATER);
}
+ if (this.retryVerificationAfter > 0) {
+ mHandler.post(VERIFICATION_TIMEOUT_UPDATER);
+ }
}
@Override
public void onStop() {
super.onStop();
mHandler.removeCallbacks(SMS_TIMEOUT_UPDATER);
+ mHandler.removeCallbacks(VERIFICATION_TIMEOUT_UPDATER);
clipboardManager.removePrimaryClipChangedListener(this);
if (xmppConnectionService != null) {
xmppConnectionService.getQuickConversationsService().removeOnVerificationListener(this);
@@ 233,6 260,14 @@ 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();
+ }
+
@Override
public void onPrimaryClipChanged() {
this.pasted = null;
@@ 242,39 277,49 @@ public class VerifyActivity extends XmppActivity implements ClipboardManager.OnP
}
@Override
- public void onVerificationFailed(int code) {
+ public void onVerificationFailed(final int code) {
runOnUiThread(() -> {
setVerifyingState(false);
+ if (code == 401) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setMessage(R.string.incorrect_pin);
+ builder.setPositiveButton(R.string.ok, null);
+ builder.create().show();
+ } else {
+ ApiErrorDialogHelper.create(this, code).show();
+ }
});
- Log.d(Config.LOGTAG,"code="+code);
}
@Override
public void onVerificationSucceeded() {
-
+ runOnUiThread(this::performPostVerificationRedirect);
}
@Override
public void onVerificationRetryAt(long timestamp) {
-
+ this.retryVerificationAfter = timestamp;
+ runOnUiThread(() -> setVerifyingState(false));
+ mHandler.removeCallbacks(VERIFICATION_TIMEOUT_UPDATER);
+ runOnUiThread(VERIFICATION_TIMEOUT_UPDATER);
}
//send sms again button callback
@Override
public void onVerificationRequestFailed(int code) {
- runOnUiThread(()->{
+ runOnUiThread(() -> {
setRequestingVerificationState(false);
+ ApiErrorDialogHelper.create(this, code).show();
});
- Log.d(Config.LOGTAG,"code="+code);
}
//send sms again button callback
@Override
public void onVerificationRequested() {
- runOnUiThread(()-> {
+ runOnUiThread(() -> {
setRequestingVerificationState(false);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setMessage(R.string.we_have_sent_you_the_sms_again);
+ builder.setMessage(R.string.we_have_sent_you_another_sms);
builder.setPositiveButton(R.string.ok, null);
builder.create().show();
});
@@ 283,7 328,7 @@ public class VerifyActivity extends XmppActivity implements ClipboardManager.OnP
@Override
public void onVerificationRequestedRetryAt(long timestamp) {
this.retrySmsAfter = timestamp;
- runOnUiThread(()-> setRequestingVerificationState(false));
+ runOnUiThread(() -> setRequestingVerificationState(false));
mHandler.removeCallbacks(SMS_TIMEOUT_UPDATER);
runOnUiThread(SMS_TIMEOUT_UPDATER);
}
A src/quick/java/eu/siacs/conversations/ui/util/ApiErrorDialogHelper.java => src/quick/java/eu/siacs/conversations/ui/util/ApiErrorDialogHelper.java +47 -0
@@ 0,0 1,47 @@
+package eu.siacs.conversations.ui.util;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.Context;
+import android.support.annotation.StringRes;
+
+import eu.siacs.conversations.R;
+import eu.siacs.conversations.services.QuickConversationsService;
+
+public class ApiErrorDialogHelper {
+
+ public static Dialog create(Context context, int code) {
+ @StringRes final int res;
+ switch (code) {
+ case QuickConversationsService.API_ERROR_AIRPLANE_MODE:
+ res = R.string.no_network_connection;
+ break;
+ case QuickConversationsService.API_ERROR_OTHER:
+ res = R.string.unknown_api_error_network;
+ break;
+ case QuickConversationsService.API_ERROR_CONNECT:
+ res = R.string.unable_to_connect_to_server;
+ break;
+ case QuickConversationsService.API_ERROR_SSL_HANDSHAKE:
+ res = R.string.unable_to_establish_secure_connection;
+ break;
+ case QuickConversationsService.API_ERROR_UNKNOWN_HOST:
+ res = R.string.unable_to_find_server;
+ break;
+ case 400:
+ res = R.string.invalid_user_input;
+ break;
+ case 502:
+ case 503:
+ case 504:
+ res = R.string.temporarily_unavailable;
+ break;
+ default:
+ res = R.string.unknown_api_error_response;
+ }
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setMessage(res);
+ builder.setPositiveButton(R.string.ok, null);
+ return builder.create();
+ }
+}
M src/quick/res/layout/activity_enter_number.xml => src/quick/res/layout/activity_enter_number.xml +8 -1
@@ 33,7 33,7 @@
<LinearLayout
android:id="@+id/phone_number_box"
android:layout_width="256dp"
- android:layout_height="match_parent"
+ android:layout_height="wrap_content"
android:layout_above="@+id/next"
android:layout_below="@+id/instructions"
android:layout_centerHorizontal="true"
@@ 82,6 82,13 @@
android:longClickable="false"
android:maxLines="1" />
</LinearLayout>
+
+ <ProgressBar
+ android:id="@+id/progressBar"
+ style="?android:attr/progressBarStyle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center" />
</LinearLayout>
<Button
android:id="@+id/next"