From 3c459e59ba3ac6082d65984359fcb6276965de4d Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Wed, 21 Apr 2021 00:01:31 +0300 Subject: [PATCH] fix finding the earliest transaction by date --- .../async/TransactionDateFinder.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/async/TransactionDateFinder.java b/app/src/main/java/net/ktnx/mobileledger/async/TransactionDateFinder.java index 608b4771..2bce07e1 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/TransactionDateFinder.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/TransactionDateFinder.java @@ -1,5 +1,5 @@ /* - * Copyright © 2020 Damyan Ivanov. + * Copyright © 2021 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -48,8 +48,9 @@ public class TransactionDateFinder extends AsyncTask transactions = Objects.requireNonNull( param[0].model.getDisplayedTransactions() .getValue()); + final int transactionCount = transactions.size(); Logger.debug("go-to-date", - String.format(Locale.US, "List contains %d transactions", transactions.size())); + String.format(Locale.US, "List contains %d transactions", transactionCount)); TransactionListItem target = new TransactionListItem(date, true); int found = @@ -57,7 +58,7 @@ public class TransactionDateFinder extends AsyncTask= 0) return found; else - return 1 - found; + return -1 - found; } public static class Params { @@ -72,9 +73,11 @@ public class TransactionDateFinder extends AsyncTask { @Override public int compare(@NotNull TransactionListItem a, @NotNull TransactionListItem b) { - if (a.getType() == TransactionListItem.Type.HEADER) + final TransactionListItem.Type aType = a.getType(); + if (aType == TransactionListItem.Type.HEADER) return +1; - if (b.getType() == TransactionListItem.Type.HEADER) + final TransactionListItem.Type bType = b.getType(); + if (bType == TransactionListItem.Type.HEADER) return -1; final SimpleDate aDate = a.getDate(); final SimpleDate bDate = b.getDate(); @@ -82,14 +85,14 @@ public class TransactionDateFinder extends AsyncTask