mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 20:00:50 +00:00
Add update account information
This commit is contained in:
@@ -20,9 +20,11 @@ import okhttp3.Response;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.DELETE;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.PUT;
|
||||
import retrofit2.http.Path;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
@@ -57,4 +59,7 @@ 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);
|
||||
}
|
||||
|
||||
@@ -9,26 +9,33 @@ import android.widget.DatePicker;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.capstone.foodify.API.FoodApiToken;
|
||||
import com.capstone.foodify.Common;
|
||||
import com.capstone.foodify.Model.User;
|
||||
import com.capstone.foodify.R;
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
|
||||
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 {
|
||||
|
||||
TextInputLayout textInput_email, textInput_phone, textInput_fullName, textInput_birthDay;
|
||||
|
||||
EditText edt_birthday;
|
||||
EditText edt_birthday, edt_email, edt_phone, edt_fullName;
|
||||
final Calendar myCalendar= Calendar.getInstance();
|
||||
LinearLayout change_password;
|
||||
Button update_button;
|
||||
|
||||
ImageView back_image;
|
||||
|
||||
@Override
|
||||
@@ -38,6 +45,10 @@ public class AccountAndProfileActivity extends AppCompatActivity {
|
||||
|
||||
initComponent();
|
||||
setFontUI();
|
||||
|
||||
//Init data
|
||||
initData();
|
||||
|
||||
chooseDateOfBirth();
|
||||
|
||||
change_password.setOnClickListener(new View.OnClickListener() {
|
||||
@@ -54,22 +65,39 @@ public class AccountAndProfileActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
update_button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
updateUser();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
private void initComponent() {
|
||||
//Init Component
|
||||
|
||||
textInput_email= (TextInputLayout) findViewById(R.id.textInput_email);
|
||||
textInput_phone = (TextInputLayout) findViewById(R.id.textInput_phone);
|
||||
textInput_fullName = (TextInputLayout) findViewById(R.id.textInput_fullName);
|
||||
textInput_birthDay = (TextInputLayout) findViewById(R.id.textInput_birthDay);
|
||||
change_password = (LinearLayout) findViewById(R.id.change_password);
|
||||
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);
|
||||
change_password = findViewById(R.id.change_password);
|
||||
|
||||
update_button = (Button) findViewById(R.id.updated_button);
|
||||
update_button = findViewById(R.id.updated_button);
|
||||
|
||||
back_image = (ImageView) findViewById(R.id.back_image);
|
||||
back_image = findViewById(R.id.back_image);
|
||||
|
||||
edt_birthday = (EditText) findViewById(R.id.edt_birthDay);
|
||||
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);
|
||||
}
|
||||
|
||||
private void setFontUI() {
|
||||
@@ -82,9 +110,14 @@ public class AccountAndProfileActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void chooseDateOfBirth() {
|
||||
//Calendar date of birth
|
||||
//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];
|
||||
|
||||
DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
|
||||
//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);
|
||||
@@ -92,18 +125,39 @@ public class AccountAndProfileActivity extends AppCompatActivity {
|
||||
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) {
|
||||
new DatePickerDialog(AccountAndProfileActivity.this, date, myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show();
|
||||
datePickerDialog.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateLabel(){
|
||||
String myFormat="dd/MM/yyyy";
|
||||
SimpleDateFormat dateFormat=new SimpleDateFormat(myFormat, Locale.US);
|
||||
SimpleDateFormat dateFormat=new SimpleDateFormat(Common.FORMAT_DATE, Locale.US);
|
||||
edt_birthday.setText(dateFormat.format(myCalendar.getTime()));
|
||||
}
|
||||
|
||||
private void updateUser() {
|
||||
//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);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<User> call, Throwable t) {
|
||||
Common.showErrorServerNotification(AccountAndProfileActivity.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -131,6 +131,11 @@ public class FavoriteFoodActivity extends AppCompatActivity implements ItemTouch
|
||||
LAST_PAGE = foodData.getPage().isLast();
|
||||
}
|
||||
|
||||
if(LAST_PAGE){
|
||||
progressBar.setVisibility(View.GONE);
|
||||
endOfListText.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
|
||||
Collections.sort(listFavoriteFood);
|
||||
|
||||
|
||||
@@ -164,6 +164,8 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
favorite_icon.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//TODO Check food has been in favorite food or not
|
||||
|
||||
addFoodToFavorite();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -53,7 +53,6 @@ import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class SignUpActivity extends AppCompatActivity {
|
||||
public static final String FORMAT_DATE="dd/MM/yyyy";
|
||||
TextInputLayout textInput_password, textInput_phone, textInput_email,
|
||||
textInput_address, textInput_confirmPassword, textInput_fullName, textInput_birthDay;
|
||||
final Calendar myCalendar= Calendar.getInstance();
|
||||
@@ -210,7 +209,7 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
|
||||
} else {
|
||||
//Calculate user age
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(FORMAT_DATE);
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Common.FORMAT_DATE);
|
||||
LocalDate birthday = LocalDate.parse(edt_birthday.getText().toString(), formatter);
|
||||
if(calculateAge(birthday, LocalDate.now()) < 16){
|
||||
textInput_birthDay.setError("Xin lỗi, bạn chưa đủ tuổi đề dùng app này!");
|
||||
@@ -260,6 +259,7 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
return dataHasValidate;
|
||||
}
|
||||
|
||||
|
||||
private void getDataFromForm(){
|
||||
email = edt_email.getText().toString();
|
||||
phone = edt_phone.getText().toString();
|
||||
@@ -465,7 +465,7 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void updateLabel(){
|
||||
SimpleDateFormat dateFormat=new SimpleDateFormat(FORMAT_DATE, Locale.US);
|
||||
SimpleDateFormat dateFormat=new SimpleDateFormat(Common.FORMAT_DATE, Locale.US);
|
||||
edt_birthday.setText(dateFormat.format(myCalendar.getTime()));
|
||||
}
|
||||
|
||||
|
||||
@@ -30,12 +30,12 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Common {
|
||||
public static final String FORMAT_DATE="dd-MM-yyyy";
|
||||
public static final String VALID_EMAIL_ADDRESS_REGEX = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$";
|
||||
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 List<Food> LIST_FAVORITE_FOOD = new ArrayList<>();
|
||||
public static String TOKEN = null;
|
||||
public static User CURRENT_USER = null;
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ public class ProfileFragment extends Fragment {
|
||||
Paper.book().delete("user");
|
||||
|
||||
Common.TOKEN = null;
|
||||
Common.CURRENT_USER = null;
|
||||
startActivity(new Intent(getContext(), MainActivity.class));
|
||||
}
|
||||
|
||||
@@ -115,4 +116,12 @@ public class ProfileFragment extends Fragment {
|
||||
});
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
//Update user name on textview
|
||||
user_name.setText(Common.CURRENT_USER.getFullName());
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ public class User implements Serializable {
|
||||
private boolean isLocked;
|
||||
private String phoneNumber;
|
||||
private String roleName;
|
||||
private int defaultAddress;
|
||||
private List<Address> addresses;
|
||||
|
||||
public User() {
|
||||
@@ -114,6 +115,14 @@ public class User implements Serializable {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
public int getDefaultAddress() {
|
||||
return defaultAddress;
|
||||
}
|
||||
|
||||
public void setDefaultAddress(int defaultAddress) {
|
||||
this.defaultAddress = defaultAddress;
|
||||
}
|
||||
|
||||
public void setAddresses(List<Address> addresses) {
|
||||
this.addresses = addresses;
|
||||
}
|
||||
|
||||
@@ -88,15 +88,14 @@
|
||||
app:boxBackgroundColor="@color/white"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/textInput_birthDay"
|
||||
app:startIconDrawable="@drawable/baseline_phone_24"
|
||||
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="phone"
|
||||
android:enabled="false"
|
||||
android:inputType="text"
|
||||
/>
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
@@ -120,7 +119,6 @@
|
||||
android:id="@+id/edt_birthDay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="25/5/2001"
|
||||
android:clickable="false"
|
||||
android:cursorVisible="false"
|
||||
android:focusable="false"
|
||||
|
||||
Reference in New Issue
Block a user