From 42e0fc74b0fd03a223ad2bf5bbfcc37b6d02b296 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Thu, 7 Feb 2019 16:42:57 -0600 Subject: [PATCH] Changed the comparator used to sort the transactions in TransactionsActivity to compare the Long representation of the transfer ID instead of the String representation. Even though transfer IDs are incremental in the form 1.11.x where x is the number that increments for each transfer, the field is a string and that causes errors when doing the comparisons because the string 9 is 'greater' than 123456789 so instead of doing the string comparison we had to convert the ID to a long number and only then do the comparison to make sure the transactions are correctly ordered. --- .../adapters/TransfersDetailsAdapter.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/adapters/TransfersDetailsAdapter.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/adapters/TransfersDetailsAdapter.kt index 533fa84..8f5b5aa 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/adapters/TransfersDetailsAdapter.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/adapters/TransfersDetailsAdapter.kt @@ -26,7 +26,16 @@ class TransfersDetailsAdapter(private val context: Context) : RecyclerView.Adapter() { private val mComparator = - Comparator { a, b -> b.id.compareTo(a.id) } + Comparator { a, b -> + getTransferNumber(b.id).compareTo(getTransferNumber(a.id)) + } + + /** A transferId has the format 1.11.x where x is the identifier of the transfer, this identifier is converted + * to Long and returned */ + private fun getTransferNumber(transferId: String): Long { + val transferNumber = transferId.split(".").last() + return transferNumber.toLong() + } private val mSortedList = SortedList(TransferDetail::class.java, object : SortedList.Callback() {