Skip to content

Commit

Permalink
added example of how to implement leave behind pattern, using daimaji…
Browse files Browse the repository at this point in the history
…a’s swipelayout
  • Loading branch information
gotev committed Jan 4, 2017
1 parent 7671c65 commit fa24051
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ dependencies {
compile project(':recycleradapter')
compile "com.jakewharton:butterknife:${butterKnifeVersion}"
apt "com.jakewharton:butterknife-compiler:${butterKnifeVersion}"
compile "com.daimajia.swipelayout:library:1.2.0@aar"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.support.v7.widget.RecyclerView;

import net.gotev.recycleradapter.RecyclerAdapter;
import net.gotev.recycleradapterdemo.leavebehind.MyLeaveBehindItem;

import java.util.Random;
import java.util.UUID;
Expand Down Expand Up @@ -42,6 +43,8 @@ protected void onCreate(Bundle savedInstanceState) {
recyclerView.setAdapter(adapter);
adapter.enableDragDrop(recyclerView);

adapter.add(new MyLeaveBehindItem("swipe to left to leave behind", "option"));

for (int i = 0; i < getRandom().nextInt(200) + 50; i++) {
if (i % 2 == 0)
adapter.add(new ExampleItem(this, "example item " + i));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.gotev.recycleradapterdemo.leavebehind;


import net.gotev.recycleradapter.AdapterItem;
import net.gotev.recycleradapterdemo.R;


/**
* Base adapter item to extend when implementing leave-behind material pattern.
* @author Aleksandar Gotev
*/

public abstract class LeaveBehindAdapterItem<T extends LeaveBehindViewHolder> extends AdapterItem<T> {

@Override
public final int getLayoutId() {
return R.layout.item_leave_behind;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.gotev.recycleradapterdemo.leavebehind;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import net.gotev.recycleradapter.RecyclerAdapterNotifier;
import net.gotev.recycleradapter.RecyclerAdapterViewHolder;
import net.gotev.recycleradapterdemo.R;

/**
* Base RecyclerAdapterViewHolder to extend when implementing leave-behind material pattern.
* @author Aleksandar Gotev
*/

public abstract class LeaveBehindViewHolder extends RecyclerAdapterViewHolder {

FrameLayout contentView;
FrameLayout leaveBehindView;

public LeaveBehindViewHolder(final View itemView, final RecyclerAdapterNotifier adapter) {
super(itemView, adapter);

Context context = itemView.getContext();

contentView = (FrameLayout) findViewById(R.id.swipe_content_view);
leaveBehindView = (FrameLayout) findViewById(R.id.swipe_background_layout);

LayoutInflater.from(context).inflate(getContentViewId(), contentView);
LayoutInflater.from(context).inflate(getLeaveBehindId(), leaveBehindView);
}

public abstract int getContentViewId();

public abstract int getLeaveBehindId();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package net.gotev.recycleradapterdemo.leavebehind;

import android.view.View;
import android.widget.TextView;

import net.gotev.recycleradapter.RecyclerAdapterNotifier;
import net.gotev.recycleradapterdemo.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
* @author Aleksandar Gotev
*/

public class MyLeaveBehindItem extends LeaveBehindAdapterItem<MyLeaveBehindItem.Holder> {

private String value;
private String background;

public MyLeaveBehindItem(String value, String background) {
this.value = value;
this.background = background;
}

@Override
protected void bind(Holder holder) {
holder.name.setText(value);
holder.delete.setText(background);
}

public static class Holder extends LeaveBehindViewHolder {

@BindView(R.id.name)
TextView name;

@BindView(R.id.delete)
TextView delete;

public Holder(final View itemView, final RecyclerAdapterNotifier adapter) {
super(itemView, adapter);
ButterKnife.bind(this, itemView);
}

@Override
public int getContentViewId() {
return R.layout.swipe_foregound_layout;
}

@Override
public int getLeaveBehindId() {
return R.layout.swipe_background_layout;
}
}
}
20 changes: 20 additions & 0 deletions app/demo/src/main/res/layout/item_leave_behind.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<com.daimajia.swipe.SwipeLayout
xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:swipe="http:https://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
swipe:leftEdgeSwipeOffset="0dp"
swipe:rightEdgeSwipeOffset="0dp">

<FrameLayout
android:id="@+id/swipe_background_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent" />

<FrameLayout
android:id="@+id/swipe_content_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</com.daimajia.swipe.SwipeLayout>
14 changes: 14 additions & 0 deletions app/demo/src/main/res/layout/swipe_background_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="match_parent"
xmlns:android="http:https://schemas.android.com/apk/res/android">

<TextView
android:id="@+id/delete"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="delete"
android:gravity="center"
android:background="@android:color/holo_blue_bright"/>

</LinearLayout>
17 changes: 17 additions & 0 deletions app/demo/src/main/res/layout/swipe_foregound_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@android:color/white"
android:padding="10dp"
xmlns:android="http:https://schemas.android.com/apk/res/android">

<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textSize="16sp"
android:gravity="center_vertical"
android:textColor="@android:color/black"/>

</LinearLayout>

0 comments on commit fa24051

Please sign in to comment.