Added custom username option when creating a phone number account

This commit is contained in:
Sylvain Berfini 2019-06-05 13:07:39 +02:00
parent 05a440f27a
commit 6d96221f99
5 changed files with 96 additions and 23 deletions

View file

@ -19,6 +19,11 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import static org.linphone.core.AccountCreator.UsernameStatus.Invalid;
import static org.linphone.core.AccountCreator.UsernameStatus.InvalidCharacters;
import static org.linphone.core.AccountCreator.UsernameStatus.TooLong;
import static org.linphone.core.AccountCreator.UsernameStatus.TooShort;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
@ -281,4 +286,18 @@ public abstract class AssistantActivity extends LinphoneGenericActivity
}
return null;
}
String getErrorFromUsernameStatus(AccountCreator.UsernameStatus status) {
switch (status) {
case Invalid:
return getString(R.string.username_invalid_size);
case InvalidCharacters:
return getString(R.string.invalid_characters);
case TooLong:
return getString(R.string.username_too_long);
case TooShort:
return getString(R.string.username_too_short);
}
return null;
}
}

View file

@ -73,20 +73,7 @@ public class EmailAccountCreationAssistantActivity extends AssistantActivity {
status == AccountCreator.UsernameStatus.Ok
? View.INVISIBLE
: View.VISIBLE);
switch (status) {
case Invalid:
mUsernameError.setText(getString(R.string.username_invalid_size));
break;
case InvalidCharacters:
mUsernameError.setText(getString(R.string.invalid_characters));
break;
case TooLong:
mUsernameError.setText(getString(R.string.username_too_long));
break;
case TooShort:
mUsernameError.setText(getString(R.string.username_too_short));
break;
}
mUsernameError.setText(getErrorFromUsernameStatus(status));
updateCreateButton();
}
});

View file

