purchaseorder view

Purchase Order view only so changes only to view
This commit is contained in:
Nikitha
2026-03-29 16:33:27 -06:00
parent 13916236eb
commit 862ece691a
8 changed files with 567 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
package com.example.petstoremobile.adapters;
import android.graphics.Color;
import android.view.*;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.petstoremobile.R;
import com.example.petstoremobile.dtos.PurchaseOrderDTO;
import java.util.List;
public class PurchaseOrderAdapter extends RecyclerView.Adapter<PurchaseOrderAdapter.POViewHolder> {
private List<PurchaseOrderDTO> list;
private OnPurchaseOrderClickListener listener;
public interface OnPurchaseOrderClickListener {
void onPurchaseOrderClick(int position);
}
public PurchaseOrderAdapter(List<PurchaseOrderDTO> list, OnPurchaseOrderClickListener listener) {
this.list = list;
this.listener = listener;
}
public static class POViewHolder extends RecyclerView.ViewHolder {
TextView tvId, tvSupplier, tvDate, tvStatus;
public POViewHolder(@NonNull View v) {
super(v);
tvId = v.findViewById(R.id.tvPOId);
tvSupplier = v.findViewById(R.id.tvPOSupplier);
tvDate = v.findViewById(R.id.tvPODate);
tvStatus = v.findViewById(R.id.tvPOStatus);
}
}
@NonNull
@Override
public POViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_purchase_order, parent, false);
return new POViewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull POViewHolder holder, int position) {
PurchaseOrderDTO po = list.get(position);
holder.tvId.setText("PO #" + (po.getPurchaseOrderId() != null ? po.getPurchaseOrderId() : ""));
holder.tvSupplier.setText("Supplier: " + (po.getSupplierName() != null ? po.getSupplierName() : ""));
holder.tvDate.setText("Date: " + (po.getOrderDate() != null ? po.getOrderDate() : ""));
String status = po.getStatus() != null ? po.getStatus() : "";
holder.tvStatus.setText(status);
switch (status) {
case "Completed":
holder.tvStatus.setBackgroundColor(Color.parseColor("#4CAF50"));
break;
case "Pending":
holder.tvStatus.setBackgroundColor(Color.parseColor("#FF9800"));
break;
case "Cancelled":
holder.tvStatus.setBackgroundColor(Color.parseColor("#F44336"));
break;
default:
holder.tvStatus.setBackgroundColor(Color.parseColor("#9E9E9E"));
break;
}
holder.itemView.setOnClickListener(v -> listener.onPurchaseOrderClick(position));
}
@Override
public int getItemCount() {
return list.size();
}
}

View File

@@ -0,0 +1,19 @@
package com.example.petstoremobile.api;
import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.dtos.PurchaseOrderDTO;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
import retrofit2.http.Query;
public interface PurchaseOrderApi {
@GET("api/v1/purchase-orders")
Call<PageResponse<PurchaseOrderDTO>> getAllPurchaseOrders(
@Query("page") int page,
@Query("size") int size);
@GET("api/v1/purchase-orders/{id}")
Call<PurchaseOrderDTO> getPurchaseOrderById(@Path("id") Long id);
}

View File

@@ -0,0 +1,39 @@
package com.example.petstoremobile.dtos;
public class PurchaseOrderDTO {
private Long purchaseOrderId;
private Long supId;
private String supplierName;
private String orderDate;
private String status;
private String createdAt;
private String updatedAt;
public Long getPurchaseOrderId() {
return purchaseOrderId;
}
public Long getSupId() {
return supId;
}
public String getSupplierName() {
return supplierName;
}
public String getOrderDate() {
return orderDate;
}
public String getStatus() {
return status;
}
public String getCreatedAt() {
return createdAt;
}
public String getUpdatedAt() {
return updatedAt;
}
}

View File

