mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 13:38:41 +00:00
Fix calculate total not correctly
This commit is contained in:
@@ -32,7 +32,7 @@ public interface FoodApi {
|
||||
Gson gson = new GsonBuilder().setDateFormat("HH:mm:ss dd-MM-yyyy").setLenient().create();
|
||||
|
||||
FoodApi apiService = new Retrofit.Builder()
|
||||
.baseUrl("http://192.168.1.183:8080/api/").addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.baseUrl("https://foodify-backend-production.up.railway.app/api/").addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.build()
|
||||
.create(FoodApi.class);
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@ import com.capstone.foodify.Model.Address;
|
||||
import com.capstone.foodify.Model.Comment;
|
||||
import com.capstone.foodify.Model.Food;
|
||||
import com.capstone.foodify.Model.Order;
|
||||
import com.capstone.foodify.Model.Response.Addresses;
|
||||
import com.capstone.foodify.Model.Response.Comments;
|
||||
import com.capstone.foodify.Model.Response.CustomResponse;
|
||||
import com.capstone.foodify.Model.Response.Foods;
|
||||
import com.capstone.foodify.Model.Response.Orders;
|
||||
@@ -18,7 +16,6 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
@@ -50,7 +47,7 @@ public interface FoodApiToken {
|
||||
|
||||
FoodApiToken apiService = new Retrofit.Builder()
|
||||
.client(client)
|
||||
.baseUrl("http://192.168.1.183:8080/api/").addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.baseUrl("https://foodify-backend-production.up.railway.app/api/").addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.build()
|
||||
.create(FoodApiToken.class);
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
|
||||
if (totalPrice >= 0)
|
||||
totalPrice = price * i;
|
||||
add_to_basket_button.setText("Add to basket - " + Common.changeCurrencyUnit(totalPrice));
|
||||
add_to_basket_button.setText("THÊM VÀO GIỎ HÀNG - " + Common.changeCurrencyUnit(totalPrice));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -491,7 +491,7 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
|
||||
add_to_basket_button.setText("ADD TO BASKET - " + Common.changeCurrencyUnit(0));
|
||||
add_to_basket_button.setText("THÊM VÀO GIỎ HÀNG - " + Common.changeCurrencyUnit(0));
|
||||
|
||||
//Set slider image food
|
||||
List<SlideModel> slideModels = new ArrayList<>();
|
||||
|
||||
@@ -90,7 +90,7 @@ public class OrderCheckOutActivity extends AppCompatActivity {
|
||||
RadioButton list_address_input, auto_detect_location, manual_input_address, radio_button_selected, take_food_from_shop;
|
||||
RadioGroup address_option;
|
||||
ConstraintLayout progress_layout;
|
||||
float total, shipCost;
|
||||
float total, totalProduct, shipCost;
|
||||
private static final ArrayList<String> wardList = new ArrayList<>();
|
||||
private static final ArrayList<String> districtList = new ArrayList<>();
|
||||
|
||||
@@ -143,7 +143,7 @@ public class OrderCheckOutActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
if(getIntent() != null){
|
||||
total = getIntent().getFloatExtra("total", 0);
|
||||
totalProduct = getIntent().getFloatExtra("total", 0);
|
||||
txt_total.setText(Common.changeCurrencyUnit(total));
|
||||
}
|
||||
|
||||
@@ -236,9 +236,10 @@ public class OrderCheckOutActivity extends AppCompatActivity {
|
||||
|
||||
if(radio_button_selected != take_food_from_shop){
|
||||
|
||||
if(LAT_SHOP != 0.0 && LNG_SHOP != 0.0)
|
||||
if(LAT_SHOP != 0.0 && LNG_SHOP != 0.0){
|
||||
total = 0;
|
||||
getDistanceAndCalculateShipCost(finalAddress);
|
||||
else {
|
||||
} else {
|
||||
new AestheticDialog.Builder(OrderCheckOutActivity.this, DialogStyle.FLAT, DialogType.INFO)
|
||||
.setTitle("Thông báo!")
|
||||
.setMessage("Chưa thể lấy được vị trí shop, vui lòng thử lại hoặc có thể chọn \"Đến shop lấy\" để tiếp tục!")
|
||||
@@ -248,8 +249,19 @@ public class OrderCheckOutActivity extends AppCompatActivity {
|
||||
progress_layout.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
} else {
|
||||
//Show distance to user
|
||||
txt_distance.setText("0 km");
|
||||
|
||||
txt_ship_cost.setText(Common.changeCurrencyUnit(0));
|
||||
|
||||
//Change total value
|
||||
total = totalProduct;
|
||||
|
||||
txt_total.setText(Common.changeCurrencyUnit(total));
|
||||
progress_layout.setVisibility(View.GONE);
|
||||
}
|
||||
progress_layout.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -272,6 +284,7 @@ public class OrderCheckOutActivity extends AppCompatActivity {
|
||||
|
||||
if(!Common.CURRENT_USER.isLocked()){
|
||||
if(finalAddress != null){
|
||||
//Create order tracking number
|
||||
createOrderFood(Helpers.getAppTransId(), CASH_PAYMENT);
|
||||
} else {
|
||||
Toast.makeText(OrderCheckOutActivity.this, "Bạn chưa xác nhận địa chỉ!", Toast.LENGTH_SHORT).show();
|
||||
@@ -339,11 +352,12 @@ public class OrderCheckOutActivity extends AppCompatActivity {
|
||||
|
||||
CreateOrder orderApi = new CreateOrder();
|
||||
|
||||
//Create order tracking number
|
||||
String orderTrackingNumber = Helpers.getAppTransId();
|
||||
try {
|
||||
JSONObject data = orderApi.createOrder(String.valueOf((int) total));
|
||||
JSONObject data = orderApi.createOrder(String.valueOf((int) total), orderTrackingNumber);
|
||||
String code = data.getString("return_code");
|
||||
|
||||
|
||||
if (code.equals("1")) {
|
||||
//Success create order
|
||||
String token = data.getString("zp_trans_token");
|
||||
@@ -354,7 +368,7 @@ public class OrderCheckOutActivity extends AppCompatActivity {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
createOrderFood(transactionId, ZALO_PAYMENT_METHOD);
|
||||
createOrderFood(orderTrackingNumber, ZALO_PAYMENT_METHOD);
|
||||
}
|
||||
|
||||
});
|
||||
@@ -434,6 +448,8 @@ public class OrderCheckOutActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onClick(@NonNull AestheticDialog.Builder builder) {
|
||||
Common.LIST_BASKET_FOOD.clear();
|
||||
Common.FINAL_SHOP = null;
|
||||
|
||||
startActivity(new Intent(OrderCheckOutActivity.this, OrderActivity.class));
|
||||
builder.dismiss();
|
||||
finish();
|
||||
@@ -485,7 +501,7 @@ public class OrderCheckOutActivity extends AppCompatActivity {
|
||||
txt_ship_cost.setText(Common.changeCurrencyUnit(shipCost));
|
||||
|
||||
//Update total order
|
||||
total = total + shipCost;
|
||||
total = totalProduct + shipCost;
|
||||
txt_total.setText(Common.changeCurrencyUnit(total));
|
||||
|
||||
progress_layout.setVisibility(View.GONE);
|
||||
|
||||
@@ -59,7 +59,7 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
||||
holder.value.setText(foodBasket.getQuantity());
|
||||
|
||||
//Check value discountPercent
|
||||
float cost = 0;
|
||||
float cost;
|
||||
if(foodBasket.getDiscountPercent() > 0){
|
||||
|
||||
//Calculate final cost when apply discountPercent
|
||||
@@ -195,12 +195,12 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
||||
}
|
||||
|
||||
private void showRecycleViewAndHideNotificationEmpty(){
|
||||
basketFragment.recyclerView_basket_food.setVisibility(View.VISIBLE);
|
||||
basketFragment.listBasketFoodLayout.setVisibility(View.VISIBLE);
|
||||
basketFragment.empty_layout.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void hideRecyclerViewAndShowNotificationEmpty(){
|
||||
basketFragment.recyclerView_basket_food.setVisibility(View.GONE);
|
||||
basketFragment.listBasketFoodLayout.setVisibility(View.GONE);
|
||||
basketFragment.empty_layout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,13 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.core.widget.NestedScrollView;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
@@ -36,7 +38,8 @@ public class BasketFragment extends Fragment implements ItemTouchHelperListener
|
||||
public RecyclerView recyclerView_basket_food;
|
||||
private BasketAdapter adapter;
|
||||
private List<Basket> listBasketFood = new ArrayList<>();
|
||||
private RelativeLayout listBasketFoodView;
|
||||
private LinearLayout listBasketFoodView;
|
||||
public NestedScrollView listBasketFoodLayout;
|
||||
private Button btnCheckOut;
|
||||
public ConstraintLayout empty_layout;
|
||||
public TextView total;
|
||||
@@ -56,6 +59,7 @@ public class BasketFragment extends Fragment implements ItemTouchHelperListener
|
||||
total = view.findViewById(R.id.total_text_view);
|
||||
empty_layout = view.findViewById(R.id.empty_layout);
|
||||
btnCheckOut = view.findViewById(R.id.btnCheckOut);
|
||||
listBasketFoodLayout = view.findViewById(R.id.list_basket_food_layout);
|
||||
|
||||
//Init data
|
||||
total.setText(Common.changeCurrencyUnit(0));
|
||||
@@ -99,16 +103,17 @@ public class BasketFragment extends Fragment implements ItemTouchHelperListener
|
||||
showRecycleViewAndHideNotificationEmpty();
|
||||
} else {
|
||||
hideRecyclerViewAndShowNotificationEmpty();
|
||||
total.setText(Common.changeCurrencyUnit(0));
|
||||
}
|
||||
}
|
||||
|
||||
private void showRecycleViewAndHideNotificationEmpty(){
|
||||
recyclerView_basket_food.setVisibility(View.VISIBLE);
|
||||
listBasketFoodLayout.setVisibility(View.VISIBLE);
|
||||
empty_layout.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void hideRecyclerViewAndShowNotificationEmpty(){
|
||||
recyclerView_basket_food.setVisibility(View.GONE);
|
||||
listBasketFoodLayout.setVisibility(View.GONE);
|
||||
empty_layout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
private void getListBasketFood(){
|
||||
|
||||
@@ -23,13 +23,13 @@ public class CreateOrder {
|
||||
String Description;
|
||||
String Mac;
|
||||
|
||||
private CreateOrderData(String amount) throws Exception {
|
||||
private CreateOrderData(String amount, String appTransId) throws Exception {
|
||||
long appTime = new Date().getTime();
|
||||
AppId = String.valueOf(AppInfo.APP_ID);
|
||||
AppUser = "Android_Demo";
|
||||
AppTime = String.valueOf(appTime);
|
||||
Amount = amount;
|
||||
AppTransId = Helpers.getAppTransId();
|
||||
AppTransId = appTransId;
|
||||
EmbedData = "{}";
|
||||
Items = "[]";
|
||||
BankCode = "zalopayapp";
|
||||
@@ -47,8 +47,8 @@ public class CreateOrder {
|
||||
}
|
||||
}
|
||||
|
||||
public JSONObject createOrder(String amount) throws Exception {
|
||||
CreateOrderData input = new CreateOrderData(amount);
|
||||
public JSONObject createOrder(String amount, String appTransId) throws Exception {
|
||||
CreateOrderData input = new CreateOrderData(amount, appTransId);
|
||||
|
||||
RequestBody formBody = new FormBody.Builder()
|
||||
.add("app_id", input.AppId)
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/student_shop_text_view"
|
||||
android:text="Student Shop"
|
||||
android:text="Shop sinh viên"
|
||||
android:fontFamily="@font/bebas"
|
||||
android:textColor="@color/red"
|
||||
android:layout_marginTop="20dp"
|
||||
@@ -64,7 +64,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@+id/txt_shop_name"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:visibility="visible"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
|
||||
@@ -1,77 +1,96 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:context=".Fragment.BasketFragment"
|
||||
android:id="@+id/list_basket_food_view"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_basket_food"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:listitem="@layout/item_food_basket"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/empty_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/cardView"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_view"
|
||||
android:src="@drawable/cart_empty"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
tools:ignore="ContentDescription" />
|
||||
>
|
||||
<ImageView
|
||||
android:id="@+id/image_view"
|
||||
android:src="@drawable/cart_empty"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_view_header"
|
||||
android:text="Quên chưa đặt món rồi nè bạn ơi!"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/black"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/image_view"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/text_view_header"
|
||||
android:text="Quên chưa đặt món rồi nè bạn ơi!"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/black"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/image_view"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_view_description"
|
||||
android:textAlignment="center"
|
||||
android:text="Bạn sẽ nhìn thấy các món ăn tại đây sau khi bỏ những món ăn bạn muốn vào giỏ hàng."
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/gray"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginEnd="40dp"
|
||||
android:layout_marginStart="40dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/text_view_header"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/text_view_description"
|
||||
android:textAlignment="center"
|
||||
android:text="Bạn sẽ nhìn thấy các món ăn tại đây sau khi bỏ những món ăn bạn muốn vào giỏ hàng."
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/gray"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginEnd="40dp"
|
||||
android:layout_marginStart="40dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/text_view_header"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/list_basket_food_layout"
|
||||
>
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_basket_food"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:listitem="@layout/item_food_basket"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
/>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/cardView"
|
||||
android:layout_alignParentBottom="true"
|
||||
app:cardBackgroundColor="@color/green"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
@@ -125,6 +144,4 @@
|
||||
</RelativeLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
@@ -55,7 +55,9 @@
|
||||
android:src="@drawable/food"
|
||||
android:scaleType="centerCrop"
|
||||
app:riv_corner_radius="10dip"
|
||||
tools:ignore="ContentDescription" />
|
||||
tools:ignore="ContentDescription"
|
||||
android:layout_gravity="center_vertical"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<TextView
|
||||
android:id="@+id/food_name_text_view"
|
||||
android:text="Food Name"
|
||||
android:textSize="15sp"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/black"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
Reference in New Issue
Block a user