Skip to content

Commit 5e14e08

Browse files
SUPERCILEXsamtstern
authored andcommitted
Improve phone auth UX (#846)
1 parent fba3335 commit 5e14e08

File tree

4 files changed

+47
-20
lines changed

4 files changed

+47
-20
lines changed

auth/src/main/java/com/firebase/ui/auth/ui/phone/SubmitConfirmationCodeFragment.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.firebase.ui.auth.ui.ExtraConstants;
3333
import com.firebase.ui.auth.ui.FlowParameters;
3434
import com.firebase.ui.auth.ui.FragmentBase;
35+
import com.firebase.ui.auth.ui.ImeHelper;
3536
import com.firebase.ui.auth.ui.email.PreambleHandler;
3637

3738
/**
@@ -165,13 +166,15 @@ private void setupSubmitConfirmationCodeButton() {
165166
mSubmitConfirmationButton.setOnClickListener(new View.OnClickListener() {
166167
@Override
167168
public void onClick(View v) {
168-
final String confirmationCode = mConfirmationCodeEditText.getUnspacedText()
169-
.toString();
170-
mVerifier.submitConfirmationCode(confirmationCode);
169+
submitConfirmationCode();
171170
}
172171
});
173172
}
174173

174+
private void submitConfirmationCode() {
175+
mVerifier.submitConfirmationCode(mConfirmationCodeEditText.getUnspacedText().toString());
176+
}
177+
175178
private void setupEditPhoneNumberTextView(@Nullable String phoneNumber) {
176179
mEditPhoneTextView.setText(TextUtils.isEmpty(phoneNumber) ? "" : phoneNumber);
177180
mEditPhoneTextView.setOnClickListener(new View.OnClickListener() {
@@ -188,6 +191,15 @@ private void setupConfirmationCodeEditText() {
188191
mConfirmationCodeEditText.setText("------");
189192
BucketedTextChangeListener listener = createBucketedTextChangeListener();
190193
mConfirmationCodeEditText.addTextChangedListener(listener);
194+
ImeHelper.setImeOnDoneListener(mConfirmationCodeEditText,
195+
new ImeHelper.DonePressedListener() {
196+
@Override
197+
public void onDonePressed() {
198+
if (mSubmitConfirmationButton.isEnabled()) {
199+
submitConfirmationCode();
200+
}
201+
}
202+
});
191203
}
192204

193205
private BucketedTextChangeListener createBucketedTextChangeListener() {

auth/src/main/java/com/firebase/ui/auth/ui/phone/VerifyPhoneNumberFragment.java

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.firebase.ui.auth.ui.ExtraConstants;
3737
import com.firebase.ui.auth.ui.FlowParameters;
3838
import com.firebase.ui.auth.ui.FragmentBase;
39+
import com.firebase.ui.auth.ui.ImeHelper;
3940
import com.firebase.ui.auth.util.GoogleApiHelper;
4041
import com.google.android.gms.auth.api.Auth;
4142
import com.google.android.gms.auth.api.credentials.Credential;
@@ -56,10 +57,10 @@ public class VerifyPhoneNumberFragment extends FragmentBase implements View.OnCl
5657

5758
private Context mAppContext;
5859

59-
private CountryListSpinner countryListSpinner;
60+
private CountryListSpinner mCountryListSpinner;
6061
private EditText mPhoneEditText;
61-
private TextView errorEditText;
62-
private Button sendCodeButton;
62+
private TextView mErrorEditText;
63+
private Button mSendCodeButton;
6364
private PhoneVerificationActivity mVerifier;
6465
private TextView mSmsTermsText;
6566

@@ -88,15 +89,22 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
8889

8990
View v = inflater.inflate(R.layout.fui_phone_layout, container, false);
9091

91-
countryListSpinner = v.findViewById(R.id.country_list);
92+
mCountryListSpinner = v.findViewById(R.id.country_list);
9293
mPhoneEditText = v.findViewById(R.id.phone_number);
93-
errorEditText = v.findViewById(R.id.phone_number_error);
94-
sendCodeButton = v.findViewById(R.id.send_code);
94+
mErrorEditText = v.findViewById(R.id.phone_number_error);
95+
mSendCodeButton = v.findViewById(R.id.send_code);
9596
mSmsTermsText = v.findViewById(R.id.send_sms_tos);
9697

98+
ImeHelper.setImeOnDoneListener(mPhoneEditText, new ImeHelper.DonePressedListener() {
99+
@Override
100+
public void onDonePressed() {
101+
onNext();
102+
}
103+
});
104+
97105
FragmentActivity parentActivity = getActivity();
98106
parentActivity.setTitle(getString(R.string.fui_verify_phone_number_title));
99-
setUpCountrySpinner();
107+
setupCountrySpinner();
100108
setupSendCodeButton();
101109
setupTerms();
102110

@@ -159,24 +167,29 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
159167
PhoneNumberUtils.getPhoneNumber(formattedPhone);
160168
setPhoneNumber(phoneNumberObj);
161169
setCountryCode(phoneNumberObj);
170+
onNext();
162171
}
163172
}
164173
}
165174
}
166175

167176
@Override
168177
public void onClick(View v) {
178+
onNext();
179+
}
180+
181+
private void onNext() {
169182
String phoneNumber = getPseudoValidPhoneNumber();
170183
if (phoneNumber == null) {
171-
errorEditText.setText(R.string.fui_invalid_phone_number);
184+
mErrorEditText.setText(R.string.fui_invalid_phone_number);
172185
} else {
173186
mVerifier.verifyPhoneNumber(phoneNumber, false);
174187
}
175188
}
176189

177190
@Nullable
178191
private String getPseudoValidPhoneNumber() {
179-
final CountryInfo countryInfo = (CountryInfo) countryListSpinner.getTag();
192+
final CountryInfo countryInfo = (CountryInfo) mCountryListSpinner.getTag();
180193
final String everythingElse = mPhoneEditText.getText().toString();
181194

182195
if (TextUtils.isEmpty(everythingElse)) {
@@ -186,18 +199,18 @@ private String getPseudoValidPhoneNumber() {
186199
return PhoneNumberUtils.formatPhoneNumber(everythingElse, countryInfo);
187200
}
188201

189-
private void setUpCountrySpinner() {
202+
private void setupCountrySpinner() {
190203
//clear error when spinner is clicked on
191-
countryListSpinner.setOnClickListener(new View.OnClickListener() {
204+
mCountryListSpinner.setOnClickListener(new View.OnClickListener() {
192205
@Override
193206
public void onClick(View v) {
194-
errorEditText.setText("");
207+
mErrorEditText.setText("");
195208
}
196209
});
197210
}
198211

199212
private void setupSendCodeButton() {
200-
sendCodeButton.setOnClickListener(this);
213+
mSendCodeButton.setOnClickListener(this);
201214
}
202215

203216
private void showPhoneAutoCompleteHint() {
@@ -243,12 +256,12 @@ private void setPhoneNumber(PhoneNumber phoneNumber) {
243256

244257
private void setCountryCode(PhoneNumber phoneNumber) {
245258
if (PhoneNumber.isCountryValid(phoneNumber)) {
246-
countryListSpinner.setSelectedForCountry(new Locale("", phoneNumber.getCountryIso()),
259+
mCountryListSpinner.setSelectedForCountry(new Locale("", phoneNumber.getCountryIso()),
247260
phoneNumber.getCountryCode());
248261
}
249262
}
250263

251264
void showError(String e) {
252-
errorEditText.setText(e);
265+
mErrorEditText.setText(e);
253266
}
254267
}

auth/src/main/res/layout/fui_confirmation_code_layout.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
android:ems="10"
4242
android:fontFamily="monospace"
4343
android:gravity="center"
44-
android:imeOptions="actionNext"
44+
android:imeOptions="actionDone"
4545
android:inputType="number"
4646
android:textSize="32sp"
4747
android:typeface="monospace"

auth/src/main/res/layout/fui_phone_layout.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
android:layout_toEndOf="@id/country_list"
2020
android:layout_toRightOf="@id/country_list"
2121
android:layout_alignBaseline="@id/country_list"
22-
android:layout_gravity="end" />
22+
android:layout_gravity="end"
23+
android:imeOptions="actionDone" />
2324

2425
<TextView
2526
android:id="@+id/phone_number_error"
@@ -50,6 +51,7 @@
5051
android:layout_below="@id/send_code"
5152
android:textColor="?android:textColorTertiary"
5253
android:textIsSelectable="false" />
54+
5355
</RelativeLayout>
5456

5557
</ScrollView>

0 commit comments

Comments
 (0)