forked from penguin86/luna-tracker
MainActivity: use unique templates for notes
This commit is contained in:
@@ -557,11 +557,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
val nextTextView = dialogView.findViewById<TextView>(R.id.notes_template_next)
|
val nextTextView = dialogView.findViewById<TextView>(R.id.notes_template_next)
|
||||||
val prevTextView = dialogView.findViewById<TextView>(R.id.notes_template_prev)
|
val prevTextView = dialogView.findViewById<TextView>(R.id.notes_template_prev)
|
||||||
|
val templates = getAllEvents().filter { it.type == event.type }.distinctBy { it.notes }.sortedBy { it.time }
|
||||||
|
|
||||||
fun updateContent(current: LunaEvent) {
|
fun updateContent(current: LunaEvent) {
|
||||||
val allEvents = getAllEvents()
|
val prevEvent = getPreviousSameEvent(current, templates)
|
||||||
val prevEvent = getPreviousSameEvent(current, allEvents)
|
var nextEvent = getNextSameEvent(current, templates)
|
||||||
var nextEvent = getNextSameEvent(current, allEvents)
|
|
||||||
|
|
||||||
notesET.setText(current.notes)
|
notesET.setText(current.notes)
|
||||||
if (useQuantity) {
|
if (useQuantity) {
|
||||||
@@ -612,7 +612,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
updateContent(event)
|
updateContent(event)
|
||||||
|
|
||||||
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
||||||
val notes = notesET.text.toString()
|
val notes = notesET.text.toString().trim()
|
||||||
|
|
||||||
if (useQuantity) {
|
if (useQuantity) {
|
||||||
val quantity = qtyET.text.toString().toIntOrNull()
|
val quantity = qtyET.text.toString().toIntOrNull()
|
||||||
@@ -669,7 +669,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPreviousSameEvent(event: LunaEvent, items: ArrayList<LunaEvent>): LunaEvent? {
|
fun getPreviousSameEvent(event: LunaEvent, items: List<LunaEvent>): LunaEvent? {
|
||||||
var previousEvent: LunaEvent? = null
|
var previousEvent: LunaEvent? = null
|
||||||
for (item in items) {
|
for (item in items) {
|
||||||
if (item.type == event.type && item.time < event.time) {
|
if (item.type == event.type && item.time < event.time) {
|
||||||
@@ -683,7 +683,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
return previousEvent
|
return previousEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getNextSameEvent(event: LunaEvent, items: ArrayList<LunaEvent>): LunaEvent? {
|
fun getNextSameEvent(event: LunaEvent, items: List<LunaEvent>): LunaEvent? {
|
||||||
var nextEvent: LunaEvent? = null
|
var nextEvent: LunaEvent? = null
|
||||||
for (item in items) {
|
for (item in items) {
|
||||||
if (item.type == event.type && item.time > event.time) {
|
if (item.type == event.type && item.time > event.time) {
|
||||||
|
|||||||
Reference in New Issue
Block a user