@ -24,6 +24,8 @@ import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
@ -36,7 +38,8 @@ import org.linphone.core.tools.Log;
public class PhoneAccountCreationAssistantActivity extends AssistantActivity {
private TextView mCountryPicker, mError, mSipUri, mCreate;
private EditText mPrefix, mPhoneNumber;
private EditText mPrefix, mPhoneNumber, mUsername;
private CheckBox mUseUsernameInsteadOfPhoneNumber;
private AccountCreatorListenerStub mListener;
@ -69,7 +72,11 @@ public class PhoneAccountCreationAssistantActivity extends AssistantActivity {
public void onClick(View v) {
enableButtonsAndFields(false);
mAccountCreator.setUsername(mAccountCreator.getPhoneNumber());
if (mUseUsernameInsteadOfPhoneNumber.isChecked()) {
mAccountCreator.setUsername(mUsername.getText().toString());
} else {
mAccountCreator.setUsername(mAccountCreator.getPhoneNumber());
}
mAccountCreator.setDomain(getString(R.string.default_domain));
AccountCreator.Status status = mAccountCreator.isAccountExist();
@ -133,6 +140,32 @@ public class PhoneAccountCreationAssistantActivity extends AssistantActivity {
}
});
mUseUsernameInsteadOfPhoneNumber = findViewById(R.id.use_username);
mUseUsernameInsteadOfPhoneNumber.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mUsername.setVisibility(isChecked ? View.VISIBLE : View.GONE);
updateCreateButtonAndDisplayError();
}
});
mUsername = findViewById(R.id.username);
mUsername.addTextChangedListener(
new TextWatcher() {
@Override
public void beforeTextChanged(
CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
updateCreateButtonAndDisplayError();
}
});
mListener =
new AccountCreatorListenerStub() {
public void onIsAccountExist(
@ -209,18 +242,34 @@ public class PhoneAccountCreationAssistantActivity extends AssistantActivity {
if (mPrefix.getText().toString().isEmpty() || mPhoneNumber.getText().toString().isEmpty())
return;
mCreate.setEnabled(true);
mError.setText("");
mError.setVisibility(View.INVISIBLE);
int status = arePhoneNumberAndPrefixOk(mPrefix, mPhoneNumber);
if (status == AccountCreator.PhoneNumberStatus.Ok.toInt()) {
mCreate.setEnabled(true);
mError.setText("");
mError.setVisibility(View.INVISIBLE);
if (mUseUsernameInsteadOfPhoneNumber.isChecked()) {
AccountCreator.UsernameStatus usernameStatus =
mAccountCreator.setUsername(mUsername.getText().toString());
if (usernameStatus != AccountCreator.UsernameStatus.Ok) {
mCreate.setEnabled(false);
mError.setText(getErrorFromUsernameStatus(usernameStatus));
mError.setVisibility(View.VISIBLE);
}
}
} else {
mCreate.setEnabled(false);
mError.setText(getErrorFromPhoneNumberStatus(status));
mError.setVisibility(View.VISIBLE);
}
String username = mAccountCreator.getPhoneNumber();
String username;
if (mUseUsernameInsteadOfPhoneNumber.isChecked()) {
username = mUsername.getText().toString();
} else {
username = mAccountCreator.getPhoneNumber();
}
if (username != null) {
String sip =
getString(R.string.assistant_create_account_phone_number_address)

View file

@ -117,6 +117,24 @@
</LinearLayout>
<CheckBox
android:id="@+id/use_username"
android:text="@string/use_username_instead_or_phone_number"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/username"
android:background="@drawable/resizable_textfield"
android:textColor="@color/black_color"
android:contentDescription="@string/content_description_username_field"
android:inputType="text|textNoSuggestions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/username"
android:visibility="gone"
android:maxLines="1"/>
<TextView
android:id="@+id/phone_number_error"
android:text="@string/error"

View file

@ -102,7 +102,7 @@
<string name="assistant_ec_calibration">Echo canceler calibration in progress</string>
<string name="assistant_remote_provisioning_login">Enter your login</string>
<string name="assistant_account_not_validated">Your account has not been validated yet.</string>
<string name="assistant_error_confirmation_code">The confirmation code is invalid.\r\nPlease try again.</string>
<string name="assistant_error_confirmation_code">The confirmation code is invalid.\nPlease try again.</string>
<string name="assistant_account_validated">Your account has been validated.</string>
<string name="assistant_error_bad_credentials">Incorrect username or password</string>
<string name="assistant_codec_down_question">Do you agree to download OpenH264 Video Codec provided by Cisco Systems, Inc.?</string>
@ -114,13 +114,13 @@
<string name="wizard_failed">An error occurred, try again later.</string>
<string name="wizard_server_unavailable">Server unreachable, verify your network connection.</string>
<string name="wizard_username_unavailable">This username is already taken.</string>
<string name="assistant_phone_number_unavailable">This phone number is already used.\r\nPlease type a different number.\r\nYou can delete your existing account if you want to reuse your phone number.</string>
<string name="assistant_phone_number_unavailable">This phone number is already used.\nPlease type a different number.\nYou can delete your existing account if you want to reuse your phone number.</string>
<string name="wizard_username_incorrect">Your username is invalid.</string>
<string name="assistant_phone_number_incorrect">Your phone number is invalid.</string>
<string name="wizard_email_incorrect">Your email is invalid.</string>
<string name="wizard_password_incorrect">Your password is invalid</string>
<string name="wizard_passwords_unmatched">Passwords do not match.</string>
<string name="setup_confirm_username">Your username will be %s.\r\n\r\nIt may differ from your input to match requirements.\r\nDo you accept?</string>
<string name="setup_confirm_username">Your username will be %s.\n\nIt may differ from your input to match requirements.\nDo you accept?</string>
<string name="first_launch_no_login_password">Please enter your login and password</string>
<string name="forgot_password">Forgot password ?</string>
<string name="assistant_choose_country">Choose a country</string>