This commit is contained in:
riz081 2025-08-08 15:10:48 +07:00
parent a49aab14f8
commit dd57975908

View File

@ -156,7 +156,7 @@ public class HistoryActivity extends AppCompatActivity {
historyItem.setDate(formatDate(transactionDate)); historyItem.setDate(formatDate(transactionDate));
historyItem.setAmount((long) amountValue); historyItem.setAmount((long) amountValue);
historyItem.setChannelName(formatChannelName(channelCode)); historyItem.setChannelName(formatChannelName(channelCode));
historyItem.setStatus(status); historyItem.setStatus(status.toUpperCase()); // Ensure uppercase for consistency
historyItem.setReferenceId(referenceId); historyItem.setReferenceId(referenceId);
historyItem.setFullDate(transactionDate); historyItem.setFullDate(transactionDate);
historyItem.setChannelCode(channelCode); historyItem.setChannelCode(channelCode);
@ -194,17 +194,21 @@ public class HistoryActivity extends AppCompatActivity {
JSONObject item = dataArray.getJSONObject(i); JSONObject item = dataArray.getJSONObject(i);
String amount = item.getString("amount"); String amount = item.getString("amount");
String status = item.getString("status");
// Parse amount safely // Only count if status is settlement or success
double amountValue = 0; if ("SETTLEMENT".equalsIgnoreCase(status) || "SUCCESS".equalsIgnoreCase(status)) {
try { // Parse amount safely
amountValue = Double.parseDouble(amount); double amountValue = 0;
} catch (NumberFormatException e) { try {
amountValue = 0; amountValue = Double.parseDouble(amount);
} catch (NumberFormatException e) {
amountValue = 0;
}
totalAmount += (long) amountValue;
totalTransactions++;
} }
totalAmount += (long) amountValue;
totalTransactions++;
} }
final long finalTotalAmount = totalAmount; final long finalTotalAmount = totalAmount;
@ -509,17 +513,23 @@ class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.HistoryViewHold
holder.tvAmount.setText("Rp. " + formatCurrency(item.getAmount())); holder.tvAmount.setText("Rp. " + formatCurrency(item.getAmount()));
holder.tvChannel.setText(item.getChannelName()); holder.tvChannel.setText(item.getChannelName());
// Set status color and text // Set status color and text based on API response
String status = item.getStatus(); String status = item.getStatus();
if ("SUCCESS".equals(status)) { if ("SETTLEMENT".equalsIgnoreCase(status)) {
holder.tvStatus.setText("Berhasil"); holder.tvStatus.setText("Success");
holder.tvStatus.setTextColor(Color.parseColor("#4CAF50")); // Green holder.tvStatus.setTextColor(Color.parseColor("#4CAF50")); // Green
} else if ("FAILED".equals(status)) { } else if ("SUCCESS".equalsIgnoreCase(status)) {
holder.tvStatus.setText("Gagal"); holder.tvStatus.setText("Success");
holder.tvStatus.setTextColor(Color.parseColor("#4CAF50")); // Green
} else if ("EXPIRE".equalsIgnoreCase(status)) {
holder.tvStatus.setText("Expired");
holder.tvStatus.setTextColor(Color.parseColor("#F44336")); // Red
} else if ("FAILED".equalsIgnoreCase(status)) {
holder.tvStatus.setText("Failed");
holder.tvStatus.setTextColor(Color.parseColor("#F44336")); // Red holder.tvStatus.setTextColor(Color.parseColor("#F44336")); // Red
} else { } else {
holder.tvStatus.setText("Tertunda"); holder.tvStatus.setText("Pending");
holder.tvStatus.setTextColor(Color.parseColor("#FF9800")); // Orange holder.tvStatus.setTextColor(Color.parseColor("#3141FF")); // Blue
} }
} }