From b2d83009f48c698180a1eaa8c20f95af80bcb7da Mon Sep 17 00:00:00 2001 From: stefan-niedermann Date: Sun, 19 Jan 2020 22:42:19 +0100 Subject: [PATCH] Fix #670 Undo for bulk delete --- .../activity/NotesListViewActivity.java | 39 ++++++++++++++++--- app/src/main/res/values/strings.xml | 6 ++- .../metadata/android/en-US/changelogs/72.txt | 2 + 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java index 68f4517a..445c8a9e 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java @@ -602,7 +602,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap adapter.remove(dbNote); refreshLists(); Log.v(TAG, "Item deleted through swipe ----------------------------------------------"); - Snackbar.make(swipeRefreshLayout, R.string.action_note_deleted, Snackbar.LENGTH_LONG) + Snackbar.make(swipeRefreshLayout, getString(R.string.action_note_deleted, dbNote.getTitle()), Snackbar.LENGTH_LONG) .setAction(R.string.action_undo, (View v) -> { db.getNoteServerSyncHelper().addCallbackPush(new ICallback() { @Override @@ -617,7 +617,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap }); db.addNoteAndSync(dbNote.getAccountId(), dbNote); refreshLists(); - Snackbar.make(swipeRefreshLayout, R.string.action_note_restored, Snackbar.LENGTH_SHORT) + Snackbar.make(swipeRefreshLayout, getString(R.string.action_note_restored, dbNote.getTitle()), Snackbar.LENGTH_SHORT) .show(); }) .show(); @@ -955,17 +955,44 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.menu_delete: { + List deletedNotes = new ArrayList<>(); List selection = adapter.getSelected(); for (Integer i : selection) { DBNote note = (DBNote) adapter.getItem(i); + deletedNotes.add(db.getNote(note.getAccountId(), note.getId())); db.deleteNoteAndSync(note.getId()); - // Not needed because of dbsync - //adapter.remove(note); } mode.finish(); // Action picked, so close the CAB //after delete selection has to be cleared searchView.setIconified(true); refreshLists(); + String deletedSnackbarTitle = deletedNotes.size() == 1 + ? getString(R.string.action_note_deleted, deletedNotes.get(0).getTitle()) + : getString(R.string.bulk_notes_deleted, deletedNotes.size()); + Snackbar.make(swipeRefreshLayout, deletedSnackbarTitle, Snackbar.LENGTH_LONG) + .setAction(R.string.action_undo, (View v) -> { + db.getNoteServerSyncHelper().addCallbackPush(new ICallback() { + @Override + public void onFinish() { + refreshLists(); + } + + @Override + public void onScheduled() { + + } + }); + for (DBNote deletedNote : deletedNotes) { + db.addNoteAndSync(deletedNote.getAccountId(), deletedNote); + } + refreshLists(); + String restoreSnackbarTitle = deletedNotes.size() == 1 + ? getString(R.string.action_note_restored, deletedNotes.get(0).getTitle()) + : getString(R.string.bulk_notes_restored, deletedNotes.size()); + Snackbar.make(swipeRefreshLayout, restoreSnackbarTitle, Snackbar.LENGTH_SHORT) + .show(); + }) + .show(); return true; } case R.id.menu_move: { @@ -991,9 +1018,9 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap adapter.deselect(0); for (Integer i : selection) { DBNote note = (DBNote) adapter.getItem(i); - db.moveNoteToAnotherAccount(note.getAccountId(),db.getNote(note.getAccountId(), note.getId()), account.getId()); + db.moveNoteToAnotherAccount(note.getAccountId(), db.getNote(note.getAccountId(), note.getId()), account.getId()); RecyclerView.ViewHolder viewHolder = listView.findViewHolderForAdapterPosition(i); - if(viewHolder != null) { + if (viewHolder != null) { viewHolder.itemView.setSelected(false); } else { Log.w(TAG, "Could not found viewholder to remove selection"); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 32fed779..e5f3542e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -16,8 +16,8 @@ Bold Link Italic - Note deleted - Note restored + Deleted %1$s + Restored %1$s Undo open navigation close navigation @@ -141,6 +141,8 @@ Move Is your files app version up to date? Checkbox could not be toggled. + Deleted %1$d notes + Restored %1$d notes diff --git a/fastlane/metadata/android/en-US/changelogs/72.txt b/fastlane/metadata/android/en-US/changelogs/72.txt index 7854bdc4..6c7c443f 100644 --- a/fastlane/metadata/android/en-US/changelogs/72.txt +++ b/fastlane/metadata/android/en-US/changelogs/72.txt @@ -1,6 +1,8 @@ - Move notes to another account (#655) - Internal Note Links (#646, #623, #202) - Cancel and Delete are redundant on new note (#640) +- Undo for bulk delete (#670) + Requires at least Files app¹ version 3.9.0 ¹ https://github.com/nextcloud/android \ No newline at end of file