mirror of
https://github.com/Nezumi-2711/PRM392.git
synced 2026-09-22 20:00:53 +00:00
Improve app, layout
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@@ -19,6 +19,9 @@
|
||||
android:theme="@style/Theme.Foodify"
|
||||
tools:replace="android:theme"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".OrderStatusDetail"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".FavoritesActivity"
|
||||
android:exported="false" />
|
||||
|
||||
@@ -92,7 +92,7 @@ public class OrderDetail extends AppCompatActivity {
|
||||
btnPay = findViewById(R.id.btnPay);
|
||||
btnZaloPay = findViewById(R.id.btnZaloPay);
|
||||
|
||||
lstFoods = (RecyclerView) findViewById(R.id.lstFoods);
|
||||
lstFoods = findViewById(R.id.lstFoods);
|
||||
lstFoods.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
lstFoods.setLayoutManager(layoutManager);
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
package com.waterbase.foodify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@@ -24,11 +27,6 @@ import com.waterbase.foodify.Common.Common;
|
||||
import com.waterbase.foodify.Model.Request;
|
||||
import com.waterbase.foodify.ViewHolder.OrderViewHolder;
|
||||
|
||||
import io.github.inflationx.calligraphy3.CalligraphyConfig;
|
||||
import io.github.inflationx.calligraphy3.CalligraphyInterceptor;
|
||||
import io.github.inflationx.viewpump.ViewPump;
|
||||
import io.github.inflationx.viewpump.ViewPumpContextWrapper;
|
||||
|
||||
public class OrderStatus extends AppCompatActivity {
|
||||
|
||||
public RecyclerView recyclerView;
|
||||
@@ -86,6 +84,18 @@ public class OrderStatus extends AppCompatActivity {
|
||||
orderViewHolder.txtOrderAddress.setText("Địa chỉ: " + model.getAddress());
|
||||
orderViewHolder.txtOrderDate.setText("Ngày đặt: " + Common.getDate(Long.parseLong(adapter.getRef(i).getKey())));
|
||||
orderViewHolder.txtOrderPayment.setText("Tình trạng thanh toán: " + Common.convertCodePaymentToStatus(model.getPaymentStatus()));
|
||||
|
||||
orderViewHolder.btn_detail.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//Pass object to another activity!
|
||||
Intent intent = new Intent(OrderStatus.this, OrderStatusDetail.class);
|
||||
intent.putExtra("requests", model);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
orderViewHolder.btn_delete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -110,15 +120,34 @@ public class OrderStatus extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void deleteOrder(String key) {
|
||||
requests.child(key)
|
||||
.removeValue().addOnSuccessListener(new OnSuccessListener<Void>() {
|
||||
AlertDialog alertDialog = new AlertDialog.Builder(OrderStatus.this).setTitle("Xác nhận").setMessage("Bạn có muốn xoá đơn #" + key).setPositiveButton("Đồng ý",null)
|
||||
.setNegativeButton("Thoát", null)
|
||||
.create();
|
||||
|
||||
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||
@Override
|
||||
public void onShow(DialogInterface dialog) {
|
||||
Button agree = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
agree.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onSuccess(Void unused) {
|
||||
Toast.makeText(OrderStatus.this, new StringBuilder("Đơn hàng ").append(key).append(" đã xoá!").toString(), Toast.LENGTH_SHORT).show();
|
||||
public void onClick(View v) {
|
||||
requests.child(key)
|
||||
.removeValue().addOnSuccessListener(new OnSuccessListener<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void unused) {
|
||||
Toast.makeText(OrderStatus.this, new StringBuilder("Đơn hàng ").append(key).append(" đã xoá!").toString(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}).addOnFailureListener((e) -> {
|
||||
Toast.makeText(OrderStatus.this, e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
}).addOnFailureListener((e) -> {
|
||||
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
alertDialog.show();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -136,4 +165,10 @@ public class OrderStatus extends AppCompatActivity {
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
adapter.startListening();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.waterbase.foodify;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.waterbase.foodify.Model.Request;
|
||||
import com.waterbase.foodify.ViewHolder.OrderDetailAdapter;
|
||||
import com.waterbase.foodify.ViewHolder.OrderStatusDetailAdapter;
|
||||
|
||||
public class OrderStatusDetail extends AppCompatActivity {
|
||||
|
||||
TextView order_address, order_total, order_comment;
|
||||
Request request;
|
||||
RecyclerView lstFoods;
|
||||
RecyclerView.LayoutManager layoutManager;
|
||||
|
||||
FirebaseDatabase database;
|
||||
DatabaseReference requests;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_order_status_detail);
|
||||
|
||||
String comment = "";
|
||||
|
||||
setTitle("Thông tin chi tiết đơn hàng");
|
||||
|
||||
order_address = findViewById(R.id.order_address);
|
||||
order_total = findViewById(R.id.order_total);
|
||||
order_comment = findViewById(R.id.order_comment);
|
||||
|
||||
lstFoods = findViewById(R.id.lstFoods);
|
||||
lstFoods.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
lstFoods.setLayoutManager(layoutManager);
|
||||
|
||||
//Firebase
|
||||
database = FirebaseDatabase.getInstance();
|
||||
requests = database.getReference("Requests");
|
||||
|
||||
if (getIntent() != null)
|
||||
request = (Request) getIntent().getSerializableExtra("requests");
|
||||
|
||||
//Set value
|
||||
order_total.setText("Tổng cộng: " + request.getTotal());
|
||||
order_address.setText("Địa chỉ giao: " + request.getAddress());
|
||||
if (TextUtils.isEmpty(request.getComment()))
|
||||
comment = "Không có";
|
||||
else
|
||||
comment = request.getComment();
|
||||
order_comment.setText("Ghi chú: " + comment);
|
||||
|
||||
OrderStatusDetailAdapter adapter = new OrderStatusDetailAdapter(request.getFoods(), this);
|
||||
adapter.notifyDataSetChanged();
|
||||
lstFoods.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.waterbase.foodify.ViewHolder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.waterbase.foodify.R;
|
||||
|
||||
public class MyViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView name, quantity, price, discount;
|
||||
public ImageView cart_image;
|
||||
|
||||
public MyViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
name = (TextView) itemView.findViewById(R.id.product_name);
|
||||
quantity = (TextView) itemView.findViewById(R.id.product_quantity);
|
||||
price = (TextView) itemView.findViewById(R.id.product_price);
|
||||
discount = (TextView) itemView.findViewById(R.id.product_discount);
|
||||
cart_image = (ImageView) itemView.findViewById(R.id.cart_image);
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,11 @@ package com.waterbase.foodify.ViewHolder;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.waterbase.foodify.Cart;
|
||||
import com.waterbase.foodify.Model.Order;
|
||||
import com.waterbase.foodify.OrderDetail;
|
||||
import com.waterbase.foodify.R;
|
||||
@@ -20,21 +16,6 @@ import java.text.NumberFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
class MyViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView name, quantity, price, discount;
|
||||
public ImageView cart_image;
|
||||
|
||||
public MyViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
name = (TextView) itemView.findViewById(R.id.product_name);
|
||||
quantity = (TextView) itemView.findViewById(R.id.product_quantity);
|
||||
price = (TextView) itemView.findViewById(R.id.product_price);
|
||||
discount = (TextView) itemView.findViewById(R.id.product_discount);
|
||||
cart_image = (ImageView) itemView.findViewById(R.id.cart_image);
|
||||
}
|
||||
}
|
||||
|
||||
public class OrderDetailAdapter extends RecyclerView.Adapter<MyViewHolder>{
|
||||
|
||||
List<Order> myOrders;
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.waterbase.foodify.ViewHolder;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.waterbase.foodify.Model.Order;
|
||||
import com.waterbase.foodify.OrderStatusDetail;
|
||||
import com.waterbase.foodify.R;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class OrderStatusDetailAdapter extends RecyclerView.Adapter<MyViewHolder>{
|
||||
|
||||
List<Order> myOrders;
|
||||
private OrderStatusDetail orderStatusDetail;
|
||||
|
||||
public OrderStatusDetailAdapter(List<Order> myOrders, OrderStatusDetail orderStatusDetail) {
|
||||
this.myOrders = myOrders;
|
||||
this.orderStatusDetail = orderStatusDetail;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View itemView = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.order_detail_layout, parent, false);
|
||||
return new MyViewHolder(itemView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
|
||||
double totalPrice;
|
||||
Order order = myOrders.get(position);
|
||||
|
||||
Picasso.with(orderStatusDetail.getBaseContext())
|
||||
.load(myOrders.get(position).getImage())
|
||||
.resize(70,70)
|
||||
.centerCrop()
|
||||
.into(holder.cart_image);
|
||||
|
||||
totalPrice = Double.parseDouble(order.getQuantity()) * Double.parseDouble(order.getPrice());
|
||||
Locale locale = new Locale("vi", "VN");
|
||||
NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
|
||||
|
||||
|
||||
holder.name.setText(String.format("Món ăn: %s", order.getProductName()));
|
||||
holder.quantity.setText(String.format("Số lượng: %s", order.getQuantity()));
|
||||
holder.price.setText("Giá: " + fmt.format(totalPrice));
|
||||
holder.discount.setText(String.format("Giảm giá: %s", order.getDiscount()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return myOrders.size();
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ public class OrderViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView txtOrderId, txtOrderStatus, txtOrderAddress, txtOrderDate, txtOrderPayment;
|
||||
|
||||
public ImageView btn_delete;
|
||||
public ImageView btn_delete, btn_detail;
|
||||
|
||||
public OrderViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
@@ -25,5 +25,6 @@ public class OrderViewHolder extends RecyclerView.ViewHolder {
|
||||
txtOrderDate = itemView.findViewById(R.id.order_date);
|
||||
txtOrderPayment = itemView.findViewById(R.id.order_payment);
|
||||
btn_delete = itemView.findViewById(R.id.btn_delete);
|
||||
btn_detail = itemView.findViewById(R.id.btn_detail);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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="M19,3h-4.18C14.4,1.84 13.3,1 12,1c-1.3,0 -2.4,0.84 -2.82,2L5,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM12,3c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM14,17L7,17v-2h7v2zM17,13L7,13v-2h10v2zM17,9L7,9L7,7h10v2z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,106 @@
|
||||
<?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=".OrderStatusDetail">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/relativeLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/order_info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
app:cardElevation="4dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="9"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/order_total"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:fontFamily="@font/bold"
|
||||
android:gravity="center_vertical|start"
|
||||
android:text="100000 VND"
|
||||
android:textAllCaps="true" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/order_address"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:fontFamily="@font/italic"
|
||||
android:gravity="center_vertical|start"
|
||||
android:text="Address"
|
||||
android:textAllCaps="true" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/order_comment"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:fontFamily="@font/italic"
|
||||
android:gravity="center_vertical|start"
|
||||
android:text="Comment"
|
||||
android:textAllCaps="true" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/regular"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:text="Chi tiết đơn:"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/relativeLayout" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/lstFoods"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constrainedHeight="true"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHeight_max="500dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView2"
|
||||
app:layout_constraintVertical_bias="0.02"
|
||||
app:layout_constraintVertical_chainStyle="packed"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
/>
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -77,14 +77,35 @@
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/btn_delete"
|
||||
android:src="@drawable/ic_baseline_delete_24"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginRight="8dp"
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
android:layout_gravity="center"
|
||||
>
|
||||
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/btn_detail"
|
||||
android:src="@drawable/ic_baseline_assignment_24"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/btn_delete"
|
||||
android:src="@drawable/ic_baseline_delete_24"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
Reference in New Issue
Block a user