From 9398e5c4063c4bef358f1da95bf18de11b07fcc3 Mon Sep 17 00:00:00 2001 From: Moritz Warning Date: Tue, 18 Nov 2025 22:06:01 +0100 Subject: [PATCH] MainActivity: use unique templates for notes --- .../it/danieleverducci/lunatracker/MainActivity.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt b/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt index 70de1c6..a079cbc 100644 --- a/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt +++ b/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt @@ -557,11 +557,11 @@ class MainActivity : AppCompatActivity() { val nextTextView = dialogView.findViewById(R.id.notes_template_next) val prevTextView = dialogView.findViewById(R.id.notes_template_prev) + val templates = getAllEvents().filter { it.type == event.type }.distinctBy { it.notes.trim() }.sortedBy { it.time } fun updateContent(current: LunaEvent) { - val allEvents = getAllEvents() - val prevEvent = getPreviousSameEvent(current, allEvents) - var nextEvent = getNextSameEvent(current, allEvents) + val prevEvent = getPreviousSameEvent(current, templates) + var nextEvent = getNextSameEvent(current, templates) notesET.setText(current.notes) if (useQuantity) { @@ -669,7 +669,7 @@ class MainActivity : AppCompatActivity() { } } - fun getPreviousSameEvent(event: LunaEvent, items: ArrayList): LunaEvent? { + fun getPreviousSameEvent(event: LunaEvent, items: List): LunaEvent? { var previousEvent: LunaEvent? = null for (item in items) { if (item.type == event.type && item.time < event.time) { @@ -683,7 +683,7 @@ class MainActivity : AppCompatActivity() { return previousEvent } - fun getNextSameEvent(event: LunaEvent, items: ArrayList): LunaEvent? { + fun getNextSameEvent(event: LunaEvent, items: List): LunaEvent? { var nextEvent: LunaEvent? = null for (item in items) { if (item.type == event.type && item.time > event.time) {