mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 05:31:59 +00:00
Fix bug
This commit is contained in:
@@ -60,7 +60,7 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
private RecyclerView recyclerView_review;
|
||||
private ReviewAdapter reviewAdapter;
|
||||
private Button rating_button;
|
||||
private PopupDialog popupDialog;
|
||||
private ConstraintLayout progressLayout;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -84,8 +84,7 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
recyclerView_review = findViewById(R.id.recycler_view_review);
|
||||
rating_button = findViewById(R.id.rating_button);
|
||||
content_view = findViewById(R.id.content_view);
|
||||
|
||||
popupDialog = PopupDialog.getInstance(this);
|
||||
progressLayout = findViewById(R.id.progress_layout);
|
||||
|
||||
reviewAdapter = new ReviewAdapter(this);
|
||||
|
||||
@@ -210,15 +209,12 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
|
||||
private void hideUI() {
|
||||
content_view.setVisibility(View.GONE);
|
||||
|
||||
popupDialog.setStyle(Styles.PROGRESS).setProgressDialogTint(getResources().getColor(R.color.primaryColor, null))
|
||||
.setCancelable(false).showDialog();
|
||||
}
|
||||
|
||||
private void showUI() {
|
||||
content_view.setVisibility(View.VISIBLE);
|
||||
|
||||
popupDialog.dismissDialog();
|
||||
progressLayout.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.capstone.foodify.API.FoodApi;
|
||||
import com.capstone.foodify.Common;
|
||||
@@ -30,6 +31,9 @@ import com.saadahmedsoft.popupdialog.Styles;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import io.paperdb.Paper;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
@@ -39,11 +43,12 @@ public class SignInActivity extends AppCompatActivity {
|
||||
|
||||
private FirebaseAuth mAuth;
|
||||
TextView signUp_textView, forgotPassword_textView;
|
||||
TextInputLayout textInput_account, textInput_password;
|
||||
TextInputEditText email, password;
|
||||
TextInputLayout textInput_phone, textInput_password;
|
||||
TextInputEditText edt_phone, edt_password;
|
||||
MaterialButton signInButton;
|
||||
ImageView back_image;
|
||||
PopupDialog popupDialog;
|
||||
ConstraintLayout progressLayout;
|
||||
String phone, password = null;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -58,9 +63,6 @@ public class SignInActivity extends AppCompatActivity {
|
||||
// Initialize Firebase Auth
|
||||
mAuth = FirebaseAuth.getInstance();
|
||||
|
||||
//Init Popup Dialog
|
||||
popupDialog = PopupDialog.getInstance(SignInActivity.this);
|
||||
|
||||
initComponent();
|
||||
setFontUI();
|
||||
|
||||
@@ -91,68 +93,115 @@ public class SignInActivity extends AppCompatActivity {
|
||||
signInButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
initData();
|
||||
|
||||
//Show progress bar
|
||||
popupDialog.setStyle(Styles.PROGRESS).setProgressDialogTint(getResources().getColor(R.color.primaryColor, null))
|
||||
.setCancelable(false).showDialog();
|
||||
|
||||
mAuth.setLanguageCode("vi");
|
||||
|
||||
mAuth.signInWithEmailAndPassword(email.getText().toString(), password.getText().toString())
|
||||
.addOnCompleteListener(SignInActivity.this, new OnCompleteListener<AuthResult>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<AuthResult> task) {
|
||||
if (task.isSuccessful()) {
|
||||
// Sign in success, update UI with the signed-in user's information
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
|
||||
//Save user
|
||||
Paper.book().write("user", user);
|
||||
|
||||
user.getIdToken(true)
|
||||
.addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<GetTokenResult> task) {
|
||||
if(task.isSuccessful()){
|
||||
Common.TOKEN = task.getResult().getToken();
|
||||
|
||||
//Dismiss progress bar dialog
|
||||
popupDialog.dismissDialog();
|
||||
|
||||
startActivity(new Intent(SignInActivity.this, MainActivity.class));
|
||||
} else {
|
||||
Toast.makeText(SignInActivity.this, "Error when taking token!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// If sign in fails, display a message to the user.
|
||||
Toast.makeText(SignInActivity.this, "Thông tin đăng nhập không đúng! Vui lòng kiểm tra và thử lại!",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
|
||||
popupDialog.dismissDialog();
|
||||
}
|
||||
}
|
||||
});
|
||||
if(validData()){
|
||||
signIn();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initData(){
|
||||
phone = edt_phone.getText().toString();
|
||||
password = edt_password.getText().toString();
|
||||
}
|
||||
|
||||
private boolean validData(){
|
||||
boolean dataHasValidate = true;
|
||||
|
||||
//Check phone number
|
||||
if(phone.isEmpty()){
|
||||
textInput_phone.setError("Số điện thoại không được bỏ trống!");
|
||||
dataHasValidate = false;
|
||||
} else {
|
||||
|
||||
|
||||
Pattern patternPhone = Pattern.compile(Common.PHONE_PATTERN);
|
||||
Matcher matcherPhone = patternPhone.matcher(phone);
|
||||
if(!matcherPhone.find()){
|
||||
textInput_phone.setError("Số điện thoại không đúng định dạng. Vui lòng kiểm tra lại!");
|
||||
dataHasValidate = false;
|
||||
} else {
|
||||
textInput_phone.setErrorEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
//Check password
|
||||
Pattern patternPassword = Pattern.compile(Common.PASSWORD_PATTERN);
|
||||
Matcher matcherPassword = patternPassword.matcher(edt_password.getText().toString());
|
||||
|
||||
if(!matcherPassword.matches() || edt_password.getText().toString().length() < 8) {
|
||||
textInput_password.setError("Mật khẩu của bạn cần tối thiểu có 8 ký tự, 1 ký tự viết hoa, 1 số và 1 ký tự đặc biệt!");
|
||||
dataHasValidate = false;
|
||||
} else {
|
||||
textInput_password.setErrorEnabled(false);
|
||||
}
|
||||
|
||||
return dataHasValidate;
|
||||
}
|
||||
|
||||
private void signIn(){
|
||||
//Show progress bar
|
||||
progressLayout.setVisibility(View.VISIBLE);
|
||||
|
||||
mAuth.setLanguageCode("vi");
|
||||
|
||||
mAuth.signInWithEmailAndPassword(edt_phone.getText().toString(), edt_password.getText().toString())
|
||||
.addOnCompleteListener(SignInActivity.this, new OnCompleteListener<AuthResult>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<AuthResult> task) {
|
||||
if (task.isSuccessful()) {
|
||||
// Sign in success, update UI with the signed-in user's information
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
|
||||
//Save user
|
||||
Paper.book().write("user", user);
|
||||
|
||||
user.getIdToken(true)
|
||||
.addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<GetTokenResult> task) {
|
||||
if(task.isSuccessful()){
|
||||
Common.TOKEN = task.getResult().getToken();
|
||||
|
||||
//Dismiss progress bar
|
||||
progressLayout.setVisibility(View.GONE);
|
||||
|
||||
startActivity(new Intent(SignInActivity.this, MainActivity.class));
|
||||
} else {
|
||||
Toast.makeText(SignInActivity.this, "Error when taking token!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// If sign in fails, display a message to the user.
|
||||
Toast.makeText(SignInActivity.this, "Thông tin đăng nhập không đúng! Vui lòng kiểm tra và thử lại!",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
|
||||
//Dismiss progress bar
|
||||
progressLayout.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initComponent() {
|
||||
textInput_account = findViewById(R.id.textInput_account);
|
||||
textInput_phone = findViewById(R.id.textInput_phone);
|
||||
textInput_password = findViewById(R.id.textInput_password);
|
||||
signUp_textView = findViewById(R.id.sign_up_textView);
|
||||
forgotPassword_textView = findViewById(R.id.forgotPassword_textView);
|
||||
back_image = findViewById(R.id.back_image);
|
||||
|
||||
email = findViewById(R.id.edt_email);
|
||||
password = findViewById(R.id.edt_password);
|
||||
edt_phone = findViewById(R.id.edt_email);
|
||||
edt_password = findViewById(R.id.edt_password);
|
||||
|
||||
signInButton = findViewById(R.id.sign_in_button);
|
||||
|
||||
progressLayout = findViewById(R.id.progress_layout);
|
||||
|
||||
}
|
||||
private void setFontUI() {
|
||||
textInput_account.setTypeface(Common.setFontBebas(getAssets()));
|
||||
textInput_phone.setTypeface(Common.setFontBebas(getAssets()));
|
||||
textInput_password.setTypeface(Common.setFontBebas(getAssets()));
|
||||
}
|
||||
|
||||
|
||||
@@ -53,10 +53,6 @@ import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class SignUpActivity extends AppCompatActivity {
|
||||
|
||||
private static final String PHONE_CODE = "+84";
|
||||
private final String PASSWORD_PATTERN = "^(?=.*[0-9])(?=.*[A-Z])(?=.*[@#$%^&+=!_])(?=\\S+$).{4,}$";
|
||||
private final String PHONE_PATTERN = "^0[98753]{1}\\d{8}$";
|
||||
public static final String VALID_EMAIL_ADDRESS_REGEX = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$";
|
||||
public static final String FORMAT_DATE="dd/MM/yyyy";
|
||||
TextInputLayout textInput_password, textInput_phone, textInput_email,
|
||||
@@ -183,15 +179,23 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
//Check phone number
|
||||
Pattern patternPhone = Pattern.compile(PHONE_PATTERN);
|
||||
Matcher matcherPhone = patternPhone.matcher(phone);
|
||||
if(!matcherPhone.find()){
|
||||
textInput_phone.setError("Số điện thoại không đúng định dạng. Vui lòng kiểm tra lại!");
|
||||
if(phone.isEmpty()){
|
||||
textInput_phone.setError("Số điện thoại không được bỏ trống!");
|
||||
dataHasValidate = false;
|
||||
} else {
|
||||
textInput_phone.setErrorEnabled(false);
|
||||
|
||||
|
||||
Pattern patternPhone = Pattern.compile(Common.PHONE_PATTERN);
|
||||
Matcher matcherPhone = patternPhone.matcher(phone);
|
||||
if(!matcherPhone.find()){
|
||||
textInput_phone.setError("Số điện thoại không đúng định dạng. Vui lòng kiểm tra lại!");
|
||||
dataHasValidate = false;
|
||||
} else {
|
||||
textInput_phone.setErrorEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Check full name
|
||||
if(name.length() < 8){
|
||||
textInput_fullName.setError("Tên của bạn cần phải có 8 ký tự trở lên!");
|
||||
@@ -237,7 +241,7 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
//Check password
|
||||
Pattern patternPassword = Pattern.compile(PASSWORD_PATTERN);
|
||||
Pattern patternPassword = Pattern.compile(Common.PASSWORD_PATTERN);
|
||||
Matcher matcherPassword = patternPassword.matcher(edt_passWord.getText().toString());
|
||||
|
||||
if(!matcherPassword.matches() || edt_passWord.getText().toString().length() < 8) {
|
||||
@@ -280,7 +284,7 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
private void signUp(){
|
||||
FirebaseAuth auth = FirebaseAuth.getInstance();
|
||||
PhoneAuthOptions options = PhoneAuthOptions.newBuilder(auth)
|
||||
.setPhoneNumber(PHONE_CODE + edt_phone.getText().toString())
|
||||
.setPhoneNumber(Common.PHONE_CODE + edt_phone.getText().toString())
|
||||
.setTimeout(60L, TimeUnit.SECONDS)
|
||||
.setActivity(this)
|
||||
.setCallbacks(new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
|
||||
|
||||
@@ -28,6 +28,9 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Common {
|
||||
public static final String PHONE_CODE = "+84";
|
||||
public static final String PASSWORD_PATTERN = "^(?=.*[0-9])(?=.*[A-Z])(?=.*[@#$%^&+=!_])(?=\\S+$).{4,}$";
|
||||
public static final String PHONE_PATTERN = "^0[98753]{1}\\d{8}$";
|
||||
public static List<Basket> LIST_BASKET_FOOD = new ArrayList<>();
|
||||
|
||||
public static String TOKEN = null;
|
||||
|
||||
@@ -281,6 +281,26 @@
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#80000000"
|
||||
android:id="@+id/progress_layout"
|
||||
>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBarLoadData"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminateTint="@color/primaryColor"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_bar"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginBottom="40dp"
|
||||
android:layout_marginTop="50dp"
|
||||
android:hint="@string/phone_or_email"
|
||||
android:hint="@string/phone"
|
||||
app:boxBackgroundColor="@color/white"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
||||
@@ -40,14 +40,14 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/textInput_account"
|
||||
android:id="@+id/textInput_phone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:hint="@string/phone_or_email"
|
||||
android:hint="@string/phone"
|
||||
app:boxBackgroundColor="@color/white"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/logo_image"
|
||||
@@ -58,14 +58,14 @@
|
||||
android:id="@+id/edt_email"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:inputType="text" />
|
||||
android:inputType="phone" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/textInput_password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginTop="20dp"
|
||||
@@ -73,7 +73,7 @@
|
||||
app:boxBackgroundColor="@color/white"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textInput_account"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textInput_phone"
|
||||
app:passwordToggleEnabled="true"
|
||||
app:passwordToggleTint="@color/primaryColor"
|
||||
app:startIconDrawable="@drawable/baseline_vpn_key_24"
|
||||
@@ -148,4 +148,25 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#80000000"
|
||||
android:id="@+id/progress_layout"
|
||||
android:visibility="gone"
|
||||
>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBarLoadData"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminateTint="@color/primaryColor"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -113,4 +113,6 @@
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
@@ -18,7 +18,7 @@
|
||||
<string name="last_name_text">Tên</string>
|
||||
<string name="birthday_text">ngày tháng năm sinh</string>
|
||||
<string name="address_text">địa chỉ</string>
|
||||
<string name="phone_or_email">số điện thoại hoặc email</string>
|
||||
<string name="phone">số điện thoại</string>
|
||||
<string name="forgot_password">Quên mật khẩu?</string>
|
||||
<string name="dont_have_an_account">Bạn chưa có tài khoản?</string>
|
||||
<string name="forgot_password_description">Chúng tôi sẽ gửi mã xác nhận qua email của bạn.</string>
|
||||
|
||||
Reference in New Issue
Block a user