X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fasync%2FTransactionDateFinder.java;h=2bce07e1ca08fc4218aa7aba911491c9fc2c5c87;hb=3c459e59ba3ac6082d65984359fcb6276965de4d;hp=e90a2ae32381032b6dcff00386ed3dce4e8a621f;hpb=5bba2c06a81c87327fdcf3f2a85c3206d932c2f9;p=mobile-ledger.git 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 e90a2ae3..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 @@ -24,6 +24,8 @@ import net.ktnx.mobileledger.ui.MainModel; import net.ktnx.mobileledger.utils.Logger; import net.ktnx.mobileledger.utils.SimpleDate; +import org.jetbrains.annotations.NotNull; + import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -46,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 = @@ -55,13 +58,13 @@ public class TransactionDateFinder extends AsyncTask= 0) return found; else - return 1 - found; + return -1 - found; } public static class Params { - public MainModel model; - public SimpleDate date; - public Params(MainModel model, SimpleDate date) { + public final MainModel model; + public final SimpleDate date; + public Params(@NotNull MainModel model, @NotNull SimpleDate date) { this.model = model; this.date = date; } @@ -69,21 +72,27 @@ public class TransactionDateFinder extends AsyncTask { @Override - public int compare(TransactionListItem a, TransactionListItem b) { + public int compare(@NotNull TransactionListItem a, @NotNull TransactionListItem b) { + final TransactionListItem.Type aType = a.getType(); + if (aType == TransactionListItem.Type.HEADER) + return +1; + final TransactionListItem.Type bType = b.getType(); + if (bType == TransactionListItem.Type.HEADER) + return -1; final SimpleDate aDate = a.getDate(); final SimpleDate bDate = b.getDate(); int res = aDate.compareTo(bDate); if (res != 0) return -res; // transactions are reverse sorted by date - if (a.getType() == TransactionListItem.Type.DELIMITER) { - if (b.getType() == TransactionListItem.Type.DELIMITER) + if (aType == TransactionListItem.Type.DELIMITER) { + if (bType == TransactionListItem.Type.DELIMITER) return 0; else return -1; } else { - if (b.getType() == TransactionListItem.Type.DELIMITER) + if (bType == TransactionListItem.Type.DELIMITER) return +1; else return 0;