Skip to content

Commit

Permalink
Merge branch 'release/v1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepenz committed Feb 25, 2016
2 parents 04c3456 + 5937319 commit e38d04e
Show file tree
Hide file tree
Showing 29 changed files with 559 additions and 118 deletions.
14 changes: 14 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FastAdapter contributors (sorted alphabeticaly)
============================================

* **[Fabian Terhorst](https://github.com/FabianTerhorst)**

* EndlessScroll-Listener (EndlessScroll Sample)

* **[Mattias Isegran Bergander](https://github.com/mattiasbe)**

* "Leave-Behind"-Pattern (SwipeList Sample)

* **[Rainer Lang](https://github.com/Rainer-Lang)**

*
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@ Beside being blazing fast, minimizing the code you need to write, it is also rea

##A quick overview:
- Click / Long-Click listeners
- Selection / Multi-Selection [MultiselectSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java)
- Selection / Multi-Selection [
- [MultiselectSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java)
- [CheckBoxSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/CheckBoxSampleActivity.java)
- [RadioButtonSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/RadioButtonSampleActivity.java)
- Expandable items
- [ExpandableSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/ExpandableSampleActivity.java)
- [IconGridSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/IconGridActivity.java)
- [AdvancedSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.java)
- Write less code, get better results
- Simple Drag & Drop
- [SimpleItemListSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java)
- Highly optimized code
- Simple Drag & Drop [(SimpleItemListSample)](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java)
- Headers
- [StickyHeaderSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/StickyHeaderSampleActivity.java)
- [AdvancedSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.java)
- Footers
- FastScroller (external lib)
- [SimpleItemListSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java)
- Filter
- [SimpleItemListSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java)
- Highly optimized code
- Filter [(SimpleItemListSample)](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java)
- Includes suggestions from the Android Team
- Easily extensible
- Endless Scroll [(EndlessScrollSample)](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/EndlessScrollListActivity.java)
- "Leave-Behind"-Pattern [(SwipeListSample)](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java)
- Split item view and model
- [GenericItem](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/GenericItemActivity.java)
- [MultiTypeGenericItem](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/MultiTypeGenericItemActivity.java)
- Chain other Adapters
- [SimpleItemListSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java)
- [StickyHeaderSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/StickyHeaderSampleActivity.java)
- Comes with useful Helpers
- ActionModeHelper [MultiselectSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java)
- UndoHelper [MultiselectSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java)
- ActionModeHelper [(MultiselectSample)](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java)
- UndoHelper [(MultiselectSample)](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java)
- More to come...
- FastScroller (external lib) [(SimpleItemListSample)](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java)

#Preview
##Demo
Expand All @@ -52,14 +52,14 @@ You can try it out here [Google Play](https://play.google.com/store/apps/details

The library is split up into core, and extensions. The core functions are included in the following dependency.
```gradle
compile('com.mikepenz:fastadapter:1.1.2@aar') {
compile('com.mikepenz:fastadapter:1.2.0@aar') {
transitive = true
}
```

All additions are included in the following dependency.
```gradle
compile 'com.mikepenz:fastadapter-extensions:1.1.2@aar'
compile 'com.mikepenz:fastadapter-extensions:1.2.0@aar'
```


Expand Down Expand Up @@ -142,6 +142,10 @@ Other Libs:
* Mike Penz
* [mikepenz.com](http://mikepenz.com) - <[email protected]>
* [paypal.me/mikepenz](http://paypal.me/mikepenz)

#Contributors

This free, open source software was also made possible by a group of volunteers that put many hours of hard work into it. See the [CONTRIBUTORS.md](CONTRIBUTORS.md) file for details.

#License

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dependencies {

//used to generate the drawer on the left
//https://github.com/mikepenz/MaterialDrawer
compile('com.mikepenz:materialdrawer:5.0.0@aar') {
compile('com.mikepenz:materialdrawer:5.0.6-SNAPSHOT@aar') {
transitive = true
exclude module: "fastadapter"
}
Expand All @@ -63,7 +63,7 @@ dependencies {
compile 'com.mikepenz:itemanimators:0.2.1@aar'
//used to generate the Open Source section
//https://github.com/mikepenz/AboutLibraries
compile('com.mikepenz:aboutlibraries:5.5.2@aar') {
compile('com.mikepenz:aboutlibraries:5.5.6@aar') {
transitive = true
exclude module: "fastadapter"
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,8 @@
<activity
android:name=".RadioButtonSampleActivity"
android:label="@string/sample_radiobutton_item" />
<activity
android:name=".EndlessScrollListActivity"
android:label="@string/sample_endless_scroll_item" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.os.Bundle;
import android.support.v4.view.LayoutInflaterCompat;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.DefaultItemAnimator;
Expand Down Expand Up @@ -77,23 +76,13 @@ protected void onCreate(Bundle savedInstanceState) {

//configure our mFastAdapter
//as we provide id's for the items we want the hasStableIds enabled to speed up things
mFastAdapter.setHasStableIds(true);
mFastAdapter.withMultiSelect(true);
mFastAdapter.withSelectOnLongClick(true);
mFastAdapter.withOnPreClickListener(new FastAdapter.OnClickListener<IItem>() {
@Override
public boolean onClick(View v, IAdapter adapter, IItem item, int position) {
//we handle the default onClick behavior for the actionMode. This will return null if it didn't do anything and you can handle a normal onClick
Boolean res = mActionModeHelper.onClick(item, position);

if (res != null && res) {
if (!((IExpandable) item).isExpanded()) {
ViewCompat.animate(v.findViewById(R.id.material_drawer_icon)).rotation(0).start();
} else {
ViewCompat.animate(v.findViewById(R.id.material_drawer_icon)).rotation(180).start();
}
}

Boolean res = mActionModeHelper.onClick(item);
return res != null ? res : false;
}
});
Expand All @@ -108,13 +97,12 @@ public boolean onLongClick(View v, IAdapter adapter, IItem item, int position) {
}
}

//handle the longclick actions
ActionMode actionMode = mActionModeHelper.onLongClick(AdvancedSampleActivity.this, position);

if (actionMode != null) {
//we want color our CAB
findViewById(R.id.action_mode_bar).setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(AdvancedSampleActivity.this, R.attr.colorPrimary, R.color.material_drawer_primary));
}

//if we have no actionMode we do not consume the event
return actionMode != null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
package com.mikepenz.fastadapter.app;

import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
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;
import android.view.View;
import android.widget.Toast;

import com.mikepenz.fastadapter.FastAdapter;
import com.mikepenz.fastadapter.IAdapter;
import com.mikepenz.fastadapter.IItemAdapter;
import com.mikepenz.fastadapter.adapters.FastItemAdapter;
import com.mikepenz.fastadapter.adapters.FooterAdapter;
import com.mikepenz.fastadapter.adapters.ItemAdapter.ItemFilterListener;
import com.mikepenz.fastadapter.app.items.SampleItem;
import com.mikepenz.fastadapter_extensions.drag.ItemTouchCallback;
import com.mikepenz.fastadapter_extensions.drag.SimpleDragCallback;
import com.mikepenz.fastadapter_extensions.items.ProgressItem;
import com.mikepenz.fastadapter_extensions.scroll.EndlessRecyclerOnScrollListener;
import com.mikepenz.materialize.MaterializeBuilder;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class EndlessScrollListActivity extends AppCompatActivity implements ItemTouchCallback, ItemFilterListener {

//save our FastAdapter
private FastItemAdapter<SampleItem> fastItemAdapter;
private FooterAdapter<ProgressItem> footerAdapter;

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

@Override
protected void onCreate(Bundle savedInstanceState) {
findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);

// Handle Toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);


//style our ui
new MaterializeBuilder().withActivity(this).build();

//create our FastAdapter which will manage everything
fastItemAdapter = new FastItemAdapter<>();

//create our FooterAdapter which will manage the progress items
footerAdapter = new FooterAdapter<>();

//configure our fastAdapter
fastItemAdapter.withOnClickListener(new FastAdapter.OnClickListener<SampleItem>() {
@Override
public boolean onClick(View v, IAdapter<SampleItem> adapter, SampleItem item, int position) {
Toast.makeText(v.getContext(), (item).name.getText(v.getContext()), Toast.LENGTH_LONG).show();
return false;
}
});

//configure the itemAdapter
fastItemAdapter.withFilterPredicate(new IItemAdapter.Predicate<SampleItem>() {
@Override
public boolean filter(SampleItem item, CharSequence constraint) {
//return true if we should filter it out
//return false to keep it
return !item.name.getText().toLowerCase().contains(constraint.toString().toLowerCase());
}
});

fastItemAdapter.getItemAdapter().withItemFilterListener(this);

//get our recyclerView and do basic setup
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv);
LinearLayoutManager manager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(manager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(footerAdapter.wrap(fastItemAdapter));
recyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener(manager, 15) {
@Override
public void onLoadMore(final int currentPage) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
footerAdapter.clear();
footerAdapter.add(new ProgressItem());
//simulate networking (2 seconds)
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
footerAdapter.clear();
for (int i = 1; i < 16; i++) {
fastItemAdapter.add(fastItemAdapter.getAdapterItemCount(), new SampleItem().withName("Item " + i + " Page " + currentPage));
}
}
}, 2000);
}
}, 10);

}
});

//fill with some sample data (load the first page here)
List<SampleItem> items = new ArrayList<>();
for (int i = 1; i < 16; i++) {
items.add(new SampleItem().withName("Item " + i + " Page " + 1));
}
fastItemAdapter.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
fastItemAdapter.withSavedInstanceState(savedInstanceState);

//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
//add the values which need to be saved from the adapter to the bundel
outState = fastItemAdapter.saveInstanceState(outState);
super.onSaveInstanceState(outState);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
//handle the click on the back arrow click
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;

default:
return super.onOptionsItemSelected(item);
}
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.search, menu);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
final SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
touchCallback.setIsDragEnabled(false);
fastItemAdapter.filter(s);
return true;
}


@Override
public boolean onQueryTextChange(String s) {
fastItemAdapter.filter(s);
touchCallback.setIsDragEnabled(TextUtils.isEmpty(s));
return true;
}
});
} else {
menu.findItem(R.id.search).setVisible(false);
}

return super.onCreateOptionsMenu(menu);
}

@Override
public boolean itemTouchOnMove(int oldPosition, int newPosition) {
Collections.swap(fastItemAdapter.getAdapterItems(), oldPosition, newPosition); // change position
fastItemAdapter.notifyAdapterItemMoved(oldPosition, newPosition);
return true;
}

@Override
public void itemsFiltered() {
Toast.makeText(EndlessScrollListActivity.this, "filtered items count: " + fastItemAdapter.getItemCount(), Toast.LENGTH_SHORT).show();
}
}
Loading

0 comments on commit e38d04e

Please sign in to comment.