#310 Swipe left favorite

The swipe from right to left marks a note as favorite.
Open question: how to handle the background color? It should be yellow when swiping from left and red when swiping from right.
This commit is contained in:
Niedermann IT-Dienstleistungen 2018-04-10 17:16:16 +02:00
parent f23a4f5970
commit 420c4e65cf
3 changed files with 33 additions and 23 deletions

View file

@ -381,23 +381,33 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
*/
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
if (direction == ItemTouchHelper.LEFT || direction == ItemTouchHelper.RIGHT) {
final DBNote dbNote = (DBNote) adapter.getItem(viewHolder.getAdapterPosition());
db.deleteNoteAndSync((dbNote).getId());
adapter.remove(dbNote);
refreshLists();
Log.v("Note", "Item deleted through swipe ----------------------------------------------");
Snackbar.make(swipeRefreshLayout, R.string.action_note_deleted, Snackbar.LENGTH_LONG)
.setAction(R.string.action_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
db.addNoteAndSync(dbNote);
refreshLists();
Snackbar.make(swipeRefreshLayout, R.string.action_note_restored, Snackbar.LENGTH_SHORT)
.show();
}
})
.show();
switch(direction) {
case ItemTouchHelper.LEFT: {
final DBNote dbNote = (DBNote) adapter.getItem(viewHolder.getAdapterPosition());
db.deleteNoteAndSync((dbNote).getId());
adapter.remove(dbNote);
refreshLists();
Log.v("Note", "Item deleted through swipe ----------------------------------------------");
Snackbar.make(swipeRefreshLayout, R.string.action_note_deleted, Snackbar.LENGTH_LONG)
.setAction(R.string.action_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
db.addNoteAndSync(dbNote);
refreshLists();
Snackbar.make(swipeRefreshLayout, R.string.action_note_restored, Snackbar.LENGTH_SHORT)
.show();
}
})
.show();
break;
}
case ItemTouchHelper.RIGHT: {
final DBNote dbNote = (DBNote) adapter.getItem(viewHolder.getAdapterPosition());
db.toggleFavorite(dbNote, null);
adapter.notifyItemChanged(viewHolder.getAdapterPosition());
refreshLists();
break;
}
}
}

View file

@ -164,7 +164,7 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public class NoteViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener, View.OnClickListener {
public View noteSwipeable;
ImageView noteDeleteLeft, noteDeleteRight;
ImageView noteFavoriteLeft, noteDeleteRight;
TextView noteTitle;
TextView noteCategory;
TextView noteExcerpt;
@ -174,7 +174,7 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private NoteViewHolder(View v) {
super(v);
this.noteSwipeable = v.findViewById(R.id.noteSwipeable);
this.noteDeleteLeft = v.findViewById(R.id.noteDeleteLeft);
this.noteFavoriteLeft = v.findViewById(R.id.noteFavoriteLeft);
this.noteDeleteRight = v.findViewById(R.id.noteDeleteRight);
this.noteTitle = v.findViewById(R.id.noteTitle);
this.noteCategory = v.findViewById(R.id.noteCategory);
@ -196,7 +196,7 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}
public void showSwipeDelete(boolean left) {
noteDeleteLeft.setVisibility(left ? View.VISIBLE : View.INVISIBLE);
noteFavoriteLeft.setVisibility(left ? View.VISIBLE : View.INVISIBLE);
noteDeleteRight.setVisibility(left ? View.INVISIBLE : View.VISIBLE);
}
}

View file

@ -5,20 +5,20 @@
android:background="@color/bg_attention">
<ImageView
android:id="@+id/noteDeleteLeft"
android:id="@+id/noteFavoriteLeft"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/button_padding"
android:layout_marginStart="@dimen/button_padding"
android:contentDescription="@string/menu_delete"
android:src="@drawable/ic_action_delete" />
android:src="@drawable/ic_star_white_24dp" />
<ImageView
android:id="@+id/noteDeleteRight"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_gravity="right|end|center_vertical"
android:layout_marginEnd="@dimen/button_padding"
android:layout_marginRight="@dimen/button_padding"
android:contentDescription="@string/menu_delete"