From 23a535bf35295604b9f1a41992f67c01d0239b33 Mon Sep 17 00:00:00 2001 From: stefan-niedermann Date: Sat, 11 Jan 2020 11:49:43 +0100 Subject: [PATCH] #655 Move notes to another account Fixed ui states on bulk move --- .../activity/NotesListViewActivity.java | 20 ++++++++++++------- .../owncloud/notes/model/ItemAdapter.java | 13 +++++++++++- 2 files changed, 25 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 06e82736..ea5597c7 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 @@ -148,7 +148,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap private ICallback syncCallBack = new ICallback() { @Override public void onFinish() { - adapter.clearSelection(); + adapter.clearSelection(listView); if (mActionMode != null) { mActionMode.finish(); } @@ -973,14 +973,13 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap AccountChooserDialogFragment.newInstance().show(getFragmentManager(), NotesListViewActivity.class.getCanonicalName()); return true; } - default: - return false; } + return false; } @Override public void onDestroyActionMode(ActionMode mode) { - adapter.clearSelection(); + adapter.clearSelection(listView); mActionMode = null; adapter.notifyDataSetChanged(); } @@ -988,14 +987,21 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap @Override public void onAccountChosen(LocalAccount account) { - List selection = adapter.getSelected(); + List selection = new ArrayList<>(adapter.getSelected()); + + 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()); + RecyclerView.ViewHolder viewHolder = listView.findViewHolderForAdapterPosition(i); + if(viewHolder != null) { + viewHolder.itemView.setSelected(false); + } else { + Log.w(TAG, "Could not found viewholder to remove selection"); + } } - mActionMode.finish(); // Act// ion picked, so close the CAB - //after delete selection has to be cleared + mActionMode.finish(); searchView.setIconified(true); refreshLists(); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java b/app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java index 57b5f203..ad19f5f0 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java @@ -1,6 +1,7 @@ package it.niedermann.owncloud.notes.model; import android.text.Html; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -21,6 +22,8 @@ import static androidx.recyclerview.widget.RecyclerView.NO_POSITION; public class ItemAdapter extends RecyclerView.Adapter { + private static final String TAG = ItemAdapter.class.getCanonicalName(); + private static final int section_type = 0; private static final int note_type = 1; private final NoteClickListener noteClickListener; @@ -105,7 +108,15 @@ public class ItemAdapter extends RecyclerView.Adapter { return !selected.contains(position) && selected.add(position); } - public void clearSelection() { + public void clearSelection(RecyclerView recyclerView) { + for (Integer i : getSelected()) { + RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(i); + if(viewHolder != null) { + viewHolder.itemView.setSelected(false); + } else { + Log.w(TAG, "Could not found viewholder to remove selection"); + } + } selected.clear(); }