Skip to content

Commit

Permalink
Merge branch 'release/v0.8.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepenz committed Jan 15, 2016
2 parents e9a6dc0 + 59e9425 commit f3378aa
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 21 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
```
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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"
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
</intent-filter>
</activity>
<activity
android:name=".SimpleActivity"
android:label="@string/sample_simple" />
android:name=".SimpleItemListActivity"
android:label="@string/sample_simple_item_list" />
<activity
android:name=".ImageListActivity"
android:label="@string/sample_image_list" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<SampleItem> fastAdapter;
private ItemAdapter<SampleItem> itemAdapter;

//drag & drop
private SimpleDragCallback touchCallback;
private ItemTouchHelper touchHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
});
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>
<string name="app_name">FastAdapter</string>

<string name="sample_simple">Simple Sample</string>
<string name="sample_simple_item_list">SimpleItemList Sample</string>
<string name="sample_icon_grid">IconGrid Sample</string>
<string name="sample_image_list">ImageList Sample</string>
<string name="sample_multi_select">MultiSelect Sample</string>
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 10
targetSdkVersion 23
versionCode 80
versionName '0.8.0'
versionCode 81
versionName '0.8.1'
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<b>FastAdapter</b>, the bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
]]>
</string>
<string name="library_fastadapter_libraryVersion">0.8.0</string>
<string name="library_fastadapter_libraryVersion">0.8.1</string>
<string name="library_fastadapter_libraryWebsite">https://github.com/mikepenz/FastAdapter</string>
<string name="library_fastadapter_licenseId">apache_2_0</string>
<string name="library_fastadapter_isOpenSource">true</string>
Expand Down

0 comments on commit f3378aa

Please sign in to comment.