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.
This commit is contained in:
Severiano Jaramillo 2019-02-07 16:42:57 -06:00
parent e5677436b1
commit 42e0fc74b0

View file

@ -26,7 +26,16 @@ class TransfersDetailsAdapter(private val context: Context) :
RecyclerView.Adapter<TransfersDetailsAdapter.ViewHolder>() { RecyclerView.Adapter<TransfersDetailsAdapter.ViewHolder>() {
private val mComparator = private val mComparator =
Comparator<TransferDetail> { a, b -> b.id.compareTo(a.id) } Comparator<TransferDetail> { 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 = private val mSortedList =
SortedList<TransferDetail>(TransferDetail::class.java, object : SortedList.Callback<TransferDetail>() { SortedList<TransferDetail>(TransferDetail::class.java, object : SortedList.Callback<TransferDetail>() {