More Related Content
Similar to Creating an Uber Clone - Part XIV.pdf (20)
More from ShaiAlmog1 (20)
Creating an Uber Clone - Part XIV.pdf
- 2. fab.addActionListener(e -> {
String number = phoneNumber.getText();
if(number.startsWith("0")) {
number = number.substring(1);
}
String phone = countryCodeButton.getText() + "-" + number;
EnterSMSVerificationDigitsForm es =
new EnterSMSVerificationDigitsForm(phone);
es.show();
es.addShowListener(ee -> {
if(SMSInterceptor.isSupported()) {
SMSInterceptor.grabNextSMS(s -> {
if(UserService.validateSMSActivationCode(s)) {
new EnterPasswordForm(phone).show();
ToastBar.showMessage("Automatically Validated Phone Number!",
FontImage.MATERIAL_THUMB_UP);
}
});
}
UserService.sendSMSActivationCode(phone);
});
});
EnterMobileNumberForm
- 3. fab.addActionListener(e -> {
String number = phoneNumber.getText();
if(number.startsWith("0")) {
number = number.substring(1);
}
String phone = countryCodeButton.getText() + "-" + number;
EnterSMSVerificationDigitsForm es =
new EnterSMSVerificationDigitsForm(phone);
es.show();
es.addShowListener(ee -> {
if(SMSInterceptor.isSupported()) {
SMSInterceptor.grabNextSMS(s -> {
if(UserService.validateSMSActivationCode(s)) {
new EnterPasswordForm(phone).show();
ToastBar.showMessage("Automatically Validated Phone Number!",
FontImage.MATERIAL_THUMB_UP);
}
});
}
UserService.sendSMSActivationCode(phone);
});
});
EnterMobileNumberForm
- 4. fab.addActionListener(e -> {
String number = phoneNumber.getText();
if(number.startsWith("0")) {
number = number.substring(1);
}
String phone = countryCodeButton.getText() + "-" + number;
EnterSMSVerificationDigitsForm es =
new EnterSMSVerificationDigitsForm(phone);
es.show();
es.addShowListener(ee -> {
if(SMSInterceptor.isSupported()) {
SMSInterceptor.grabNextSMS(s -> {
if(UserService.validateSMSActivationCode(s)) {
new EnterPasswordForm(phone).show();
ToastBar.showMessage("Automatically Validated Phone Number!",
FontImage.MATERIAL_THUMB_UP);
}
});
}
UserService.sendSMSActivationCode(phone);
});
});
EnterMobileNumberForm
- 5. fab.addActionListener(e -> {
String number = phoneNumber.getText();
if(number.startsWith("0")) {
number = number.substring(1);
}
String phone = countryCodeButton.getText() + "-" + number;
EnterSMSVerificationDigitsForm es =
new EnterSMSVerificationDigitsForm(phone);
es.show();
es.addShowListener(ee -> {
if(SMSInterceptor.isSupported()) {
SMSInterceptor.grabNextSMS(s -> {
if(UserService.validateSMSActivationCode(s)) {
new EnterPasswordForm(phone).show();
ToastBar.showMessage("Automatically Validated Phone Number!",
FontImage.MATERIAL_THUMB_UP);
}
});
}
UserService.sendSMSActivationCode(phone);
});
});
EnterMobileNumberForm
- 6. public final boolean isValid(String s) {
return UserService.validateSMSActivationCode(s);
}
EnterSMSVerificationDigitsForm
- 7. private int resendTime = 120;
private UITimer timer;
private String formatSeconds(int time) {
return twoDigits(time / 60) + ":" + twoDigits(time % 60);
}
private String twoDigits(int t) {
if(t < 10) {
return "0" + t;
}
return "" + t;
}
EnterSMSVerificationDigitsForm
- 8. private int resendTime = 120;
private UITimer timer;
private String formatSeconds(int time) {
return twoDigits(time / 60) + ":" + twoDigits(time % 60);
}
private String twoDigits(int t) {
if(t < 10) {
return "0" + t;
}
return "" + t;
}
EnterSMSVerificationDigitsForm
- 9. Label resend = new Label("Resend code in " +
formatSeconds(resendTime), "ResendCode");
add(SOUTH, resend);
timer = UITimer.timer(1000, true, this, () -> {
if(resendTime > 0) {
resendTime--;
resend.setText("Resend code in " +
formatSeconds(resendTime));
return;
}
timer.cancel();
UserService.resendSMSActivationCode(phone);
});
EnterSMSVerificationDigitsForm
- 10. Label resend = new Label("Resend code in " +
formatSeconds(resendTime), "ResendCode");
add(SOUTH, resend);
timer = UITimer.timer(1000, true, this, () -> {
if(resendTime > 0) {
resendTime--;
resend.setText("Resend code in " +
formatSeconds(resendTime));
return;
}
timer.cancel();
UserService.resendSMSActivationCode(phone);
});
EnterSMSVerificationDigitsForm
- 11. Label resend = new Label("Resend code in " +
formatSeconds(resendTime), "ResendCode");
add(SOUTH, resend);
timer = UITimer.timer(1000, true, this, () -> {
if(resendTime > 0) {
resendTime--;
resend.setText("Resend code in " +
formatSeconds(resendTime));
return;
}
timer.cancel();
UserService.resendSMSActivationCode(phone);
});
EnterSMSVerificationDigitsForm
- 12. InfiniteProgress ip = new InfiniteProgress();
Dialog dlg = ip.showInifiniteBlocking();
boolean exists = UserService.userExists(phone);
dlg.dispose();
getToolbar().setBackCommand("",
Toolbar.BackCommandPolicy.AS_ARROW,
e -> previous.showBack());
Container box = new Container(BoxLayout.y());
box.setScrollableY(true);
if(exists) {
box.add(new SpanLabel(
"Welcome back, signin to continue", "FlagButton"));
} else {
box.add(new SpanLabel(
"Please enter a new password", "FlagButton"));
}
EnterPasswordForm
- 13. InfiniteProgress ip = new InfiniteProgress();
Dialog dlg = ip.showInifiniteBlocking();
boolean exists = UserService.userExists(phone);
dlg.dispose();
getToolbar().setBackCommand("",
Toolbar.BackCommandPolicy.AS_ARROW,
e -> previous.showBack());
Container box = new Container(BoxLayout.y());
box.setScrollableY(true);
if(exists) {
box.add(new SpanLabel(
"Welcome back, signin to continue", "FlagButton"));
} else {
box.add(new SpanLabel(
"Please enter a new password", "FlagButton"));
}
EnterPasswordForm
- 14. fab.addActionListener(e -> {
Dialog ipDlg = new InfiniteProgress().showInifiniteBlocking();
if(exists) {
UserService.loginWithPhone(phone, password.getText(), (value) -> {
MapForm.get().show();
}, (sender, err, errorCode, errorMessage) -> {
ipDlg.dispose();
error.setText("Login error");
error.setVisible(true);
revalidate();
});
} else {
if(UserService.addNewUser(new User().
phone.set(phone).
password.set(password.getText()).
driver.set(false))) {
MapForm.get().show();
} else {
ipDlg.dispose();
error.setText("Signup error");
error.setVisible(true);
revalidate();
}
}
EnterPasswordForm
- 15. fab.addActionListener(e -> {
Dialog ipDlg = new InfiniteProgress().showInifiniteBlocking();
if(exists) {
UserService.loginWithPhone(phone, password.getText(), (value) -> {
MapForm.get().show();
}, (sender, err, errorCode, errorMessage) -> {
ipDlg.dispose();
error.setText("Login error");
error.setVisible(true);
revalidate();
});
} else {
if(UserService.addNewUser(new User().
phone.set(phone).
password.set(password.getText()).
driver.set(false))) {
MapForm.get().show();
} else {
ipDlg.dispose();
error.setText("Signup error");
error.setVisible(true);
revalidate();
}
}
EnterPasswordForm
- 16. fab.addActionListener(e -> {
Dialog ipDlg = new InfiniteProgress().showInifiniteBlocking();
if(exists) {
UserService.loginWithPhone(phone, password.getText(), (value) -> {
MapForm.get().show();
}, (sender, err, errorCode, errorMessage) -> {
ipDlg.dispose();
error.setText("Login error");
error.setVisible(true);
revalidate();
});
} else {
if(UserService.addNewUser(new User().
phone.set(phone).
password.set(password.getText()).
driver.set(false))) {
MapForm.get().show();
} else {
ipDlg.dispose();
error.setText("Signup error");
error.setVisible(true);
revalidate();
}
}
EnterPasswordForm