From 3ac35983599a183b0d922828896e3056f67a95ef Mon Sep 17 00:00:00 2001 From: riz081 Date: Sat, 28 Jun 2025 21:42:32 +0700 Subject: [PATCH] implement History --- .../bdkipoc/histori/HistoryActivity.java | 86 +++++-- app/src/main/res/drawable/card_background.xml | 14 +- app/src/main/res/layout/activity_history.xml | 231 +++++++++--------- app/src/main/res/layout/item_history.xml | 95 +++---- 4 files changed, 230 insertions(+), 196 deletions(-) diff --git a/app/src/main/java/com/example/bdkipoc/histori/HistoryActivity.java b/app/src/main/java/com/example/bdkipoc/histori/HistoryActivity.java index 3b17901..f576ac9 100644 --- a/app/src/main/java/com/example/bdkipoc/histori/HistoryActivity.java +++ b/app/src/main/java/com/example/bdkipoc/histori/HistoryActivity.java @@ -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 historyList; - private ImageView btnBack; + private LinearLayout backNavigation; // Store full data for detail view private static List 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,14 +161,10 @@ public class HistoryActivity extends AppCompatActivity { historyItem.setFullDate(transactionDate); historyItem.setChannelCode(channelCode); - // Add to full data + // Add to both lists (since we're limiting to 10 in API call) + historyList.add(historyItem); fullHistoryData.add(historyItem); - // Add first 10 to display list - if (i < 10) { - historyList.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 - - - - \ No newline at end of file + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_history.xml b/app/src/main/res/layout/activity_history.xml index c8d7652..520d37b 100644 --- a/app/src/main/res/layout/activity_history.xml +++ b/app/src/main/res/layout/activity_history.xml @@ -3,137 +3,125 @@ 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"> - - + + + + + android:layout_height="wrap_content" + android:layout_marginStart="16dp" + android:layout_marginTop="-70dp" + android:layout_marginEnd="16dp" + android:layout_marginBottom="11dp" + app:cardCornerRadius="16dp" + app:cardElevation="6dp"> - - - - - - - - - + android:layout_height="wrap_content" + android:background="@drawable/card_background" + android:padding="16dp"> - + + - + + - - + + - + + - + + - + + - - - - - - - - - - - - + + + @@ -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" /> \ No newline at end of file diff --git a/app/src/main/res/layout/item_history.xml b/app/src/main/res/layout/item_history.xml index 26e2aa0..50be5b3 100644 --- a/app/src/main/res/layout/item_history.xml +++ b/app/src/main/res/layout/item_history.xml @@ -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"> + android:orientation="vertical"> - + android:orientation="horizontal" + android:padding="12dp" + android:gravity="center_vertical"> + + android:layout_weight="2" + android:text="H:mm, dd MMM yyyy" + android:textColor="#000000" + android:fontFamily="@font/inter" + android:textStyle="normal" + android:textSize="10sp" /> + - - - - - + 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" /> + + android:layout_weight="1.5" + android:text="-" + android:textColor="#000000" + android:fontFamily="@font/inter" + android:textStyle="normal" + android:textSize="10sp" + android:gravity="center_horizontal" /> + + - - - - \ No newline at end of file + + +