Change information, password user

This commit is contained in:
Nezumi
2023-04-04 11:23:58 +07:00
parent 91193e50b8
commit 809e92074d
14 changed files with 931 additions and 65 deletions
+2
View File
@@ -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'
}
+4 -1
View File
@@ -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">
<activity
android:name=".Activity.AccountAndProfileActivity"
android:exported="false" />
<activity
android:name=".Activity.ChangePasswordActivity"
android:exported="false" />
@@ -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<Foods> 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<User> updateUser(@Path("userId") int userId, @Body User user);
@PUT("users/{userId}")
Call<User> updateUser(@Path("userId") int userId, @Body User user);
//
// @GET("users/{userId}/loves/{productId}")
// Call<CustomResponse> checkFoodIsFavorite(@Path("userId") int userId, @Path("productId") int productId);
@@ -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<Intent> activityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@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<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
imageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
if(!Common.CURRENT_USER.getImageUrl().isEmpty())
deleteOldImage();
updateUser(uri.toString());
}
});
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@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<Void>() {
@Override
public void onComplete(@NonNull Task<Void> 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<User>() {
@Override
public void onResponse(Call<User> call, Response<User> 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<User> 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()));
}
}
@@ -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<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
user.updatePassword(newPassword).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> 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()));
}
}
@@ -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);
@@ -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() + "!");
}
}
@@ -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("")
.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);
}
}
}
@@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#000000" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M17,7l-1.41,1.41L18.17,11H8v2h10.17l-2.58,2.58L17,17l5,-5zM4,5h8V3H4c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h8v-2H4V5z"/>
</vector>
@@ -0,0 +1,5 @@
<vector android:height="48dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/primaryColor" />
<corners android:topLeftRadius="10dp" android:topRightRadius="10dp"
android:bottomLeftRadius="10dp" android:bottomRightRadius="10dp"/>
</shape>
@@ -0,0 +1,202 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity.AccountAndProfileActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
>
<ImageView
android:id="@+id/back_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:src="@drawable/back_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="35dp"
android:fontFamily="@font/bebas"
android:text="THAY ĐỔI THÔNG TIN"
android:textColor="@color/black"
android:textSize="40sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/back_image" />
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/profile_avatar"
android:src="@drawable/profile_avatar"
android:layout_marginTop="15dp"
app:riv_corner_radius="180dp"
android:layout_width="100dp"
android:layout_height="100dp"
android:scaleType="centerCrop"
app:layout_constraintTop_toBottomOf="@id/textView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<Button
android:id="@+id/change_image_button"
android:text="Đổi ảnh"
android:textColor="@color/white"
android:fontFamily="@font/bebas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:layout_constraintTop_toBottomOf="@id/profile_avatar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInput_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:layout_marginBottom="20dp"
android:hint="Email"
app:boxBackgroundColor="@color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/textInput_phone"
app:startIconDrawable="@drawable/baseline_email_24"
app:startIconTint="@color/primaryColor">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edt_email"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textEmailAddress"
android:enabled="false"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInput_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:hint="Số điện thoại"
app:boxBackgroundColor="@color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/textInput_fullName"
app:startIconDrawable="@drawable/baseline_phone_24"
app:startIconTint="@color/primaryColor">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edt_phone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="phone"
android:enabled="false"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInput_fullName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:hint="Họ và tên"
app:boxBackgroundColor="@color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/textInput_birthDay"
app:startIconDrawable="@drawable/baseline_abc_24"
app:startIconTint="@color/primaryColor">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edt_fullName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="text"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInput_birthDay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="40dp"
android:hint="Ngày sinh nhật"
app:boxBackgroundColor="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/updated_button"
app:startIconDrawable="@drawable/baseline_calendar_month_24"
app:startIconTint="@color/primaryColor">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edt_birthDay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/updated_button"
style="@style/DefaultSolid"
android:fontFamily="@font/bebas"
android:text="Cập nhật"
android:textSize="20sp"
android:padding="10dp"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:layout_marginBottom="17dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#80000000"
android:id="@+id/progress_layout"
android:clickable="true"
android:visibility="visible"
>
<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>
+125 -38
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@@ -39,19 +39,29 @@
app:layout_constraintEnd_toEndOf="parent"
/>
<Button
android:id="@+id/change_image_button"
android:text="Đổi ảnh"
android:textColor="@color/white"
android:fontFamily="@font/bebas"
android:layout_width="wrap_content"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInput_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:layout_constraintTop_toBottomOf="@id/profile_avatar"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginTop="30dp"
android:hint="Địa chỉ email"
app:boxBackgroundColor="@color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
app:layout_constraintTop_toBottomOf="@id/profile_avatar"
app:startIconDrawable="@drawable/baseline_email_24"
app:startIconTint="@color/primaryColor">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edt_email"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="phone"
android:enabled="false"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInput_phone"
@@ -59,11 +69,11 @@
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="30dp"
android:hint="Số điện thoại"
app:boxBackgroundColor="@color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/textInput_fullName"
app:layout_constraintTop_toBottomOf="@id/textInput_email"
app:startIconDrawable="@drawable/baseline_phone_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 @@
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#80000000"
android:id="@+id/progress_layout"
android:clickable="true"
android:visibility="gone"
>
<ProgressBar
android:id="@+id/progressBarLoadData"
android:layout_width="wrap_content"
<LinearLayout
android:id="@+id/change_information"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminateTint="@color/primaryColor"
android:layout_marginTop="30dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
app:layout_constraintTop_toBottomOf="@id/change_password"
android:orientation="horizontal"
>
<ImageView
android:src="@drawable/baseline_mode_edit_24"
android:layout_width="24dp"
android:layout_height="24dp"
tools:ignore="ContentDescription"
app:tint="@color/primaryColor"
/>
<TextView
android:text="Chỉnh sửa thông tin"
android:textSize="18sp"
android:fontFamily="@font/opensans"
android:textColor="@color/black"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="12dp"
android:layout_weight="1"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:rotation="180"
android:src="@drawable/back_button"
tools:ignore="ContentDescription" />
</LinearLayout>
<LinearLayout
android:id="@+id/log_out"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/change_information"
android:orientation="horizontal"
>
<ImageView
android:src="@drawable/baseline_logout_24"
android:layout_width="24dp"
android:layout_height="24dp"
tools:ignore="ContentDescription"
app:tint="@color/primaryColor"
/>
<TextView
android:text="Đăng xuất"
android:textSize="18sp"
android:fontFamily="@font/opensans"
android:textColor="@color/black"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="12dp"
android:layout_weight="1"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:rotation="180"
android:src="@drawable/back_button"
tools:ignore="ContentDescription" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/log_out"
android:orientation="horizontal"
>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
+6
View File
@@ -12,6 +12,7 @@
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:datePickerDialogTheme">@style/MyDatePickerDialogTheme</item>
</style>
<style name="DefaultSolid" parent="Widget.MaterialComponents.Button">
@@ -23,4 +24,9 @@
<item name="cornerSize">20dp</item>
<item name="android:color">@color/primaryColor</item>
</style>
<style name="MyDatePickerDialogTheme" parent="android:Theme.Material.Light.Dialog">
<item name="android:colorAccent">@color/primaryColor</item>
<item name="colorOnPrimary">@color/primaryColor</item>
</style>
</resources>