Commit 09c1bc83 authored by Alfansyah Fadlian's avatar Alfansyah Fadlian

register logic

parent d4a3673d
package com.yono.messeripos; package com.yono.messeripos;
import android.annotation.SuppressLint;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
...@@ -7,6 +8,7 @@ import android.content.SharedPreferences; ...@@ -7,6 +8,7 @@ import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
...@@ -21,6 +23,7 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior; ...@@ -21,6 +23,7 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialog; import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment; import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.google.android.material.button.MaterialButton; import com.google.android.material.button.MaterialButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputEditText;
import com.yono.messeripos.api.client.Client; import com.yono.messeripos.api.client.Client;
import com.yono.messeripos.api.service.UsersService; import com.yono.messeripos.api.service.UsersService;
...@@ -29,6 +32,9 @@ import com.yono.messeripos.models.UsersModels; ...@@ -29,6 +32,9 @@ import com.yono.messeripos.models.UsersModels;
import com.yono.messeripos.response.DataResponse; import com.yono.messeripos.response.DataResponse;
import com.yono.messeripos.utils.Utils; import com.yono.messeripos.utils.Utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
...@@ -47,6 +53,8 @@ public class RegisterState extends BottomSheetDialogFragment { ...@@ -47,6 +53,8 @@ public class RegisterState extends BottomSheetDialogFragment {
SharedPreferences sharedPreferences; SharedPreferences sharedPreferences;
Utils utils; Utils utils;
String busername,bemail,bpassword,brepassword;
public RegisterState(Context context, MainViewModels mainViewModels) { public RegisterState(Context context, MainViewModels mainViewModels) {
this.context = context; this.context = context;
this.mainViewModels = mainViewModels; this.mainViewModels = mainViewModels;
...@@ -89,6 +97,40 @@ public class RegisterState extends BottomSheetDialogFragment { ...@@ -89,6 +97,40 @@ public class RegisterState extends BottomSheetDialogFragment {
Log.d(TAG, "onCreateDialog: " + sheetBehavior2.getState()); Log.d(TAG, "onCreateDialog: " + sheetBehavior2.getState());
email.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (TextUtils.isEmpty(username.getText().toString()) &&
TextUtils.isEmpty(email.getText().toString()) && TextUtils.isEmpty(password.getText().toString()) && TextUtils.isEmpty(repassword.getText().toString())){
username.setError("This field can't empty");
email.setError("This field can't empty");
password.setError("This field can't empty");
repassword.setError("This field can't empty");
}else if (TextUtils.isEmpty(username.getText().toString())){
username.setError("This field can't empty");
}else if (TextUtils.isEmpty(email.getText().toString())){
email.setError("This field can't empty");
}else if (TextUtils.isEmpty(password.getText().toString())){
password.setError("This field can't empty");
}else if (TextUtils.isEmpty(repassword.getText().toString())){
repassword.setError("This field can't empty");
}else if (!utils.isValidEmail(charSequence.toString())){
email.setError("Please enter the correct email format");
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
//same data password //same data password
password.addTextChangedListener(new TextWatcher() { password.addTextChangedListener(new TextWatcher() {
@Override @Override
...@@ -98,7 +140,9 @@ public class RegisterState extends BottomSheetDialogFragment { ...@@ -98,7 +140,9 @@ public class RegisterState extends BottomSheetDialogFragment {
@Override @Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (!utils.isValidPassword(charSequence.toString())){
password.setError("Password Must Be 8 Character");
}
} }
@Override @Override
...@@ -111,7 +155,13 @@ public class RegisterState extends BottomSheetDialogFragment { ...@@ -111,7 +155,13 @@ public class RegisterState extends BottomSheetDialogFragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
mainViewModels.postRegis(new UsersModels(username.getText().toString(),email.getText().toString(),password.getText().toString(),repassword.getText().toString())); mainViewModels.postRegis(new UsersModels(username.getText().toString(),email.getText().toString(),password.getText().toString(),repassword.getText().toString()));
/**
* Jika tombol sign up ditekan
*
* kembali ke halaman login utama dengan Snackbar Cek Email*/
Snackbar mySnackbar = Snackbar.make(view, "Cek Email Anda", 3000);
mySnackbar.show();
registerButton.setEnabled(false);
} }
}); });
...@@ -124,21 +174,5 @@ public class RegisterState extends BottomSheetDialogFragment { ...@@ -124,21 +174,5 @@ public class RegisterState extends BottomSheetDialogFragment {
return sheetDialog2; return sheetDialog2;
} }
private void registerUser(View view){
// Client client = new Client();
// UsersService usersService = client.Client(UsersService.class);
// usersService.postRegister(new UsersModels(username.getText().toString(),email.getText().toString(),password.getText().toString(),repassword.getText().toString()).enqueue(new Callback<DataResponse<UsersModels>>() {
// @Override
// public void onResponse(Call<DataResponse<UsersModels>> call, Response<DataResponse<UsersModels>> response) {
//
// }
//
// @Override
// public void onFailure(Call<DataResponse<UsersModels>> call, Throwable t) {
//
// }
// });
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment