#655 Move notes to another account

Fixed ui states on bulk move
This commit is contained in:
stefan-niedermann 2020-01-11 11:49:43 +01:00
parent 9da687f847
commit 23a535bf35
2 changed files with 25 additions and 8 deletions

View file

@ -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<Integer> selection = adapter.getSelected();
List<Integer> 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();
}

View file

@ -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<RecyclerView.ViewHolder> {
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<RecyclerView.ViewHolder> {
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();
}