Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.app.SearchManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Canvas;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
Expand Down Expand Up @@ -319,6 +320,20 @@ public void onClick(View v) {
.show();
}
}

@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);
// move only swipeable part of item (not leave-behind)
getDefaultUIUtil().onDraw(c, recyclerView, noteViewHolder.noteSwipeable, dX, dY, actionState, isCurrentlyActive);
}

@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
getDefaultUIUtil().clearView(((ItemAdapter.NoteViewHolder) viewHolder).noteSwipeable);
}
});
touchHelper.attachToRecyclerView(listView);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public interface NoteClickListener {
}

public class NoteViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener, View.OnClickListener {
// each data item is just a string in this case
public View noteSwipeable;
public ImageView noteDeleteLeft, noteDeleteRight;
public TextView noteTitle;
public TextView noteCategory;
public TextView noteExcerpt;
Expand All @@ -166,6 +167,9 @@ public class NoteViewHolder extends RecyclerView.ViewHolder implements View.OnLo

private NoteViewHolder(View v) {
super(v);
this.noteSwipeable = v.findViewById(R.id.noteSwipeable);
this.noteDeleteLeft = (ImageView) v.findViewById(R.id.noteDeleteLeft);
this.noteDeleteRight = (ImageView) v.findViewById(R.id.noteDeleteRight);
this.noteTitle = (TextView) v.findViewById(R.id.noteTitle);
this.noteCategory = (TextView) v.findViewById(R.id.noteCategory);
this.noteExcerpt = (TextView) v.findViewById(R.id.noteExcerpt);
Expand All @@ -188,6 +192,11 @@ public void onClick(View v) {
public boolean onLongClick(View v) {
return noteClickListener.onNoteLongClick(position, v);
}

public void showSwipeDelete(boolean left) {
noteDeleteLeft.setVisibility(left ? View.VISIBLE : View.INVISIBLE);
noteDeleteRight.setVisibility(left ? View.INVISIBLE : View.VISIBLE);
}
}

public static class SectionViewHolder extends RecyclerView.ViewHolder {
Expand Down
176 changes: 101 additions & 75 deletions app/src/main/res/layout/fragment_notes_list_note_item.xml
Original file line number Diff line number Diff line change
@@ -1,87 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_item_background_selector"
>
android:background="@color/bg_attention">

<TextView
android:id="@+id/noteTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
<ImageView
android:id="@+id/noteDeleteLeft"
android:layout_marginLeft="16dp"
android:layout_marginEnd="70dp"
android:layout_marginRight="70dp"
android:ellipsize="marquee"
android:maxLines="1"
android:textColor="@drawable/list_item_color_selector"
android:textSize="16sp" />

<TextView
android:id="@+id/noteCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_below="@id/noteTitle"
android:maxLines="1"
android:textColor="@drawable/list_item_color_selector"
android:textSize="14sp" />

<TextView
android:id="@+id/noteExcerpt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/noteCategory"
android:layout_toEndOf="@id/noteCategory"
android:layout_alignWithParentIfMissing="true"
android:layout_below="@id/noteTitle"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@drawable/list_item_color_selector_low"
android:textSize="14sp" />
android:layout_height="fill_parent"
android:src="@drawable/ic_action_delete"
android:layout_gravity="left"
/>

<ImageView
android:id="@+id/noteStatus"
android:id="@+id/noteDeleteRight"
android:layout_marginRight="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_sync_alert_grey600_18dp"
android:layout_toEndOf="@id/noteTitle"
android:layout_toRightOf="@id/noteTitle"
android:layout_marginStart="-65dp"
android:layout_marginLeft="-65dp"
android:layout_alignBaseline="@id/noteTitle"
android:baseline="14dp"
android:layout_height="fill_parent"
android:src="@drawable/ic_action_delete"
android:layout_gravity="right"
/>

<ImageView
android:id="@+id/noteFavorite"
android:layout_width="wrap_content"
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginEnd="6dp"
android:layout_marginRight="6dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignBaseline="@id/noteTitle"
android:baseline="29dp"
/>
android:background="@drawable/list_item_background_selector"
android:id="@+id/noteSwipeable"
>

<ImageView
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_below="@id/noteExcerpt"
android:layout_marginTop="16dp"
android:src="@color/separator" />
</RelativeLayout>
<TextView
android:id="@+id/noteTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="70dp"
android:layout_marginRight="70dp"
android:ellipsize="marquee"
android:maxLines="1"
android:textColor="@drawable/list_item_color_selector"
android:textSize="16sp" />

<TextView
android:id="@+id/noteCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_below="@id/noteTitle"
android:maxLines="1"
android:textColor="@drawable/list_item_color_selector"
android:textSize="14sp" />

<TextView
android:id="@+id/noteExcerpt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/noteCategory"
android:layout_toEndOf="@id/noteCategory"
android:layout_alignWithParentIfMissing="true"
android:layout_below="@id/noteTitle"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@drawable/list_item_color_selector_low"
android:textSize="14sp" />

<ImageView
android:id="@+id/noteStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_sync_alert_grey600_18dp"
android:layout_toEndOf="@id/noteTitle"
android:layout_toRightOf="@id/noteTitle"
android:layout_marginStart="-65dp"
android:layout_marginLeft="-65dp"
android:layout_alignBaseline="@id/noteTitle"
android:baseline="14dp"
/>

<ImageView
android:id="@+id/noteFavorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginEnd="6dp"
android:layout_marginRight="6dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignBaseline="@id/noteTitle"
android:baseline="29dp"
/>

<ImageView
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_below="@id/noteExcerpt"
android:layout_marginTop="16dp"
android:src="@color/separator" />
</RelativeLayout>

</FrameLayout>