Loading app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java +28 −19 Original line number Diff line number Diff line Loading @@ -390,13 +390,14 @@ 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); refreshLists(); Log.v("Note", "Item deleted through swipe ----------------------------------------------"); Snackbar.make(swipeRefreshLayout, R.string.action_note_deleted, 7 * 1000) 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) { Loading @@ -407,14 +408,22 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap } }) .show(); break; } case ItemTouchHelper.RIGHT: { final DBNote dbNote = (DBNote) adapter.getItem(viewHolder.getAdapterPosition()); db.toggleFavorite(dbNote, null); refreshLists(); break; } } } @Override public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { ItemAdapter.NoteViewHolder noteViewHolder = (ItemAdapter.NoteViewHolder) viewHolder; // show delete icon on the right side noteViewHolder.showSwipeDelete(dX > 0); // show swipe icon on the side noteViewHolder.showSwipe(dX>0); // move only swipeable part of item (not leave-behind) getDefaultUIUtil().onDraw(c, recyclerView, noteViewHolder.noteSwipeable, dX, dY, actionState, isCurrentlyActive); } Loading app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java +18 −12 Original line number Diff line number Diff line Loading @@ -172,11 +172,8 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { public class NoteViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener, View.OnClickListener { @BindView(R.id.noteSwipeable) public View noteSwipeable; @BindView(R.id.noteDeleteLeft) ImageView noteDeleteLeft; @BindView(R.id.noteDeleteRight) ImageView noteDeleteRight; @BindView(R.id.noteTitle) View noteSwipeFrame; ImageView noteFavoriteLeft, noteDeleteRight; TextView noteTitle; @BindView(R.id.noteCategory) TextView noteCategory; Loading @@ -187,11 +184,19 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @BindView(R.id.noteFavorite) ImageView noteFavorite; private NoteViewHolder(View view) { super(view); ButterKnife.bind(this, view); view.setOnClickListener(this); view.setOnLongClickListener(this); private NoteViewHolder(View v) { super(v); this.noteSwipeFrame = v.findViewById(R.id.noteSwipeFrame); this.noteSwipeable = v.findViewById(R.id.noteSwipeable); 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); this.noteExcerpt = v.findViewById(R.id.noteExcerpt); this.noteStatus = v.findViewById(R.id.noteStatus); this.noteFavorite = v.findViewById(R.id.noteFavorite); v.setOnClickListener(this); v.setOnLongClickListener(this); } @Override Loading @@ -204,9 +209,10 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { return noteClickListener.onNoteLongClick(getAdapterPosition(), v); } public void showSwipeDelete(boolean left) { noteDeleteLeft.setVisibility(left ? View.VISIBLE : View.INVISIBLE); public void showSwipe(boolean left) { noteFavoriteLeft.setVisibility(left ? View.VISIBLE : View.INVISIBLE); noteDeleteRight.setVisibility(left ? View.INVISIBLE : View.VISIBLE); noteSwipeFrame.setBackgroundResource(left ? R.color.bg_warning : R.color.bg_attention); } } Loading app/src/main/res/layout/fragment_notes_list_note_item.xml +8 −7 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/noteSwipeFrame" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/bg_attention"> <ImageView android:id="@+id/noteDeleteLeft" android:layout_width="wrap_content" android:layout_height="wrap_content" 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_delete_white_32dp" /> android:src="@drawable/ic_star_white_24dp" /> <ImageView android:id="@+id/noteDeleteRight" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end|center_vertical" android:layout_width="32dp" android:layout_height="32dp" 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 app/src/main/res/values/colors.xml +2 −1 Original line number Diff line number Diff line Loading @@ -10,7 +10,8 @@ <color name="bg_transparent">#aa000000</color> <color name="bg_highlighted">#f3f3f3</color> <color name="bg_normal">#ffffff</color> <color name="bg_attention">#662020</color> <color name="bg_attention">#d40000</color> <color name="bg_warning">#ffcc00</color> <color name="fg_default">#000000</color> <color name="fg_default_selection">#333333</color> <color name="fg_default_low">#666666</color> Loading Loading
app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java +28 −19 Original line number Diff line number Diff line Loading @@ -390,13 +390,14 @@ 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); refreshLists(); Log.v("Note", "Item deleted through swipe ----------------------------------------------"); Snackbar.make(swipeRefreshLayout, R.string.action_note_deleted, 7 * 1000) 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) { Loading @@ -407,14 +408,22 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap } }) .show(); break; } case ItemTouchHelper.RIGHT: { final DBNote dbNote = (DBNote) adapter.getItem(viewHolder.getAdapterPosition()); db.toggleFavorite(dbNote, null); refreshLists(); break; } } } @Override public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { ItemAdapter.NoteViewHolder noteViewHolder = (ItemAdapter.NoteViewHolder) viewHolder; // show delete icon on the right side noteViewHolder.showSwipeDelete(dX > 0); // show swipe icon on the side noteViewHolder.showSwipe(dX>0); // move only swipeable part of item (not leave-behind) getDefaultUIUtil().onDraw(c, recyclerView, noteViewHolder.noteSwipeable, dX, dY, actionState, isCurrentlyActive); } Loading
app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java +18 −12 Original line number Diff line number Diff line Loading @@ -172,11 +172,8 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { public class NoteViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener, View.OnClickListener { @BindView(R.id.noteSwipeable) public View noteSwipeable; @BindView(R.id.noteDeleteLeft) ImageView noteDeleteLeft; @BindView(R.id.noteDeleteRight) ImageView noteDeleteRight; @BindView(R.id.noteTitle) View noteSwipeFrame; ImageView noteFavoriteLeft, noteDeleteRight; TextView noteTitle; @BindView(R.id.noteCategory) TextView noteCategory; Loading @@ -187,11 +184,19 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @BindView(R.id.noteFavorite) ImageView noteFavorite; private NoteViewHolder(View view) { super(view); ButterKnife.bind(this, view); view.setOnClickListener(this); view.setOnLongClickListener(this); private NoteViewHolder(View v) { super(v); this.noteSwipeFrame = v.findViewById(R.id.noteSwipeFrame); this.noteSwipeable = v.findViewById(R.id.noteSwipeable); 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); this.noteExcerpt = v.findViewById(R.id.noteExcerpt); this.noteStatus = v.findViewById(R.id.noteStatus); this.noteFavorite = v.findViewById(R.id.noteFavorite); v.setOnClickListener(this); v.setOnLongClickListener(this); } @Override Loading @@ -204,9 +209,10 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { return noteClickListener.onNoteLongClick(getAdapterPosition(), v); } public void showSwipeDelete(boolean left) { noteDeleteLeft.setVisibility(left ? View.VISIBLE : View.INVISIBLE); public void showSwipe(boolean left) { noteFavoriteLeft.setVisibility(left ? View.VISIBLE : View.INVISIBLE); noteDeleteRight.setVisibility(left ? View.INVISIBLE : View.VISIBLE); noteSwipeFrame.setBackgroundResource(left ? R.color.bg_warning : R.color.bg_attention); } } Loading
app/src/main/res/layout/fragment_notes_list_note_item.xml +8 −7 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/noteSwipeFrame" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/bg_attention"> <ImageView android:id="@+id/noteDeleteLeft" android:layout_width="wrap_content" android:layout_height="wrap_content" 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_delete_white_32dp" /> android:src="@drawable/ic_star_white_24dp" /> <ImageView android:id="@+id/noteDeleteRight" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end|center_vertical" android:layout_width="32dp" android:layout_height="32dp" 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
app/src/main/res/values/colors.xml +2 −1 Original line number Diff line number Diff line Loading @@ -10,7 +10,8 @@ <color name="bg_transparent">#aa000000</color> <color name="bg_highlighted">#f3f3f3</color> <color name="bg_normal">#ffffff</color> <color name="bg_attention">#662020</color> <color name="bg_attention">#d40000</color> <color name="bg_warning">#ffcc00</color> <color name="fg_default">#000000</color> <color name="fg_default_selection">#333333</color> <color name="fg_default_low">#666666</color> Loading