implement History

This commit is contained in:
riz081 2025-06-28 21:42:32 +07:00
parent 6660fca373
commit 3ac3598359
4 changed files with 230 additions and 196 deletions

View File

@ -8,8 +8,10 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.graphics.Color;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -39,12 +41,12 @@ public class HistoryActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private HistoryAdapter adapter;
private List<HistoryItem> historyList;
private ImageView btnBack;
private LinearLayout backNavigation;
// Store full data for detail view
private static List<HistoryItem> fullHistoryData = new ArrayList<>();
private String API_URL = "https://be-edc.msvc.app/transactions?page=0&limit=50&sortOrder=DESC&from_date=2025-05-10&to_date=2025-05-21&location_id=0&merchant_id=0&sortColumn=id";
private String API_URL;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -53,17 +55,37 @@ public class HistoryActivity extends AppCompatActivity {
initViews();
setupRecyclerView();
buildApiUrl();
fetchApiData();
setupClickListeners();
}
private void buildApiUrl() {
// Option 1: Get today's date (current implementation)
// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
// String todayDate = dateFormat.format(new Date());
// Option 2: Set specific date (uncomment and modify if needed)
String specificDate = "2025-06-27"; // Format: yyyy-MM-dd
String todayDate = specificDate;
// Option 3: Set date using Calendar for specific date
// Calendar calendar = Calendar.getInstance();
// calendar.set(2025, Calendar.JUNE, 27); // Year, Month (0-based), Day
// String todayDate = dateFormat.format(calendar.getTime());
// Build API URL with date as both from_date and to_date, and limit=10
API_URL = "https://be-edc.msvc.app/transactions?page=0&limit=10&sortOrder=DESC&from_date="
+ todayDate + "&to_date=" + todayDate + "&location_id=0&merchant_id=0&tid=&mid=&sortColumn=id";
}
private void initViews() {
tvTotalAmount = findViewById(R.id.tv_total_amount);
tvTotalTransactions = findViewById(R.id.tv_total_transactions);
btnLihatDetailTop = findViewById(R.id.btn_lihat_detail);
btnLihatDetailBottom = findViewById(R.id.btn_lihat_detail_bottom);
recyclerView = findViewById(R.id.recycler_view);
btnBack = findViewById(R.id.btn_back);
backNavigation = findViewById(R.id.back_navigation);
historyList = new ArrayList<>();
}
@ -75,7 +97,7 @@ public class HistoryActivity extends AppCompatActivity {
}
private void setupClickListeners() {
btnBack.setOnClickListener(new View.OnClickListener() {
backNavigation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
@ -139,13 +161,9 @@ public class HistoryActivity extends AppCompatActivity {
historyItem.setFullDate(transactionDate);
historyItem.setChannelCode(channelCode);
// Add to full data
fullHistoryData.add(historyItem);
// Add first 10 to display list
if (i < 10) {
// Add to both lists (since we're limiting to 10 in API call)
historyList.add(historyItem);
}
fullHistoryData.add(historyItem);
totalAmountArray[0] += (long) amountValue;
totalTransactionsArray[0]++;
@ -180,24 +198,35 @@ public class HistoryActivity extends AppCompatActivity {
historyList.clear();
fullHistoryData.clear();
// Create sample data
// Get today's date for sample data
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault());
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
Date now = new Date();
String todayDate = dateFormat.format(now);
String currentTime = timeFormat.format(now);
// Create sample data with today's date - limit to 10 items
HistoryItem[] sampleData = {
new HistoryItem("03:44", "11-05-2025", 2018619, "Kredit", "FAILED", "197870"),
new HistoryItem("03:10", "12-05-2025", 3974866, "QRIS", "SUCCESS", "053059"),
new HistoryItem("15:17", "13-05-2025", 2418167, "QRIS", "FAILED", "668320"),
new HistoryItem("12:09", "11-05-2025", 3429230, "Debit", "FAILED", "454790"),
new HistoryItem("08:39", "10-05-2025", 4656447, "QRIS", "FAILED", "454248"),
new HistoryItem("00:35", "12-05-2025", 3507704, "QRIS", "FAILED", "301644"),
new HistoryItem("22:43", "13-05-2025", 4277904, "Debit", "SUCCESS", "388709"),
new HistoryItem("18:16", "11-05-2025", 4456904, "Debit", "FAILED", "986861")
new HistoryItem("08:30", todayDate, 1500000, "QRIS", "SUCCESS", "TXN001"),
new HistoryItem("09:15", todayDate, 750000, "Debit", "SUCCESS", "TXN002"),
new HistoryItem("10:20", todayDate, 2250000, "QRIS", "FAILED", "TXN003"),
new HistoryItem("11:45", todayDate, 980000, "Kredit", "SUCCESS", "TXN004"),
new HistoryItem("12:30", todayDate, 1800000, "QRIS", "SUCCESS", "TXN005"),
new HistoryItem("13:15", todayDate, 650000, "Debit", "FAILED", "TXN006"),
new HistoryItem("14:00", todayDate, 3200000, "QRIS", "SUCCESS", "TXN007"),
new HistoryItem("15:30", todayDate, 1100000, "Kredit", "SUCCESS", "TXN008"),
new HistoryItem("16:45", todayDate, 890000, "Debit", "FAILED", "TXN009"),
new HistoryItem("17:20", todayDate, 2100000, "QRIS", "SUCCESS", "TXN010")
};
long totalAmount = 0;
for (HistoryItem item : sampleData) {
historyList.add(item);
fullHistoryData.add(item);
totalAmount += item.getAmount();
}
tvTotalAmount.setText("RP 36.166.829");
tvTotalAmount.setText("RP " + formatCurrency(totalAmount));
tvTotalTransactions.setText("10");
adapter.notifyDataSetChanged();
@ -235,7 +264,9 @@ public class HistoryActivity extends AppCompatActivity {
Date date = inputFormat.parse(isoDate);
return outputFormat.format(date);
} catch (ParseException e) {
return "01-01-2025";
// Return today's date as fallback
SimpleDateFormat fallbackFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault());
return fallbackFormat.format(new Date());
}
}
@ -366,21 +397,24 @@ class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.HistoryViewHold
public void onBindViewHolder(@NonNull HistoryViewHolder holder, int position) {
HistoryItem item = historyList.get(position);
holder.tvTime.setText(item.getTime() + ", " + item.getDate());
// Format time with dots instead of colons (09.00 instead of 09:00)
String formattedTime = item.getTime().replace(":", ".");
holder.tvTime.setText(formattedTime + ", " + item.getDate());
holder.tvAmount.setText("Rp. " + formatCurrency(item.getAmount()));
holder.tvChannel.setText(item.getChannelName());
// Set status color
// Set status color and text
String status = item.getStatus();
if ("SUCCESS".equals(status)) {
holder.tvStatus.setText("Berhasil");
holder.tvStatus.setTextColor(0xFF4CAF50); // Green
holder.tvStatus.setTextColor(Color.parseColor("#4CAF50")); // Green
} else if ("FAILED".equals(status)) {
holder.tvStatus.setText("Gagal");
holder.tvStatus.setTextColor(0xFFF44336); // Red
holder.tvStatus.setTextColor(Color.parseColor("#F44336")); // Red
} else {
holder.tvStatus.setText("Tertunda");
holder.tvStatus.setTextColor(0xFFFF9800); // Orange
holder.tvStatus.setTextColor(Color.parseColor("#FF9800")); // Orange
}
}

View File

@ -1,6 +1,12 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#3498DB" />
<corners android:radius="12dp" />
<stroke android:width="0dp" />
<!-- Warna solid (biru cerah seperti #4299E1) -->
<solid android:color="#4299E1" />
<!-- Sudut melengkung -->
<corners android:radius="16dp" />
<!-- Hilangkan stroke jika tidak dibutuhkan -->
<stroke android:width="0dp" android:color="#00000000" />
</shape>

View File

@ -3,136 +3,124 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F5F5F5"
android:background="#FFFFFF"
android:orientation="vertical">
<!-- Header with red background -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#E53E3E">
<!-- Back button -->
<ImageView
android:id="@+id/btn_back"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentStart="true"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:padding="4dp"
android:src="@android:drawable/ic_menu_revert"
app:tint="@android:color/white" />
<!-- Title -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_toEndOf="@id/btn_back"
android:text="Kembali"
android:textColor="@android:color/white"
android:textSize="16sp" />
<!-- Custom AppBar -->
<include layout="@layout/component_appbar" />
<!-- History Card -->
<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="120dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="64dp"
android:layout_marginTop="-70dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:cardCornerRadius="12dp"
app:cardElevation="4dp">
android:layout_marginBottom="11dp"
app:cardCornerRadius="16dp"
app:cardElevation="6dp">
<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4299E1"
android:orientation="vertical"
android:layout_height="wrap_content"
android:background="@drawable/card_background"
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">
<!-- Judul -->
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Transaksi Hari Ini"
android:textColor="@android:color/white"
android:textSize="14sp"
android:textStyle="bold" />
android:textSize="20sp"
android:fontFamily="@font/inter"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<!-- Lihat Detail -->
<TextView
android:id="@+id/btn_lihat_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="Lihat Detail"
android:textColor="@android:color/white"
android:textSize="10sp"
android:fontFamily="@font/inter"
android:textStyle="normal"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:padding="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintVertical_bias="0.5" />
<!-- Label Total Transaksi -->
<TextView
android:id="@+id/label_total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Total Transaksi"
android:textColor="#E0FFFFFF"
android:textSize="12sp" />
android:textSize="10sp"
android:fontFamily="@font/inter"
android:textStyle="normal"
app:layout_constraintTop_toBottomOf="@id/title"
app:layout_constraintStart_toStartOf="parent" />
<!-- Nilai Total Transaksi -->
<TextView
android:id="@+id/tv_total_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="RP 4.500.000"
android:text="RP 0"
android:textColor="@android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
android:fontFamily="@font/inter"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="@id/label_total"
app:layout_constraintStart_toStartOf="parent" />
<!-- Label Jumlah Transaksi -->
<TextView
android:id="@+id/label_jumlah"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginTop="12dp"
android:text="Jumlah Transaksi"
android:textColor="#E0FFFFFF"
android:textSize="12sp" />
android:fontFamily="@font/inter"
android:textStyle="normal"
android:textSize="10sp"
app:layout_constraintTop_toBottomOf="@id/tv_total_amount"
app:layout_constraintStart_toStartOf="parent" />
<!-- Nilai Jumlah Transaksi -->
<TextView
android:id="@+id/tv_total_transactions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="30"
android:text="0"
android:textColor="@android:color/white"
android:textSize="16sp"
android:textStyle="bold" />
android:textSize="20sp"
android:fontFamily="@font/inter"
android:textStyle="bold"
android:layout_marginTop="4dp"
app:layout_constraintTop_toBottomOf="@id/label_jumlah"
app:layout_constraintStart_toStartOf="parent" />
</LinearLayout>
<TextView
android:id="@+id/btn_lihat_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:padding="8dp"
android:text="Lihat Detail"
android:textColor="@android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
<!-- Content -->
<LinearLayout
@ -145,10 +133,11 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginBottom="2dp"
android:text="Transaksi Terbaru"
android:textColor="#333333"
android:textColor="#000000"
android:textSize="16sp"
android:fontFamily="@font/inter"
android:textStyle="bold" />
<!-- Transaction List -->
@ -170,6 +159,8 @@
android:text="Lihat Detail"
android:textColor="@android:color/white"
android:textSize="16sp"
android:textStyle="bold" />
android:fontFamily="@font/inter"
android:textStyle="bold"
app:cornerRadius="8dp" />
</LinearLayout>

View File

@ -3,67 +3,70 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:padding="16dp">
<!-- Left Content -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="12dp"
android:gravity="center_vertical">
<!-- Tanggal -->
<TextView
android:id="@+id/tv_time"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="09:00, 07-05-2025"
android:textColor="#333333"
android:textSize="14sp" />
android:layout_weight="2"
android:text="H:mm, dd MMM yyyy"
android:textColor="#000000"
android:fontFamily="@font/inter"
android:textStyle="normal"
android:textSize="10sp" />
<!-- Jumlah -->
<TextView
android:id="@+id/tv_amount"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="Rp. 78.000"
android:textColor="#333333"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<!-- Center Content -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="16dp"
android:orientation="vertical">
android:layout_weight="2"
android:text="Rp. 0"
android:textColor="#000000"
android:fontFamily="@font/inter"
android:textStyle="normal"
android:textSize="10sp"
android:gravity="center_horizontal" />
<!-- Channel -->
<TextView
android:id="@+id/tv_channel"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Kredit"
android:textColor="#333333"
android:textSize="14sp"
android:textStyle="bold" />
android:layout_weight="1.5"
android:text="-"
android:textColor="#000000"
android:fontFamily="@font/inter"
android:textStyle="normal"
android:textSize="10sp"
android:gravity="center_horizontal" />
</LinearLayout>
<!-- Right Content -->
<!-- Status -->
<TextView
android:id="@+id/tv_status"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="16dp"
android:text="Berhasil"
android:textColor="#4CAF50"
android:textSize="12sp"
android:textStyle="bold" />
android:layout_weight="1.5"
android:text="-"
android:textColor="#000000"
android:fontFamily="@font/inter"
android:textStyle="normal"
android:textSize="10sp"
android:gravity="end" />
</LinearLayout>
<!-- Garis pemisah -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#DDDDDD" />
</LinearLayout>