From b4f47ea6bbcd39498c8256a9dc8048d90d10a6c6 Mon Sep 17 00:00:00 2001 From: Daniele Verducci Date: Sun, 19 Jan 2025 09:16:49 +0100 Subject: [PATCH] Implemented event deletion --- .../danieleverducci/lunatracker/MainActivity.kt | 17 ++++++++++++++++- app/src/main/res/values-it/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt b/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt index a600c8d..9c03c05 100644 --- a/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt +++ b/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt @@ -1,5 +1,6 @@ package it.danieleverducci.lunatracker +import android.content.DialogInterface import android.content.Intent import android.os.Bundle import android.os.Handler @@ -306,9 +307,11 @@ class MainActivity : AppCompatActivity() { ) dialogView.findViewById(R.id.dialog_event_detail_type_notes).setText(event.notes) d.setView(dialogView) - d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> dialogInterface.dismiss() } + d.setPositiveButton(R.string.dialog_event_detail_save_button) { dialogInterface, i -> dialogInterface.dismiss() } + d.setNeutralButton(R.string.dialog_event_detail_delete_button) { dialogInterface, i -> deleteEvent(event) } val alertDialog = d.create() alertDialog.show() + alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setTextColor(ContextCompat.getColor(this, R.color.danger)) } fun showAddLogbookDialog(requestedByUser: Boolean) { @@ -520,6 +523,18 @@ class MainActivity : AppCompatActivity() { } } + fun deleteEvent(event: LunaEvent) { + // Update view + savingEvent(true) + adapter.items.remove(event) + adapter.notifyDataSetChanged() + + // Update data + setLoading(true) + logbook.logs.remove(event) + saveLogbook() + } + /** * Saves the logbook. If saving while adding an event, please specify the event so in case * of error can be removed from the list. diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 6f2cdd6..f110cec 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -80,6 +80,8 @@ Inserisci le note Dettaglio evento + Salva + Elimina Aggiungi diario 👶 Nome del diario diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 11bb9d1..f99d7c9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -103,6 +103,8 @@ °C Event detail + Save + Delete Add logbook 👶 Logbook name