Skip to content

Commit

Permalink
fix country code phone register
Browse files Browse the repository at this point in the history
  • Loading branch information
nuryadincjr committed Jan 31, 2022
1 parent df6b04d commit 56e0883
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 11 deletions.
Binary file modified .gradle/7.3/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/7.3/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.3/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.3/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/7.3/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
2 changes: 2 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import com.nuryadincjr.merdekabelanja.databinding.ActivityAddStafsBinding;
import com.nuryadincjr.merdekabelanja.interfaces.ItemClickListener;
import com.nuryadincjr.merdekabelanja.models.Staffs;
import com.nuryadincjr.merdekabelanja.models.Users;
import com.nuryadincjr.merdekabelanja.pojo.ImagesPreference;
import com.nuryadincjr.merdekabelanja.viewmodel.MainViewModel;

Expand All @@ -53,6 +52,7 @@ public class AddStaffsActivity extends AppCompatActivity {
private Staffs staffs;
private boolean isEdit;
private String imageOld;
private String emailOld;
private List<Uri> uriImageList;

@Override
Expand Down Expand Up @@ -89,6 +89,7 @@ private String getEdited(String titleBar) {
if(isEdit) {
staffs = getIntent().getParcelableExtra(NAME_DATA);
imageOld = staffs.getPhoto();
emailOld = staffs.getEmail();
onDataSet(staffs);
binding.btnRegister.setText("Save Data");
titleBar = "Edit Staff";
Expand Down Expand Up @@ -170,18 +171,20 @@ private void getInputValidations() {
String address = valueOf(binding.etAddress.getText());
String division = valueOf(binding.actDevisions.getText());

if(!fullName.isEmpty() && !phone.isEmpty() && !email.isEmpty() &&
!password.isEmpty() && !confpassword.isEmpty() && !division.isEmpty()) {
if(password.length() > 7) {
if(password.equals(confpassword)){
Staffs staffs = new Staffs(id, fullName, phone, email, photo, address, email,
password, time(), "register", division);
if(phone.contains("+")){
if(!fullName.isEmpty() && !phone.isEmpty() && !email.isEmpty() &&
!password.isEmpty() && !confpassword.isEmpty() && !division.isEmpty()) {
if(password.length() > 7) {
if(password.equals(confpassword)){
Staffs staffs = new Staffs(id, fullName, phone, email, photo, address, email,
password, time(), "register", division);

onRegister(staffs);
onRegister(staffs);

} else binding.etPassword.setError("Password cannot equals!");
} else binding.etConfPassword.setError("Password too short!");
} else Toast.makeText(this,"Empty credentials!", Toast.LENGTH_SHORT).show();
} else binding.etPassword.setError("Password cannot equals!");
} else binding.etConfPassword.setError("Password too short!");
} else Toast.makeText(this,"Empty credentials!", Toast.LENGTH_SHORT).show();
}else binding.etPhone.setError("Please used the country code!");
}

private void onRegister(Staffs staffs) {
Expand Down Expand Up @@ -255,6 +258,22 @@ private void onDataUpdated(Staffs staffs) {
}

private void startDataUpdated(Staffs staffs) {
MainViewModel mainViewModel = new ViewModelProvider(this).get(MainViewModel.class);
mainViewModel.getUsername(staffs.getUsername()).observe(this, user -> {
if(user.size() ==0){
getDataUpdated(staffs);
}else {
if(user.get(0).getUsername().equals(emailOld)){
getDataUpdated(staffs);
}else {
dialog.dismiss();
binding.etEmail.setError("The email for the login session with this username already exists!");
}
}
});
}

private void getDataUpdated(Staffs staffs) {
new StaffsRepository().updateStaffs(staffs).addOnSuccessListener(documentReference -> {
Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference);
dialog.dismiss();
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_add_stafs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="@string/str_phone_number"
app:helperText="ex: +62xxxxxxxx"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">

<com.google.android.material.textfield.TextInputEditText
Expand Down

0 comments on commit 56e0883

Please sign in to comment.