mirror of
https://github.com/Nezumi-2711/PRM392.git
synced 2026-09-22 13:48:29 +00:00
Add order management
This commit is contained in:
@@ -13,6 +13,9 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.FoodifyServer"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".OrderStatus"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".FoodList"
|
||||
android:exported="false" />
|
||||
|
||||
@@ -8,4 +8,13 @@ public class Common {
|
||||
public static final String UPDATE = "Cập nhật";
|
||||
public static final String DELETE = "Xoá";
|
||||
public static final int PICK_IMAGE_REQUEST = 71;
|
||||
|
||||
public static String coverCodeToStatus(String code){
|
||||
if(code.equals("0"))
|
||||
return "Placed";
|
||||
else if(code.equals("1"))
|
||||
return "On my way";
|
||||
else
|
||||
return "Shipped";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.google.firebase.storage.StorageReference;
|
||||
import com.google.firebase.storage.UploadTask;
|
||||
import com.rengwuxian.materialedittext.MaterialEditText;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.waterbase.foodifyServer.Common.Category;
|
||||
import com.waterbase.foodifyServer.Common.Common;
|
||||
import com.waterbase.foodifyServer.Interface.ItemClickListener;
|
||||
import com.waterbase.foodifyServer.Model.Food;
|
||||
|
||||
@@ -24,10 +24,6 @@ import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.view.GravityCompat;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.navigation.ui.AppBarConfiguration;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
@@ -41,11 +37,10 @@ import com.google.firebase.storage.StorageReference;
|
||||
import com.google.firebase.storage.UploadTask;
|
||||
import com.rengwuxian.materialedittext.MaterialEditText;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.waterbase.foodifyServer.Common.Category;
|
||||
import com.waterbase.foodifyServer.Model.Category;
|
||||
import com.waterbase.foodifyServer.Common.Common;
|
||||
import com.waterbase.foodifyServer.Interface.ItemClickListener;
|
||||
import com.waterbase.foodifyServer.ViewHolder.MenuViewHolder;
|
||||
import com.waterbase.foodifyServer.databinding.ActivityHomeBinding;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -268,6 +263,10 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
|
||||
if(id == R.id.nav_orders) {
|
||||
Intent orders = new Intent(Home.this, OrderStatus.class);
|
||||
startActivity(orders);
|
||||
}
|
||||
|
||||
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
drawerLayout.closeDrawer(GravityCompat.START);
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.waterbase.foodifyServer.Common;
|
||||
package com.waterbase.foodifyServer.Model;
|
||||
|
||||
public class Category {
|
||||
private String Name;
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.waterbase.foodifyServer.Model;
|
||||
|
||||
public class Order {
|
||||
|
||||
private String ProductId;
|
||||
private String ProductName;
|
||||
private String Quantity;
|
||||
private String Price;
|
||||
private String Discount;
|
||||
|
||||
public Order() {
|
||||
}
|
||||
|
||||
public Order(String productId, String productName, String quantity, String price, String discount) {
|
||||
ProductId = productId;
|
||||
ProductName = productName;
|
||||
Quantity = quantity;
|
||||
Price = price;
|
||||
Discount = discount;
|
||||
}
|
||||
|
||||
public String getProductId() {
|
||||
return ProductId;
|
||||
}
|
||||
|
||||
public void setProductId(String productId) {
|
||||
ProductId = productId;
|
||||
}
|
||||
|
||||
public String getProductName() {
|
||||
return ProductName;
|
||||
}
|
||||
|
||||
public void setProductName(String productName) {
|
||||
ProductName = productName;
|
||||
}
|
||||
|
||||
public String getQuantity() {
|
||||
return Quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(String quantity) {
|
||||
Quantity = quantity;
|
||||
}
|
||||
|
||||
public String getPrice() {
|
||||
return Price;
|
||||
}
|
||||
|
||||
public void setPrice(String price) {
|
||||
Price = price;
|
||||
}
|
||||
|
||||
public String getDiscount() {
|
||||
return Discount;
|
||||
}
|
||||
|
||||
public void setDiscount(String discount) {
|
||||
Discount = discount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.waterbase.foodifyServer.Model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Request {
|
||||
private String phone;
|
||||
private String name;
|
||||
private String address;
|
||||
private String total;
|
||||
private String status;
|
||||
private List<com.waterbase.foodifyServer.Model.Order> foods; // list of food order
|
||||
|
||||
public Request() {
|
||||
}
|
||||
|
||||
public Request(String phone, String name, String address, String total, List<com.waterbase.foodifyServer.Model.Order> foods) {
|
||||
this.phone = phone;
|
||||
this.name = name;
|
||||
this.address = address;
|
||||
this.total = total;
|
||||
this.foods = foods;
|
||||
this.status = "0"; // Default is 0, 0: Placed, 1: Shipping, 2: Shipped
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(String total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List<com.waterbase.foodifyServer.Model.Order> getFoods() {
|
||||
return foods;
|
||||
}
|
||||
|
||||
public void setFoods(List<com.waterbase.foodifyServer.Model.Order> foods) {
|
||||
this.foods = foods;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.waterbase.foodifyServer;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.firebase.ui.database.FirebaseRecyclerAdapter;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.jaredrummler.materialspinner.MaterialSpinner;
|
||||
import com.waterbase.foodifyServer.Common.Common;
|
||||
import com.waterbase.foodifyServer.Interface.ItemClickListener;
|
||||
import com.waterbase.foodifyServer.Model.Request;
|
||||
import com.waterbase.foodifyServer.ViewHolder.OrderViewHolder;
|
||||
|
||||
public class OrderStatus extends AppCompatActivity {
|
||||
|
||||
RecyclerView recyclerView;
|
||||
RecyclerView.LayoutManager layoutManager;
|
||||
|
||||
FirebaseRecyclerAdapter<Request, OrderViewHolder> adapter;
|
||||
|
||||
FirebaseDatabase db;
|
||||
DatabaseReference requests;
|
||||
|
||||
MaterialSpinner spinner;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_order_status);
|
||||
|
||||
//Firebase
|
||||
db = FirebaseDatabase.getInstance();
|
||||
requests = db.getReference("Requests");
|
||||
|
||||
//Init
|
||||
recyclerView = (RecyclerView) findViewById(R.id.listOrders);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
loadOrders();
|
||||
}
|
||||
|
||||
private void loadOrders() {
|
||||
adapter = new FirebaseRecyclerAdapter<Request, OrderViewHolder>(
|
||||
Request.class,
|
||||
R.layout.order_layout,
|
||||
OrderViewHolder.class,
|
||||
requests
|
||||
) {
|
||||
@Override
|
||||
protected void populateViewHolder(OrderViewHolder viewHolder, Request model, int i) {
|
||||
viewHolder.txtOrderId.setText(adapter.getRef(i).getKey());
|
||||
viewHolder.txtOrderStatus.setText(Common.coverCodeToStatus(model.getStatus()));
|
||||
viewHolder.txtOrderAddress.setText(model.getAddress());
|
||||
viewHolder.txtOrderPhone.setText(model.getPhone());
|
||||
|
||||
viewHolder.setItemClickListener(new ItemClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int position, boolean isLongClick) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
adapter.notifyDataSetChanged();
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(@NonNull MenuItem item) {
|
||||
if(item.getTitle().equals(Common.UPDATE))
|
||||
showUpdateDialog(adapter.getRef(item.getOrder()).getKey(), adapter.getItem(item.getOrder()));
|
||||
else if(item.getTitle().equals(Common.DELETE))
|
||||
deleteOrder(adapter.getRef(item.getOrder()).getKey());
|
||||
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
|
||||
private void deleteOrder(String key) {
|
||||
requests.child(key).removeValue();
|
||||
}
|
||||
|
||||
private void showUpdateDialog(String key, Request item) {
|
||||
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(OrderStatus.this);
|
||||
alertDialog.setTitle("Cập nhật tình trạng đơn hàng");
|
||||
alertDialog.setMessage("Vui lòng chọn tình trạng đơn:");
|
||||
|
||||
LayoutInflater inflater = this.getLayoutInflater();
|
||||
final View view = inflater.inflate(R.layout.update_order_layout, null);
|
||||
|
||||
spinner = (MaterialSpinner) view.findViewById(R.id.statusSpinner);
|
||||
spinner.setItems("Placed", "On my way", "Shipped");
|
||||
|
||||
alertDialog.setView(view);
|
||||
|
||||
final String localKey = key;
|
||||
alertDialog.setPositiveButton("Cập nhật", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();;
|
||||
item.setStatus(String.valueOf(spinner.getSelectedIndex()));
|
||||
|
||||
requests.child(localKey).setValue(item);
|
||||
}
|
||||
});
|
||||
alertDialog.setNegativeButton("Huỷ", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
alertDialog.show();
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.waterbase.foodifyServer.ViewHolder;
|
||||
|
||||
import android.view.ContextMenu;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.waterbase.foodifyServer.Interface.ItemClickListener;
|
||||
import com.waterbase.foodifyServer.R;
|
||||
|
||||
public class OrderViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnCreateContextMenuListener {
|
||||
|
||||
public TextView txtOrderId, txtOrderStatus, txtOrderPhone, txtOrderAddress;
|
||||
|
||||
private ItemClickListener itemClickListener;
|
||||
|
||||
public OrderViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
txtOrderAddress = (TextView) itemView.findViewById(R.id.order_address);
|
||||
txtOrderId = (TextView) itemView.findViewById(R.id.order_id);
|
||||
txtOrderStatus = (TextView) itemView.findViewById(R.id.order_status);
|
||||
txtOrderPhone = (TextView) itemView.findViewById(R.id.order_phone);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setOnCreateContextMenuListener(this);
|
||||
}
|
||||
|
||||
public void setItemClickListener(ItemClickListener itemClickListener) {
|
||||
this.itemClickListener = itemClickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
itemClickListener.onClick(v, getAdapterPosition(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu contextMenu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
contextMenu.setHeaderTitle("Tuỳ chọn");
|
||||
|
||||
contextMenu.add(0,0, getAdapterPosition(), "Cập nhật");
|
||||
contextMenu.add(0,1, getAdapterPosition(), "Xoá");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout 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"
|
||||
tools:context=".OrderStatus">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/listOrders"
|
||||
android:background="@android:color/transparent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"></androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
app:cardElevation="4dp"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:orientation="horizontal"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_weight="9"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/order_id"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:gravity="center_vertical|start"
|
||||
android:textAllCaps="true"
|
||||
android:textStyle="bold"
|
||||
android:text="#11111"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/order_status"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:gravity="center_vertical|start"
|
||||
android:textAllCaps="true"
|
||||
android:textStyle="italic"
|
||||
android:text="Status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/order_phone"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:gravity="center_vertical|start"
|
||||
android:textAllCaps="true"
|
||||
android:textStyle="italic"
|
||||
android:text="Phone"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/order_address"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:gravity="center_vertical|start"
|
||||
android:textAllCaps="true"
|
||||
android:textStyle="italic"
|
||||
android:text="Address"
|
||||
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