Add comment and show detail order

This commit is contained in:
phanhuuloi27
2022-06-13 21:23:26 +07:00
parent 6f1439e375
commit f26cacbfa5
11 changed files with 420 additions and 38 deletions
@@ -16,10 +16,14 @@
android:supportsRtl="true"
android:theme="@style/Theme.FoodifyServer"
tools:targetApi="31">
<activity
android:name=".OrderDetail"
android:exported="false" />
<service
android:name=".Service.ListenOrder"
android:enabled="true"
android:exported="true"></service>
android:exported="true" />
<uses-library
android:name="org.apache.http.legacy"
@@ -8,26 +8,20 @@ public class Request {
private String address;
private String total;
private String status;
private String comment;
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) {
public Request(String phone, String name, String address, String total, String status, String comment, List<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;
this.comment = comment;
this.foods = foods;
}
public String getPhone() {
@@ -62,11 +56,27 @@ public class Request {
this.total = total;
}
public List<com.waterbase.foodifyServer.Model.Order> getFoods() {
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public List<Order> getFoods() {
return foods;
}
public void setFoods(List<com.waterbase.foodifyServer.Model.Order> foods) {
public void setFoods(List<Order> foods) {
this.foods = foods;
}
}
@@ -0,0 +1,51 @@
package com.waterbase.foodifyServer;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.widget.TextView;
import com.waterbase.foodifyServer.Common.Common;
import com.waterbase.foodifyServer.Model.Order;
import com.waterbase.foodifyServer.ViewHolder.OrderDetailAdapter;
public class OrderDetail extends AppCompatActivity {
TextView order_id, order_phone, order_address, order_total, order_comment;
String order_id_value = "";
RecyclerView lstFoods;
RecyclerView.LayoutManager layoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order_detail);
order_id = (TextView) findViewById(R.id.order_id);
order_phone = (TextView) findViewById(R.id.order_phone);
order_address = (TextView) findViewById(R.id.order_address);
order_total = (TextView) findViewById(R.id.order_total);
order_comment = (TextView) findViewById(R.id.order_comment);
lstFoods = (RecyclerView) findViewById(R.id.lstFoods);
lstFoods.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
lstFoods.setLayoutManager(layoutManager);
if(getIntent() != null)
order_id_value = getIntent().getStringExtra("OrderId");
//Set value
order_id.setText(order_id_value);
order_phone.setText(Common.currentRequest.getPhone());
order_total.setText(Common.currentRequest.getTotal());
order_address.setText(Common.currentRequest.getAddress());
order_comment.setText(Common.currentRequest.getComment());
OrderDetailAdapter adapter = new OrderDetailAdapter(Common.currentRequest.getFoods());
adapter.notifyDataSetChanged();
lstFoods.setAdapter(adapter);
}
}
@@ -69,9 +69,16 @@ public class OrderStatus extends AppCompatActivity {
viewHolder.setItemClickListener(new ItemClickListener() {
@Override
public void onClick(View view, int position, boolean isLongClick) {
Intent trackingOrder = new Intent(OrderStatus.this, TrackingOrder.class);
Common.currentRequest = model;
startActivity(trackingOrder);
if(!isLongClick){
Intent trackingOrder = new Intent(OrderStatus.this, TrackingOrder.class);
Common.currentRequest = model;
startActivity(trackingOrder);
} else {
Intent orderDetail = new Intent(OrderStatus.this, OrderDetail.class);
Common.currentRequest = model;
orderDetail.putExtra("OrderId", adapter.getRef(position).getKey());
startActivity(orderDetail);
}
}
});
}
@@ -0,0 +1,59 @@
package com.waterbase.foodifyServer.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.waterbase.foodifyServer.Model.Order;
import com.waterbase.foodifyServer.R;
import java.util.List;
class MyViewHolder extends RecyclerView.ViewHolder {
public TextView name, quantity, price, discount;
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);
}
}
public class OrderDetailAdapter extends RecyclerView.Adapter<MyViewHolder>{
List<Order> myOrders;
public OrderDetailAdapter(List<Order> myOrders) {
this.myOrders = myOrders;
}
@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) {
Order order = myOrders.get(position);
holder.name.setText(String.format("Name: %s", order.getProductName()));
holder.quantity.setText(String.format("Quantity: %s", order.getQuantity()));
holder.price.setText(String.format("Price: %s", order.getPrice()));
holder.discount.setText(String.format("Discount: %s", order.getDiscount()));
}
@Override
public int getItemCount() {
return myOrders.size();
}
}
@@ -10,7 +10,8 @@ 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 class OrderViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnCreateContextMenuListener,
View.OnLongClickListener{
public TextView txtOrderId, txtOrderStatus, txtOrderPhone, txtOrderAddress;
@@ -26,6 +27,7 @@ public class OrderViewHolder extends RecyclerView.ViewHolder implements View.OnC
itemView.setOnClickListener(this);
itemView.setOnCreateContextMenuListener(this);
itemView.setOnLongClickListener(this);
}
public void setItemClickListener(ItemClickListener itemClickListener) {
@@ -44,4 +46,10 @@ public class OrderViewHolder extends RecyclerView.ViewHolder implements View.OnC
contextMenu.add(0,0, getAdapterPosition(), "Cập nhật");
contextMenu.add(0,1, getAdapterPosition(), "Xoá");
}
@Override
public boolean onLongClick(View view) {
itemClickListener.onClick(view, getAdapterPosition(), true);
return true;
}
}
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="@drawable/background"
tools:context=".OrderDetail">
<com.google.android.material.card.MaterialCardView
android:id="@+id/order_info"
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="Order ID"
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="Order Phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/order_total"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="italic"
android:text="100000 VND"
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" />
<TextView
android:id="@+id/order_comment"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="italic"
android:text="Comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<LinearLayout
android:layout_below="@+id/order_info"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Detail"
android:textColor="@color/white"
android:textSize="30sp"
android:layout_marginBottom="20dp"
android:layout_marginLeft="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lstFoods"/>
</LinearLayout>
</RelativeLayout>
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/order_info"
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/product_name"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:text="Product Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/product_quantity"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="italic"
android:text="Product Quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/product_price"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="italic"
android:text="Product Price"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/product_discount"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="italic"
android:text="Product Discount"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>