mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-26 23:27:55 +03:00
Fix #670 Undo for bulk delete
This commit is contained in:
parent
4608a904f5
commit
b2d83009f4
3 changed files with 39 additions and 8 deletions
|
@ -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<DBNote> deletedNotes = new ArrayList<>();
|
||||
List<Integer> 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");
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
<string name="simple_bold">Bold</string>
|
||||
<string name="simple_link">Link</string>
|
||||
<string name="simple_italic">Italic</string>
|
||||
<string name="action_note_deleted">Note deleted</string>
|
||||
<string name="action_note_restored">Note restored</string>
|
||||
<string name="action_note_deleted">Deleted %1$s</string>
|
||||
<string name="action_note_restored">Restored %1$s</string>
|
||||
<string name="action_undo">Undo</string>
|
||||
<string name="action_drawer_open">open navigation</string>
|
||||
<string name="action_drawer_close">close navigation</string>
|
||||
|
@ -141,6 +141,8 @@
|
|||
<string name="simple_move">Move</string>
|
||||
<string name="error_files_app_version_too_old">Is your files app version up to date?</string>
|
||||
<string name="checkbox_could_not_be_toggled">Checkbox could not be toggled.</string>
|
||||
<string name="bulk_notes_deleted">Deleted %1$d notes</string>
|
||||
<string name="bulk_notes_restored">Restored %1$d notes</string>
|
||||
|
||||
<!-- Array: note modes -->
|
||||
<string-array name="noteMode_entries">
|
||||
|
|
|
@ -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
|
Loading…
Reference in a new issue