edited adapters in andriod to use viewbinding
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
package com.example.petstoremobile.adapters;
|
package com.example.petstoremobile.adapters;
|
||||||
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.view.*;
|
import android.view.LayoutInflater;
|
||||||
import android.widget.TextView;
|
import android.view.ViewGroup;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.example.petstoremobile.R;
|
import com.example.petstoremobile.databinding.ItemAdoptionBinding;
|
||||||
import com.example.petstoremobile.dtos.AdoptionDTO;
|
import com.example.petstoremobile.dtos.AdoptionDTO;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -24,50 +24,46 @@ public class AdoptionAdapter extends RecyclerView.Adapter<AdoptionAdapter.Adopti
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class AdoptionViewHolder extends RecyclerView.ViewHolder {
|
public static class AdoptionViewHolder extends RecyclerView.ViewHolder {
|
||||||
TextView tvCustomerName, tvPetName, tvDate, tvFee, tvStatus;
|
final ItemAdoptionBinding binding;
|
||||||
|
|
||||||
public AdoptionViewHolder(@NonNull View v) {
|
public AdoptionViewHolder(@NonNull ItemAdoptionBinding binding) {
|
||||||
super(v);
|
super(binding.getRoot());
|
||||||
tvCustomerName = v.findViewById(R.id.tvAdoptionCustomerName);
|
this.binding = binding;
|
||||||
tvPetName = v.findViewById(R.id.tvAdoptionPetName);
|
|
||||||
tvDate = v.findViewById(R.id.tvAdoptionDate);
|
|
||||||
tvFee = v.findViewById(R.id.tvAdoptionFee);
|
|
||||||
tvStatus = v.findViewById(R.id.tvAdoptionStatus);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public AdoptionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public AdoptionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext())
|
ItemAdoptionBinding binding = ItemAdoptionBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||||
.inflate(R.layout.item_adoption, parent, false);
|
return new AdoptionViewHolder(binding);
|
||||||
return new AdoptionViewHolder(v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull AdoptionViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull AdoptionViewHolder holder, int position) {
|
||||||
AdoptionDTO a = adoptionList.get(position);
|
AdoptionDTO a = adoptionList.get(position);
|
||||||
|
ItemAdoptionBinding binding = holder.binding;
|
||||||
|
|
||||||
holder.tvCustomerName.setText(a.getCustomerName() != null ? a.getCustomerName() : "");
|
binding.tvAdoptionCustomerName.setText(a.getCustomerName() != null ? a.getCustomerName() : "");
|
||||||
holder.tvPetName.setText("Pet: " + (a.getPetName() != null ? a.getPetName() : ""));
|
binding.tvAdoptionPetName.setText("Pet: " + (a.getPetName() != null ? a.getPetName() : ""));
|
||||||
holder.tvDate.setText("Date: " + (a.getAdoptionDate() != null ? a.getAdoptionDate() : ""));
|
binding.tvAdoptionDate.setText("Date: " + (a.getAdoptionDate() != null ? a.getAdoptionDate() : ""));
|
||||||
holder.tvFee.setText(a.getAdoptionFee() != null ? "$" + a.getAdoptionFee() : "");
|
binding.tvAdoptionFee.setText(a.getAdoptionFee() != null ? "$" + a.getAdoptionFee() : "");
|
||||||
|
|
||||||
String status = a.getAdoptionStatus() != null ? a.getAdoptionStatus() : "";
|
String status = a.getAdoptionStatus() != null ? a.getAdoptionStatus() : "";
|
||||||
holder.tvStatus.setText(status);
|
binding.tvAdoptionStatus.setText(status);
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case "Completed":
|
case "Completed":
|
||||||
holder.tvStatus.setBackgroundColor(Color.parseColor("#4CAF50"));
|
binding.tvAdoptionStatus.setBackgroundColor(Color.parseColor("#4CAF50"));
|
||||||
break;
|
break;
|
||||||
case "Pending":
|
case "Pending":
|
||||||
holder.tvStatus.setBackgroundColor(Color.parseColor("#FF9800"));
|
binding.tvAdoptionStatus.setBackgroundColor(Color.parseColor("#FF9800"));
|
||||||
break;
|
break;
|
||||||
case "Rejected":
|
case "Rejected":
|
||||||
holder.tvStatus.setBackgroundColor(Color.parseColor("#F44336"));
|
binding.tvAdoptionStatus.setBackgroundColor(Color.parseColor("#F44336"));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
holder.tvStatus.setBackgroundColor(Color.parseColor("#9E9E9E"));
|
binding.tvAdoptionStatus.setBackgroundColor(Color.parseColor("#9E9E9E"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,10 @@ package com.example.petstoremobile.adapters;
|
|||||||
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.example.petstoremobile.R;
|
import com.example.petstoremobile.databinding.ItemAppointmentBinding;
|
||||||
import com.example.petstoremobile.dtos.AppointmentDTO;
|
import com.example.petstoremobile.dtos.AppointmentDTO;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -27,50 +25,48 @@ public class AppointmentAdapter extends RecyclerView.Adapter<AppointmentAdapter.
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class AppointmentViewHolder extends RecyclerView.ViewHolder {
|
public static class AppointmentViewHolder extends RecyclerView.ViewHolder {
|
||||||
TextView tvCustomerName, tvPetName, tvServiceType, tvDateTime, tvAppointmentStatus;
|
private final ItemAppointmentBinding binding;
|
||||||
|
|
||||||
public AppointmentViewHolder(@NonNull View v) {
|
public AppointmentViewHolder(@NonNull ItemAppointmentBinding binding) {
|
||||||
super(v);
|
super(binding.getRoot());
|
||||||
tvCustomerName = v.findViewById(R.id.tvCustomerName);
|
this.binding = binding;
|
||||||
tvPetName = v.findViewById(R.id.tvApptPetName);
|
|
||||||
tvServiceType = v.findViewById(R.id.tvServiceType);
|
|
||||||
tvDateTime = v.findViewById(R.id.tvDateTime);
|
|
||||||
tvAppointmentStatus = v.findViewById(R.id.tvAppointmentStatus);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public AppointmentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public AppointmentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_appointment, parent, false);
|
ItemAppointmentBinding binding = ItemAppointmentBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||||
return new AppointmentViewHolder(v);
|
return new AppointmentViewHolder(binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull AppointmentViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull AppointmentViewHolder holder, int position) {
|
||||||
AppointmentDTO a = appointmentList.get(position);
|
AppointmentDTO a = appointmentList.get(position);
|
||||||
|
ItemAppointmentBinding binding = holder.binding;
|
||||||
|
|
||||||
holder.tvCustomerName.setText(a.getCustomerName() != null ? a.getCustomerName() : "");
|
binding.tvCustomerName.setText(a.getCustomerName() != null ? a.getCustomerName() : "");
|
||||||
holder.tvPetName.setText("Pet: " + (a.getPetName() != null ? a.getPetName() : ""));
|
binding.tvApptPetName.setText("Pet: " + (a.getPetName() != null ? a.getPetName() : ""));
|
||||||
holder.tvServiceType.setText(a.getServiceType() != null ? a.getServiceType() : "");
|
binding.tvServiceType.setText(a.getServiceType() != null ? a.getServiceType() : "");
|
||||||
holder.tvDateTime.setText((a.getAppointmentDate() != null ? a.getAppointmentDate() : "") +
|
binding.tvStaffName.setText("Staff: " + (a.getEmployeeName() != null ? a.getEmployeeName() : "Unassigned"));
|
||||||
|
binding.tvDateTime.setText((a.getAppointmentDate() != null ? a.getAppointmentDate() : "") +
|
||||||
" at " + (a.getAppointmentTime() != null ? a.getAppointmentTime() : ""));
|
" at " + (a.getAppointmentTime() != null ? a.getAppointmentTime() : ""));
|
||||||
|
|
||||||
String status = a.getStatus() != null ? a.getStatus() : "";
|
String status = a.getStatus() != null ? a.getStatus() : "";
|
||||||
holder.tvAppointmentStatus.setText(status);
|
binding.tvAppointmentStatus.setText(status);
|
||||||
|
|
||||||
switch (status.toUpperCase()) {
|
switch (status.toUpperCase()) {
|
||||||
case "BOOKED":
|
case "BOOKED":
|
||||||
holder.tvAppointmentStatus.setBackgroundColor(Color.parseColor("#2196F3")); // blue
|
binding.tvAppointmentStatus.setBackgroundColor(Color.parseColor("#2196F3")); // blue
|
||||||
break;
|
break;
|
||||||
case "COMPLETED":
|
case "COMPLETED":
|
||||||
holder.tvAppointmentStatus.setBackgroundColor(Color.parseColor("#4CAF50")); // green
|
binding.tvAppointmentStatus.setBackgroundColor(Color.parseColor("#4CAF50")); // green
|
||||||
break;
|
break;
|
||||||
case "CANCELLED":
|
case "CANCELLED":
|
||||||
holder.tvAppointmentStatus.setBackgroundColor(Color.parseColor("#F44336")); // red
|
binding.tvAppointmentStatus.setBackgroundColor(Color.parseColor("#F44336")); // red
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
holder.tvAppointmentStatus.setBackgroundColor(Color.parseColor("#9E9E9E")); // gray
|
binding.tvAppointmentStatus.setBackgroundColor(Color.parseColor("#9E9E9E")); // gray
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
package com.example.petstoremobile.adapters;
|
package com.example.petstoremobile.adapters;
|
||||||
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.example.petstoremobile.R;
|
import com.example.petstoremobile.databinding.ItemChatBinding;
|
||||||
import com.example.petstoremobile.models.Chat;
|
import com.example.petstoremobile.models.Chat;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -30,15 +28,15 @@ public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.ChatViewHolder
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ChatViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public ChatViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_chat, parent, false);
|
ItemChatBinding binding = ItemChatBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||||
return new ChatViewHolder(view);
|
return new ChatViewHolder(binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ChatViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull ChatViewHolder holder, int position) {
|
||||||
Chat chat = chatList.get(position);
|
Chat chat = chatList.get(position);
|
||||||
holder.tvCustomerName.setText(chat.getCustomerName());
|
holder.binding.tvCustomerName.setText(chat.getCustomerName());
|
||||||
holder.tvLastMessage.setText(chat.getLastMessage());
|
holder.binding.tvLastMessage.setText(chat.getLastMessage());
|
||||||
holder.itemView.setOnClickListener(v -> listener.onChatClick(chat));
|
holder.itemView.setOnClickListener(v -> listener.onChatClick(chat));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,12 +46,11 @@ public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.ChatViewHolder
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class ChatViewHolder extends RecyclerView.ViewHolder {
|
public static class ChatViewHolder extends RecyclerView.ViewHolder {
|
||||||
TextView tvCustomerName, tvLastMessage;
|
final ItemChatBinding binding;
|
||||||
|
|
||||||
public ChatViewHolder(@NonNull View itemView) {
|
public ChatViewHolder(@NonNull ItemChatBinding binding) {
|
||||||
super(itemView);
|
super(binding.getRoot());
|
||||||
tvCustomerName = itemView.findViewById(R.id.tvCustomerName);
|
this.binding = binding;
|
||||||
tvLastMessage = itemView.findViewById(R.id.tvLastMessage);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,13 +4,11 @@ import android.graphics.Color;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.example.petstoremobile.R;
|
import com.example.petstoremobile.databinding.ItemInventoryBinding;
|
||||||
import com.example.petstoremobile.dtos.InventoryDTO;
|
import com.example.petstoremobile.dtos.InventoryDTO;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -35,68 +33,61 @@ public class InventoryAdapter extends RecyclerView.Adapter<InventoryAdapter.Inve
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class InventoryViewHolder extends RecyclerView.ViewHolder {
|
public static class InventoryViewHolder extends RecyclerView.ViewHolder {
|
||||||
// Matches desktop table columns: Inventory ID, Product ID, Product Name,
|
final ItemInventoryBinding binding;
|
||||||
// Quantity
|
|
||||||
TextView tvInventoryId, tvProdId, tvProductName, tvQuantity;
|
|
||||||
CheckBox checkBox;
|
|
||||||
|
|
||||||
public InventoryViewHolder(@NonNull View v) {
|
public InventoryViewHolder(@NonNull ItemInventoryBinding binding) {
|
||||||
super(v);
|
super(binding.getRoot());
|
||||||
tvInventoryId = v.findViewById(R.id.tvInventoryId);
|
this.binding = binding;
|
||||||
tvProdId = v.findViewById(R.id.tvProdId);
|
|
||||||
tvProductName = v.findViewById(R.id.tvProductName);
|
|
||||||
tvQuantity = v.findViewById(R.id.tvQuantity);
|
|
||||||
checkBox = v.findViewById(R.id.cbSelectInventory);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public InventoryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public InventoryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext())
|
ItemInventoryBinding binding = ItemInventoryBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||||
.inflate(R.layout.item_inventory, parent, false);
|
return new InventoryViewHolder(binding);
|
||||||
return new InventoryViewHolder(v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull InventoryViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull InventoryViewHolder holder, int position) {
|
||||||
InventoryDTO inv = inventoryList.get(position);
|
InventoryDTO inv = inventoryList.get(position);
|
||||||
|
ItemInventoryBinding binding = holder.binding;
|
||||||
|
|
||||||
// Column: Inventory ID
|
// Column: Inventory ID
|
||||||
String invIdStr = inv.getInventoryId() != null ? String.valueOf(inv.getInventoryId()) : "—";
|
String invIdStr = inv.getInventoryId() != null ? String.valueOf(inv.getInventoryId()) : "—";
|
||||||
holder.tvInventoryId.setText("Inv ID: " + invIdStr);
|
binding.tvInventoryId.setText("Inv ID: " + invIdStr);
|
||||||
|
|
||||||
// Column: Product ID
|
// Column: Product ID
|
||||||
String prodIdStr = inv.getProdId() != null ? String.valueOf(inv.getProdId()) : "—";
|
String prodIdStr = inv.getProdId() != null ? String.valueOf(inv.getProdId()) : "—";
|
||||||
holder.tvProdId.setText("Prod ID: " + prodIdStr);
|
binding.tvProdId.setText("Prod ID: " + prodIdStr);
|
||||||
|
|
||||||
// Column: Product Name
|
// Column: Product Name
|
||||||
holder.tvProductName.setText(inv.getProductName() != null ? inv.getProductName() : "—");
|
binding.tvProductName.setText(inv.getProductName() != null ? inv.getProductName() : "—");
|
||||||
|
|
||||||
// Column: Quantity
|
// Column: Quantity
|
||||||
int qty = inv.getQuantity() != null ? inv.getQuantity() : 0;
|
int qty = inv.getQuantity() != null ? inv.getQuantity() : 0;
|
||||||
holder.tvQuantity.setText(String.valueOf(qty));
|
binding.tvQuantity.setText(String.valueOf(qty));
|
||||||
|
|
||||||
// Low stock = red, normal = green (like desktop reorder concept)
|
// Low stock = red, normal = green (like desktop reorder concept)
|
||||||
if (qty <= 5) {
|
if (qty <= 5) {
|
||||||
holder.tvQuantity.setTextColor(Color.parseColor("#F44336"));
|
binding.tvQuantity.setTextColor(Color.parseColor("#F44336"));
|
||||||
} else {
|
} else {
|
||||||
holder.tvQuantity.setTextColor(Color.parseColor("#4CAF50"));
|
binding.tvQuantity.setTextColor(Color.parseColor("#4CAF50"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bulk delete selection mode
|
// Bulk delete selection mode
|
||||||
if (selectionMode) {
|
if (selectionMode) {
|
||||||
holder.checkBox.setVisibility(View.VISIBLE);
|
binding.cbSelectInventory.setVisibility(View.VISIBLE);
|
||||||
holder.checkBox.setChecked(inv.getInventoryId() != null
|
binding.cbSelectInventory.setChecked(inv.getInventoryId() != null
|
||||||
&& selectedIds.contains(inv.getInventoryId()));
|
&& selectedIds.contains(inv.getInventoryId()));
|
||||||
} else {
|
} else {
|
||||||
holder.checkBox.setVisibility(View.GONE);
|
binding.cbSelectInventory.setVisibility(View.GONE);
|
||||||
holder.checkBox.setChecked(false);
|
binding.cbSelectInventory.setChecked(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.itemView.setOnClickListener(v -> {
|
holder.itemView.setOnClickListener(v -> {
|
||||||
if (selectionMode) {
|
if (selectionMode) {
|
||||||
toggleSelection(inv.getInventoryId(), holder.checkBox);
|
toggleSelection(inv.getInventoryId(), binding.cbSelectInventory);
|
||||||
} else {
|
} else {
|
||||||
clickListener.onInventoryClick(holder.getAdapterPosition());
|
clickListener.onInventoryClick(holder.getAdapterPosition());
|
||||||
}
|
}
|
||||||
@@ -105,14 +96,14 @@ public class InventoryAdapter extends RecyclerView.Adapter<InventoryAdapter.Inve
|
|||||||
holder.itemView.setOnLongClickListener(v -> {
|
holder.itemView.setOnLongClickListener(v -> {
|
||||||
if (!selectionMode) {
|
if (!selectionMode) {
|
||||||
selectionMode = true;
|
selectionMode = true;
|
||||||
toggleSelection(inv.getInventoryId(), holder.checkBox);
|
toggleSelection(inv.getInventoryId(), binding.cbSelectInventory);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleSelection(Long id, CheckBox checkBox) {
|
private void toggleSelection(Long id, android.widget.CheckBox checkBox) {
|
||||||
if (id == null)
|
if (id == null)
|
||||||
return;
|
return;
|
||||||
if (selectedIds.contains(id)) {
|
if (selectedIds.contains(id)) {
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|||||||
import com.bumptech.glide.load.model.GlideUrl;
|
import com.bumptech.glide.load.model.GlideUrl;
|
||||||
import com.bumptech.glide.load.model.LazyHeaders;
|
import com.bumptech.glide.load.model.LazyHeaders;
|
||||||
import com.example.petstoremobile.R;
|
import com.example.petstoremobile.R;
|
||||||
|
import com.example.petstoremobile.databinding.ItemMessageReceivedBinding;
|
||||||
|
import com.example.petstoremobile.databinding.ItemMessageSentBinding;
|
||||||
import com.example.petstoremobile.models.Message;
|
import com.example.petstoremobile.models.Message;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -51,11 +53,11 @@ public class MessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
|||||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
LayoutInflater inf = LayoutInflater.from(parent.getContext());
|
LayoutInflater inf = LayoutInflater.from(parent.getContext());
|
||||||
if (viewType == TYPE_SENT) {
|
if (viewType == TYPE_SENT) {
|
||||||
View v = inf.inflate(R.layout.item_message_sent, parent, false);
|
ItemMessageSentBinding binding = ItemMessageSentBinding.inflate(inf, parent, false);
|
||||||
return new SentHolder(v);
|
return new SentHolder(binding);
|
||||||
} else {
|
} else {
|
||||||
View v = inf.inflate(R.layout.item_message_received, parent, false);
|
ItemMessageReceivedBinding binding = ItemMessageReceivedBinding.inflate(inf, parent, false);
|
||||||
return new ReceivedHolder(v);
|
return new ReceivedHolder(binding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,32 +71,26 @@ public class MessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
|||||||
@Override public int getItemCount() { return messages.size(); }
|
@Override public int getItemCount() { return messages.size(); }
|
||||||
|
|
||||||
static class SentHolder extends RecyclerView.ViewHolder {
|
static class SentHolder extends RecyclerView.ViewHolder {
|
||||||
TextView tvMessage, tvAttachmentName;
|
final ItemMessageSentBinding binding;
|
||||||
ImageView ivAttachment;
|
SentHolder(ItemMessageSentBinding binding) {
|
||||||
SentHolder(View v) {
|
super(binding.getRoot());
|
||||||
super(v);
|
this.binding = binding;
|
||||||
tvMessage = v.findViewById(R.id.tvMessageContent);
|
|
||||||
tvAttachmentName = v.findViewById(R.id.tvAttachmentName);
|
|
||||||
ivAttachment = v.findViewById(R.id.ivAttachment);
|
|
||||||
}
|
}
|
||||||
void bind(Message m, String token) {
|
void bind(Message m, String token) {
|
||||||
tvMessage.setText(m.getContent());
|
binding.tvMessageContent.setText(m.getContent());
|
||||||
displayAttachment(m, ivAttachment, tvAttachmentName, token);
|
displayAttachment(m, binding.ivAttachment, binding.tvAttachmentName, token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ReceivedHolder extends RecyclerView.ViewHolder {
|
static class ReceivedHolder extends RecyclerView.ViewHolder {
|
||||||
TextView tvMessage, tvAttachmentName;
|
final ItemMessageReceivedBinding binding;
|
||||||
ImageView ivAttachment;
|
ReceivedHolder(ItemMessageReceivedBinding binding) {
|
||||||
ReceivedHolder(View v) {
|
super(binding.getRoot());
|
||||||
super(v);
|
this.binding = binding;
|
||||||
tvMessage = v.findViewById(R.id.tvMessageContent);
|
|
||||||
tvAttachmentName = v.findViewById(R.id.tvAttachmentName);
|
|
||||||
ivAttachment = v.findViewById(R.id.ivAttachment);
|
|
||||||
}
|
}
|
||||||
void bind(Message m, String token) {
|
void bind(Message m, String token) {
|
||||||
tvMessage.setText(m.getContent());
|
binding.tvMessageContent.setText(m.getContent());
|
||||||
displayAttachment(m, ivAttachment, tvAttachmentName, token);
|
displayAttachment(m, binding.ivAttachment, binding.tvAttachmentName, token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,15 +2,13 @@ package com.example.petstoremobile.adapters;
|
|||||||
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.example.petstoremobile.R;
|
import com.example.petstoremobile.R;
|
||||||
import com.example.petstoremobile.api.PetApi;
|
import com.example.petstoremobile.api.PetApi;
|
||||||
|
import com.example.petstoremobile.databinding.ItemPetBinding;
|
||||||
import com.example.petstoremobile.dtos.PetDTO;
|
import com.example.petstoremobile.dtos.PetDTO;
|
||||||
import com.example.petstoremobile.utils.GlideUtils;
|
import com.example.petstoremobile.utils.GlideUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -43,17 +41,11 @@ public class PetAdapter extends RecyclerView.Adapter<PetAdapter.PetViewHolder> {
|
|||||||
|
|
||||||
// Get the controls of each row in recycler view
|
// Get the controls of each row in recycler view
|
||||||
public static class PetViewHolder extends RecyclerView.ViewHolder {
|
public static class PetViewHolder extends RecyclerView.ViewHolder {
|
||||||
TextView tvPetName, tvPetSpeciesBreed, tvPetAge, tvPetPrice, tvPetStatus;
|
private final ItemPetBinding binding;
|
||||||
ImageView ivPetProfile;
|
|
||||||
|
|
||||||
public PetViewHolder(@NonNull View v) {
|
public PetViewHolder(@NonNull ItemPetBinding binding) {
|
||||||
super(v);
|
super(binding.getRoot());
|
||||||
tvPetName = v.findViewById(R.id.tvPetName);
|
this.binding = binding;
|
||||||
tvPetSpeciesBreed = v.findViewById(R.id.tvPetSpeciesBreed);
|
|
||||||
tvPetAge = v.findViewById(R.id.tvPetAge);
|
|
||||||
tvPetPrice = v.findViewById(R.id.tvPetPrice);
|
|
||||||
tvPetStatus = v.findViewById(R.id.tvPetStatus);
|
|
||||||
ivPetProfile = v.findViewById(R.id.ivPetProfile);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,41 +53,42 @@ public class PetAdapter extends RecyclerView.Adapter<PetAdapter.PetViewHolder> {
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public PetViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public PetViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_pet, parent, false);
|
ItemPetBinding binding = ItemPetBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||||
return new PetViewHolder(v);
|
return new PetViewHolder(binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
//populate the row with pet data
|
//populate the row with pet data
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull PetViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull PetViewHolder holder, int position) {
|
||||||
PetDTO pet = petList.get(position);
|
PetDTO pet = petList.get(position);
|
||||||
|
ItemPetBinding binding = holder.binding;
|
||||||
|
|
||||||
holder.tvPetName.setText(pet.getPetName());
|
binding.tvPetName.setText(pet.getPetName());
|
||||||
holder.tvPetSpeciesBreed.setText(pet.getPetSpecies() + " - " + pet.getPetBreed());
|
binding.tvPetSpeciesBreed.setText(pet.getPetSpecies() + " - " + pet.getPetBreed());
|
||||||
holder.tvPetAge.setText("Age: " + pet.getPetAge() + " yr(s)");
|
binding.tvPetAge.setText("Age: " + pet.getPetAge() + " yr(s)");
|
||||||
|
|
||||||
Double price = pet.getPetPrice();
|
Double price = pet.getPetPrice();
|
||||||
if (price != null) {
|
if (price != null) {
|
||||||
holder.tvPetPrice.setText("$" + String.format("%.2f", price));
|
binding.tvPetPrice.setText("$" + String.format("%.2f", price));
|
||||||
} else {
|
} else {
|
||||||
holder.tvPetPrice.setText("$0.00");
|
binding.tvPetPrice.setText("$0.00");
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.tvPetStatus.setText(pet.getPetStatus());
|
binding.tvPetStatus.setText(pet.getPetStatus());
|
||||||
|
|
||||||
//Set the status color depending on availability. If available, green, otherwise red
|
//Set the status color depending on availability. If available, green, otherwise red
|
||||||
if (pet.getPetStatus() != null && pet.getPetStatus().equals("Available")) {
|
if (pet.getPetStatus() != null && pet.getPetStatus().equals("Available")) {
|
||||||
holder.tvPetStatus.setBackgroundColor(Color.parseColor("#4CAF50"));
|
binding.tvPetStatus.setBackgroundColor(Color.parseColor("#4CAF50"));
|
||||||
} else {
|
} else {
|
||||||
holder.tvPetStatus.setBackgroundColor(Color.parseColor("#F44336"));
|
binding.tvPetStatus.setBackgroundColor(Color.parseColor("#F44336"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load pet image using Glide
|
// Load pet image using Glide
|
||||||
if (baseUrl != null) {
|
if (baseUrl != null) {
|
||||||
String imageUrl = baseUrl + String.format(PetApi.PET_IMAGE_PATH, pet.getPetId());
|
String imageUrl = baseUrl + String.format(PetApi.PET_IMAGE_PATH, pet.getPetId());
|
||||||
GlideUtils.loadImageWithTokenCircle(holder.itemView.getContext(), holder.ivPetProfile, imageUrl, token, R.drawable.placeholder);
|
GlideUtils.loadImageWithTokenCircle(holder.itemView.getContext(), binding.ivPetProfile, imageUrl, token, R.drawable.placeholder);
|
||||||
} else {
|
} else {
|
||||||
holder.ivPetProfile.setImageResource(R.drawable.placeholder);
|
binding.ivPetProfile.setImageResource(R.drawable.placeholder);
|
||||||
}
|
}
|
||||||
|
|
||||||
//when a row is clicked, open the detail view
|
//when a row is clicked, open the detail view
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package com.example.petstoremobile.adapters;
|
package com.example.petstoremobile.adapters;
|
||||||
|
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.example.petstoremobile.R;
|
import com.example.petstoremobile.R;
|
||||||
import com.example.petstoremobile.api.ProductApi;
|
import com.example.petstoremobile.api.ProductApi;
|
||||||
|
import com.example.petstoremobile.databinding.ItemProductBinding;
|
||||||
import com.example.petstoremobile.dtos.ProductDTO;
|
import com.example.petstoremobile.dtos.ProductDTO;
|
||||||
import com.example.petstoremobile.utils.GlideUtils;
|
import com.example.petstoremobile.utils.GlideUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -37,41 +36,37 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.ProductV
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class ProductViewHolder extends RecyclerView.ViewHolder {
|
public static class ProductViewHolder extends RecyclerView.ViewHolder {
|
||||||
TextView tvName, tvCategory, tvDesc, tvPrice;
|
final ItemProductBinding binding;
|
||||||
ImageView ivProductImage;
|
|
||||||
|
|
||||||
public ProductViewHolder(@NonNull View v) {
|
public ProductViewHolder(@NonNull ItemProductBinding binding) {
|
||||||
super(v);
|
super(binding.getRoot());
|
||||||
tvName = v.findViewById(R.id.tvProductName);
|
this.binding = binding;
|
||||||
tvCategory = v.findViewById(R.id.tvProductCategory);
|
|
||||||
tvDesc = v.findViewById(R.id.tvProductDesc);
|
|
||||||
tvPrice = v.findViewById(R.id.tvProductPrice);
|
|
||||||
ivProductImage = v.findViewById(R.id.ivProductImage);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ProductViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public ProductViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext())
|
ItemProductBinding binding = ItemProductBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||||
.inflate(R.layout.item_product, parent, false);
|
return new ProductViewHolder(binding);
|
||||||
return new ProductViewHolder(v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ProductViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull ProductViewHolder holder, int position) {
|
||||||
ProductDTO p = productList.get(position);
|
ProductDTO p = productList.get(position);
|
||||||
holder.tvName.setText(p.getProdName() != null ? p.getProdName() : "");
|
ItemProductBinding binding = holder.binding;
|
||||||
holder.tvCategory.setText("Category: " + (p.getCategoryName() != null ? p.getCategoryName() : ""));
|
|
||||||
holder.tvDesc.setText(p.getProdDesc() != null ? p.getProdDesc() : "");
|
binding.tvProductName.setText(p.getProdName() != null ? p.getProdName() : "");
|
||||||
holder.tvPrice.setText(p.getProdPrice() != null ? "$" + p.getProdPrice() : "");
|
binding.tvProductCategory.setText("Category: " + (p.getCategoryName() != null ? p.getCategoryName() : ""));
|
||||||
|
binding.tvProductDesc.setText(p.getProdDesc() != null ? p.getProdDesc() : "");
|
||||||
|
binding.tvProductPrice.setText(p.getProdPrice() != null ? "$" + p.getProdPrice() : "");
|
||||||
|
|
||||||
// Load product image using Glide
|
// Load product image using Glide
|
||||||
if (baseUrl != null) {
|
if (baseUrl != null) {
|
||||||
String imageUrl = baseUrl + String.format(ProductApi.PRODUCT_IMAGE_PATH, p.getProdId());
|
String imageUrl = baseUrl + String.format(ProductApi.PRODUCT_IMAGE_PATH, p.getProdId());
|
||||||
GlideUtils.loadImageWithTokenCircle(holder.itemView.getContext(), holder.ivProductImage, imageUrl, token, R.drawable.placeholder);
|
GlideUtils.loadImageWithTokenCircle(holder.itemView.getContext(), binding.ivProductImage, imageUrl, token, R.drawable.placeholder);
|
||||||
} else {
|
} else {
|
||||||
holder.ivProductImage.setImageResource(R.drawable.placeholder);
|
binding.ivProductImage.setImageResource(R.drawable.placeholder);
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.itemView.setOnClickListener(v -> listener.onProductClick(position));
|
holder.itemView.setOnClickListener(v -> listener.onProductClick(position));
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.example.petstoremobile.adapters;
|
package com.example.petstoremobile.adapters;
|
||||||
|
|
||||||
import android.view.*;
|
import android.view.LayoutInflater;
|
||||||
import android.widget.TextView;
|
import android.view.ViewGroup;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.example.petstoremobile.R;
|
import com.example.petstoremobile.databinding.ItemProductSupplierBinding;
|
||||||
import com.example.petstoremobile.dtos.ProductSupplierDTO;
|
import com.example.petstoremobile.dtos.ProductSupplierDTO;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -23,30 +23,29 @@ public class ProductSupplierAdapter extends RecyclerView.Adapter<ProductSupplier
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class PSViewHolder extends RecyclerView.ViewHolder {
|
public static class PSViewHolder extends RecyclerView.ViewHolder {
|
||||||
TextView tvProductName, tvSupplierName, tvCost;
|
final ItemProductSupplierBinding binding;
|
||||||
|
|
||||||
public PSViewHolder(@NonNull View v) {
|
public PSViewHolder(@NonNull ItemProductSupplierBinding binding) {
|
||||||
super(v);
|
super(binding.getRoot());
|
||||||
tvProductName = v.findViewById(R.id.tvPSProductName);
|
this.binding = binding;
|
||||||
tvSupplierName = v.findViewById(R.id.tvPSSupplierName);
|
|
||||||
tvCost = v.findViewById(R.id.tvPSCost);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public PSViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public PSViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext())
|
ItemProductSupplierBinding binding = ItemProductSupplierBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||||
.inflate(R.layout.item_product_supplier, parent, false);
|
return new PSViewHolder(binding);
|
||||||
return new PSViewHolder(v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull PSViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull PSViewHolder holder, int position) {
|
||||||
ProductSupplierDTO ps = list.get(position);
|
ProductSupplierDTO ps = list.get(position);
|
||||||
holder.tvProductName.setText(ps.getProductName() != null ? ps.getProductName() : "");
|
ItemProductSupplierBinding binding = holder.binding;
|
||||||
holder.tvSupplierName.setText("Supplier: " + (ps.getSupplierName() != null ? ps.getSupplierName() : ""));
|
|
||||||
holder.tvCost.setText(ps.getCost() != null ? "Cost: $" + ps.getCost() : "");
|
binding.tvPSProductName.setText(ps.getProductName() != null ? ps.getProductName() : "");
|
||||||
|
binding.tvPSSupplierName.setText("Supplier: " + (ps.getSupplierName() != null ? ps.getSupplierName() : ""));
|
||||||
|
binding.tvPSCost.setText(ps.getCost() != null ? "Cost: $" + ps.getCost() : "");
|
||||||
holder.itemView.setOnClickListener(v -> listener.onProductSupplierClick(position));
|
holder.itemView.setOnClickListener(v -> listener.onProductSupplierClick(position));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package com.example.petstoremobile.adapters;
|
package com.example.petstoremobile.adapters;
|
||||||
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.view.*;
|
import android.view.LayoutInflater;
|
||||||
import android.widget.TextView;
|
import android.view.ViewGroup;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.example.petstoremobile.R;
|
import com.example.petstoremobile.databinding.ItemPurchaseOrderBinding;
|
||||||
import com.example.petstoremobile.dtos.PurchaseOrderDTO;
|
import com.example.petstoremobile.dtos.PurchaseOrderDTO;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -24,47 +24,45 @@ public class PurchaseOrderAdapter extends RecyclerView.Adapter<PurchaseOrderAdap
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class POViewHolder extends RecyclerView.ViewHolder {
|
public static class POViewHolder extends RecyclerView.ViewHolder {
|
||||||
TextView tvId, tvSupplier, tvDate, tvStatus;
|
final ItemPurchaseOrderBinding binding;
|
||||||
|
|
||||||
public POViewHolder(@NonNull View v) {
|
public POViewHolder(@NonNull ItemPurchaseOrderBinding binding) {
|
||||||
super(v);
|
super(binding.getRoot());
|
||||||
tvId = v.findViewById(R.id.tvPOId);
|
this.binding = binding;
|
||||||
tvSupplier = v.findViewById(R.id.tvPOSupplier);
|
|
||||||
tvDate = v.findViewById(R.id.tvPODate);
|
|
||||||
tvStatus = v.findViewById(R.id.tvPOStatus);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public POViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public POViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext())
|
ItemPurchaseOrderBinding binding = ItemPurchaseOrderBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||||
.inflate(R.layout.item_purchase_order, parent, false);
|
return new POViewHolder(binding);
|
||||||
return new POViewHolder(v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull POViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull POViewHolder holder, int position) {
|
||||||
PurchaseOrderDTO po = list.get(position);
|
PurchaseOrderDTO po = list.get(position);
|
||||||
holder.tvId.setText("PO #" + (po.getPurchaseOrderId() != null ? po.getPurchaseOrderId() : ""));
|
ItemPurchaseOrderBinding binding = holder.binding;
|
||||||
holder.tvSupplier.setText("Supplier: " + (po.getSupplierName() != null ? po.getSupplierName() : ""));
|
|
||||||
holder.tvDate.setText("Date: " + (po.getOrderDate() != null ? po.getOrderDate() : ""));
|
binding.tvPOId.setText("PO #" + (po.getPurchaseOrderId() != null ? po.getPurchaseOrderId() : ""));
|
||||||
|
binding.tvPOSupplier.setText("Supplier: " + (po.getSupplierName() != null ? po.getSupplierName() : ""));
|
||||||
|
binding.tvPODate.setText("Date: " + (po.getOrderDate() != null ? po.getOrderDate() : ""));
|
||||||
|
|
||||||
String status = po.getStatus() != null ? po.getStatus() : "";
|
String status = po.getStatus() != null ? po.getStatus() : "";
|
||||||
holder.tvStatus.setText(status);
|
binding.tvPOStatus.setText(status);
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case "Completed":
|
case "Completed":
|
||||||
holder.tvStatus.setBackgroundColor(Color.parseColor("#4CAF50"));
|
binding.tvPOStatus.setBackgroundColor(Color.parseColor("#4CAF50"));
|
||||||
break;
|
break;
|
||||||
case "Pending":
|
case "Pending":
|
||||||
holder.tvStatus.setBackgroundColor(Color.parseColor("#FF9800"));
|
binding.tvPOStatus.setBackgroundColor(Color.parseColor("#FF9800"));
|
||||||
break;
|
break;
|
||||||
case "Cancelled":
|
case "Cancelled":
|
||||||
holder.tvStatus.setBackgroundColor(Color.parseColor("#F44336"));
|
binding.tvPOStatus.setBackgroundColor(Color.parseColor("#F44336"));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
holder.tvStatus.setBackgroundColor(Color.parseColor("#9E9E9E"));
|
binding.tvPOStatus.setBackgroundColor(Color.parseColor("#9E9E9E"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,9 @@ import android.graphics.Color;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.example.petstoremobile.R;
|
import com.example.petstoremobile.databinding.ItemSaleBinding;
|
||||||
import com.example.petstoremobile.models.Sale;
|
import com.example.petstoremobile.models.Sale;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -26,46 +25,41 @@ public class SaleAdapter extends RecyclerView.Adapter<SaleAdapter.SaleViewHolder
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class SaleViewHolder extends RecyclerView.ViewHolder {
|
public static class SaleViewHolder extends RecyclerView.ViewHolder {
|
||||||
TextView tvSaleId, tvItemName, tvEmployeeName, tvSaleDate, tvTotal, tvPaymentMethod, tvRefundBadge;
|
final ItemSaleBinding binding;
|
||||||
|
|
||||||
public SaleViewHolder(@NonNull View v) {
|
public SaleViewHolder(@NonNull ItemSaleBinding binding) {
|
||||||
super(v);
|
super(binding.getRoot());
|
||||||
tvSaleId = v.findViewById(R.id.tvSaleId);
|
this.binding = binding;
|
||||||
tvItemName = v.findViewById(R.id.tvSaleItemName);
|
|
||||||
tvEmployeeName = v.findViewById(R.id.tvSaleEmployee);
|
|
||||||
tvSaleDate = v.findViewById(R.id.tvSaleDate);
|
|
||||||
tvTotal = v.findViewById(R.id.tvSaleTotal);
|
|
||||||
tvPaymentMethod = v.findViewById(R.id.tvSalePayment);
|
|
||||||
tvRefundBadge = v.findViewById(R.id.tvRefundBadge);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public SaleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public SaleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sale, parent, false);
|
ItemSaleBinding binding = ItemSaleBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||||
return new SaleViewHolder(v);
|
return new SaleViewHolder(binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull SaleViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull SaleViewHolder holder, int position) {
|
||||||
Sale sale = saleList.get(position);
|
Sale sale = saleList.get(position);
|
||||||
|
ItemSaleBinding binding = holder.binding;
|
||||||
|
|
||||||
holder.tvSaleId.setText("ID: " + sale.getSaleId());
|
binding.tvSaleId.setText("ID: " + sale.getSaleId());
|
||||||
holder.tvItemName.setText(sale.getItemName());
|
binding.tvSaleItemName.setText(sale.getItemName());
|
||||||
holder.tvEmployeeName.setText("By: " + sale.getEmployeeName());
|
binding.tvSaleEmployee.setText("By: " + sale.getEmployeeName());
|
||||||
holder.tvSaleDate.setText(sale.getSaleDate());
|
binding.tvSaleDate.setText(sale.getSaleDate());
|
||||||
holder.tvTotal.setText("$" + String.format("%.2f", sale.getTotal()));
|
binding.tvSaleTotal.setText("$" + String.format("%.2f", sale.getTotal()));
|
||||||
holder.tvPaymentMethod.setText(sale.getPaymentMethod());
|
binding.tvSalePayment.setText(sale.getPaymentMethod());
|
||||||
|
|
||||||
// Show refund badge if it's a refund
|
// Show refund badge if it's a refund
|
||||||
if (sale.isRefund()) {
|
if (sale.isRefund()) {
|
||||||
holder.tvRefundBadge.setVisibility(View.VISIBLE);
|
binding.tvRefundBadge.setVisibility(View.VISIBLE);
|
||||||
holder.tvRefundBadge.setBackgroundColor(Color.parseColor("#F44336"));
|
binding.tvRefundBadge.setBackgroundColor(Color.parseColor("#F44336"));
|
||||||
holder.tvTotal.setTextColor(Color.parseColor("#F44336"));
|
binding.tvSaleTotal.setTextColor(Color.parseColor("#F44336"));
|
||||||
} else {
|
} else {
|
||||||
holder.tvRefundBadge.setVisibility(View.GONE);
|
binding.tvRefundBadge.setVisibility(View.GONE);
|
||||||
holder.tvTotal.setTextColor(Color.parseColor("#4CAF50"));
|
binding.tvSaleTotal.setTextColor(Color.parseColor("#4CAF50"));
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.itemView.setOnClickListener(v -> saleClickListener.onSaleClick(position));
|
holder.itemView.setOnClickListener(v -> saleClickListener.onSaleClick(position));
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package com.example.petstoremobile.adapters;
|
package com.example.petstoremobile.adapters;
|
||||||
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.example.petstoremobile.R;
|
import com.example.petstoremobile.databinding.ItemServiceBinding;
|
||||||
import com.example.petstoremobile.dtos.ServiceDTO;
|
import com.example.petstoremobile.dtos.ServiceDTO;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -28,14 +26,11 @@ public class ServiceAdapter extends RecyclerView.Adapter<ServiceAdapter.ServiceV
|
|||||||
|
|
||||||
// Get the controls of each row in recycler view
|
// Get the controls of each row in recycler view
|
||||||
public static class ServiceViewHolder extends RecyclerView.ViewHolder {
|
public static class ServiceViewHolder extends RecyclerView.ViewHolder {
|
||||||
TextView tvServiceName, tvServiceDesc, tvServiceDuration, tvServicePrice;
|
final ItemServiceBinding binding;
|
||||||
|
|
||||||
public ServiceViewHolder(@NonNull View v) {
|
public ServiceViewHolder(@NonNull ItemServiceBinding binding) {
|
||||||
super(v);
|
super(binding.getRoot());
|
||||||
tvServiceName = v.findViewById(R.id.tvServiceName);
|
this.binding = binding;
|
||||||
tvServiceDesc = v.findViewById(R.id.tvServiceDesc);
|
|
||||||
tvServiceDuration = v.findViewById(R.id.tvServiceDuration);
|
|
||||||
tvServicePrice = v.findViewById(R.id.tvServicePrice);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,19 +38,20 @@ public class ServiceAdapter extends RecyclerView.Adapter<ServiceAdapter.ServiceV
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ServiceViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public ServiceViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_service, parent, false);
|
ItemServiceBinding binding = ItemServiceBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||||
return new ServiceViewHolder(v);
|
return new ServiceViewHolder(binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
//populate the row with service data
|
//populate the row with service data
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ServiceViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull ServiceViewHolder holder, int position) {
|
||||||
ServiceDTO service = serviceList.get(position);
|
ServiceDTO service = serviceList.get(position);
|
||||||
|
ItemServiceBinding binding = holder.binding;
|
||||||
|
|
||||||
holder.tvServiceName.setText(service.getServiceName());
|
binding.tvServiceName.setText(service.getServiceName());
|
||||||
holder.tvServiceDesc.setText(service.getServiceDesc());
|
binding.tvServiceDesc.setText(service.getServiceDesc());
|
||||||
holder.tvServiceDuration.setText("Duration: " + service.getServiceDuration() + " min");
|
binding.tvServiceDuration.setText("Duration: " + service.getServiceDuration() + " min");
|
||||||
holder.tvServicePrice.setText("$" + String.format("%.2f", service.getServicePrice()));
|
binding.tvServicePrice.setText("$" + String.format("%.2f", service.getServicePrice()));
|
||||||
|
|
||||||
//when a row is clicked, open the detail view
|
//when a row is clicked, open the detail view
|
||||||
holder.itemView.setOnClickListener(v -> serviceClickListener.onServiceClick(position));
|
holder.itemView.setOnClickListener(v -> serviceClickListener.onServiceClick(position));
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package com.example.petstoremobile.adapters;
|
package com.example.petstoremobile.adapters;
|
||||||
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.example.petstoremobile.R;
|
import com.example.petstoremobile.databinding.ItemSupplierBinding;
|
||||||
import com.example.petstoremobile.dtos.SupplierDTO;
|
import com.example.petstoremobile.dtos.SupplierDTO;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -28,14 +26,11 @@ public class SupplierAdapter extends RecyclerView.Adapter<SupplierAdapter.Suppli
|
|||||||
|
|
||||||
// Get the controls of each row in recycler view
|
// Get the controls of each row in recycler view
|
||||||
public static class SupplierViewHolder extends RecyclerView.ViewHolder {
|
public static class SupplierViewHolder extends RecyclerView.ViewHolder {
|
||||||
TextView tvSupCompany, tvSupContactName, tvSupEmail, tvSupPhone;
|
final ItemSupplierBinding binding;
|
||||||
|
|
||||||
public SupplierViewHolder(@NonNull View v) {
|
public SupplierViewHolder(@NonNull ItemSupplierBinding binding) {
|
||||||
super(v);
|
super(binding.getRoot());
|
||||||
tvSupCompany = v.findViewById(R.id.tvSupCompany);
|
this.binding = binding;
|
||||||
tvSupContactName = v.findViewById(R.id.tvSupContactName);
|
|
||||||
tvSupEmail = v.findViewById(R.id.tvSupEmail);
|
|
||||||
tvSupPhone = v.findViewById(R.id.tvSupPhone);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,19 +38,20 @@ public class SupplierAdapter extends RecyclerView.Adapter<SupplierAdapter.Suppli
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public SupplierViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public SupplierViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_supplier, parent, false);
|
ItemSupplierBinding binding = ItemSupplierBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||||
return new SupplierViewHolder(v);
|
return new SupplierViewHolder(binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
//populate the row with supplier data
|
//populate the row with supplier data
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull SupplierViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull SupplierViewHolder holder, int position) {
|
||||||
SupplierDTO supplier = supplierList.get(position);
|
SupplierDTO supplier = supplierList.get(position);
|
||||||
|
ItemSupplierBinding binding = holder.binding;
|
||||||
|
|
||||||
holder.tvSupCompany.setText(supplier.getSupCompany());
|
binding.tvSupCompany.setText(supplier.getSupCompany());
|
||||||
holder.tvSupContactName.setText(supplier.getSupContactFirstName() + " " + supplier.getSupContactLastName());
|
binding.tvSupContactName.setText(supplier.getSupContactFirstName() + " " + supplier.getSupContactLastName());
|
||||||
holder.tvSupEmail.setText(supplier.getSupEmail());
|
binding.tvSupEmail.setText(supplier.getSupEmail());
|
||||||
holder.tvSupPhone.setText(supplier.getSupPhone());
|
binding.tvSupPhone.setText(supplier.getSupPhone());
|
||||||
|
|
||||||
//when a row is clicked, open the detail view
|
//when a row is clicked, open the detail view
|
||||||
holder.itemView.setOnClickListener(v -> supplierClickListener.onSupplierClick(position));
|
holder.itemView.setOnClickListener(v -> supplierClickListener.onSupplierClick(position));
|
||||||
|
|||||||
@@ -55,6 +55,15 @@
|
|||||||
android:textColor="#666666"
|
android:textColor="#666666"
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvStaffName"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="2dp"
|
||||||
|
android:text="Staff: name"
|
||||||
|
android:textColor="#666666"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvDateTime"
|
android:id="@+id/tvDateTime"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
Reference in New Issue
Block a user