From 809e92074d140f87f6a86e31d6b8cb4051b030d5 Mon Sep 17 00:00:00 2001
From: Nezumi <123229563+Nez27@users.noreply.github.com>
Date: Tue, 4 Apr 2023 11:23:58 +0700
Subject: [PATCH] Change information, password user
---
app/build.gradle | 2 +
app/src/main/AndroidManifest.xml | 5 +-
.../foodify/shipper/API/FoodApiToken.java | 6 +-
.../Activity/AccountAndProfileActivity.java | 290 ++++++++++++++++++
.../Activity/ChangePasswordActivity.java | 186 +++++++++++
.../shipper/Activity/MainActivity.java | 3 +
.../shipper/Fragment/OrderFragment.java | 9 +
.../shipper/Fragment/ProfileFragment.java | 107 +++++--
.../main/res/drawable/baseline_logout_24.xml | 5 +
.../res/drawable/baseline_mode_edit_24.xml | 5 +
.../res/drawable/bg_color_primary_corner.xml | 7 +
.../layout/activity_account_and_profile.xml | 202 ++++++++++++
app/src/main/res/layout/fragment_profile.xml | 163 +++++++---
app/src/main/res/values/themes.xml | 6 +
14 files changed, 931 insertions(+), 65 deletions(-)
create mode 100644 app/src/main/java/com/capstone/foodify/shipper/Activity/AccountAndProfileActivity.java
create mode 100644 app/src/main/res/drawable/baseline_logout_24.xml
create mode 100644 app/src/main/res/drawable/baseline_mode_edit_24.xml
create mode 100644 app/src/main/res/drawable/bg_color_primary_corner.xml
create mode 100644 app/src/main/res/layout/activity_account_and_profile.xml
diff --git a/app/build.gradle b/app/build.gradle
index a852d33..579fc29 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -46,4 +46,6 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.9.0'
implementation 'com.github.gabriel-TheCode:AestheticDialogs:1.3.6'
+ implementation 'com.saadahmedev.popup-dialog:popup-dialog:1.0.2'
+ implementation 'com.squareup.picasso:picasso:2.71828'
}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 0d24464..3808799 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -12,9 +12,12 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
- android:usesCleartextTraffic="true"
android:theme="@style/Theme.FoodifyShipper"
+ android:usesCleartextTraffic="true"
tools:targetApi="31">
+
diff --git a/app/src/main/java/com/capstone/foodify/shipper/API/FoodApiToken.java b/app/src/main/java/com/capstone/foodify/shipper/API/FoodApiToken.java
index 2d9c7bc..2f618d2 100644
--- a/app/src/main/java/com/capstone/foodify/shipper/API/FoodApiToken.java
+++ b/app/src/main/java/com/capstone/foodify/shipper/API/FoodApiToken.java
@@ -16,7 +16,9 @@ import okhttp3.Response;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
+import retrofit2.http.Body;
import retrofit2.http.GET;
+import retrofit2.http.PUT;
import retrofit2.http.Path;
public interface FoodApiToken {
@@ -51,8 +53,8 @@ public interface FoodApiToken {
// @GET("users/{userId}/loves")
// Call getListFavoriteFood(@Path("userId") int userId, @Query("pageNo") int pageNo, @Query("pageSize") int pageSize, @Query("sortBy") String sortBy, @Query("sortDir") String sortDir);
//
-// @PUT("users/{userId}")
-// Call updateUser(@Path("userId") int userId, @Body User user);
+ @PUT("users/{userId}")
+ Call updateUser(@Path("userId") int userId, @Body User user);
//
// @GET("users/{userId}/loves/{productId}")
// Call checkFoodIsFavorite(@Path("userId") int userId, @Path("productId") int productId);
diff --git a/app/src/main/java/com/capstone/foodify/shipper/Activity/AccountAndProfileActivity.java b/app/src/main/java/com/capstone/foodify/shipper/Activity/AccountAndProfileActivity.java
new file mode 100644
index 0000000..324000a
--- /dev/null
+++ b/app/src/main/java/com/capstone/foodify/shipper/Activity/AccountAndProfileActivity.java
@@ -0,0 +1,290 @@
+package com.capstone.foodify.shipper.Activity;
+
+import androidx.activity.result.ActivityResult;
+import androidx.activity.result.ActivityResultCallback;
+import androidx.activity.result.ActivityResultLauncher;
+import androidx.activity.result.contract.ActivityResultContracts;
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.constraintlayout.widget.ConstraintLayout;
+
+import android.app.Activity;
+import android.app.DatePickerDialog;
+import android.content.ContentResolver;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.CountDownTimer;
+import android.view.View;
+import android.webkit.MimeTypeMap;
+import android.widget.Button;
+import android.widget.DatePicker;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.capstone.foodify.shipper.API.FoodApiToken;
+import com.capstone.foodify.shipper.Common;
+import com.capstone.foodify.shipper.Model.User;
+import com.capstone.foodify.shipper.R;
+import com.google.android.gms.tasks.OnCompleteListener;
+import com.google.android.gms.tasks.OnFailureListener;
+import com.google.android.gms.tasks.OnSuccessListener;
+import com.google.android.gms.tasks.Task;
+import com.google.android.material.textfield.TextInputLayout;
+import com.google.firebase.auth.FirebaseAuth;
+import com.google.firebase.auth.FirebaseUser;
+import com.google.firebase.storage.FirebaseStorage;
+import com.google.firebase.storage.OnProgressListener;
+import com.google.firebase.storage.StorageReference;
+import com.google.firebase.storage.UploadTask;
+import com.makeramen.roundedimageview.RoundedImageView;
+import com.squareup.picasso.Picasso;
+import com.thecode.aestheticdialogs.AestheticDialog;
+import com.thecode.aestheticdialogs.DialogAnimation;
+import com.thecode.aestheticdialogs.DialogStyle;
+import com.thecode.aestheticdialogs.DialogType;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Locale;
+
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+
+public class AccountAndProfileActivity extends AppCompatActivity {
+
+ private static final String FOLDER_DIRECTORY = "UserImages/";
+ TextInputLayout textInput_email, textInput_phone, textInput_fullName, textInput_birthDay;
+ EditText edt_birthday, edt_email, edt_phone, edt_fullName;
+ final Calendar myCalendar= Calendar.getInstance();
+ Button update_button, update_image_button;
+ ImageView back_image;
+ RoundedImageView profile_avatar;
+ private Uri imageUri;
+ final private StorageReference storageReference = FirebaseStorage.getInstance().getReference();
+ ConstraintLayout progressLayout;
+ FirebaseAuth mAuth;
+ FirebaseUser firebaseUser;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_account_and_profile);
+
+ initComponent();
+ setFontUI();
+
+ //Init data
+ initData();
+
+ //Initialize Firebase Auth
+ mAuth = FirebaseAuth.getInstance();
+
+ chooseDateOfBirth();
+
+ back_image.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ onBackPressed();
+ }
+ });
+
+ update_button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ progressLayout.setVisibility(View.VISIBLE);
+ if(imageUri != null)
+ uploadToFirebase(imageUri);
+ else
+ updateUser(null);
+ }
+ });
+
+ //Activity choose image
+ ActivityResultLauncher activityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
+ new ActivityResultCallback() {
+ @Override
+ public void onActivityResult(ActivityResult result) {
+ if(result.getResultCode() == Activity.RESULT_OK){
+ Intent data = result.getData();
+ imageUri = data.getData();
+ profile_avatar.setImageURI(imageUri);
+
+ Toast.makeText(AccountAndProfileActivity.this, "Hãy bấm nút cập nhật phía dưới để thay đổi có hiệu lực!", Toast.LENGTH_SHORT).show();
+ } else {
+ Toast.makeText(AccountAndProfileActivity.this, "Không ảnh nào được chọn!", Toast.LENGTH_SHORT).show();
+ }
+ }
+ });
+
+ //Set event on button upload image avatar
+ update_image_button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent photoPicker = new Intent();
+ photoPicker.setAction(Intent.ACTION_GET_CONTENT);
+ photoPicker.setType("image/*");
+ activityResultLauncher.launch(photoPicker);
+ }
+ });
+
+ }
+ private void uploadToFirebase(Uri uri){
+
+ //Name of image user
+ String imageName = Common.CURRENT_USER.getFullName().replace(" " , "_") + "_" + Common.CURRENT_USER.getDateOfBirth().replace("-", "_")
+ + "_" + System.currentTimeMillis();
+
+ final StorageReference imageReference = storageReference.child(FOLDER_DIRECTORY + imageName + "." + getFileExtension(uri));
+ imageReference.putFile(uri).addOnSuccessListener(new OnSuccessListener() {
+ @Override
+ public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
+ imageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener() {
+ @Override
+ public void onSuccess(Uri uri) {
+ if(!Common.CURRENT_USER.getImageUrl().isEmpty())
+ deleteOldImage();
+
+ updateUser(uri.toString());
+ }
+ });
+ }
+ }).addOnProgressListener(new OnProgressListener() {
+ @Override
+ public void onProgress(@NonNull UploadTask.TaskSnapshot snapshot) {
+
+ }
+ }).addOnFailureListener(new OnFailureListener() {
+ @Override
+ public void onFailure(@NonNull Exception e) {
+
+ Toast.makeText(AccountAndProfileActivity.this, "Failed", Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+
+ private void deleteOldImage() {
+ StorageReference storageReference = FirebaseStorage.getInstance().getReferenceFromUrl(Common.CURRENT_USER.getImageUrl());
+
+ storageReference.delete().addOnCompleteListener(new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+
+ }
+ }).addOnFailureListener(new OnFailureListener() {
+ @Override
+ public void onFailure(@NonNull Exception e) {
+ Toast.makeText(AccountAndProfileActivity.this, "Can't delete old image!", Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+
+ private String getFileExtension(Uri fileUri){
+ ContentResolver contentResolver = getContentResolver();
+ MimeTypeMap mime = MimeTypeMap.getSingleton();
+ return mime.getExtensionFromMimeType(contentResolver.getType(fileUri));
+ }
+
+ private void initData() {
+ edt_email.setText(Common.CURRENT_USER.getEmail());
+ edt_phone.setText(Common.CURRENT_USER.getPhoneNumber());
+ edt_fullName.setText(Common.CURRENT_USER.getFullName());
+ edt_birthday.setText(Common.CURRENT_USER.getDateOfBirth());
+
+ //Set image for user
+ if(Common.CURRENT_USER.getImageUrl().isEmpty()){
+ profile_avatar.setImageResource(R.drawable.profile_avatar);
+ } else {
+ Picasso.get().load(Common.CURRENT_USER.getImageUrl()).into(profile_avatar);
+ }
+
+ progressLayout.setVisibility(View.GONE);
+ }
+
+ private void updateUser(String imageUrl) {
+ //Get data from form
+ String fullName = edt_fullName.getText().toString();
+ String dateOfBirth = edt_birthday.getText().toString();
+
+ //Create object User
+ Common.CURRENT_USER.setFullName(fullName);
+ Common.CURRENT_USER.setDateOfBirth(dateOfBirth);
+ if(imageUrl != null)
+ Common.CURRENT_USER.setImageUrl(imageUrl);
+
+ FoodApiToken.apiService.updateUser(Common.CURRENT_USER.getId(), Common.CURRENT_USER).enqueue(new Callback() {
+ @Override
+ public void onResponse(Call call, Response response) {
+ Toast.makeText(AccountAndProfileActivity.this, "Cập nhật thành công!", Toast.LENGTH_SHORT).show();
+ progressLayout.setVisibility(View.GONE);
+ }
+
+ @Override
+ public void onFailure(Call call, Throwable t) {
+ Common.showErrorServerNotification(AccountAndProfileActivity.this, "Không thể cập nhật thông tin, vui lòng thử lại sau!");
+ progressLayout.setVisibility(View.GONE);
+ }
+ });
+ }
+ private void initComponent() {
+ //Init Component
+ textInput_email= findViewById(R.id.textInput_email);
+ textInput_phone = findViewById(R.id.textInput_phone);
+ textInput_fullName = findViewById(R.id.textInput_fullName);
+ textInput_birthDay = findViewById(R.id.textInput_birthDay);
+
+ update_button = findViewById(R.id.updated_button);
+ update_image_button = findViewById(R.id.change_image_button);
+
+ back_image = findViewById(R.id.back_image);
+
+ edt_birthday = findViewById(R.id.edt_birthDay);
+ edt_email = findViewById(R.id.edt_email);
+ edt_phone = findViewById(R.id.edt_phone);
+ edt_fullName = findViewById(R.id.edt_fullName);
+
+ profile_avatar = findViewById(R.id.profile_avatar);
+
+ progressLayout = findViewById(R.id.progress_layout);
+ }
+ private void setFontUI() {
+ textInput_email.setTypeface(Common.setFontBebas(getAssets()));
+ textInput_phone.setTypeface(Common.setFontBebas(getAssets()));
+ textInput_fullName.setTypeface(Common.setFontBebas(getAssets()));
+ textInput_birthDay.setTypeface(Common.setFontBebas(getAssets()));
+
+ edt_birthday.setTypeface(Common.setFontBebas(getAssets()));
+ }
+ private void chooseDateOfBirth() {
+ //Get date, month, year from user
+ String [] dateParts = edt_birthday.getText().toString().split("-");
+ String day = dateParts[0];
+ String month = dateParts[1];
+ String year = dateParts[2];
+
+ //Calendar date of birth
+ DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener(){
+ @Override
+ public void onDateSet(DatePicker view, int year, int month, int day) {
+ myCalendar.set(Calendar.YEAR, year);
+ myCalendar.set(Calendar.MONTH,month);
+ myCalendar.set(Calendar.DAY_OF_MONTH,day);
+ updateLabel();
+ }
+ }, Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day));
+ edt_birthday.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ datePickerDialog.show();
+ }
+ });
+ }
+ private void updateLabel(){
+ SimpleDateFormat dateFormat=new SimpleDateFormat(Common.FORMAT_DATE, Locale.US);
+ edt_birthday.setText(dateFormat.format(myCalendar.getTime()));
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/capstone/foodify/shipper/Activity/ChangePasswordActivity.java b/app/src/main/java/com/capstone/foodify/shipper/Activity/ChangePasswordActivity.java
index 810874f..c1c258b 100644
--- a/app/src/main/java/com/capstone/foodify/shipper/Activity/ChangePasswordActivity.java
+++ b/app/src/main/java/com/capstone/foodify/shipper/Activity/ChangePasswordActivity.java
@@ -1,16 +1,202 @@
package com.capstone.foodify.shipper.Activity;
+import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.constraintlayout.widget.ConstraintLayout;
import android.os.Bundle;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.Toast;
+import com.capstone.foodify.shipper.Common;
import com.capstone.foodify.shipper.R;
+import com.google.android.gms.tasks.OnCompleteListener;
+import com.google.android.gms.tasks.Task;
+import com.google.android.material.textfield.TextInputLayout;
+import com.google.firebase.auth.AuthCredential;
+import com.google.firebase.auth.EmailAuthProvider;
+import com.google.firebase.auth.FirebaseAuth;
+import com.google.firebase.auth.FirebaseUser;
+import com.thecode.aestheticdialogs.AestheticDialog;
+import com.thecode.aestheticdialogs.DialogStyle;
+import com.thecode.aestheticdialogs.DialogType;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class ChangePasswordActivity extends AppCompatActivity {
+ TextInputLayout textInput_old_password, textInput_password, textInput_password_confirm;
+ EditText edtOldPassword, edtPassword, edtPasswordConfirm;
+ ImageView back_image;
+ ConstraintLayout progressLayout;
+
+ Button changePasswordButton;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_change_password);
+
+ initComponent();
+ setFontUI();
+
+ //Handle event when back image on click
+ back_image.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ onBackPressed();
+ }
+ });
+
+ changePasswordButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ //Show progress bar
+ progressLayout.setVisibility(View.VISIBLE);
+
+ if(validateData()){
+ changePassword(edtOldPassword.getText().toString(), edtPasswordConfirm.getText().toString());
+ } else {
+ progressLayout.setVisibility(View.GONE);
+ }
+ }
+ });
+
+ textInput_password.setOnFocusChangeListener(new View.OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ textInput_password.setErrorEnabled(false);
+ }
+ });
+
+ edtPassword.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ textInput_password.setErrorEnabled(false);
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+
+ }
+ });
+
+ edtPasswordConfirm.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ textInput_password_confirm.setErrorEnabled(false);
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+
+ }
+ });
+ }
+
+ private boolean validateData(){
+ boolean dataHasValidate = true;
+
+ //Check password
+ Pattern patternPassword = Pattern.compile(Common.PASSWORD_PATTERN);
+ Matcher matcherPassword = patternPassword.matcher(edtPassword.getText().toString());
+
+ if(!matcherPassword.matches() || edtPassword.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);
+ }
+
+ if(!edtPassword.getText().toString().equals(edtPasswordConfirm.getText().toString())){
+ textInput_password_confirm.setError("Mật khẩu không giống nhau. Vui lòng kiểm tra lại!");
+ dataHasValidate = false;
+ } else {
+ textInput_password_confirm.setErrorEnabled(false);
+ }
+
+ return dataHasValidate;
+ }
+
+ private void changePassword(String oldPassword, String newPassword){
+ FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
+
+ // Get auth credentials from the user for re-authentication. The example below shows
+ // email and password credentials but there are multiple possible providers,
+ // such as GoogleAuthProvider or FacebookAuthProvider.
+ AuthCredential credential = EmailAuthProvider
+ .getCredential(Common.CURRENT_USER.getEmail(), oldPassword);
+
+ // Prompt the user to re-provide their sign-in credentials
+ user.reauthenticate(credential)
+ .addOnCompleteListener(new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+ if (task.isSuccessful()) {
+ user.updatePassword(newPassword).addOnCompleteListener(new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+ if (task.isSuccessful()) {
+ new AestheticDialog.Builder(ChangePasswordActivity.this, DialogStyle.RAINBOW, DialogType.SUCCESS)
+ .setTitle("Thàng công!")
+ .setMessage("Đã thay đổi mật khẩu thành công!")
+ .setCancelable(true)
+ .show();
+
+ progressLayout.setVisibility(View.GONE);
+ } else {
+ Toast.makeText(ChangePasswordActivity.this, "Đã có lỗi từ hệ thống, vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
+ progressLayout.setVisibility(View.GONE);
+ }
+ }
+ });
+ } else {
+ new AestheticDialog.Builder(ChangePasswordActivity.this, DialogStyle.RAINBOW, DialogType.ERROR)
+ .setTitle("Lỗi!")
+ .setMessage("Mật khẩu không đúng! Xin vui lòng thử lại!")
+ .setCancelable(true)
+ .show();
+ progressLayout.setVisibility(View.GONE);
+ }
+ }
+ });
+ }
+
+ private void initComponent() {
+ textInput_old_password = findViewById(R.id.textInput_old_password);
+ textInput_password = findViewById(R.id.textInput_password);
+ textInput_password_confirm = findViewById(R.id.textInput_password_confirm);
+
+ edtOldPassword = findViewById(R.id.edt_old_password);
+ edtPassword = findViewById(R.id.edt_password);
+ edtPasswordConfirm = findViewById(R.id.edt_confirmPassword);
+
+ back_image = findViewById(R.id.back_image);
+
+ changePasswordButton = findViewById(R.id.change_password_button);
+
+ progressLayout = findViewById(R.id.progress_layout);
+ }
+
+ private void setFontUI() {
+ textInput_password.setTypeface(Common.setFontBebas(getAssets()));
+ textInput_old_password.setTypeface(Common.setFontBebas(getAssets()));
+ textInput_password_confirm.setTypeface(Common.setFontBebas(getAssets()));
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/capstone/foodify/shipper/Activity/MainActivity.java b/app/src/main/java/com/capstone/foodify/shipper/Activity/MainActivity.java
index 29ef096..3dff0ef 100644
--- a/app/src/main/java/com/capstone/foodify/shipper/Activity/MainActivity.java
+++ b/app/src/main/java/com/capstone/foodify/shipper/Activity/MainActivity.java
@@ -7,9 +7,11 @@ import androidx.core.splashscreen.SplashScreen;
import androidx.viewpager2.widget.ViewPager2;
import android.annotation.SuppressLint;
+import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
+import com.capstone.foodify.shipper.Common;
import com.capstone.foodify.shipper.R;
import com.capstone.foodify.shipper.ViewPagerAdapter;
import com.google.android.material.bottomnavigation.BottomNavigationView;
@@ -26,6 +28,7 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+
//Init Component
bottomNavigationView = findViewById(R.id.bottom_nav);
viewPager2 = findViewById(R.id.viewPager);
diff --git a/app/src/main/java/com/capstone/foodify/shipper/Fragment/OrderFragment.java b/app/src/main/java/com/capstone/foodify/shipper/Fragment/OrderFragment.java
index 269e6bf..0fb934c 100644
--- a/app/src/main/java/com/capstone/foodify/shipper/Fragment/OrderFragment.java
+++ b/app/src/main/java/com/capstone/foodify/shipper/Fragment/OrderFragment.java
@@ -15,6 +15,7 @@ import com.capstone.foodify.shipper.Adapter.OrderAdapter;
import com.capstone.foodify.shipper.Common;
import com.capstone.foodify.shipper.Model.Order;
import com.capstone.foodify.shipper.R;
+import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import java.util.List;
@@ -55,4 +56,12 @@ public class OrderFragment extends Fragment {
return view;
}
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ //Update user name on textview
+ welcome_text.setText("Xin chào, " + Common.CURRENT_USER.getFullName() + "!");
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/capstone/foodify/shipper/Fragment/ProfileFragment.java b/app/src/main/java/com/capstone/foodify/shipper/Fragment/ProfileFragment.java
index 594a842..c50e81e 100644
--- a/app/src/main/java/com/capstone/foodify/shipper/Fragment/ProfileFragment.java
+++ b/app/src/main/java/com/capstone/foodify/shipper/Fragment/ProfileFragment.java
@@ -1,51 +1,43 @@
package com.capstone.foodify.shipper.Fragment;
+import android.app.Activity;
+import android.app.Dialog;
import android.content.Intent;
-import android.net.Uri;
import android.os.Bundle;
-
-import androidx.constraintlayout.widget.ConstraintLayout;
-import androidx.fragment.app.Fragment;
-
-import android.os.CountDownTimer;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.Button;
import android.widget.EditText;
-import android.widget.ImageView;
import android.widget.LinearLayout;
-import android.widget.TextView;
+import androidx.fragment.app.Fragment;
+
+import com.capstone.foodify.shipper.Activity.AccountAndProfileActivity;
import com.capstone.foodify.shipper.Activity.ChangePasswordActivity;
+import com.capstone.foodify.shipper.Activity.MainActivity;
+import com.capstone.foodify.shipper.Activity.SignInActivity;
import com.capstone.foodify.shipper.Common;
import com.capstone.foodify.shipper.R;
-import com.google.android.material.textfield.TextInputLayout;
import com.google.firebase.auth.FirebaseAuth;
-import com.google.firebase.auth.FirebaseUser;
-import com.google.firebase.storage.FirebaseStorage;
-import com.google.firebase.storage.StorageReference;
import com.makeramen.roundedimageview.RoundedImageView;
-
-import java.util.Calendar;
+import com.saadahmedsoft.popupdialog.PopupDialog;
+import com.saadahmedsoft.popupdialog.Styles;
+import com.saadahmedsoft.popupdialog.listener.OnDialogButtonClickListener;
+import com.squareup.picasso.Picasso;
public class ProfileFragment extends Fragment {
- private static final String FOLDER_DIRECTORY = "UserImages/";
- TextView txt_countdown, txt_resend_code, txt_verify_email;
- EditText edt_birthday, edt_phone, edt_fullName;
- Button update_image_button;
+ EditText edt_birthday, edt_phone, edt_fullName, edt_email;
+ LinearLayout changePasswordLayout, changeInformationLayout, logOutLayout;
RoundedImageView profile_avatar;
- private Uri imageUri;
- final private StorageReference storageReference = FirebaseStorage.getInstance().getReference();
- ConstraintLayout progressLayout;
-
- LinearLayout changePasswordLayout;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_profile, container, false);
+ if(Common.CURRENT_USER == null)
+ startActivity(new Intent(getContext(), SignInActivity.class));
+
//Init component
initComponent(view);
initData();
@@ -58,6 +50,20 @@ public class ProfileFragment extends Fragment {
}
});
+ changeInformationLayout.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ startActivity(new Intent(getContext(), AccountAndProfileActivity.class));
+ }
+ });
+
+ logOutLayout.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ logOutDialog();
+ }
+ });
+
return view;
}
@@ -65,11 +71,64 @@ public class ProfileFragment extends Fragment {
edt_phone.setText(Common.CURRENT_USER.getPhoneNumber());
edt_birthday.setText(Common.CURRENT_USER.getDateOfBirth());
edt_fullName.setText(Common.CURRENT_USER.getFullName());
+ edt_email.setText(Common.CURRENT_USER.getEmail());
}
private void initComponent(View view){
changePasswordLayout = view.findViewById(R.id.change_password);
+ changeInformationLayout = view.findViewById(R.id.change_information);
+ logOutLayout = view.findViewById(R.id.log_out);
+
edt_phone = view.findViewById(R.id.edt_phone);
edt_birthday = view.findViewById(R.id.edt_birthDay);
edt_fullName = view.findViewById(R.id.edt_fullName);
+ edt_email = view.findViewById(R.id.edt_email);
+
+ profile_avatar = view.findViewById(R.id.profile_avatar);
+ }
+
+ private void logOutDialog(){
+ PopupDialog.getInstance(getContext())
+ .setStyle(Styles.STANDARD)
+ .setHeading("Đăng xuất?")
+ .setDescription("Bạn thực sự muốn đăng xuất?")
+ .setPopupDialogIcon(R.drawable.baseline_logout_24)
+ .setPopupDialogIconTint(R.color.primaryColor)
+ .setPositiveButtonBackground(R.drawable.bg_color_primary_corner)
+ .setPositiveButtonText("Có")
+ .setNegativeButtonText("Không")
+ .setCancelable(false)
+ .showDialog(new OnDialogButtonClickListener() {
+ @Override
+ public void onPositiveClicked(Dialog dialog) {
+ FirebaseAuth.getInstance().signOut();
+ Common.CURRENT_USER = null;
+ dialog.dismiss();
+
+ getActivity().startActivity(new Intent(getContext(), SignInActivity.class));
+ getActivity().finish();
+ }
+
+ @Override
+ public void onNegativeClicked(Dialog dialog) {
+ super.onNegativeClicked(dialog);
+ }
+ });
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ //Update user name and date of birth on textview
+ edt_fullName.setText(Common.CURRENT_USER.getFullName());
+ edt_birthday.setText(Common.CURRENT_USER.getDateOfBirth());
+
+
+ //Set image for user
+ if(Common.CURRENT_USER.getImageUrl().isEmpty()){
+ profile_avatar.setImageResource(R.drawable.profile_avatar);
+ } else {
+ Picasso.get().load(Common.CURRENT_USER.getImageUrl()).into(profile_avatar);
+ }
}
}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/baseline_logout_24.xml b/app/src/main/res/drawable/baseline_logout_24.xml
new file mode 100644
index 0000000..bceb2ec
--- /dev/null
+++ b/app/src/main/res/drawable/baseline_logout_24.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/drawable/baseline_mode_edit_24.xml b/app/src/main/res/drawable/baseline_mode_edit_24.xml
new file mode 100644
index 0000000..192862d
--- /dev/null
+++ b/app/src/main/res/drawable/baseline_mode_edit_24.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/drawable/bg_color_primary_corner.xml b/app/src/main/res/drawable/bg_color_primary_corner.xml
new file mode 100644
index 0000000..7641064
--- /dev/null
+++ b/app/src/main/res/drawable/bg_color_primary_corner.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_account_and_profile.xml b/app/src/main/res/layout/activity_account_and_profile.xml
new file mode 100644
index 0000000..a7f4734
--- /dev/null
+++ b/app/src/main/res/layout/activity_account_and_profile.xml
@@ -0,0 +1,202 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml
index 65bdb14..36c8cfe 100644
--- a/app/src/main/res/layout/fragment_profile.xml
+++ b/app/src/main/res/layout/fragment_profile.xml
@@ -1,5 +1,5 @@
-
-
+ app:layout_constraintTop_toBottomOf="@id/profile_avatar"
+ app:startIconDrawable="@drawable/baseline_email_24"
+ app:startIconTint="@color/primaryColor">
+
+
+
@@ -83,11 +93,11 @@
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
- android:layout_marginBottom="20dp"
+ android:layout_marginTop="30dp"
android:hint="Họ và tên"
app:boxBackgroundColor="@color/white"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintBottom_toTopOf="@id/textInput_birthDay"
+ app:layout_constraintTop_toBottomOf="@id/textInput_phone"
app:startIconDrawable="@drawable/baseline_abc_24"
app:startIconTint="@color/primaryColor">
@@ -107,12 +117,12 @@
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
- android:layout_marginBottom="40dp"
+ android:layout_marginTop="30dp"
android:hint="Ngày tháng năm sinh"
app:boxBackgroundColor="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintBottom_toTopOf="@id/change_password"
+ app:layout_constraintTop_toBottomOf="@id/textInput_fullName"
app:startIconDrawable="@drawable/baseline_calendar_month_24"
app:startIconTint="@color/primaryColor">
@@ -132,12 +142,12 @@
android:id="@+id/change_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginBottom="30dp"
+ android:layout_marginTop="30dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintTop_toBottomOf="@id/textInput_birthDay"
android:orientation="horizontal"
>
@@ -172,28 +182,105 @@
-
-
-
-
-
+ app:layout_constraintTop_toBottomOf="@id/change_password"
+ android:orientation="horizontal"
+ >
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index e8020ae..d5b0e77 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -12,6 +12,7 @@
- false
- true
+ - @style/MyDatePickerDialogTheme
+
+
\ No newline at end of file