mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 13:38:41 +00:00
Add order detail screen, fix calculate of price food
This commit is contained in:
Generated
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="11" />
|
||||
<bytecodeTargetLevel target="17" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+1
-1
@@ -7,7 +7,7 @@
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="Embedded JDK" />
|
||||
<option name="gradleJvm" value="JDK" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
||||
Generated
+1
-2
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="jbr-11" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
@@ -53,7 +53,7 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
private ImageView back_image, not_favorite, is_favorite;
|
||||
private String foodId = "";
|
||||
private Food food;
|
||||
private TextView foodName_txt, shopName_txt, discount_txt, price_txt, total_txt, countRating_txt, description_content_txt;
|
||||
private TextView foodName_txt, shopName_txt, discount_txt, price_txt, countRating_txt, description_content_txt;
|
||||
private ConstraintLayout content_view;
|
||||
private Button add_to_basket_button;
|
||||
private float totalPrice, price;
|
||||
@@ -79,7 +79,6 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
add_to_basket_button = findViewById(R.id.add_to_basket_button);
|
||||
not_favorite = findViewById(R.id.not_favorite);
|
||||
is_favorite = findViewById(R.id.is_favorite);
|
||||
total_txt = findViewById(R.id.total_text_view);
|
||||
countRating_txt = findViewById(R.id.count_rating_text_view);
|
||||
description_content_txt = findViewById(R.id.content_description_text_view);
|
||||
recyclerView_review = findViewById(R.id.recycler_view_review);
|
||||
@@ -279,12 +278,9 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
//Set data price to calculate
|
||||
price = food.getCost();
|
||||
|
||||
foodName_txt.setText(food.getName());
|
||||
shopName_txt.setText(food.getShop().getName());
|
||||
price_txt.setText(Common.changeCurrencyUnit(food.getCost()));
|
||||
description_content_txt.setText(food.getDescription());
|
||||
countRating_txt.setText(food.getReviewCount() + " rating");
|
||||
|
||||
@@ -301,11 +297,22 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
}
|
||||
imageSlider.setImageList(slideModels, ScaleTypes.FIT);
|
||||
|
||||
//Show discount percent when value greater than 0
|
||||
//Show discount percent when value greater than 0 and show the final cost after discount!
|
||||
if (food.getDiscountPercent() > 0) {
|
||||
discount_txt.setText("-" + food.getDiscountPercent() + "%");
|
||||
|
||||
float finalCost = food.getCost() - (food.getCost() * food.getDiscountPercent() / 100);
|
||||
price_txt.setText(Common.changeCurrencyUnit(finalCost));
|
||||
|
||||
//Set data price to calculate
|
||||
price = finalCost;
|
||||
} else {
|
||||
discount_txt.setVisibility(View.GONE);
|
||||
|
||||
price_txt.setText(Common.changeCurrencyUnit(food.getCost()));
|
||||
|
||||
//Set data price to calculate
|
||||
price = food.getCost();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,40 +1,422 @@
|
||||
package com.capstone.foodify.Activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.capstone.foodify.API.FoodApi;
|
||||
import com.capstone.foodify.Adapter.OrderDetailAdapter;
|
||||
import com.capstone.foodify.Common;
|
||||
import com.capstone.foodify.Model.Address;
|
||||
import com.capstone.foodify.Model.Basket;
|
||||
import com.capstone.foodify.Model.DistrictWardResponse;
|
||||
import com.capstone.foodify.Model.OrderDetail;
|
||||
import com.capstone.foodify.R;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OrderCheckOutActivity extends AppCompatActivity {
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public List<OrderDetail> listOrderDetails = new ArrayList<>();
|
||||
public class OrderCheckOutActivity extends AppCompatActivity {
|
||||
private static String finalAddress = null;
|
||||
ImageView back_image;
|
||||
OrderDetailAdapter adapter;
|
||||
RecyclerView recyclerView;
|
||||
TextView txt_userName, txt_phone, edt_address_detect, errorTextDistrictWard, txt_total;
|
||||
TextInputLayout textInput_address;
|
||||
EditText edt_address;
|
||||
Spinner spn_list_address, spn_district, spn_ward;
|
||||
ConstraintLayout manual_input_address_layout;
|
||||
Button change_address_button, confirm_address_button;
|
||||
RadioButton list_address_input, auto_detect_location, manual_input_address, radio_button_selected;
|
||||
RadioGroup address_option;
|
||||
float total;
|
||||
private static final ArrayList<String> wardList = new ArrayList<>();
|
||||
private static final ArrayList<String> districtList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_order_check_out);
|
||||
|
||||
//Check user is login or not!
|
||||
if(Common.CURRENT_USER == null)
|
||||
startActivity(new Intent(this, SignInActivity.class));
|
||||
|
||||
|
||||
//Init Component
|
||||
txt_userName = findViewById(R.id.txt_userName);
|
||||
txt_phone = findViewById(R.id.txt_phone);
|
||||
spn_list_address = findViewById(R.id.list_address);
|
||||
spn_district = findViewById(R.id.district);
|
||||
spn_ward = findViewById(R.id.ward);
|
||||
edt_address_detect = findViewById(R.id.edt_address_detect);
|
||||
manual_input_address_layout = findViewById(R.id.manual_input_address_layout);
|
||||
adapter = new OrderDetailAdapter();
|
||||
recyclerView = findViewById(R.id.list_order);
|
||||
back_image = findViewById(R.id.back_image);
|
||||
change_address_button = findViewById(R.id.change_address_button);
|
||||
confirm_address_button = findViewById(R.id.confirm_address_button);
|
||||
list_address_input = findViewById(R.id.list_address_input);
|
||||
auto_detect_location = findViewById(R.id.auto_detect_location);
|
||||
manual_input_address = findViewById(R.id.manual_input_address);
|
||||
edt_address = findViewById(R.id.edt_address);
|
||||
address_option = findViewById(R.id.address_option);
|
||||
errorTextDistrictWard = findViewById(R.id.errorTextDistrictWard);
|
||||
textInput_address = findViewById(R.id.textInput_address);
|
||||
txt_total = findViewById(R.id.txt_total);
|
||||
|
||||
for(int i = 0; i < 5; i++){
|
||||
listOrderDetails.add(new OrderDetail());
|
||||
if(getIntent() != null){
|
||||
total = getIntent().getFloatExtra("total", 0);
|
||||
txt_total.setText(Common.changeCurrencyUnit(total));
|
||||
}
|
||||
|
||||
//Show list food in basket
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
|
||||
recyclerView.setLayoutManager(linearLayoutManager);
|
||||
|
||||
adapter.setData(listOrderDetails);
|
||||
adapter.setData(Common.LIST_BASKET_FOOD);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
showListAddressUser();
|
||||
|
||||
//Get list district, ward
|
||||
initDataDistrictWard();
|
||||
|
||||
//Set user name and phone
|
||||
txt_userName.setText(Common.CURRENT_USER.getFullName());
|
||||
txt_phone.setText(Common.CURRENT_USER.getPhoneNumber());
|
||||
|
||||
//Set event for change address button
|
||||
change_address_button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
confirm_address_button.setEnabled(true);
|
||||
change_address_button.setVisibility(View.GONE);
|
||||
|
||||
enabledAllInputAddressOption();
|
||||
}
|
||||
});
|
||||
|
||||
//Set event for confirm address button
|
||||
confirm_address_button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int selectedOptionId = address_option.getCheckedRadioButtonId();
|
||||
|
||||
radio_button_selected = findViewById(selectedOptionId);
|
||||
|
||||
if(radio_button_selected == list_address_input){
|
||||
//Action 1
|
||||
finalAddress = spn_list_address.getSelectedItem().toString();
|
||||
}
|
||||
|
||||
if(radio_button_selected == auto_detect_location){
|
||||
//Action 2
|
||||
|
||||
}
|
||||
|
||||
if(radio_button_selected == manual_input_address){
|
||||
//Action 3
|
||||
if(validForm()){
|
||||
if(spn_district.getSelectedItem().toString().equals("Huyện Hoàng Sa")){
|
||||
finalAddress = edt_address.getText().toString() + ", " + spn_district.getSelectedItem().toString();
|
||||
} else {
|
||||
finalAddress = edt_address.getText().toString() + ", " + spn_ward.getSelectedItem().toString() + ", " + spn_district.getSelectedItem().toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(finalAddress == null){
|
||||
Toast.makeText(OrderCheckOutActivity.this, "Bạn chưa chọn địa chỉ!", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(OrderCheckOutActivity.this, finalAddress, Toast.LENGTH_SHORT).show();
|
||||
|
||||
confirm_address_button.setEnabled(false);
|
||||
change_address_button.setVisibility(View.VISIBLE);
|
||||
|
||||
disableAllInputAddressOption();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//Set event for back icon
|
||||
back_image.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onBackPressed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean validForm(){
|
||||
//Valid data
|
||||
boolean dataHasValidate = true;
|
||||
|
||||
//Check address
|
||||
if(edt_address.getText().toString().length() < 8) {
|
||||
textInput_address.setError("Trường địa chỉ của bạn tối thiếu từ 8 ký tự trở lên");
|
||||
dataHasValidate = false;
|
||||
} else {
|
||||
textInput_address.setErrorEnabled(false);
|
||||
}
|
||||
|
||||
//Check district and ward
|
||||
if(spn_district.getSelectedItem().toString().equals("---Quận") || spn_ward.getSelectedItem().toString().equals("---Phường")){
|
||||
|
||||
if(!spn_district.getSelectedItem().toString().equals("Huyện Hoàng Sa")){
|
||||
errorTextDistrictWard.setVisibility(View.VISIBLE);
|
||||
dataHasValidate = false;
|
||||
} else{
|
||||
errorTextDistrictWard.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
} else {
|
||||
errorTextDistrictWard.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
return dataHasValidate;
|
||||
}
|
||||
|
||||
private void initDataDistrictWard(){
|
||||
if(districtList.size() == 0){
|
||||
getListDistrict();
|
||||
} else {
|
||||
setAdapter(districtList, "---Quận", spn_district);
|
||||
}
|
||||
getListWard(0);
|
||||
|
||||
//Add event for district spinner
|
||||
spn_district.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
getListWard(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> adapterView) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void disableAllInputAddressOption(){
|
||||
list_address_input.setEnabled(false);
|
||||
auto_detect_location.setEnabled(false);
|
||||
manual_input_address.setEnabled(false);
|
||||
|
||||
spn_list_address.setEnabled(false);
|
||||
edt_address.setEnabled(false);
|
||||
spn_ward.setEnabled(false);
|
||||
spn_district.setEnabled(false);
|
||||
}
|
||||
|
||||
private void enabledAllInputAddressOption(){
|
||||
list_address_input.setEnabled(true);
|
||||
auto_detect_location.setEnabled(true);
|
||||
manual_input_address.setEnabled(true);
|
||||
|
||||
spn_list_address.setEnabled(true);
|
||||
edt_address.setEnabled(true);
|
||||
spn_ward.setEnabled(true);
|
||||
spn_district.setEnabled(true);
|
||||
}
|
||||
|
||||
private void showListAddressUser(){
|
||||
List<String> listAddress = new ArrayList<>();
|
||||
String defaultAddress = "";
|
||||
|
||||
//Get all list address
|
||||
for(Address tempAddress: Common.CURRENT_USER.getAddresses()){
|
||||
String fullAddress;
|
||||
|
||||
if(tempAddress.getWard().equals("---Phường")){
|
||||
fullAddress = tempAddress.getAddress() + ", " + tempAddress.getDistrict();
|
||||
} else {
|
||||
fullAddress = tempAddress.getAddress() + ", " + tempAddress.getWard() + ", " + tempAddress.getDistrict();
|
||||
}
|
||||
|
||||
listAddress.add(fullAddress);
|
||||
|
||||
if(tempAddress.getId() == Common.CURRENT_USER.getDefaultAddress()){
|
||||
defaultAddress = fullAddress;
|
||||
}
|
||||
}
|
||||
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, listAddress);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
|
||||
spn_list_address.setAdapter(adapter);
|
||||
spn_list_address.setSelection(listAddress.indexOf(defaultAddress));
|
||||
}
|
||||
|
||||
public void onRadioButtonClicked(View view) {
|
||||
// Is the button now checked?
|
||||
boolean checked = ((RadioButton) view).isChecked();
|
||||
|
||||
// Check which radio button was clicked
|
||||
switch(view.getId()) {
|
||||
case R.id.list_address_input:
|
||||
if (checked){
|
||||
//If option 1 is checked
|
||||
//Config UI
|
||||
spn_list_address.setVisibility(View.VISIBLE);
|
||||
|
||||
edt_address_detect.setVisibility(View.GONE);
|
||||
manual_input_address_layout.setVisibility(View.GONE);
|
||||
|
||||
//Reset address;
|
||||
finalAddress = null;
|
||||
}
|
||||
break;
|
||||
case R.id.auto_detect_location:
|
||||
if (checked){
|
||||
//If option 2 is checked
|
||||
//Config UI
|
||||
edt_address_detect.setVisibility(View.VISIBLE);
|
||||
|
||||
spn_list_address.setVisibility(View.GONE);
|
||||
manual_input_address_layout.setVisibility(View.GONE);
|
||||
|
||||
//Reset address;
|
||||
finalAddress = null;
|
||||
}
|
||||
break;
|
||||
case R.id.manual_input_address:
|
||||
if (checked){
|
||||
//If option 3 is checked
|
||||
//Config UI
|
||||
manual_input_address_layout.setVisibility(View.VISIBLE);
|
||||
|
||||
spn_list_address.setVisibility(View.GONE);
|
||||
edt_address_detect.setVisibility(View.GONE);
|
||||
|
||||
//Reset address;
|
||||
finalAddress = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void getListDistrict() {
|
||||
|
||||
districtList.add("---Quận");
|
||||
|
||||
FoodApi.apiService.districtResponse().enqueue(new Callback<List<DistrictWardResponse>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<DistrictWardResponse>> call, Response<List<DistrictWardResponse>> response) {
|
||||
List<DistrictWardResponse> districtResponse = response.body();
|
||||
if(districtResponse != null){
|
||||
for(DistrictWardResponse tempDistrict: districtResponse){
|
||||
districtList.add(tempDistrict.getName());
|
||||
}
|
||||
}
|
||||
|
||||
setAdapter(districtList, "---Quận", spn_district);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<DistrictWardResponse>> call, Throwable t) {
|
||||
Toast.makeText(OrderCheckOutActivity.this, "Đã xảy ra lỗi hệ thống. Vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getListWard(int districtCode) {
|
||||
|
||||
if(wardList.size() > 1)
|
||||
wardList.clear();
|
||||
|
||||
if(wardList.size() == 0)
|
||||
wardList.add("---Phường");
|
||||
|
||||
spn_ward.setEnabled(false);
|
||||
|
||||
if(districtCode != 0){
|
||||
FoodApi.apiService.wardResponse(districtCode).enqueue(new Callback<List<DistrictWardResponse>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<DistrictWardResponse>> call, Response<List<DistrictWardResponse>> response) {
|
||||
List<DistrictWardResponse> wardData = response.body();
|
||||
|
||||
if(wardData != null){
|
||||
for(DistrictWardResponse tempWard: wardData){
|
||||
wardList.add(tempWard.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if(wardList.size() <= 1){
|
||||
spn_ward.setEnabled(false);
|
||||
} else {
|
||||
spn_ward.setEnabled(true);
|
||||
}
|
||||
|
||||
setAdapter(wardList, "---Phường", spn_ward);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<DistrictWardResponse>> call, Throwable t) {
|
||||
Toast.makeText(OrderCheckOutActivity.this, "Đã xảy ra lỗi hệ thống. Vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
setAdapter(wardList, "---Phường", spn_ward);
|
||||
}
|
||||
}
|
||||
|
||||
private void setAdapter(ArrayList<String> data, String defaultItem, Spinner dataSpinner){
|
||||
OrderCheckOutActivity.MySpinnerAdapter adapterWard = new OrderCheckOutActivity.MySpinnerAdapter(getApplicationContext(), android.R.layout.simple_spinner_item, data);
|
||||
dataSpinner.setAdapter(adapterWard); // this will set list of values to spinner
|
||||
dataSpinner.setSelection(data.indexOf(defaultItem));//set selected value in spinner
|
||||
}
|
||||
|
||||
private static class MySpinnerAdapter extends ArrayAdapter<String> {
|
||||
// Initialise custom font, for example:
|
||||
Typeface font = Typeface.createFromAsset(getContext().getAssets(),
|
||||
"font/bebas.ttf");
|
||||
|
||||
// (In reality I used a manager which caches the Typeface objects)
|
||||
// Typeface font = FontManager.getInstance().getFont(getContext(), BLAMBOT);
|
||||
|
||||
private MySpinnerAdapter(Context context, int resource, List<String> items) {
|
||||
super(context, resource, items);
|
||||
}
|
||||
|
||||
// Affects default (closed) state of the spinner
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
TextView view = (TextView) super.getView(position, convertView, parent);
|
||||
view.setTypeface(font);
|
||||
return view;
|
||||
}
|
||||
|
||||
// Affects opened state of the spinner
|
||||
@Override
|
||||
public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
||||
TextView view = (TextView) super.getDropDownView(position, convertView, parent);
|
||||
view.setTypeface(font);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public class OrderDetailActivity extends AppCompatActivity {
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
|
||||
recyclerView.setLayoutManager(linearLayoutManager);
|
||||
|
||||
adapter.setData(listOrderDetails);
|
||||
// adapter.setData(listOrderDetails);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
back_image.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@@ -54,9 +54,24 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
||||
//Init data
|
||||
holder.foodName.setText(foodBasket.getName());
|
||||
holder.shopName.setText(foodBasket.getShopName());
|
||||
holder.price.setText(Common.changeCurrencyUnit(foodBasket.getCost()));
|
||||
holder.quantity.setNumber(foodBasket.getQuantity());
|
||||
|
||||
//Check value discountPercent
|
||||
float cost = 0;
|
||||
if(foodBasket.getDiscountPercent() > 0){
|
||||
|
||||
//Calculate final cost when apply discountPercent
|
||||
cost = foodBasket.getCost() - (foodBasket.getCost() * foodBasket.getDiscountPercent()/100);
|
||||
|
||||
//Show discountPercent value on screen
|
||||
holder.discount.setVisibility(View.VISIBLE);
|
||||
holder.discount.setText("-" + foodBasket.getDiscountPercent()+ "%");
|
||||
} else {
|
||||
cost = foodBasket.getCost();
|
||||
}
|
||||
|
||||
holder.price.setText(Common.changeCurrencyUnit(cost));
|
||||
|
||||
//Check food image is null or not null
|
||||
if(foodBasket.getImg() == null){
|
||||
holder.imageView.setImageResource(R.drawable.default_image_food);
|
||||
@@ -88,9 +103,10 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
||||
float total = 0;
|
||||
|
||||
for(Basket foodTemp: listBasketFood){
|
||||
total += (foodTemp.getCost()) * (Float.parseFloat(foodTemp.getQuantity())) * (100 - foodTemp.getDiscount())/100;
|
||||
total += (foodTemp.getCost()) * (Float.parseFloat(foodTemp.getQuantity())) * (100 - foodTemp.getDiscountPercent())/100;
|
||||
}
|
||||
basketFragment.total.setText(Common.changeCurrencyUnit(total));
|
||||
basketFragment.totalFloat = total;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,7 +118,7 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
||||
|
||||
public static class BasketViewHolder extends RecyclerView.ViewHolder{
|
||||
|
||||
TextView foodName, shopName, price, total;
|
||||
TextView foodName, shopName, price, total, discount;
|
||||
public LinearLayout layoutForeGround;
|
||||
ImageView imageView;
|
||||
ElegantNumberButton quantity;
|
||||
@@ -117,6 +133,7 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
||||
imageView = itemView.findViewById(R.id.image_view);
|
||||
quantity = itemView.findViewById(R.id.quantity);
|
||||
total = itemView.findViewById(R.id.total_text_view);
|
||||
discount = itemView.findViewById(R.id.discount);
|
||||
|
||||
layoutForeGround = itemView.findViewById(R.id.layout_foreground);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.capstone.foodify.Common;
|
||||
import com.capstone.foodify.Model.Basket;
|
||||
import com.capstone.foodify.Model.OrderDetail;
|
||||
import com.capstone.foodify.R;
|
||||
import com.squareup.picasso.Picasso;
|
||||
@@ -17,12 +19,12 @@ import java.util.List;
|
||||
|
||||
public class OrderDetailAdapter extends RecyclerView.Adapter<OrderDetailAdapter.OrderDetailViewHolder>{
|
||||
|
||||
public List<OrderDetail> listOrderDetails;
|
||||
public List<Basket> listFoodInBasket;
|
||||
|
||||
public OrderDetailAdapter(){}
|
||||
|
||||
public void setData(List<OrderDetail> listOrderDetails){
|
||||
this.listOrderDetails = listOrderDetails;
|
||||
public void setData(List<Basket> listFoodInBasket){
|
||||
this.listFoodInBasket = listFoodInBasket;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,28 +37,43 @@ public class OrderDetailAdapter extends RecyclerView.Adapter<OrderDetailAdapter.
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull OrderDetailViewHolder holder, int position) {
|
||||
OrderDetail orderDetail = listOrderDetails.get(position);
|
||||
Basket food = listFoodInBasket.get(position);
|
||||
|
||||
if(orderDetail == null)
|
||||
if(food == null)
|
||||
return;
|
||||
|
||||
Picasso.get().load("https://images.unsplash.com/photo-1546069901-ba9599a7e63c?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8MXx8fGVufDB8fHx8&w=1000&q=80").into(holder.image_view);
|
||||
holder.food_name.setText("Food Name");
|
||||
holder.shop_name.setText("Shop Name");
|
||||
holder.price.setText("120000 đ");
|
||||
holder.quantity.setText("Số lượng: 2");
|
||||
Picasso.get().load(food.getImg()).into(holder.image_view);
|
||||
holder.food_name.setText(food.getName());
|
||||
holder.shop_name.setText(food.getShopName());
|
||||
holder.quantity.setText("Số lượng: " + food.getQuantity());
|
||||
|
||||
//Check value discountPercent
|
||||
float cost = 0;
|
||||
if(food.getDiscountPercent() > 0){
|
||||
|
||||
//Calculate final cost when apply discountPercent
|
||||
cost = food.getCost() - (food.getCost() * food.getDiscountPercent()/100);
|
||||
|
||||
//Show discountPercent value on screen
|
||||
holder.discount.setVisibility(View.VISIBLE);
|
||||
holder.discount.setText("-" + food.getDiscountPercent()+ "%");
|
||||
} else {
|
||||
cost = food.getCost();
|
||||
}
|
||||
|
||||
holder.price.setText(Common.changeCurrencyUnit(cost));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if(listOrderDetails != null)
|
||||
return listOrderDetails.size();
|
||||
if(listFoodInBasket != null)
|
||||
return listFoodInBasket.size();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public class OrderDetailViewHolder extends RecyclerView.ViewHolder{
|
||||
ImageView image_view;
|
||||
TextView food_name, shop_name, price, quantity;
|
||||
TextView food_name, shop_name, price, quantity, discount;
|
||||
|
||||
public OrderDetailViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
@@ -67,6 +84,7 @@ public class OrderDetailAdapter extends RecyclerView.Adapter<OrderDetailAdapter.
|
||||
shop_name = itemView.findViewById(R.id.shop_name_text_view);
|
||||
price = itemView.findViewById(R.id.price_text_view);
|
||||
quantity = itemView.findViewById(R.id.quantity_text_view);
|
||||
discount = itemView.findViewById(R.id.discount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
@@ -37,8 +38,10 @@ public class BasketFragment extends Fragment implements ItemTouchHelperListener
|
||||
private RelativeLayout listBasketFoodView;
|
||||
private Button btnCheckOut;
|
||||
public ConstraintLayout empty_layout;
|
||||
|
||||
public TextView total;
|
||||
public float totalFloat;
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
@@ -76,7 +79,14 @@ public class BasketFragment extends Fragment implements ItemTouchHelperListener
|
||||
btnCheckOut.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(getContext(), OrderCheckOutActivity.class));
|
||||
if(Common.LIST_BASKET_FOOD.size() == 0){
|
||||
Toast.makeText(getContext(), "Giỏ hàng của bạn hiện đang trống!", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Intent intent = new Intent(getContext(), OrderCheckOutActivity.class);
|
||||
intent.putExtra("total", totalFloat);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -7,16 +7,16 @@ public class Basket {
|
||||
private float cost;
|
||||
private String shopName;
|
||||
private String quantity;
|
||||
private float discount;
|
||||
private float discountPercent;
|
||||
|
||||
public Basket(String id, String img, String name, float cost, String shopName, String quantity, float discount) {
|
||||
public Basket(String id, String img, String name, float cost, String shopName, String quantity, float discountPercent) {
|
||||
this.id = id;
|
||||
this.img = img;
|
||||
this.name = name;
|
||||
this.cost = cost;
|
||||
this.shopName = shopName;
|
||||
this.quantity = quantity;
|
||||
this.discount = discount;
|
||||
this.discountPercent = discountPercent;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
@@ -66,12 +66,11 @@ public class Basket {
|
||||
public void setQuantity(String quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public float getDiscount() {
|
||||
return discount;
|
||||
public float getDiscountPercent() {
|
||||
return discountPercent;
|
||||
}
|
||||
|
||||
public void setDiscount(float discount) {
|
||||
this.discount = discount;
|
||||
public void setDiscountPercent(float discountPercent) {
|
||||
this.discountPercent = discountPercent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public class Order {
|
||||
private float total;
|
||||
private String status;
|
||||
private int address_id;
|
||||
private List<OrderDetail> listOrderDetail;
|
||||
private List<OrderDetail> orderDetails;
|
||||
|
||||
public Order(String orderTrackingNumber) {
|
||||
this.orderTrackingNumber = orderTrackingNumber;
|
||||
@@ -100,10 +100,10 @@ public class Order {
|
||||
}
|
||||
|
||||
public List<OrderDetail> getListOrderDetail() {
|
||||
return listOrderDetail;
|
||||
return orderDetails;
|
||||
}
|
||||
|
||||
public void setListOrderDetail(List<OrderDetail> listOrderDetail) {
|
||||
this.listOrderDetail = listOrderDetail;
|
||||
this.orderDetails = listOrderDetail;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/textView"
|
||||
tools:listitem="@layout/item_order_detail"
|
||||
android:visibility="visible"
|
||||
/>
|
||||
|
||||
@@ -102,6 +101,7 @@
|
||||
android:textSize="15sp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/txt_userName"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -137,6 +137,7 @@
|
||||
android:textSize="15sp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/txt_phone"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -156,22 +157,25 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
/>
|
||||
|
||||
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RadioGroup
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:checkedButton="@id/list_address_input"
|
||||
app:layout_constraintTop_toBottomOf="@id/textView3"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:id="@+id/address_option"
|
||||
>
|
||||
<RadioButton android:id="@+id/radio_pirates"
|
||||
<RadioButton android:id="@+id/list_address_input"
|
||||
android:layout_width="wrap_content"
|
||||
android:buttonTint="@color/primaryColor"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Chọn địa chỉ dưới đây:"/>
|
||||
android:text="Theo danh sách địa chỉ của bạn:"
|
||||
android:onClick="onRadioButtonClicked"
|
||||
/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/list_address"
|
||||
@@ -181,29 +185,36 @@
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/auto_detect_location"
|
||||
android:text="Lấy vị trí thiết bị của bạn"
|
||||
android:buttonTint="@color/primaryColor"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
android:buttonTint="@color/primaryColor"
|
||||
android:onClick="onRadioButtonClicked"
|
||||
android:text="Lấy vị trí thiết bị của bạn" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edt_address_detect"
|
||||
android:hint="Đang lấy vị trí...."
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:enabled="false"
|
||||
android:inputType="textMultiLine"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
<RadioButton android:id="@+id/radio_ninjas"
|
||||
<RadioButton android:id="@+id/manual_input_address"
|
||||
android:layout_width="wrap_content"
|
||||
android:buttonTint="@color/primaryColor"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Tự nhập thủ công"/>
|
||||
android:text="Tự nhập thủ công"
|
||||
android:onClick="onRadioButtonClicked"
|
||||
/>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/manual_input_address_layout"
|
||||
android:visibility="gone"
|
||||
>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/textInput_address"
|
||||
@@ -258,17 +269,56 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/errorTextDistrictWard"
|
||||
android:text="Bạn chưa chọn quận huyện!"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:textSize="12sp"
|
||||
android:textColor="#b00020"
|
||||
app:layout_constraintTop_toBottomOf="@id/linearLayout_district_ward"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</RadioGroup>
|
||||
|
||||
<Button
|
||||
android:id="@+id/confirm_address_button"
|
||||
android:text="Xác nhận"
|
||||
android:textAllCaps="false"
|
||||
android:backgroundTint="@color/primaryColor"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/address_option"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/change_address_button"
|
||||
android:text="Thay đổi"
|
||||
android:textAllCaps="false"
|
||||
android:backgroundTint="@color/secondary"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/address_option"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/address_option"
|
||||
app:layout_constraintTop_toBottomOf="@id/confirm_address_button"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:id="@+id/shipper_cost_layout"
|
||||
@@ -320,6 +370,7 @@
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_total"
|
||||
android:text="500.000 VNĐ"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textStyle="bold"
|
||||
|
||||
@@ -105,15 +105,32 @@
|
||||
app:layout_constraintTop_toBottomOf="@id/text_view_1"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/price_text_view"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"
|
||||
android:fontFamily="@font/bebas"
|
||||
android:text="$5.00"
|
||||
android:textColor="@color/primaryColor"
|
||||
android:textSize="20sp" />
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/price_text_view"
|
||||
android:text="$5.00"
|
||||
android:textSize="25sp"
|
||||
android:textColor="@color/primaryColor"
|
||||
android:fontFamily="@font/bebas"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/discount"
|
||||
android:text="-59%"
|
||||
android:textSize="8sp"
|
||||
android:textColor="@color/red"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<com.cepheuen.elegantnumberbutton.view.ElegantNumberButton
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_view"
|
||||
android:layout_width="110dp"
|
||||
android:layout_height="110dp"
|
||||
android:layout_width="95dp"
|
||||
android:layout_height="95dp"
|
||||
android:src="@drawable/food"
|
||||
android:scaleType="centerCrop"
|
||||
app:riv_corner_radius="10dip"
|
||||
@@ -25,29 +25,31 @@
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/food_name_text_view"
|
||||
android:text="@string/food_name"
|
||||
android:textSize="18sp"
|
||||
android:textSize="15sp"
|
||||
android:textColor="@color/black"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="47dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_weight="0.4"
|
||||
app:layout_constraintStart_toEndOf="@id/image_view"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:orientation="horizontal"
|
||||
android:layout_weight="0.5"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
@@ -61,7 +63,7 @@
|
||||
<TextView
|
||||
android:id="@+id/shop_name_text_view"
|
||||
android:text="Shop Name"
|
||||
android:textSize="16sp"
|
||||
android:textSize="15sp"
|
||||
android:textColor="@color/secondary"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -71,28 +73,44 @@
|
||||
app:layout_constraintTop_toBottomOf="@id/text_view_1"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/price_text_view"
|
||||
android:text="$5.00"
|
||||
android:textSize="25sp"
|
||||
android:textColor="@color/primaryColor"
|
||||
android:fontFamily="@font/bebas"
|
||||
android:layout_width="220dp"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"
|
||||
/>
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/price_text_view"
|
||||
android:text="$5.00"
|
||||
android:textSize="20sp"
|
||||
android:textColor="@color/primaryColor"
|
||||
android:fontFamily="@font/bebas"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/discount"
|
||||
android:text="-59%"
|
||||
android:textSize="8sp"
|
||||
android:textColor="@color/red"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/quantity_text_view"
|
||||
android:text="Số lượng: 5"
|
||||
android:text="Số lượng: 10"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="16sp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="0.4"
|
||||
android:layout_weight="0.3"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user