Skip to content

Commit

Permalink
Merge branch 'release/v0.5.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepenz committed Jan 9, 2016
2 parents c20ae65 + 59725ad commit 01fc364
Show file tree
Hide file tree
Showing 15 changed files with 342 additions and 61 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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.5.2-SNAPSHOT@aar') {
compile('com.mikepenz:fastadapter:0.5.5@aar') {
transitive = true
}

Expand Down
11 changes: 7 additions & 4 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 52
versionName '0.5.2-SNAPSHOT'
versionCode 55
versionName '0.5.5'

applicationVariants.all { variant ->
variant.outputs.each { output ->
Expand Down Expand Up @@ -57,8 +57,8 @@ dependencies {
exclude module: "fastadapter"
}
//used to provide different itemAnimators for the RecyclerView
//TBR
compile 'com.mikepenz:itemanimators:0.0.1-SNAPSHOT@aar'
//https://github.com/mikepenz/ItemAnimators
compile 'com.mikepenz:itemanimators:0.1.0-SNAPSHOT@aar'
//used to generate the Open Source section
//https://github.com/mikepenz/AboutLibraries
compile('com.mikepenz:aboutlibraries:5.3.4@aar') {
Expand All @@ -67,6 +67,9 @@ dependencies {
//used to display the icons in the drawer
//https://github.com/mikepenz/Android-Iconics
compile 'com.mikepenz:material-design-iconic-typeface:2.2.0.1@aar'
compile 'com.mikepenz:community-material-typeface:1.3.41.1@aar'
compile 'com.mikepenz:google-material-typeface:2.1.0.1.original@aar'
compile 'com.mikepenz:fontawesome-typeface:4.5.0.1@aar'

//Used for the StickyHeaderSample
//https://github.com/timehop/sticky-headers-recyclerview
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
android:theme="@style/CustomTheme">
<!-- android:supportsRtl="true" -->
<activity
android:name=".SampleActivity"
android:label="@string/app_name">
android:name=".IconGridActivity"
android:label="@string/sample_icon_grid">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SimpleActivity"
android:label="@string/sample_simple" />
<activity
android:name=".ImageListActivity"
android:label="@string/sample_image_list" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.mikepenz.aboutlibraries.Libs;
import com.mikepenz.aboutlibraries.LibsBuilder;
import com.mikepenz.fastadapter.FastAdapter;
import com.mikepenz.fastadapter.IAdapter;
import com.mikepenz.fastadapter.IItem;
import com.mikepenz.fastadapter.adapters.ItemAdapter;
import com.mikepenz.fastadapter.app.items.IconItem;
import com.mikepenz.fastadapter.app.items.SampleItem;
import com.mikepenz.fastadapter.helpers.UndoHelper;
import com.mikepenz.iconics.Iconics;
import com.mikepenz.iconics.typeface.ITypeface;
import com.mikepenz.itemanimators.SlideDownAlphaAnimator;
import com.mikepenz.material_design_iconic_typeface_library.MaterialDesignIconic;
import com.mikepenz.materialdrawer.Drawer;
import com.mikepenz.materialdrawer.DrawerBuilder;
Expand All @@ -28,16 +27,16 @@
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;

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

public class SampleActivity extends AppCompatActivity {
public class IconGridActivity extends AppCompatActivity {
//save our header or result
private Drawer result = null;
//save our FastAdapter
private FastAdapter<SampleItem> fastAdapter;

private UndoHelper undoHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -55,6 +54,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_wallpaper),
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 @@ -69,24 +69,26 @@ public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if (drawerItem != null) {
Intent intent = null;
if (drawerItem.getIdentifier() == 1) {
intent = new Intent(SampleActivity.this, MultiselectSampleActivity.class);
intent = new Intent(IconGridActivity.this, MultiselectSampleActivity.class);
} else if (drawerItem.getIdentifier() == 2) {
intent = new Intent(SampleActivity.this, CollapsibleSampleActivity.class);
intent = new Intent(IconGridActivity.this, CollapsibleSampleActivity.class);
} else if (drawerItem.getIdentifier() == 3) {
intent = new Intent(SampleActivity.this, StickyHeaderSampleActivity.class);
intent = new Intent(IconGridActivity.this, StickyHeaderSampleActivity.class);
} else if (drawerItem.getIdentifier() == 4) {
intent = new Intent(SampleActivity.this, AdvancedSampleActivity.class);
intent = new Intent(IconGridActivity.this, AdvancedSampleActivity.class);
} else if (drawerItem.getIdentifier() == 5) {
intent = new Intent(SampleActivity.this, ImageListActivity.class);
intent = new Intent(IconGridActivity.this, ImageListActivity.class);
} else if (drawerItem.getIdentifier() == 6) {
intent = new Intent(IconGridActivity.this, SimpleActivity.class);
} else if (drawerItem.getIdentifier() == 100) {
intent = new LibsBuilder()
.withFields(R.string.class.getFields())
.withActivityTitle(getString(R.string.open_source))
.withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
.intent(SampleActivity.this);
.intent(IconGridActivity.this);
}
if (intent != null) {
SampleActivity.this.startActivity(intent);
IconGridActivity.this.startActivity(intent);
}
}
return false;
Expand All @@ -97,53 +99,71 @@ public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {

//create our FastAdapter which will manage everything
fastAdapter = new FastAdapter<>();
fastAdapter.withOnClickListener(new FastAdapter.OnClickListener() {
@Override
public boolean onClick(View v, IAdapter adapter, IItem item, int position) {
if (item instanceof SampleItem) {
if (((SampleItem) item).getSubItems() != null) {
fastAdapter.toggleCollapsible(position);
return true;
}
}
return false;
}
});

//create our ItemAdapter which will host our items
final ItemAdapter<SampleItem> itemAdapter = new ItemAdapter<>();

//
undoHelper = new UndoHelper(itemAdapter, new UndoHelper.UndoListener() {
//get our recyclerView and do basic setup
RecyclerView rv = (RecyclerView) findViewById(R.id.rv);

GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public void commitRemove(int position, ArrayList<? extends IItem> removed) {
Log.e("UndoHelper", "Pos: " + position + " Removed: " + removed.size());
//remember that the items were removed
public int getSpanSize(int position) {
switch (fastAdapter.getItemViewType(position)) {
case R.id.fastadapter_sample_item_id:
return 3;
case R.id.fastadapter_icon_item_id:
return 1;
default:
return 1;
}
}
});
rv.setLayoutManager(gridLayoutManager);
rv.setItemAnimator(new SlideDownAlphaAnimator());
rv.setAdapter(itemAdapter.wrap(fastAdapter));

//configure our fastAdapter
//as we provide id's for the items we want the hasStableIds enabled to speed up things
fastAdapter.setHasStableIds(true);
fastAdapter.withOnClickListener(new FastAdapter.OnClickListener() {
//order fonts by their name
List<ITypeface> mFonts = new ArrayList<>(Iconics.getRegisteredFonts(this));
Collections.sort(mFonts, new Comparator<ITypeface>() {
@Override
public boolean onClick(View v, IAdapter adapter, IItem item, int position) {
Toast.makeText(v.getContext(), ((SampleItem) item).name.getText(v.getContext()), Toast.LENGTH_LONG).show();
return false;
public int compare(final ITypeface object1, final ITypeface object2) {
return object1.getFontName().compareTo(object2.getFontName());
}
});
fastAdapter.withOnLongClickListener(new FastAdapter.OnLongClickListener() {
@Override
public boolean onLongClick(View v, IAdapter adapter, IItem item, int position) {
undoHelper.remove(SampleActivity.this.findViewById(android.R.id.content), "Item removed", "Undo", Snackbar.LENGTH_LONG, position, 1);
return true;

//add all icons of all registered Fonts to the list
ArrayList<SampleItem> items = new ArrayList<>(Iconics.getRegisteredFonts(this).size());
int count = 0;
for (ITypeface font : mFonts) {
SampleItem sampleItem = new SampleItem().withName(font.getFontName());

ArrayList<IItem> icons = new ArrayList<>();
for (String icon : font.getIcons()) {
icons.add(new IconItem().withIcon(font.getIcon(icon)).withSelectable(false));
}
});
sampleItem.withSubItems(icons);

//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(itemAdapter.wrap(fastAdapter));
items.add(sampleItem);
count++;
}

//fill with some sample data
List<SampleItem> items = new ArrayList<>();
for (int i = 1; i <= 100; i++) {
items.add(new SampleItem().withName("Test " + i).withIdentifier(100 + i));
}
itemAdapter.add(items);

//init cache with the added items, this is useful for shorter lists with many many different view types (at least 4 or more
//new RecyclerViewCacheUtil().withCacheSize(2).apply(rv, items);

//restore selections (this has to be done after the items were added
fastAdapter.withSavedInstanceState(savedInstanceState);
}
Expand Down
104 changes: 104 additions & 0 deletions app/src/main/java/com/mikepenz/fastadapter/app/SimpleActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.mikepenz.fastadapter.app;

import android.os.Bundle;
import android.support.design.widget.Snackbar;
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.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.mikepenz.fastadapter.FastAdapter;
import com.mikepenz.fastadapter.IAdapter;
import com.mikepenz.fastadapter.IItem;
import com.mikepenz.fastadapter.adapters.ItemAdapter;
import com.mikepenz.fastadapter.app.items.SampleItem;
import com.mikepenz.fastadapter.helpers.UndoHelper;
import com.mikepenz.materialize.MaterializeBuilder;

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

public class SimpleActivity extends AppCompatActivity {
//save our FastAdapter
private FastAdapter<SampleItem> fastAdapter;

private UndoHelper undoHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
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
fastAdapter = new FastAdapter<>();

//create our ItemAdapter which will host our items
final ItemAdapter<SampleItem> itemAdapter = new ItemAdapter<>();

//
undoHelper = new UndoHelper(itemAdapter, new UndoHelper.UndoListener() {
@Override
public void commitRemove(int position, ArrayList<? extends IItem> removed) {
Log.e("UndoHelper", "Pos: " + position + " Removed: " + removed.size());
//remember that the items were removed
}
});

//configure our fastAdapter
//as we provide id's for the items we want the hasStableIds enabled to speed up things
fastAdapter.setHasStableIds(true);
fastAdapter.withOnClickListener(new FastAdapter.OnClickListener() {
@Override
public boolean onClick(View v, IAdapter adapter, IItem item, int position) {
Toast.makeText(v.getContext(), ((SampleItem) item).name.getText(v.getContext()), Toast.LENGTH_LONG).show();
return false;
}
});
fastAdapter.withOnLongClickListener(new FastAdapter.OnLongClickListener() {
@Override
public boolean onLongClick(View v, IAdapter adapter, IItem item, int position) {
undoHelper.remove(SimpleActivity.this.findViewById(android.R.id.content), "Item removed", "Undo", Snackbar.LENGTH_LONG, position, 1);
return true;
}
});

//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(itemAdapter.wrap(fastAdapter));

//fill with some sample data
List<SampleItem> items = new ArrayList<>();
for (int i = 1; i <= 100; i++) {
items.add(new SampleItem().withName("Test " + i).withIdentifier(100 + i));
}
itemAdapter.add(items);

//restore selections (this has to be done after the items were added
fastAdapter.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 = fastAdapter.saveInstanceState(outState);
super.onSaveInstanceState(outState);
}
}
Loading

0 comments on commit 01fc364

Please sign in to comment.