From 0e86870b8bb2774dc44fa7d476252acbd917cf16 Mon Sep 17 00:00:00 2001 From: riz081 Date: Tue, 5 Aug 2025 14:13:12 +0700 Subject: [PATCH] solve history --- .../bdkipoc/histori/HistoryActivity.java | 38 +++++++++---------- .../bdkipoc/histori/HistoryListActivity.java | 23 +++++------ app/src/main/res/layout/item_history.xml | 6 +-- app/src/main/res/layout/item_history_list.xml | 6 +-- 4 files changed, 36 insertions(+), 37 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 ee79124..c76126d 100644 --- a/app/src/main/java/com/example/bdkipoc/histori/HistoryActivity.java +++ b/app/src/main/java/com/example/bdkipoc/histori/HistoryActivity.java @@ -1,4 +1,5 @@ package com.example.bdkipoc.histori; +import com.example.bdkipoc.BuildConfig; import android.content.Intent; import android.os.AsyncTask; @@ -31,6 +32,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; +import java.util.TimeZone; import com.example.bdkipoc.R; @@ -65,25 +67,14 @@ public class HistoryActivity extends AppCompatActivity { } 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=" + // Gunakan BuildConfig untuk base URL + API_URL = BuildConfig.BACKEND_BASE_URL + "/transactions?page=0&limit=10&sortOrder=DESC&from_date=" + todayDate + "&to_date=" + todayDate + "&location_id=0&merchant_id=0&tid=&mid=&sortColumn=id"; - // Build Summary API URL for getting total amount and transaction count - SUMMARY_API_URL = "https://be-edc.msvc.app/transactions/list?from_date=" + SUMMARY_API_URL = BuildConfig.BACKEND_BASE_URL + "/transactions/list?from_date=" + todayDate + "&to_date=" + todayDate + "&location_id=0&merchant_id=0"; } @@ -303,22 +294,29 @@ public class HistoryActivity extends AppCompatActivity { private String formatTime(String isoDate) { try { SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault()); - SimpleDateFormat outputFormat = new SimpleDateFormat("HH:mm", Locale.getDefault()); + inputFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + + SimpleDateFormat outputFormat = new SimpleDateFormat("HH.mm.ss", Locale.getDefault()); + outputFormat.setTimeZone(TimeZone.getDefault()); + Date date = inputFormat.parse(isoDate); return outputFormat.format(date); } catch (ParseException e) { - return "00:00"; + return "00.00.00"; } } - + private String formatDate(String isoDate) { try { SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault()); + inputFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + SimpleDateFormat outputFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()); + outputFormat.setTimeZone(TimeZone.getDefault()); + Date date = inputFormat.parse(isoDate); return outputFormat.format(date); } catch (ParseException e) { - // Return today's date as fallback SimpleDateFormat fallbackFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()); return fallbackFormat.format(new Date()); } @@ -505,8 +503,8 @@ class HistoryAdapter extends RecyclerView.Adapter - + - + \ No newline at end of file diff --git a/app/src/main/res/layout/item_history_list.xml b/app/src/main/res/layout/item_history_list.xml index cbe196f..25fceae 100644 --- a/app/src/main/res/layout/item_history_list.xml +++ b/app/src/main/res/layout/item_history_list.xml @@ -13,13 +13,13 @@ android:paddingVertical="12dp" android:gravity="center_vertical"> - + @@ -66,4 +66,4 @@ android:layout_width="match_parent" android:layout_height="1dp" android:background="#DDDDDD" /> - + \ No newline at end of file