Skip to content

Commit

Permalink
Implemented feature request #92 to move all done tasks to recycle bin…
Browse files Browse the repository at this point in the history
… with one click.

For tasks the term "delete" was replaced by "remove" because tasks first get moved to recycle bin before they get deleted. Most texts already used "remove", only a few needed to be changed.
Merged some texts.
  • Loading branch information
Christian Adams committed Dec 30, 2024
1 parent 76e3e84 commit 5121916
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ class ModelServices(
}
}

fun setAllDoneTasksInRecycleBin(deliveryOption: DeliveryOption = DeliveryOption.POST,
resultConsumer: ResultConsumer<Pair<Int, Int>>? = null): Job {
return coroutineScope.launch(Dispatchers.IO) {
val counter = services.setAllDoneTasksInRecycleBin()
dispatchResult(deliveryOption, resultConsumer, counter)
notifyDataChanged(0, counter.first, counter.second)
}
}

fun setTaskAndSubtasksInRecycleBin(todoTask: TodoTask,
inRecycleBin: Boolean,
deliveryOption: DeliveryOption = DeliveryOption.POST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ interface TodoTaskDao {
" ORDER BY todoLists.sortOrder ASC, todoTasks.sortOrder ASC")
suspend fun getOverdueTasks(now: Long): Array<TodoTaskData>

@Query("SELECT * FROM todoTasks WHERE isInRecycleBin = 0 AND doneTime IS NOT NULL")
suspend fun getAllDoneNotInRecycleBin(): Array<TodoTaskData>

@Query("SELECT todoTasks.* FROM todoTasks" +
" LEFT JOIN todoLists" +
" ON todoTasks.listId = todoLists.id" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ class ModelServicesImpl(private val context: Context) {
return counter
}

suspend fun setAllDoneTasksInRecycleBin(): Pair<Int, Int> {
val dataArray = getDB().getTodoTaskDao().getAllDoneNotInRecycleBin()
val tasks = loadTasksSubtasks(false, *dataArray)
var counterTasks = 0
var counterSubtasks = 0
for (task in tasks) {
val counters = setTaskAndSubtasksInRecycleBin(task, true)
counterTasks += counters.first
counterSubtasks += counters.second
}
Log.i(TAG, "$counterTasks task and $counterSubtasks subtasks put into recycle bin.")
return Pair(counterTasks, counterSubtasks)
}

suspend fun setTaskAndSubtasksInRecycleBin(todoTask: TodoTask, inRecycleBin: Boolean): Pair<Int, Int> {
var counterSubtasks = 0
for (subtask in todoTask.getSubtasks()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
navigationView = findViewById(R.id.nav_view)
navigationView!!.setNavigationItemSelectedListener(this)

val navMenu = navigationView!!.menu
val btnAllTasks = navMenu.findItem(R.id.menu_home)
btnAllTasks.setActionView(R.layout.nav_action_view)
val actionButton: ImageButton = btnAllTasks.actionView!!.findViewById(R.id.action_button)
actionButton.tag = ACT_BTN_ALL_TASKS
actionButton.setOnClickListener {
registerForContextMenu(actionButton)
openContextMenu(actionButton)
unregisterForContextMenu(actionButton)
}

addTodoListsToNavigationMenu()

var tasksGetDisplayed = false
Expand Down Expand Up @@ -539,7 +550,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
deleteAllDataBeforeImport = false
importTasksLauncher.launch(intent)
}
setNeutralButton(R.string.abort) { _, _ ->
setNeutralButton(R.string.cancel) { _, _ ->
}
show()
}
Expand Down Expand Up @@ -641,7 +652,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
val item = navMenu.add(R.id.menu_group_todo_lists, entry.key, 1, entry.value)
item.isCheckable = true
item.setIcon(R.drawable.ic_label_black_24dp)
item.setActionView(R.layout.list_action_view)
item.setActionView(R.layout.nav_action_view)
val actionButton: ImageButton = item.actionView!!.findViewById(R.id.action_button)
actionButton.tag = entry.key
actionButton.setOnClickListener {
Expand Down Expand Up @@ -794,6 +805,10 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
if (pomodoroInstalled) {
menu.findItem(workItemId).setVisible(true)
}
} else if (v.tag == ACT_BTN_ALL_TASKS) {
val menuHeader = Helper.getMenuHeader(layoutInflater, v.rootView, R.string.select_option)
menu.setHeaderView(menuHeader)
menuInflater.inflate(R.menu.all_tasks_context, menu)
// Check for to-do lists in main menu.
} else if (v.tag is Int) {
selectedTodoListId = v.tag as Int
Expand All @@ -807,6 +822,26 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte

override fun onContextItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.remove_all_done_tasks -> {
MaterialAlertDialogBuilder(this).apply {
setMessage(R.string.alert_done_tasks_remove)
setCancelable(true)
setPositiveButton(R.string.yes) { dialog, setId ->
model!!.setAllDoneTasksInRecycleBin { counters ->
val msg = getString(R.string.tasks_removed, counters.first, counters.second)
Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show()
if (counters.first > 0) {
showTasksOfListOrAllTasks(activeListId)
}
}
}
setNegativeButton(R.string.cancel) { dialog, id ->
dialog.cancel()
}
show()
}
}

R.id.move_up_list -> {
moveList(true)
}
Expand Down Expand Up @@ -852,7 +887,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
}

R.id.delete_task -> {
R.id.remove_task -> {
val todoTask = contextMenuTodoTask
if (null != todoTask) {
val snackBar = Snackbar.make(fabNewTodoTask!!, R.string.task_removed, Snackbar.LENGTH_LONG)
Expand All @@ -862,7 +897,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
showTasksOfListOrAllTasks(activeListId)
showHints()
} else {
Log.w(TAG, "Task was not removed from the database.")
Log.e(TAG, "Task was not restored from recycle bin.")
}
}
}
Expand All @@ -873,7 +908,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
showHints()
snackBar.show()
} else {
Log.w(TAG, "Task was not removed from the database.")
Log.e(TAG, "Task was not moved to recycle bin.")
}
}
}
Expand Down Expand Up @@ -991,7 +1026,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
MaterialAlertDialogBuilder(this).apply {
setMessage(R.string.alert_list_delete)
setCancelable(true)
setPositiveButton(R.string.alert_delete_yes) { dialog, setId ->
setPositiveButton(R.string.yes) { dialog, setId ->
model!!.deleteTodoList(todoList.getId()) { counter ->
if (counter.first > 0) {
Log.i(TAG, "List '${todoList.getName()}' with ID ${todoList.getId()} deleted.")
Expand All @@ -1009,7 +1044,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
dialog.cancel()
}
}
setNegativeButton(R.string.alert_delete_no) { dialog, id ->
setNegativeButton(R.string.cancel) { dialog, id ->
dialog.cancel()
}
show()
Expand Down Expand Up @@ -1138,6 +1173,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
const val COMMAND = "command"
//const val COMMAND_RUN_TODO = 2
const val COMMAND_UPDATE = 3
const val ACT_BTN_ALL_TASKS = "ACT_BTN_ALL_TASKS"

// Keys
private const val KEY_IS_UNLOCKED = "restore_is_unlocked_key_with_savedinstancestate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:contentDescription="@string/edit_todo_list"
app:srcCompat="@drawable/ic_menu_black_24dp" />

</LinearLayout>
6 changes: 6 additions & 0 deletions app/src/main/res/menu/all_tasks_context.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/remove_all_done_tasks"
android:title="@string/remove_all_done_tasks" />
</menu>
4 changes: 2 additions & 2 deletions app/src/main/res/menu/todo_task_context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
android:id="@+id/share_task"
android:title="@string/share_task" />
<item
android:id="@+id/delete_task"
android:title="@string/delete_task" />
android:id="@+id/remove_task"
android:title="@string/remove_task" />
<item
android:id="@+id/work_task"
android:title="@string/work_task"
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<string name="todos">To-Do\'s</string>
<string name="home">Alle Aufgaben</string>
<string name="show_all_tasks">Alle Aufgaben</string>
<string name="remove_all_done_tasks">Alle erledigten Aufgaben entfernen</string>
<string name="calendar_view">Kalenderansicht</string>
<string name="settings">Einstellungen</string>
<string name="share_all_tasks">Daten teilen</string>
Expand All @@ -27,7 +28,7 @@
<string name="name">Name</string>
<string name="description_hint">Beschreibung</string>
<string name="ok">Okay</string>
<string name="delete">Löschen</string>
<string name="cancel">Abbrechen</string>

<!-- Common model strings -->
<string name="select_option">Auswählen</string>
Expand Down Expand Up @@ -111,8 +112,9 @@
<string name="no_deadline">Kein Termin</string>
<string name="edit_task">Aufgabe bearbeiten</string>
<string name="share_task">Aufgabe teilen</string>
<string name="delete_task">Aufgabe löschen</string>
<string name="task_removed">Aufgabe ist im Papierkorb</string>
<string name="remove_task">Aufgabe entfernen</string>
<string name="task_removed">Aufgabe wurde entfernt</string>
<string name="tasks_removed">%d Aufgabe(n) und %d Unteraufgabe(n) entfernt.</string>
<string name="deadline">Termin</string>
<string name="recurrence_every">Wiederholung alle</string>
<string name="recurrence_interval_hint">1..n</string>
Expand Down Expand Up @@ -285,13 +287,11 @@
<string name="import_question_text">Sollen alle existierenden Daten (alle To-Do Listen, Aufgaben und Unteraufgaben) vor dem Import gelöscht werden?</string>
<string name="delete_existing_data">Existierende Daten löschen</string>
<string name="keep_existing_data">Existierende Daten beibehalten</string>
<string name="abort">Abbrechen</string>

<!-- ### Delete AlertDialog ### -->
<string name="alert_list_delete">Wollen Sie die Liste wirklich löschen?</string>
<string name="alert_list_delete">Die Liste wirklich löschen?</string>
<string name="alert_done_tasks_remove">Die erledigten Aufgaben wirklich entfernen?</string>
<string name="alert_clear">Wirklich leeren?</string>
<string name="alert_delete_yes">Löschen</string>
<string name="alert_delete_no">Abbrechen</string>

<!-- ### WIDGET ### -->
<string name="add_widget">Widget hinzufügen</string>
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<string name="deadline_dd">Fecha límite:</string>
<string name="no_deadline">No hay ninguna fecha límite</string>
<string name="edit_task">Editar la tarea</string>
<string name="delete_task">Eliminar la tarea</string>
<string name="remove_task">Eliminar la tarea</string>
<string name="task_removed">Tarea eliminada</string>
<string name="deadline">Facha límite</string>
<string name="reminder">Alarma</string>
Expand Down Expand Up @@ -161,7 +161,6 @@
<string name="help_group_widget">Widget</string>
<string name="recurrence_pattern_hint">Patrón de repetición</string>
<string name="set_deadline_if_recurring">Una tarea que se repite necesita una fecha límite.</string>
<string name="delete">Borrar</string>
<string name="help_data_backup">Puede utilizar la aplicación independiente Privacy Friendly Backup para realizar copias de seguridad y restaurar los datos y la configuración de esta aplicación. También se puede utilizar para transferir los datos a otro dispositivo.</string>
<string name="help_widget">Además, esta aplicación proporciona un widget que puedes añadir a tu pantalla de inicio. El widget te presenta las tareas que pertenecen a una lista elegida. Al hacer clic en una tarea se accede a la vista principal de la aplicación. El botón de sincronización puede actualizar la lista de tareas mostradas.</string>
<string name="edit_list">Editar la lista</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<string name="deadline_dd">Date limite:</string>
<string name="no_deadline">Aucune date limite</string>
<string name="edit_task">Editer la tâche</string>
<string name="delete_task">Supprimer la tâche</string>
<string name="remove_task">Supprimer la tâche</string>
<string name="task_removed">La tâche a été supprimée.</string>
<string name="deadline">Date limite</string>
<string name="reminder">Alarme</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<string name="deadline_dd">期限:</string>
<string name="no_deadline">期限なし</string>
<string name="edit_task">タスクを編集</string>
<string name="delete_task">タスクを削除</string>
<string name="remove_task">タスクを削除</string>
<string name="task_removed">タスクを削除しました。</string>
<string name="deadline">期限</string>
<string name="reminder">リマインダー</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<string name="deadline_dd">Deadline:</string>
<string name="no_deadline">Geen Deadline</string>
<string name="edit_task">Bewerk taak</string>
<string name="delete_task">Verwijder taak</string>
<string name="remove_task">Verwijder taak</string>
<string name="task_removed">Taak is verwijderd.</string>
<string name="deadline">Deadline</string>
<string name="reminder">Herinnering</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<string name="deadline_dd">Termin:</string>
<string name="no_deadline">Brak terminu</string>
<string name="edit_task">Edytuj zadanie</string>
<string name="delete_task">Usuń zadanie</string>
<string name="remove_task">Usuń zadanie</string>
<string name="task_removed">Zadanie zostało usunięte.</string>
<string name="deadline">Termin</string>
<string name="reminder">Alarm</string>
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<string name="todos">To-Do\'s</string>
<string name="home">All tasks</string>
<string name="show_all_tasks">Show all tasks</string>
<string name="remove_all_done_tasks">Remove all done tasks</string>
<string name="calendar_view">Calendar</string>
<string name="settings">Settings</string>
<string name="share_all_tasks">Share data</string>
Expand All @@ -27,7 +28,7 @@
<string name="name">Name</string>
<string name="description_hint">Description</string>
<string name="ok">Okay</string>
<string name="delete">Delete</string>
<string name="cancel">Cancel</string>

<!-- Common model strings -->
<string name="select_option">Select option</string>
Expand Down Expand Up @@ -115,8 +116,9 @@
<string name="no_deadline">No Deadline</string>
<string name="edit_task">Edit task</string>
<string name="share_task">Share task</string>
<string name="delete_task">Delete task</string>
<string name="task_removed">Task put into recycle bin</string>
<string name="remove_task">Remove task</string>
<string name="task_removed">Task successfully removed.</string>
<string name="tasks_removed">%d task(s) and %d subtask(s) removed.</string>
<string name="deadline">Deadline</string>
<string name="recurrence_every">Recurrence every</string>
<string name="recurrence_interval_hint">1..n</string>
Expand Down Expand Up @@ -309,13 +311,11 @@
<string name="import_question_text">Delete all existing data (all To-Do lists, tasks and subtasks) before importing new data?</string>
<string name="delete_existing_data">Delete existing data</string>
<string name="keep_existing_data">Keep existing data</string>
<string name="abort">Abort</string>

<!-- ### Delete AlertDialog ### -->
<string name="alert_list_delete">Really delete this list?</string>
<string name="alert_done_tasks_remove">Really remove all done tasks?</string>
<string name="alert_clear">Really clear?</string>
<string name="alert_delete_yes">Delete</string>
<string name="alert_delete_no">Cancel</string>

<!-- ### WIDGET ### -->
<string name="add_widget">Add widget</string>
Expand Down

0 comments on commit 5121916

Please sign in to comment.