Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 420c4e65 authored by Niedermann IT-Dienstleistungen's avatar Niedermann IT-Dienstleistungen
Browse files

#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.
parent f23a4f59
Loading
Loading
Loading
Loading
+27 −17
Original line number Diff line number Diff line
@@ -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;
                    }
                }
            }

+3 −3
Original line number Diff line number Diff line
@@ -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);
        }
    }
+3 −3
Original line number Diff line number Diff line
@@ -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"