@@ -0,0 +1,139 @@
package com.example.petstoremobile.fragments.listfragments;
import android.os.Bundle;
import android.text.*;
import android.util.Log;
import android.view.*;
import android.widget.*;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.example.petstoremobile.R;
import com.example.petstoremobile.adapters.PurchaseOrderAdapter;
import com.example.petstoremobile.api.RetrofitClient;
import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.dtos.PurchaseOrderDTO;
import com.example.petstoremobile.fragments.ListFragment;
import com.example.petstoremobile.fragments.listfragments.detailfragments.PurchaseOrderDetailFragment;
import java.util.*;
import retrofit2.*;
public class PurchaseOrderFragment extends Fragment
implements PurchaseOrderAdapter.OnPurchaseOrderClickListener {
private List<PurchaseOrderDTO> poList = new ArrayList<>();
private List<PurchaseOrderDTO> filteredList = new ArrayList<>();
private PurchaseOrderAdapter adapter;
private SwipeRefreshLayout swipeRefresh;
private EditText etSearch;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_purchase_order, container, false);
setupRecyclerView(view);
setupSearch(view);
setupSwipeRefresh(view);
loadData();
ImageButton hamburger = view.findViewById(R.id.btnHamburgerPO);
hamburger.setOnClickListener(v -> {
ListFragment lf = (ListFragment) getParentFragment();
if (lf != null)
lf.openDrawer();
});
return view;
}
private void setupRecyclerView(View view) {
RecyclerView rv = view.findViewById(R.id.recyclerViewPO);
adapter = new PurchaseOrderAdapter(filteredList, this);
rv.setLayoutManager(new LinearLayoutManager(getContext()));
rv.setAdapter(adapter);
}
private void setupSearch(View view) {
etSearch = view.findViewById(R.id.etSearchPO);
etSearch.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int a, int b, int c) {
}
public void afterTextChanged(Editable s) {
}
public void onTextChanged(CharSequence s, int a, int b, int c) {
filter(s.toString());
}
});
}
private void setupSwipeRefresh(View view) {
swipeRefresh = view.findViewById(R.id.swipeRefreshPO);
swipeRefresh.setOnRefreshListener(this::loadData);
}
private void filter(String query) {
filteredList.clear();
if (query.isEmpty()) {
filteredList.addAll(poList);
} else {
String lower = query.toLowerCase();
for (PurchaseOrderDTO po : poList) {
if ((po.getSupplierName() != null && po.getSupplierName().toLowerCase().contains(lower))
|| (po.getStatus() != null && po.getStatus().toLowerCase().contains(lower))) {
filteredList.add(po);
}
}
}
adapter.notifyDataSetChanged();
}
private void loadData() {
if (swipeRefresh != null)
swipeRefresh.setRefreshing(true);
RetrofitClient.getPurchaseOrderApi(requireContext()).getAllPurchaseOrders(0, 100)
.enqueue(new Callback<PageResponse<PurchaseOrderDTO>>() {
public void onResponse(Call<PageResponse<PurchaseOrderDTO>> c,
Response<PageResponse<PurchaseOrderDTO>> r) {
if (swipeRefresh != null)
swipeRefresh.setRefreshing(false);
if (r.isSuccessful() && r.body() != null) {
poList.clear();
poList.addAll(r.body().getContent());
filter(etSearch != null ? etSearch.getText().toString() : "");
} else {
Toast.makeText(getContext(), "Failed to load purchase orders",
Toast.LENGTH_SHORT).show();
}
}
public void onFailure(Call<PageResponse<PurchaseOrderDTO>> c, Throwable t) {
if (swipeRefresh != null)
swipeRefresh.setRefreshing(false);
Log.e("POFragment", t.getMessage());
}
});
}
private void openDetail(int position) {
PurchaseOrderDetailFragment detail = new PurchaseOrderDetailFragment();
Bundle args = new Bundle();
PurchaseOrderDTO po = filteredList.get(position);
args.putLong("purchaseOrderId", po.getPurchaseOrderId());
args.putString("supplierName", po.getSupplierName());
args.putString("orderDate", po.getOrderDate());
args.putString("status", po.getStatus());
detail.setArguments(args);
ListFragment lf = (ListFragment) getParentFragment();
if (lf != null)
lf.loadFragment(detail);
}
@Override
public void onPurchaseOrderClick(int position) {
openDetail(position);
}
}

View File

@@ -0,0 +1,31 @@
package com.example.petstoremobile.models;
public class PurchaseOrder {
private int purchaseOrderId;
private String supplierName;
private String orderDate;
private String status;
public PurchaseOrder(int purchaseOrderId, String supplierName, String orderDate, String status) {
this.purchaseOrderId = purchaseOrderId;
this.supplierName = supplierName;
this.orderDate = orderDate;
this.status = status;
}
public int getPurchaseOrderId() {
return purchaseOrderId;
}
public String getSupplierName() {
return supplierName;
}
public String getOrderDate() {
return orderDate;
}
public String getStatus() {
return status;
}
}

View File

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_grey">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@color/primary_dark"
android:gravity="center_vertical"
android:paddingStart="16dp"
android:paddingEnd="16dp">
<ImageButton
android:id="@+id/btnHamburgerPO"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@drawable/baseline_menu_36"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="Open menu"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Purchase Orders"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold"/>
</LinearLayout>
<EditText
android:id="@+id/etSearchPO"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:hint="Search by supplier or status..."
android:inputType="text"
android:drawableStart="@android:drawable/ic_menu_search"
android:drawablePadding="8dp"
android:background="@android:color/white"
android:padding="12dp"
android:textColor="@color/text_dark"/>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshPO"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewPO"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/background_grey">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@color/primary_dark"
android:gravity="center_vertical"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Purchase Order Details"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="24dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/rounded_card"
android:padding="16dp"
android:layout_marginBottom="16dp">
<TextView
android:id="@+id/tvPODetailId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text_light"
android:textSize="11sp"
android:textStyle="italic"
android:layout_gravity="end"
android:layout_marginBottom="16dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Supplier"
android:textColor="@color/text_light"
android:textSize="12sp"/>
<TextView
android:id="@+id/tvPODetailSupplier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text_dark"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginBottom="16dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Order Date"
android:textColor="@color/text_light"
android:textSize="12sp"/>
<TextView
android:id="@+id/tvPODetailDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text_dark"
android:textSize="15sp"
android:layout_marginBottom="16dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Status"
android:textColor="@color/text_light"
android:textSize="12sp"/>
<TextView
android:id="@+id/tvPODetailStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:layout_marginBottom="16dp"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="16dp">
<Button
android:id="@+id/btnPOBack"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Back"
android:backgroundTint="@color/primary_medium"
android:textColor="@color/white"/>
</LinearLayout>
</LinearLayout>

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
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:cardCornerRadius="8dp"
app:cardElevation="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/tvPOId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@color/text_dark"/>
<TextView
android:id="@+id/tvPOSupplier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="13sp"
android:textColor="@color/text_light"
android:layout_marginTop="2dp"/>
<TextView
android:id="@+id/tvPODate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="@color/text_light"
android:layout_marginTop="2dp"/>
</LinearLayout>
<TextView
android:id="@+id/tvPOStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:textSize="12sp"
android:textColor="@color/white"
android:layout_gravity="center_vertical"/>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>