From 0caaeb0d77ad5c094635644a8eece0d33f4d97ec Mon Sep 17 00:00:00 2001 From: Romedius Weiss Date: Fri, 2 Oct 2020 02:49:16 +0200 Subject: [PATCH] Added ability to delete comments. fixes #60 Added translations for german and italian --- .../astrid/notes/CommentsController.kt | 34 +++++++- .../main/res/layout/comment_adapter_row.xml | 83 +++++++++++-------- .../res/layout/control_set_delete_button.xml | 15 ++++ app/src/main/res/values-de/strings.xml | 3 +- app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 6 ++ 7 files changed, 108 insertions(+), 35 deletions(-) create mode 100644 app/src/main/res/layout/control_set_delete_button.xml diff --git a/app/src/main/java/com/todoroo/astrid/notes/CommentsController.kt b/app/src/main/java/com/todoroo/astrid/notes/CommentsController.kt index aa61029e2..1bd4f2778 100644 --- a/app/src/main/java/com/todoroo/astrid/notes/CommentsController.kt +++ b/app/src/main/java/com/todoroo/astrid/notes/CommentsController.kt @@ -6,6 +6,7 @@ package com.todoroo.astrid.notes import android.app.Activity +import android.app.AlertDialog import android.graphics.Color import android.net.Uri import android.text.Html @@ -14,11 +15,12 @@ import android.view.ViewGroup import android.widget.Button import android.widget.ImageView import android.widget.TextView +import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.lifecycleScope import com.todoroo.andlib.utility.DateUtilities import com.todoroo.astrid.data.Task -import kotlinx.coroutines.launch +import kotlinx.coroutines.* import org.tasks.R import org.tasks.data.UserActivity import org.tasks.data.UserActivityDao @@ -29,6 +31,7 @@ import org.tasks.locale.Locale import org.tasks.preferences.Preferences import java.util.* import javax.inject.Inject +import kotlin.coroutines.coroutineContext import kotlin.math.min class CommentsController @Inject constructor( @@ -94,6 +97,35 @@ class CommentsController @Inject constructor( // picture val commentPictureView = view.findViewById(R.id.comment_picture) setupImagePopupForCommentView(view, commentPictureView, item.pictureUri, activity) + + // delete button + val deleteBtn = view.findViewById(R.id.delete) + deleteBtn.setOnClickListener(){ + val builder = AlertDialog.Builder(commentsContainer!!.context) + + // Display a message on alert dialog + builder.setMessage(R.string.delete_comment) + + // Set a positive button and its click listener on alert dialog + builder.setPositiveButton(R.string.delete){dialog, which -> + + (activity as AppCompatActivity).lifecycleScope.launch { + withContext(NonCancellable) { + userActivityDao.delete(item) + } + reloadView() + } + } + + // Display a negative button on alert dialog + builder.setNegativeButton(android.R.string.cancel){dialog,which -> + } + // Finally, make the alert dialog using builder + val dialog: AlertDialog = builder.create() + + // Display the alert dialog on app interface + dialog.show() + } } companion object { diff --git a/app/src/main/res/layout/comment_adapter_row.xml b/app/src/main/res/layout/comment_adapter_row.xml index 553fda5dc..b5cc65986 100644 --- a/app/src/main/res/layout/comment_adapter_row.xml +++ b/app/src/main/res/layout/comment_adapter_row.xml @@ -3,36 +3,53 @@ ** ** See the file "LICENSE" for the full license governing this code. --> - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/control_set_delete_button.xml b/app/src/main/res/layout/control_set_delete_button.xml new file mode 100644 index 000000000..df5eed2e9 --- /dev/null +++ b/app/src/main/res/layout/control_set_delete_button.xml @@ -0,0 +1,15 @@ + + \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 0eca593eb..b5c0d3f0e 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -82,7 +82,7 @@ Bildschirmeinstellungen bearbeiten Auf Standardeinstellungen zurücksetzen Aufgabentitel ganz anzeigen - Kommentare bei Aufgabeneingabe anzeigen + Kommentare bei Aufgabeneingabe anzeigen Aufgabenlisten-Optionen Zeitpunkt für Kalendereintrag Kalendereintrag endet zur Fälligkeitsuhrzeit @@ -641,4 +641,5 @@ nie Geräteeinstellungen Konto + Kommentar löschen? \ No newline at end of file diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index b3faf57fa..22a23cd9f 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -640,4 +640,5 @@ Backup automatici Sono necessari i relativi permessi per i promemoria basati sulla localizzazione. Se in precedenza è stata negata una richiesta di autorizzazione alla localizzazione, sarà necessario concedere manualmente tale autorizzazione nelle impostazioni del dispositivo. Nessuna app è in grado di gestire questa richiesta + Elimina questo commento? \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8b86abb3b..aa336d928 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -646,4 +646,5 @@ File %1$s contained %2$s.\n\n Ignore warnings Ignore backup warnings if you do not need backups or have your own backup solution WARNING: Files located in %s will be deleted if Tasks is uninstalled! Please choose a custom location to prevent Android from deleting your files. + Delete this comment? diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 82deae307..980efd8f0 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -70,6 +70,12 @@ @color/black_87 + +