Skip to content

Commit

Permalink
only show dialog when there is something to delete
Browse files Browse the repository at this point in the history
  • Loading branch information
shyuan7-software authored and truefedex committed Nov 20, 2022
1 parent 8227b3c commit bd0a9ec
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ class HistoryActivity : AppCompatActivity(), AdapterView.OnItemClickListener, Ad
}

private fun showDeleteDialog(deleteAll: Boolean) {
val items = if (deleteAll) adapter!!.items else adapter!!.selectedItems
if (items.isEmpty()) return
if (adapter!!.items.isEmpty() || (adapter!!.selectedItems.isEmpty() && !deleteAll)) return
AlertDialog.Builder(this)
.setTitle(R.string.delete)
.setMessage(if (deleteAll) R.string.msg_delete_history_all else R.string.msg_delete_history)
.setPositiveButton(android.R.string.ok) { _, _ ->
lifecycleScope.launch(Dispatchers.Main) {
if (deleteAll) {
AppDatabase.db.historyDao().deleteWhereTimeLessThan(Long.MAX_VALUE)
return@launch
adapter!!.erase()
} else {
AppDatabase.db.historyDao().delete(*(adapter!!.selectedItems).toTypedArray())
adapter!!.remove(adapter!!.selectedItems)
}
AppDatabase.db.historyDao().delete(*items.toTypedArray())
adapter!!.remove(items)
}
}
.setNeutralButton(android.R.string.cancel) { dialogInterface, i -> }
Expand Down

0 comments on commit bd0a9ec

Please sign in to comment.