mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-10-25 22:26:00 +03:00
#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:
parent
f23a4f5970
commit
420c4e65cf
3 changed files with 33 additions and 23 deletions
|
@ -381,7 +381,8 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
|
|||
*/
|
||||
@Override
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
if (direction == ItemTouchHelper.LEFT || direction == ItemTouchHelper.RIGHT) {
|
||||
switch(direction) {
|
||||
case ItemTouchHelper.LEFT: {
|
||||
final DBNote dbNote = (DBNote) adapter.getItem(viewHolder.getAdapterPosition());
|
||||
db.deleteNoteAndSync((dbNote).getId());
|
||||
adapter.remove(dbNote);
|
||||
|
@ -398,6 +399,15 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
|
|||
}
|
||||
})
|
||||
.show();
|
||||
break;
|
||||
}
|
||||
case ItemTouchHelper.RIGHT: {
|
||||
final DBNote dbNote = (DBNote) adapter.getItem(viewHolder.getAdapterPosition());
|
||||
db.toggleFavorite(dbNote, null);
|
||||
adapter.notifyItemChanged(viewHolder.getAdapterPosition());
|
||||
refreshLists();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue