Possibility to allow phone numbers in wizard
This commit is contained in:
parent
3d4234e05f
commit
80ff8aa3f8
4 changed files with 34 additions and 12 deletions
|
@ -393,7 +393,7 @@
|
|||
<string name="setup_remote_provisioning_hint">Cet assistant va télécharger une configuration existante.</string>
|
||||
<string name="setup_remote_provisioning_url_hint">addresse où télécharger la configuration</string>
|
||||
<string name="setup_remote_provisioning_login_hint">La configuration téléchargée ne contient pas votre compte. Veuillez le remplir.</string>
|
||||
<string name="setup_confirm_username">Votre nom d\'utilisateur sera %s (les majuscules sont interdites). Acceptez-vous ?</string>
|
||||
<string name="setup_confirm_username">Votre nom d\'utilisateur sera %s.\r\n\r\nIl peut différer de celui que vous avez choisi afin de remplir certains critères nécessaires.\r\nAcceptez-vous ?</string>
|
||||
<string name="setup_title_assistant">Assistant de création de compte</string>
|
||||
<string name="zrtp_accept">Accepter</string>
|
||||
<string name="zrtp_deny">Refuser</string>
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
<bool name="hide_accounts">false</bool>
|
||||
<bool name="display_account_wizard_at_first_start">true</bool>
|
||||
<bool name="use_linphone_server_ports">true</bool>
|
||||
<bool name="allow_only_phone_numbers_in_wizard">true</bool>
|
||||
|
||||
<bool name="use_android_native_contact_edit_interface">false</bool>
|
||||
<!-- The following settings are only usefull if use_android_native_contact_edit_interface = false -->
|
||||
|
|
|
@ -396,7 +396,7 @@
|
|||
<string name="setup_remote_provisioning_hint">This assistant will download an existing configuration.</string>
|
||||
<string name="setup_remote_provisioning_url_hint">provisioning url</string>
|
||||
<string name="setup_remote_provisioning_login_hint">The configuration you downloaded doesn\'t include your account. Please fill it in.</string>
|
||||
<string name="setup_confirm_username">Your username will be %s (uppercase characters are not allowed). Do you accept ?</string>
|
||||
<string name="setup_confirm_username">Your username will be %s.\r\n\r\nIt may differ from what you entered to match some requierements.\r\nDo you accept ?</string>
|
||||
<string name="setup_title_assistant">Account setup assistant</string>
|
||||
<string name="zrtp_accept">Accept</string>
|
||||
<string name="zrtp_deny">Deny</string>
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.regex.Pattern;
|
|||
import org.linphone.LinphoneManager;
|
||||
import org.linphone.LinphoneService;
|
||||
import org.linphone.R;
|
||||
import org.linphone.core.LinphoneProxyConfig;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
|
@ -65,6 +66,17 @@ public class WizardFragment extends Fragment {
|
|||
private char[] acceptedChars = new char[]{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '_', '-' };
|
||||
private char[] acceptedCharsForPhoneNumbers = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '+' };
|
||||
private String inputFilterCharacters;
|
||||
|
||||
private String getUsername() {
|
||||
String username = this.username.getText().toString();
|
||||
if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) {
|
||||
LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig();
|
||||
username = lpc.normalizePhoneNumber(username);
|
||||
}
|
||||
return username.toLowerCase(Locale.getDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
@ -73,12 +85,17 @@ public class WizardFragment extends Fragment {
|
|||
username = (EditText) view.findViewById(R.id.setup_username);
|
||||
ImageView usernameOkIV = (ImageView) view.findViewById(R.id.setup_username_ok);
|
||||
addXMLRPCUsernameHandler(username, usernameOkIV);
|
||||
|
||||
inputFilterCharacters = new String(acceptedChars);
|
||||
if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) {
|
||||
inputFilterCharacters = new String(acceptedCharsForPhoneNumbers);
|
||||
}
|
||||
InputFilter filter = new InputFilter(){
|
||||
@Override
|
||||
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
|
||||
if (end > start) {
|
||||
for (int index = start; index < end; index++) {
|
||||
if (!new String(acceptedChars).contains(String.valueOf(source.charAt(index)))) {
|
||||
if (!inputFilterCharacters.contains(String.valueOf(source.charAt(index)))) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
@ -110,20 +127,16 @@ public class WizardFragment extends Fragment {
|
|||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
createAccount(username.getText().toString().toLowerCase(Locale.getDefault()), password.getText().toString(), email.getText().toString(), false);
|
||||
createAccount(getUsername(), password.getText().toString(), email.getText().toString(), false);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
}
|
||||
});
|
||||
if(!username.getText().toString().equals(username.getText().toString().toLowerCase(Locale.getDefault()))){
|
||||
builder.setMessage(getString(R.string.setup_confirm_username).replace("%s", username.getText().toString().toLowerCase(Locale.getDefault())));
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
} else {
|
||||
createAccount(username.getText().toString().toLowerCase(Locale.getDefault()), password.getText().toString(), email.getText().toString(), false);
|
||||
}
|
||||
builder.setMessage(getString(R.string.setup_confirm_username).replace("%s", getUsername()));
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -143,7 +156,11 @@ public class WizardFragment extends Fragment {
|
|||
}
|
||||
|
||||
private boolean isUsernameCorrect(String username) {
|
||||
return username.matches("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}$");
|
||||
if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) {
|
||||
return username.matches("^(\\+)?(\\d-)?(\\d{3}-)?(\\d{3}-)?\\d{4,}$");
|
||||
} else {
|
||||
return username.matches("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}$");
|
||||
}
|
||||
}
|
||||
|
||||
private void isUsernameRegistred(String username, final ImageView icon) {
|
||||
|
@ -278,6 +295,10 @@ public class WizardFragment extends Fragment {
|
|||
usernameOk = false;
|
||||
String username = field.getText().toString().toLowerCase(Locale.getDefault());
|
||||
if (isUsernameCorrect(username)) {
|
||||
if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) {
|
||||
LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig();
|
||||
username = lpc.normalizePhoneNumber(username);
|
||||
}
|
||||
isUsernameRegistred(username, icon);
|
||||
} else {
|
||||
errorMessage.setText(R.string.wizard_username_incorrect);
|
||||
|
|
Loading…
Reference in a new issue