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
|
@Override
|
||||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
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());
|
final DBNote dbNote = (DBNote) adapter.getItem(viewHolder.getAdapterPosition());
|
||||||
db.deleteNoteAndSync((dbNote).getId());
|
db.deleteNoteAndSync((dbNote).getId());
|
||||||
adapter.remove(dbNote);
|
adapter.remove(dbNote);
|
||||||
|
@ -398,6 +399,15 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.show();
|
.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 class NoteViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener, View.OnClickListener {
|
||||||
public View noteSwipeable;
|
public View noteSwipeable;
|
||||||
ImageView noteDeleteLeft, noteDeleteRight;
|
ImageView noteFavoriteLeft, noteDeleteRight;
|
||||||
TextView noteTitle;
|
TextView noteTitle;
|
||||||
TextView noteCategory;
|
TextView noteCategory;
|
||||||
TextView noteExcerpt;
|
TextView noteExcerpt;
|
||||||
|
@ -174,7 +174,7 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
private NoteViewHolder(View v) {
|
private NoteViewHolder(View v) {
|
||||||
super(v);
|
super(v);
|
||||||
this.noteSwipeable = v.findViewById(R.id.noteSwipeable);
|
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.noteDeleteRight = v.findViewById(R.id.noteDeleteRight);
|
||||||
this.noteTitle = v.findViewById(R.id.noteTitle);
|
this.noteTitle = v.findViewById(R.id.noteTitle);
|
||||||
this.noteCategory = v.findViewById(R.id.noteCategory);
|
this.noteCategory = v.findViewById(R.id.noteCategory);
|
||||||
|
@ -196,7 +196,7 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showSwipeDelete(boolean left) {
|
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);
|
noteDeleteRight.setVisibility(left ? View.INVISIBLE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,20 +5,20 @@
|
||||||
android:background="@color/bg_attention">
|
android:background="@color/bg_attention">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/noteDeleteLeft"
|
android:id="@+id/noteFavoriteLeft"
|
||||||
android:layout_width="32dp"
|
android:layout_width="32dp"
|
||||||
android:layout_height="32dp"
|
android:layout_height="32dp"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_marginLeft="@dimen/button_padding"
|
android:layout_marginLeft="@dimen/button_padding"
|
||||||
android:layout_marginStart="@dimen/button_padding"
|
android:layout_marginStart="@dimen/button_padding"
|
||||||
android:contentDescription="@string/menu_delete"
|
android:contentDescription="@string/menu_delete"
|
||||||
android:src="@drawable/ic_action_delete" />
|
android:src="@drawable/ic_star_white_24dp" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/noteDeleteRight"
|
android:id="@+id/noteDeleteRight"
|
||||||
android:layout_width="32dp"
|
android:layout_width="32dp"
|
||||||
android:layout_height="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_marginEnd="@dimen/button_padding"
|
||||||
android:layout_marginRight="@dimen/button_padding"
|
android:layout_marginRight="@dimen/button_padding"
|
||||||
android:contentDescription="@string/menu_delete"
|
android:contentDescription="@string/menu_delete"
|
||||||
|
|
Loading…
Reference in a new issue