diff --git a/README.md b/README.md
index d73f5062e..a7404087c 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,7 @@ Beside being blazing fast, minimizing the code you need to write, it is also rea
- Selection / Multi-Selection
- Expandable items
- Write less code, get better results
+- Simple Drag & Drop
- Headers
- Footers
- Highly optimized code
@@ -27,7 +28,7 @@ Beside being blazing fast, minimizing the code you need to write, it is also rea
#Include in your project
##Using Maven
```javascript
-compile('com.mikepenz:fastadapter:0.8.0@aar') {
+compile('com.mikepenz:fastadapter:0.8.1@aar') {
transitive = true
}
```
diff --git a/app/build.gradle b/app/build.gradle
index 687103bd7..d66059356 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -12,8 +12,8 @@ android {
defaultConfig {
minSdkVersion 11
targetSdkVersion 23
- versionCode 80
- versionName '0.80'
+ versionCode 81
+ versionName '0.8.1'
applicationVariants.all { variant ->
variant.outputs.each { output ->
@@ -52,7 +52,7 @@ dependencies {
//used to generate the drawer on the left
//https://github.com/mikepenz/MaterialDrawer
- compile('com.mikepenz:materialdrawer:5.0.0.fastAdapter.b10-SNAPSHOT@aar') {
+ compile('com.mikepenz:materialdrawer:5.0.0.fastAdapter.b11-SNAPSHOT@aar') {
transitive = true
exclude module: "fastadapter"
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index d92e0497c..85fa1f80d 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -16,8 +16,8 @@
+ android:name=".SimpleItemListActivity"
+ android:label="@string/sample_simple_item_list" />
diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/IconGridActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/IconGridActivity.java
index 0b25bd92e..8085c45a0 100755
--- a/app/src/main/java/com/mikepenz/fastadapter/app/IconGridActivity.java
+++ b/app/src/main/java/com/mikepenz/fastadapter/app/IconGridActivity.java
@@ -55,7 +55,7 @@ protected void onCreate(Bundle savedInstanceState) {
.withSavedInstance(savedInstanceState)
.withShowDrawerOnFirstLaunch(true)
.addDrawerItems(
- new PrimaryDrawerItem().withName(R.string.sample_simple).withSelectable(false).withIdentifier(6).withIcon(MaterialDesignIconic.Icon.gmi_format_align_justify),
+ new PrimaryDrawerItem().withName(R.string.sample_simple_item_list).withSelectable(false).withIdentifier(6).withIcon(MaterialDesignIconic.Icon.gmi_format_align_justify),
new PrimaryDrawerItem().withName(R.string.sample_image_list).withSelectable(false).withIdentifier(5).withIcon(MaterialDesignIconic.Icon.gmi_wallpaper),
new PrimaryDrawerItem().withName(R.string.sample_multi_select).withSelectable(false).withIdentifier(1).withIcon(MaterialDesignIconic.Icon.gmi_select_all),
new PrimaryDrawerItem().withName(R.string.sample_collapsible).withSelectable(false).withIdentifier(2).withIcon(MaterialDesignIconic.Icon.gmi_check_all),
@@ -80,7 +80,7 @@ public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
} else if (drawerItem.getIdentifier() == 5) {
intent = new Intent(IconGridActivity.this, ImageListActivity.class);
} else if (drawerItem.getIdentifier() == 6) {
- intent = new Intent(IconGridActivity.this, SimpleActivity.class);
+ intent = new Intent(IconGridActivity.this, SimpleItemListActivity.class);
} else if (drawerItem.getIdentifier() == 100) {
intent = new LibsBuilder()
.withFields(R.string.class.getFields())
diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SimpleActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java
similarity index 77%
rename from app/src/main/java/com/mikepenz/fastadapter/app/SimpleActivity.java
rename to app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java
index 0ed139270..eca8a7e77 100755
--- a/app/src/main/java/com/mikepenz/fastadapter/app/SimpleActivity.java
+++ b/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java
@@ -9,6 +9,8 @@
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
+import android.support.v7.widget.helper.ItemTouchHelper;
+import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -21,21 +23,31 @@
import com.mikepenz.fastadapter.adapters.ItemAdapter;
import com.mikepenz.fastadapter.app.adapter.FastScrollIndicatorAdapter;
import com.mikepenz.fastadapter.app.items.SampleItem;
+import com.mikepenz.fastadapter.drag.ItemTouchCallback;
+import com.mikepenz.fastadapter.drag.SimpleDragCallback;
import com.mikepenz.materialize.MaterializeBuilder;
import com.turingtechnologies.materialscrollbar.AlphabetIndicator;
import com.turingtechnologies.materialscrollbar.MaterialScrollBar;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Random;
-public class SimpleActivity extends AppCompatActivity {
+public class SimpleItemListActivity extends AppCompatActivity implements ItemTouchCallback {
private static final String[] ALPHABET = new String[]{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
+ //our recyclerView
+ private RecyclerView recyclerView;
+
//save our FastAdapter
private FastAdapter fastAdapter;
private ItemAdapter itemAdapter;
+ //drag & drop
+ private SimpleDragCallback touchCallback;
+ private ItemTouchHelper touchHelper;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -76,13 +88,13 @@ public boolean filter(SampleItem item, CharSequence constraint) {
});
//get our recyclerView and do basic setup
- RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
- rv.setLayoutManager(new LinearLayoutManager(this));
- rv.setItemAnimator(new DefaultItemAnimator());
- rv.setAdapter(fastScrollIndicatorAdapter.wrap(itemAdapter.wrap(fastAdapter)));
+ recyclerView = (RecyclerView) findViewById(R.id.rv);
+ recyclerView.setLayoutManager(new LinearLayoutManager(this));
+ recyclerView.setItemAnimator(new DefaultItemAnimator());
+ recyclerView.setAdapter(fastScrollIndicatorAdapter.wrap(itemAdapter.wrap(fastAdapter)));
- //add a FastScrollBar (Showcase compatiblity)
- MaterialScrollBar materialScrollBar = new MaterialScrollBar(this, rv, true);
+ //add a FastScrollBar (Showcase compatibility)
+ MaterialScrollBar materialScrollBar = new MaterialScrollBar(this, recyclerView, true);
materialScrollBar.setHandleColour(ContextCompat.getColor(this, R.color.accent)).setAutoHide(false);
materialScrollBar.addIndicator(new AlphabetIndicator(this), true);
@@ -98,6 +110,11 @@ public boolean filter(SampleItem item, CharSequence constraint) {
}
itemAdapter.add(items);
+ //add drag and drop for item
+ touchCallback = new SimpleDragCallback(this);
+ touchHelper = new ItemTouchHelper(touchCallback); // Create ItemTouchHelper and pass with parameter the SimpleDragCallback
+ touchHelper.attachToRecyclerView(recyclerView); // Attach ItemTouchHelper to RecyclerView
+
//restore selections (this has to be done after the items were added
fastAdapter.withSavedInstanceState(savedInstanceState);
@@ -137,6 +154,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
+ touchCallback.setIsDragEnabled(false);
itemAdapter.filter(s);
return true;
}
@@ -145,6 +163,7 @@ public boolean onQueryTextSubmit(String s) {
@Override
public boolean onQueryTextChange(String s) {
itemAdapter.filter(s);
+ touchCallback.setIsDragEnabled(TextUtils.isEmpty(s));
return true;
}
});
@@ -154,4 +173,11 @@ public boolean onQueryTextChange(String s) {
return super.onCreateOptionsMenu(menu);
}
+
+ @Override
+ public boolean itemTouchOnMove(int oldPosition, int newPosition) {
+ Collections.swap(itemAdapter.getAdapterItems(), oldPosition, newPosition); // change position
+ fastAdapter.notifyAdapterItemMoved(oldPosition, newPosition);
+ return true;
+ }
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a3a185282..dbc3bf5b2 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,7 +1,7 @@
FastAdapter
- Simple Sample
+ SimpleItemList Sample
IconGrid Sample
ImageList Sample
MultiSelect Sample
diff --git a/gradle.properties b/gradle.properties
index dea771f0b..341be5ab5 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -19,8 +19,8 @@ org.gradle.daemon=true
org.gradle.parallel=true
# Maven stuff
-VERSION_NAME=0.8.0
-VERSION_CODE=80
+VERSION_NAME=0.8.1
+VERSION_CODE=81
GROUP=com.mikepenz
POM_DESCRIPTION=FastAdapter Library
diff --git a/library/build.gradle b/library/build.gradle
index 5193ffc53..c9918c932 100644
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 10
targetSdkVersion 23
- versionCode 80
- versionName '0.8.0'
+ versionCode 81
+ versionName '0.8.1'
}
buildTypes {
release {
diff --git a/library/src/main/java/com/mikepenz/fastadapter/drag/ItemTouchCallback.java b/library/src/main/java/com/mikepenz/fastadapter/drag/ItemTouchCallback.java
new file mode 100644
index 000000000..7578fcbaa
--- /dev/null
+++ b/library/src/main/java/com/mikepenz/fastadapter/drag/ItemTouchCallback.java
@@ -0,0 +1,13 @@
+package com.mikepenz.fastadapter.drag;
+
+public interface ItemTouchCallback {
+
+ /**
+ * Called when an item has been dragged
+ *
+ * @param oldPosition start position
+ * @param newPosition end position
+ * @return true if moved otherwise false
+ */
+ boolean itemTouchOnMove(int oldPosition, int newPosition);
+}
\ No newline at end of file
diff --git a/library/src/main/java/com/mikepenz/fastadapter/drag/SimpleDragCallback.java b/library/src/main/java/com/mikepenz/fastadapter/drag/SimpleDragCallback.java
new file mode 100644
index 000000000..37eb9413a
--- /dev/null
+++ b/library/src/main/java/com/mikepenz/fastadapter/drag/SimpleDragCallback.java
@@ -0,0 +1,39 @@
+package com.mikepenz.fastadapter.drag;
+
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.helper.ItemTouchHelper;
+
+/**
+ * based on the sample from
+ * https://github.com/AleBarreto/DragRecyclerView
+ */
+public class SimpleDragCallback extends ItemTouchHelper.SimpleCallback {
+
+ //our callback
+ private ItemTouchCallback mCallbackItemTouch; // interface
+ private boolean mIsDragEnabled = true;
+
+ public SimpleDragCallback(ItemTouchCallback itemTouchCallback) {
+ super(ItemTouchHelper.UP | ItemTouchHelper.DOWN, 0);
+ this.mCallbackItemTouch = itemTouchCallback;
+ }
+
+ public void setIsDragEnabled(boolean mIsDragEnabled) {
+ this.mIsDragEnabled = mIsDragEnabled;
+ }
+
+ @Override
+ public boolean isLongPressDragEnabled() {
+ return mIsDragEnabled;
+ }
+
+ @Override
+ public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
+ return mCallbackItemTouch.itemTouchOnMove(viewHolder.getAdapterPosition(), target.getAdapterPosition()); // information to the interface
+ }
+
+ @Override
+ public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
+ // swiped disabled
+ }
+}
\ No newline at end of file
diff --git a/library/src/main/res/values/library_fastadapter_strings.xml b/library/src/main/res/values/library_fastadapter_strings.xml
index 0ca1e7a2a..9881af2f5 100755
--- a/library/src/main/res/values/library_fastadapter_strings.xml
+++ b/library/src/main/res/values/library_fastadapter_strings.xml
@@ -10,7 +10,7 @@
FastAdapter, the bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
]]>
- 0.8.0
+ 0.8.1
https://github.com/mikepenz/FastAdapter
apache_2_0
true