Sorting List
This commit is contained in:
parent
eddade3200
commit
d4245c5906
@ -45,6 +45,7 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import android.app.DatePickerDialog;
|
||||
import android.widget.DatePicker;
|
||||
@ -445,13 +446,13 @@ public class TransactionActivity extends AppCompatActivity implements Transactio
|
||||
filteredList.clear();
|
||||
|
||||
if (query.isEmpty()) {
|
||||
// ✅ NO SEARCH: Show current API page data (already sorted)
|
||||
// ✅ NO SEARCH: Show current API page data (maintain sorting from API)
|
||||
filteredList.addAll(transactionList);
|
||||
totalRecords = totalRecords; // Use API total
|
||||
totalPages = (int) Math.ceil((double) totalRecords / itemsPerPage);
|
||||
|
||||
// ✅ VERIFY FILTERED LIST ORDER
|
||||
Log.d("TransactionActivity", "📋 FILTERED LIST ORDER (no search):");
|
||||
// ✅ PASTIKAN TIDAK PERLU SORT LAGI karena sudah sorted dari API response
|
||||
Log.d("TransactionActivity", "📋 FILTERED LIST ORDER (no search - maintaining API order):");
|
||||
for (int i = 0; i < Math.min(5, filteredList.size()); i++) {
|
||||
Transaction tx = filteredList.get(i);
|
||||
Log.d("TransactionActivity", " " + (i+1) + ". " + tx.createdAt + " - " + tx.referenceId);
|
||||
@ -465,7 +466,7 @@ public class TransactionActivity extends AppCompatActivity implements Transactio
|
||||
}
|
||||
}
|
||||
|
||||
// ✅ SORT SEARCH RESULTS by date
|
||||
// ✅ SORT SEARCH RESULTS by date (maintaining newest first)
|
||||
Collections.sort(filteredList, (t1, t2) -> {
|
||||
try {
|
||||
Date date1 = parseCreatedAtDate(t1.createdAt);
|
||||
@ -687,7 +688,7 @@ public class TransactionActivity extends AppCompatActivity implements Transactio
|
||||
|
||||
if (error) {
|
||||
Toast.makeText(TransactionActivity.this, "Failed to fetch transactions", Toast.LENGTH_SHORT).show();
|
||||
updatePaginationDisplay(); // Show current state even on error
|
||||
updatePaginationDisplay();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -696,33 +697,33 @@ public class TransactionActivity extends AppCompatActivity implements Transactio
|
||||
totalRecords = apiTotal;
|
||||
totalPages = (int) Math.ceil((double) totalRecords / itemsPerPage);
|
||||
|
||||
// ✅ UPDATE TRANSACTION LIST
|
||||
transactionList.clear();
|
||||
transactionList.addAll(transactions);
|
||||
|
||||
// ✅ CRITICAL: FORCE SORT AGAIN after adding to main list
|
||||
Collections.sort(filteredList, (t1, t2) -> {
|
||||
// ✅ PERBAIKAN SORTING: Sort transactions SEBELUM menambahkan ke list
|
||||
Collections.sort(transactions, (t1, t2) -> {
|
||||
try {
|
||||
Date date1 = parseCreatedAtDate(t1.createdAt);
|
||||
Date date2 = parseCreatedAtDate(t2.createdAt);
|
||||
|
||||
if (date1 != null && date2 != null) {
|
||||
int comparison = date2.compareTo(date1); // Newest first
|
||||
Log.d("TransactionActivity", "🔄 Final sort: " + t1.createdAt + " vs " + t2.createdAt + " = " + comparison);
|
||||
Log.d("TransactionActivity", "🔄 Sorting: " + t2.createdAt + " vs " + t1.createdAt + " = " + comparison);
|
||||
return comparison;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.w("TransactionActivity", "Date comparison error: " + e.getMessage());
|
||||
}
|
||||
return Integer.compare(t2.id, t1.id); // Fallback by ID
|
||||
return Integer.compare(t2.id, t1.id); // Fallback by ID (higher ID = newer)
|
||||
});
|
||||
|
||||
// ✅ UPDATE TRANSACTION LIST dengan data yang sudah tersortir
|
||||
transactionList.clear();
|
||||
transactionList.addAll(transactions);
|
||||
|
||||
Log.d("TransactionActivity", "📋 Page " + currentPage + " loaded and sorted: " +
|
||||
transactions.size() + " transactions. Total: " + totalRecords + "/" + totalPages + " pages");
|
||||
|
||||
// ✅ LOG FINAL ORDER VERIFICATION
|
||||
Log.d("TransactionActivity", "📋 FINAL DISPLAY ORDER:");
|
||||
for (int i = 0; i < Math.min(10, transactionList.size()); i++) {
|
||||
// ✅ VERIFIKASI SORTING ORDER
|
||||
Log.d("TransactionActivity", "📋 SORTED ORDER VERIFICATION:");
|
||||
for (int i = 0; i < Math.min(5, transactionList.size()); i++) {
|
||||
Transaction tx = transactionList.get(i);
|
||||
Log.d("TransactionActivity", " " + (i+1) + ". " + tx.createdAt + " - " + tx.referenceId);
|
||||
}
|
||||
@ -745,19 +746,23 @@ public class TransactionActivity extends AppCompatActivity implements Transactio
|
||||
return null;
|
||||
}
|
||||
|
||||
// List of possible date formats from API
|
||||
// List of possible date formats from API (urutan dari yang paling spesifik)
|
||||
String[] possibleFormats = {
|
||||
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", // ISO format with milliseconds
|
||||
"yyyy-MM-dd'T'HH:mm:ss'Z'", // ISO format without milliseconds
|
||||
"yyyy-MM-dd HH:mm:ss.SSS", // Standard format with milliseconds
|
||||
"yyyy-MM-dd HH:mm:ss", // Standard format
|
||||
"yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'" // ISO format with microseconds
|
||||
"yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'", // ISO format with microseconds (6 digits)
|
||||
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", // ISO format with milliseconds (3 digits)
|
||||
"yyyy-MM-dd'T'HH:mm:ss'Z'", // ISO format without milliseconds
|
||||
"yyyy-MM-dd HH:mm:ss.SSSSSS", // Standard format with microseconds
|
||||
"yyyy-MM-dd HH:mm:ss.SSS", // Standard format with milliseconds
|
||||
"yyyy-MM-dd HH:mm:ss" // Standard format
|
||||
};
|
||||
|
||||
for (String format : possibleFormats) {
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.getDefault());
|
||||
return sdf.parse(rawDate);
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("UTC")); // Handle timezone properly
|
||||
Date parsed = sdf.parse(rawDate);
|
||||
Log.d("TransactionActivity", "✅ Date parsed successfully: " + rawDate + " -> " + parsed + " using format: " + format);
|
||||
return parsed;
|
||||
} catch (Exception e) {
|
||||
// Continue to next format
|
||||
}
|
||||
@ -773,9 +778,11 @@ public class TransactionActivity extends AppCompatActivity implements Transactio
|
||||
}
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
return sdf.parse(cleanedDate);
|
||||
Date parsed = sdf.parse(cleanedDate);
|
||||
Log.d("TransactionActivity", "✅ Date parsed with fallback: " + rawDate + " -> " + parsed);
|
||||
return parsed;
|
||||
} catch (Exception e) {
|
||||
Log.w("TransactionActivity", "❌ Could not parse date: " + rawDate);
|
||||
Log.w("TransactionActivity", "❌ Could not parse date: " + rawDate + " - Error: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -87,6 +87,7 @@
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<!-- ✅ PERBAIKAN: Gunakan LinearLayout dengan weight distribution yang lebih baik -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
@ -221,44 +222,53 @@
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="8dp" />
|
||||
|
||||
<!-- ✅ PERBAIKAN: RecyclerView dengan height yang tepat untuk mencegah pagination terpotong -->
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:background="#ffffff" />
|
||||
android:background="#ffffff"
|
||||
android:clipToPadding="false"
|
||||
android:paddingBottom="8dp" />
|
||||
|
||||
<!-- Pagination Controls -->
|
||||
<!-- ✅ PERBAIKAN: Pagination Controls dengan padding dan margin yang lebih baik -->
|
||||
<LinearLayout
|
||||
android:id="@+id/paginationControls"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:background="@android:color/white"
|
||||
android:padding="20dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="20dp"
|
||||
android:paddingLeft="20dp"
|
||||
android:paddingRight="20dp"
|
||||
android:gravity="center"
|
||||
android:elevation="2dp"
|
||||
android:visibility="gone">
|
||||
android:elevation="4dp"
|
||||
android:visibility="gone"
|
||||
android:layout_marginTop="2dp">
|
||||
|
||||
<!-- First Page Button -->
|
||||
<ImageButton
|
||||
android:id="@+id/btnFirstPage"
|
||||
android:layout_width="44dp"
|
||||
android:layout_height="44dp"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:src="@android:drawable/ic_media_previous"
|
||||
android:contentDescription="First Page"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:scaleType="centerInside" />
|
||||
android:scaleType="centerInside"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless" />
|
||||
|
||||
<!-- Previous Page Button -->
|
||||
<ImageButton
|
||||
android:id="@+id/btnPrevPage"
|
||||
android:layout_width="44dp"
|
||||
android:layout_height="44dp"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:src="@android:drawable/ic_media_rew"
|
||||
android:contentDescription="Previous Page"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:scaleType="centerInside" />
|
||||
android:scaleType="centerInside"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless" />
|
||||
|
||||
<!-- Page Numbers Container -->
|
||||
<LinearLayout
|
||||
@ -268,27 +278,30 @@
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp" />
|
||||
android:layout_marginRight="8dp"
|
||||
android:minHeight="48dp" />
|
||||
|
||||
<!-- Next Page Button -->
|
||||
<ImageButton
|
||||
android:id="@+id/btnNextPage"
|
||||
android:layout_width="44dp"
|
||||
android:layout_height="44dp"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:src="@android:drawable/ic_media_ff"
|
||||
android:contentDescription="Next Page"
|
||||
android:layout_marginStart="12dp"
|
||||
android:scaleType="centerInside" />
|
||||
android:scaleType="centerInside"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless" />
|
||||
|
||||
<!-- Last Page Button -->
|
||||
<ImageButton
|
||||
android:id="@+id/btnLastPage"
|
||||
android:layout_width="44dp"
|
||||
android:layout_height="44dp"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:src="@android:drawable/ic_media_next"
|
||||
android:contentDescription="Last Page"
|
||||
android:layout_marginStart="8dp"
|
||||
android:scaleType="centerInside" />
|
||||
android:scaleType="centerInside"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user