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
@@ -9,6 +9,7 @@ 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 android.widget.EditText;
@@ -18,6 +19,7 @@ import android.widget.Toast;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.rengwuxian.materialedittext.MaterialEditText;
import com.waterbase.foodify.Common.Common;
import com.waterbase.foodify.Database.Database;
import com.waterbase.foodify.Model.Order;
@@ -85,19 +87,20 @@ public class Cart extends AppCompatActivity {
private void showAlertDialog() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(Cart.this);
alertDialog.setTitle("One more step!");
alertDialog.setMessage("Enter your address: ");
alertDialog.setTitle("Còn 1 bước nữa!");
alertDialog.setMessage("Xin vui lòng điền thông tin dưới đây: ");
final EditText edtAddress = new EditText(Cart.this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
);
edtAddress.setLayoutParams(lp);
alertDialog.setView(edtAddress); //Add edit text to Dialog
LayoutInflater inflater = this.getLayoutInflater();
View order_address_comment = inflater.inflate(R.layout.order_address_comment, null);
MaterialEditText edtAddress = (MaterialEditText) order_address_comment.findViewById(R.id.edtAddress);
MaterialEditText edtComment = (MaterialEditText) order_address_comment.findViewById(R.id.edtComment);
alertDialog.setView(order_address_comment);
alertDialog.setIcon(R.drawable.ic_baseline_shopping_cart_24);
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
alertDialog.setPositiveButton("Đặt", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Create new Request
@@ -106,6 +109,8 @@ public class Cart extends AppCompatActivity {
Common.currentUser.getName(),
edtAddress.getText().toString(),
txtTotalPrice.getText().toString(),
"0",
edtComment.getText().toString(),
cart
);
@@ -120,7 +125,7 @@ public class Cart extends AppCompatActivity {
}
});
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
alertDialog.setNegativeButton("Thoát", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
@@ -8,26 +8,20 @@ public class Request {
private String address;
private String total;
private String status;
private String comment;
private List<Order> foods; // list of food order
public Request() {
}
public Request(String phone, String name, String address, String total, List<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,6 +56,22 @@ public class Request {
this.total = total;
}
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;
}
@@ -0,0 +1,52 @@
<?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"
android:clickable="true"
app:cardElevation="4dp"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
>
<com.rengwuxian.materialedittext.MaterialEditText
android:id="@+id/edtAddress"
android:hint="Địa chỉ"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="@color/colorPrimary"
android:text=""
android:textColor="@color/colorPrimary"
android:textSize="34sp"
android:inputType="text"
app:met_baseColor="@color/colorPrimary"
app:met_floatingLabel="highlight"
app:met_primaryColor="@color/colorPrimary"
app:met_singleLineEllipsis="true"
/>
<com.rengwuxian.materialedittext.MaterialEditText
android:id="@+id/edtComment"
android:hint="Ghi chú"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="@color/colorPrimary"
android:text=""
android:textColor="@color/colorPrimary"
android:textSize="24sp"
android:inputType="textMultiLine"
app:met_baseColor="@color/colorPrimary"
app:met_floatingLabel="highlight"
app:met_primaryColor="@color/colorPrimary"
app:met_singleLineEllipsis="true"
/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
@@ -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>