fix list
This commit is contained in:
parent
b0ee2e8ee6
commit
da8bcf17cc
@ -9,6 +9,7 @@ import android.view.MenuItem;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -42,6 +43,9 @@ import java.util.Set;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import android.app.DatePickerDialog;
|
||||||
|
import android.widget.DatePicker;
|
||||||
|
|
||||||
public class TransactionActivity extends AppCompatActivity implements TransactionAdapter.OnPrintClickListener {
|
public class TransactionActivity extends AppCompatActivity implements TransactionAdapter.OnPrintClickListener {
|
||||||
private RecyclerView recyclerView;
|
private RecyclerView recyclerView;
|
||||||
@ -65,6 +69,11 @@ public class TransactionActivity extends AppCompatActivity implements Transactio
|
|||||||
private Set<String> processedReferences = new HashSet<>();
|
private Set<String> processedReferences = new HashSet<>();
|
||||||
private SharedPreferences prefs;
|
private SharedPreferences prefs;
|
||||||
|
|
||||||
|
// ✅ DATE FILTER VARIABLES
|
||||||
|
private String fromDate = "";
|
||||||
|
private String toDate = "";
|
||||||
|
private TextView filterButtonText;
|
||||||
|
|
||||||
// ✅ UPDATED PAGINATION VARIABLES
|
// ✅ UPDATED PAGINATION VARIABLES
|
||||||
private int currentPage = 1; // Start from page 1 instead of 0
|
private int currentPage = 1; // Start from page 1 instead of 0
|
||||||
private final int itemsPerPage = 15; // ✅ 15 items per page as requested
|
private final int itemsPerPage = 15; // ✅ 15 items per page as requested
|
||||||
@ -131,10 +140,16 @@ public class TransactionActivity extends AppCompatActivity implements Transactio
|
|||||||
private void setupToolbar() {
|
private void setupToolbar() {
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
|
// Hide default title since we're using custom layout
|
||||||
if (getSupportActionBar() != null) {
|
if (getSupportActionBar() != null) {
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
||||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup custom back button
|
||||||
|
ImageView backButton = findViewById(R.id.backButton);
|
||||||
|
backButton.setOnClickListener(v -> finish());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupRecyclerView() {
|
private void setupRecyclerView() {
|
||||||
@ -171,8 +186,20 @@ public class TransactionActivity extends AppCompatActivity implements Transactio
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Filter button click
|
// Filter button click
|
||||||
findViewById(R.id.filterButton).setOnClickListener(v -> {
|
LinearLayout filterButton = findViewById(R.id.filterButton);
|
||||||
Toast.makeText(this, "Filter clicked", Toast.LENGTH_SHORT).show();
|
filterButtonText = (TextView) filterButton.findViewById(R.id.filterButtonText);
|
||||||
|
|
||||||
|
filterButton.setOnClickListener(v -> {
|
||||||
|
showDateRangePickerDialog();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Long press to clear filter
|
||||||
|
filterButton.setOnLongClickListener(v -> {
|
||||||
|
if (!fromDate.isEmpty() || !toDate.isEmpty()) {
|
||||||
|
clearDateFilter();
|
||||||
|
Toast.makeText(this, "Date filter cleared", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +230,145 @@ public class TransactionActivity extends AppCompatActivity implements Transactio
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ NEW METHOD: Navigate to specific page
|
// ✅ NEW METHOD: Show date range picker dialog
|
||||||
|
private void showDateRangePickerDialog() {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
|
||||||
|
// First, pick FROM date
|
||||||
|
DatePickerDialog fromDatePicker = new DatePickerDialog(this,
|
||||||
|
(view, year, month, dayOfMonth) -> {
|
||||||
|
Calendar fromCal = Calendar.getInstance();
|
||||||
|
fromCal.set(year, month, dayOfMonth);
|
||||||
|
|
||||||
|
// Format for API (yyyy-MM-dd)
|
||||||
|
SimpleDateFormat apiFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
|
||||||
|
fromDate = apiFormat.format(fromCal.getTime());
|
||||||
|
|
||||||
|
// Now pick TO date
|
||||||
|
showToDatePicker(fromCal);
|
||||||
|
},
|
||||||
|
calendar.get(Calendar.YEAR),
|
||||||
|
calendar.get(Calendar.MONTH),
|
||||||
|
calendar.get(Calendar.DAY_OF_MONTH)
|
||||||
|
);
|
||||||
|
|
||||||
|
fromDatePicker.setTitle("Select From Date");
|
||||||
|
fromDatePicker.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ NEW METHOD: Show TO date picker
|
||||||
|
private void showToDatePicker(Calendar fromCal) {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
|
||||||
|
DatePickerDialog toDatePicker = new DatePickerDialog(this,
|
||||||
|
(view, year, month, dayOfMonth) -> {
|
||||||
|
Calendar toCal = Calendar.getInstance();
|
||||||
|
toCal.set(year, month, dayOfMonth);
|
||||||
|
|
||||||
|
// Validate date range
|
||||||
|
if (toCal.before(fromCal)) {
|
||||||
|
Toast.makeText(this, "To date cannot be before from date", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format for API (yyyy-MM-dd)
|
||||||
|
SimpleDateFormat apiFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
|
||||||
|
toDate = apiFormat.format(toCal.getTime());
|
||||||
|
|
||||||
|
// Format for display (compact format)
|
||||||
|
SimpleDateFormat displayFormat = new SimpleDateFormat("dd/MM", Locale.getDefault());
|
||||||
|
String fromDisplay = displayFormat.format(fromCal.getTime());
|
||||||
|
String toDisplay = displayFormat.format(toCal.getTime());
|
||||||
|
|
||||||
|
// Add year if different years
|
||||||
|
SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy", Locale.getDefault());
|
||||||
|
String fromYear = yearFormat.format(fromCal.getTime());
|
||||||
|
String toYear = yearFormat.format(toCal.getTime());
|
||||||
|
|
||||||
|
String dateRangeText;
|
||||||
|
if (fromYear.equals(toYear)) {
|
||||||
|
// Same year: "01/04 - 30/04"
|
||||||
|
dateRangeText = fromDisplay + " - " + toDisplay;
|
||||||
|
} else {
|
||||||
|
// Different years: "01/04/24 - 30/04/25"
|
||||||
|
SimpleDateFormat shortYearFormat = new SimpleDateFormat("dd/MM/yy", Locale.getDefault());
|
||||||
|
String fromDisplayWithYear = shortYearFormat.format(fromCal.getTime());
|
||||||
|
String toDisplayWithYear = shortYearFormat.format(toCal.getTime());
|
||||||
|
dateRangeText = fromDisplayWithYear + " - " + toDisplayWithYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update filter button text
|
||||||
|
updateFilterButtonText(dateRangeText);
|
||||||
|
|
||||||
|
// Apply filter
|
||||||
|
applyDateFilter();
|
||||||
|
},
|
||||||
|
calendar.get(Calendar.YEAR),
|
||||||
|
calendar.get(Calendar.MONTH),
|
||||||
|
calendar.get(Calendar.DAY_OF_MONTH)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set minimum date to fromDate
|
||||||
|
toDatePicker.getDatePicker().setMinDate(fromCal.getTimeInMillis());
|
||||||
|
toDatePicker.setTitle("Select To Date");
|
||||||
|
toDatePicker.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ NEW METHOD: Update filter button text with smart formatting
|
||||||
|
private void updateFilterButtonText(String dateRangeText) {
|
||||||
|
if (filterButtonText != null) {
|
||||||
|
// Smart text formatting for better display
|
||||||
|
String displayText;
|
||||||
|
|
||||||
|
if (dateRangeText.length() > 15) {
|
||||||
|
// For long date ranges, use compact format
|
||||||
|
String[] dates = dateRangeText.split(" - ");
|
||||||
|
if (dates.length == 2) {
|
||||||
|
// Convert "01/04/2025 - 30/04/2025" to "01/04\n30/04"
|
||||||
|
String fromShort = dates[0].substring(0, 5); // Get "01/04"
|
||||||
|
String toShort = dates[1].substring(0, 5); // Get "30/04"
|
||||||
|
displayText = fromShort + "\n" + toShort;
|
||||||
|
} else {
|
||||||
|
displayText = dateRangeText;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
displayText = dateRangeText;
|
||||||
|
}
|
||||||
|
|
||||||
|
filterButtonText.setText(displayText);
|
||||||
|
filterButtonText.setTextColor(getResources().getColor(android.R.color.holo_blue_dark));
|
||||||
|
filterButtonText.setTextSize(12); // Smaller text when filter is active
|
||||||
|
|
||||||
|
Log.d("TransactionActivity", "🎨 Filter button updated: " + displayText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ NEW METHOD: Apply date filter
|
||||||
|
private void applyDateFilter() {
|
||||||
|
Log.d("TransactionActivity", "🗓️ Applying date filter: " + fromDate + " to " + toDate);
|
||||||
|
|
||||||
|
// Reset to first page and reload data
|
||||||
|
currentPage = 1;
|
||||||
|
refreshTransactions();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ NEW METHOD: Clear date filter
|
||||||
|
private void clearDateFilter() {
|
||||||
|
fromDate = "";
|
||||||
|
toDate = "";
|
||||||
|
|
||||||
|
if (filterButtonText != null) {
|
||||||
|
filterButtonText.setText("Filter");
|
||||||
|
filterButtonText.setTextColor(getResources().getColor(android.R.color.darker_gray));
|
||||||
|
filterButtonText.setTextSize(14); // Reset to normal size
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.d("TransactionActivity", "🗓️ Date filter cleared");
|
||||||
|
|
||||||
|
// Reload data without date filter
|
||||||
|
currentPage = 1;
|
||||||
|
refreshTransactions();
|
||||||
|
}
|
||||||
private void goToPage(int page) {
|
private void goToPage(int page) {
|
||||||
if (page < 1 || page > totalPages || page == currentPage || isLoading) {
|
if (page < 1 || page > totalPages || page == currentPage || isLoading) {
|
||||||
return;
|
return;
|
||||||
@ -439,14 +604,15 @@ public class TransactionActivity extends AppCompatActivity implements Transactio
|
|||||||
protected List<Transaction> doInBackground(Void... voids) {
|
protected List<Transaction> doInBackground(Void... voids) {
|
||||||
List<Transaction> result = new ArrayList<>();
|
List<Transaction> result = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
// ✅ PAGINATION API CALL: Use page-based API call
|
// ✅ PAGINATION API CALL: Use page-based API call with date filter
|
||||||
int apiPage = pageToLoad - 1; // API uses 0-based indexing
|
int apiPage = pageToLoad - 1; // API uses 0-based indexing
|
||||||
|
|
||||||
String urlString = "https://be-edc.msvc.app/transactions?page=" + apiPage +
|
String urlString = "https://be-edc.msvc.app/transactions?page=" + apiPage +
|
||||||
"&limit=" + itemsPerPage + "&sortOrder=DESC&from_date=&to_date=&location_id=0&merchant_id=0&tid=73001500&mid=71000026521&sortColumn=created_at";
|
"&limit=" + itemsPerPage + "&sortOrder=DESC&from_date=" + fromDate + "&to_date=" + toDate + "&location_id=0&merchant_id=0&tid=73001500&mid=71000026521&sortColumn=created_at";
|
||||||
|
|
||||||
Log.d("TransactionActivity", "🔍 Fetching transactions page " + pageToLoad +
|
Log.d("TransactionActivity", "🔍 Fetching transactions page " + pageToLoad +
|
||||||
" (API page " + apiPage + ") with limit " + itemsPerPage + " - SORT: DESC by created_at");
|
" (API page " + apiPage + ") with limit " + itemsPerPage + " - SORT: DESC by created_at" +
|
||||||
|
" - Date Filter: " + fromDate + " to " + toDate);
|
||||||
|
|
||||||
URI uri = new URI(urlString);
|
URI uri = new URI(urlString);
|
||||||
URL url = uri.toURL();
|
URL url = uri.toURL();
|
||||||
|
@ -6,16 +6,84 @@
|
|||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:elevation="0dp"
|
||||||
|
app:elevation="0dp">
|
||||||
|
|
||||||
|
<!-- Status Bar Background -->
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:background="#F44336" />
|
||||||
|
|
||||||
|
<!-- Main Toolbar -->
|
||||||
<androidx.appcompat.widget.Toolbar
|
<androidx.appcompat.widget.Toolbar
|
||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="56dp"
|
||||||
android:background="#F44336"
|
android:background="#F44336"
|
||||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||||
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
|
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
|
||||||
app:title="CETAK ULANG STRUK" />
|
app:contentInsetStart="0dp"
|
||||||
|
app:contentInsetLeft="0dp">
|
||||||
|
|
||||||
|
<!-- Custom toolbar content -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingLeft="16dp"
|
||||||
|
android:paddingRight="16dp">
|
||||||
|
|
||||||
|
<!-- Back Button -->
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/backButton"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:src="@android:drawable/ic_menu_revert"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||||
|
android:padding="4dp"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:rotation="180" />
|
||||||
|
|
||||||
|
<!-- Title -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Cetak Ulang Struk"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:textStyle="normal"
|
||||||
|
android:fontFamily="sans-serif-medium" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</androidx.appcompat.widget.Toolbar>
|
||||||
|
|
||||||
|
<!-- Title Section (outside toolbar) -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@android:color/white"
|
||||||
|
android:paddingLeft="16dp"
|
||||||
|
android:paddingRight="16dp"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:paddingBottom="8dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Cetak Ulang Struk"
|
||||||
|
android:textColor="#333333"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:fontFamily="sans-serif" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
@ -31,7 +99,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:padding="20dp"
|
android:padding="16dp"
|
||||||
android:background="@android:color/white"
|
android:background="@android:color/white"
|
||||||
android:gravity="center_vertical">
|
android:gravity="center_vertical">
|
||||||
|
|
||||||
@ -45,7 +113,7 @@
|
|||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:paddingLeft="20dp"
|
android:paddingLeft="20dp"
|
||||||
android:paddingRight="20dp"
|
android:paddingRight="20dp"
|
||||||
android:layout_marginEnd="16dp">
|
android:layout_marginEnd="12dp">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
@ -76,24 +144,29 @@
|
|||||||
android:layout_height="56dp"
|
android:layout_height="56dp"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:paddingLeft="20dp"
|
android:paddingLeft="16dp"
|
||||||
android:paddingRight="20dp"
|
android:paddingRight="16dp"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true">
|
android:focusable="true"
|
||||||
|
android:minWidth="120dp">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="20dp"
|
android:layout_width="18dp"
|
||||||
android:layout_height="20dp"
|
android:layout_height="18dp"
|
||||||
android:src="@android:drawable/ic_menu_sort_by_size"
|
android:src="@android:drawable/ic_menu_my_calendar"
|
||||||
android:layout_marginEnd="8dp"
|
android:layout_marginEnd="6dp"
|
||||||
android:alpha="0.5" />
|
android:alpha="0.5" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/filterButtonText"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Filter"
|
android:text="Filter"
|
||||||
android:textSize="16sp"
|
android:textSize="14sp"
|
||||||
android:textColor="#666666" />
|
android:textColor="#666666"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:gravity="center" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user