From 5110e6b9b8ebae76d508e61fc4584be5b4a9a45f Mon Sep 17 00:00:00 2001 From: jacques Date: Wed, 29 Jun 2022 04:56:26 +0200 Subject: [PATCH] Create sortPrescriptionList method --- app/src/main/java/net/foucry/pilldroid/Utils.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/net/foucry/pilldroid/Utils.java b/app/src/main/java/net/foucry/pilldroid/Utils.java index 6e2f416..41f5766 100644 --- a/app/src/main/java/net/foucry/pilldroid/Utils.java +++ b/app/src/main/java/net/foucry/pilldroid/Utils.java @@ -3,7 +3,9 @@ package net.foucry.pilldroid; import net.foucry.pilldroid.models.Medicine; import net.foucry.pilldroid.models.Prescription; +import java.util.Comparator; import java.util.Date; +import java.util.List; import java.util.Locale; import java.util.Random; @@ -45,4 +47,16 @@ public class Utils { return aPrescription; } + + public static void sortPrescriptionList(List prescriptionList) { + prescriptionList.sort(new Comparator<>() { + @Override + public int compare(Prescription lhs, Prescription rhs) { + if (lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()) != 0) + return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()); + else + return (int) (lhs.getStock() - rhs.getStock()); + } + }); + } }