Skip to content

Commit

Permalink
Merge branch 'release/v0.9.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepenz committed Jan 25, 2016
2 parents cf4a05b + 47615b1 commit 79d10b5
Show file tree
Hide file tree
Showing 23 changed files with 469 additions and 310 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ You can try it out here [Google Play](https://play.google.com/store/apps/details
#Include in your project
##Using Maven
```javascript
compile('com.mikepenz:fastadapter:0.9.4@aar') {
compile('com.mikepenz:fastadapter:0.9.5@aar') {
transitive = true
}
```
Expand Down
4 changes: 2 additions & 2 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 94
versionName '0.9.4'
versionCode 95
versionName '0.9.5'

applicationVariants.all { variant ->
variant.outputs.each { output ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.mikepenz.fastadapter.FastAdapter;
import com.mikepenz.fastadapter.IAdapter;
import com.mikepenz.fastadapter.adapters.FastItemAdapter;
import com.mikepenz.fastadapter.app.dummy.ImageDummyData;
import com.mikepenz.fastadapter.app.items.ImageItem;
import com.mikepenz.fastadapter.helpers.ClickListenerHelper;
import com.mikepenz.materialize.MaterializeBuilder;

public class ImageListActivity extends AppCompatActivity {
//save our FastAdapter
private FastItemAdapter<ImageItem> fastItemAdapter;
private FastItemAdapter<ImageItem> mFastItemAdapter;

private ClickListenerHelper<ImageItem> mClickListenerHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -39,13 +43,16 @@ protected void onCreate(Bundle savedInstanceState) {
new MaterializeBuilder().withActivity(this).build();

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

//init the ClickListenerHelper which simplifies custom click listeners on views of the Adapter
mClickListenerHelper = new ClickListenerHelper<>(mFastItemAdapter);

//configure our fastAdapter
fastItemAdapter.withOnClickListener(new FastAdapter.OnClickListener<ImageItem>() {
mFastItemAdapter.withOnClickListener(new FastAdapter.OnClickListener<ImageItem>() {
@Override
public boolean onClick(View v, IAdapter<ImageItem> adapter, ImageItem item, int position) {
Toast.makeText(v.getContext(), item.mName, Toast.LENGTH_LONG).show();
Toast.makeText(v.getContext(), item.mName, Toast.LENGTH_SHORT).show();
return false;
}
});
Expand All @@ -62,30 +69,54 @@ public boolean onClick(View v, IAdapter<ImageItem> adapter, ImageItem item, int
rv.setLayoutManager(new GridLayoutManager(this, columns));
}
rv.setItemAnimator(new DefaultItemAnimator());
rv.setAdapter(fastItemAdapter);
rv.setAdapter(mFastItemAdapter);

//fill with some sample data
fastItemAdapter.add(ImageDummyData.getImages(mOnLovedClickListener));
mFastItemAdapter.add(ImageDummyData.getImageItems());

//restore selections (this has to be done after the items were added
fastItemAdapter.withSavedInstanceState(savedInstanceState);
mFastItemAdapter.withSavedInstanceState(savedInstanceState);

//a custom OnCreateViewHolder listener class which is used to create the viewHolders
//we define the listener for the imageLovedContainer here for better performance
//you can also define the listener within the items bindView method but performance is better if you do it like this
mFastItemAdapter.withOnCreateViewHolderListener(new FastAdapter.OnCreateViewHolderListener() {
@Override
public RecyclerView.ViewHolder onPreCreateViewHolder(ViewGroup parent, int viewType) {
return mFastItemAdapter.getTypeInstances().get(viewType).getViewHolder(parent);
}

@Override
public RecyclerView.ViewHolder onPostCreateViewHolder(final RecyclerView.ViewHolder viewHolder) {
//we do this for our ImageItem.ViewHolder
if (viewHolder instanceof ImageItem.ViewHolder) {
//if we click on the imageLovedContainer
mClickListenerHelper.listen(viewHolder, ((ImageItem.ViewHolder) viewHolder).imageLovedContainer, new ClickListenerHelper.OnClickListener<ImageItem>() {
@Override
public void onClick(View v, int position, ImageItem item) {
item.withStarred(!item.mStarred);
//we animate the heart
item.animateHeart(((ViewGroup) v).getChildAt(0), ((ViewGroup) v).getChildAt(1), item.mStarred);

//we display the info about the click
Toast.makeText(ImageListActivity.this, item.mImageUrl + " - " + item.mStarred, Toast.LENGTH_SHORT).show();
}
});
}

return viewHolder;
}
});

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

private ImageItem.OnItemClickListener mOnLovedClickListener = new ImageItem.OnItemClickListener() {
@Override
public void onLovedClick(String image, boolean starred) {
Toast.makeText(ImageListActivity.this, image + " - " + starred, Toast.LENGTH_SHORT).show();
}
};

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
@Override
public void run() {
//add some dummy data
mItemAdapter.add(ImageDummyData.getImages());
mItemAdapter.add(ImageDummyData.getSimpleImageItems());
}
}, 50);
}
Expand Down
Loading

0 comments on commit 79d10b5

Please sign in to comment.