Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] FastAdapter V3 #294

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
0afb9be
* cleanup (Generic)FastItemAdapter
FabianTerhorst Dec 19, 2016
4729016
* cleanup FastAdater(BottomSheet)Dialog
FabianTerhorst Dec 19, 2016
76fbc05
* more cleanup in FastAdapter(BottomSheet)Dialog
FabianTerhorst Dec 19, 2016
38d0a85
* fix deprecated tests
FabianTerhorst Dec 19, 2016
827135c
* update samples
FabianTerhorst Dec 19, 2016
b5d37cd
* fix SimpleDragCallback
FabianTerhorst Dec 19, 2016
556f4e8
* cleanup generic sample
FabianTerhorst Dec 19, 2016
5cc0722
* add dex count plugin and update gradle version
FabianTerhorst Dec 19, 2016
0bd61fb
* filter should return true if item should stay and item adapter cleanup
FabianTerhorst Dec 19, 2016
39d2d37
* simplify click listener helper
FabianTerhorst Dec 19, 2016
823fb9d
* cleanup generic item adapter
FabianTerhorst Dec 19, 2016
034fa07
* remove backward compatibility for api 11 from sample
FabianTerhorst Dec 19, 2016
b5062ad
* more sample cleanup
FabianTerhorst Dec 19, 2016
e8ae440
* revert ItemAdapter privates
FabianTerhorst Dec 19, 2016
59d929d
* improve RecyclerViewCacheUtil performance
FabianTerhorst Dec 19, 2016
bf16518
* add benchmark tests
FabianTerhorst Dec 19, 2016
0f507f2
* add benchmark to travis
FabianTerhorst Dec 19, 2016
6622fce
* update gradle wrapper, build tools and support libs
FabianTerhorst Dec 19, 2016
5ecd176
* update Realm
FabianTerhorst Dec 19, 2016
68f8f22
* use travis android emulator
FabianTerhorst Dec 19, 2016
530a7be
* fix travis
FabianTerhorst Dec 19, 2016
2679485
* update travis build tools
FabianTerhorst Dec 19, 2016
6295e18
* realm config don´t need a context anymore
FabianTerhorst Dec 19, 2016
14a4b20
* increase heap size
FabianTerhorst Dec 19, 2016
5522eaf
* rebuild before benchmark
FabianTerhorst Dec 19, 2016
ccbaed7
* specify android test runner
FabianTerhorst Dec 19, 2016
47c260f
* cleanup benchmark
FabianTerhorst Dec 19, 2016
97f1134
* init ItemFilter only when needed
FabianTerhorst Dec 19, 2016
ceb3c07
* improve benchmarks
FabianTerhorst Dec 19, 2016
aafdee3
* improve item id generation
FabianTerhorst Dec 20, 2016
8138af0
* update benchmarks
FabianTerhorst Dec 20, 2016
51e4bcf
* real id generation to support items that doesn't´t extend AbstractItem
FabianTerhorst Dec 20, 2016
badadf2
* abstract item identifier should be private
FabianTerhorst Dec 20, 2016
c861855
* remove deprecated setModel in GenericAbstractItem
FabianTerhorst Dec 20, 2016
7859e33
* improve drag drop util
FabianTerhorst Dec 20, 2016
6a3f0f6
* add test cases for issues
FabianTerhorst Dec 22, 2016
acb450f
* reproduce #298
FabianTerhorst Dec 22, 2016
71e4c72
* add wrap size test
FabianTerhorst Dec 22, 2016
3d0551c
* Add nullable support in GenericItemAdapter Function
FabianTerhorst Dec 28, 2016
9894cf9
* issues aren´t used currently
FabianTerhorst Dec 28, 2016
b5aaec8
* update gradle and android build tools plugin
FabianTerhorst Jan 11, 2017
237a92e
Merge branch 'develop' into v3
FabianTerhorst Mar 1, 2017
edb821a
* update realm to v3.0.0
FabianTerhorst Mar 1, 2017
c962d09
* update realm sample
FabianTerhorst Mar 1, 2017
92295b3
* simplify insert
FabianTerhorst Mar 1, 2017
6746f18
* add possibility to set an own ClickListenerHelper
FabianTerhorst Mar 1, 2017
8849087
* remove unnecessary semicolons
FabianTerhorst Mar 1, 2017
3dd49f7
* add new IHookable interface
FabianTerhorst Mar 1, 2017
3e00c3a
* fix realm item adapter
FabianTerhorst Mar 1, 2017
7934911
* update realm adapter to 3.0
FabianTerhorst Mar 1, 2017
b91b500
* improve realm adapter
FabianTerhorst Mar 1, 2017
34b4d8d
* update realm extension plugin version
FabianTerhorst Mar 1, 2017
570cf44
* remove view holder factory
FabianTerhorst Mar 1, 2017
d6c4d1f
* fix test item
FabianTerhorst Mar 27, 2017
a0880dc
* fix another test item
FabianTerhorst Mar 27, 2017
b07ef34
Merge pull request #353 from mikepenz/remove-factory
mikepenz Mar 31, 2017
42369f6
* use final gradle build tools
mikepenz Mar 31, 2017
b5a74a3
* if we have any listener for the FastAdapter and the clickListenerHe…
mikepenz Mar 31, 2017
893e93a
* use v3 compatible MaterialDrawer
mikepenz Apr 3, 2017
0e82274
Merge branch 'develop' into v3
mikepenz Apr 19, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ fastAdapter.filter("yourSearchTerm");
fastAdapter.withFilterPredicate(new IItemAdapter.Predicate<Item>() {
@Override
public boolean filter(Item item, CharSequence constraint) {
return item.getName().startsWith(String.valueOf(constraint));
return !item.getName().startsWith(String.valueOf(constraint));
}
});
```
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'com.getkeepsafe.dexcount'
//wrap with try and catch so the build is working even if the signing stuff is missing
try {
apply from: '../../../signing.gradle'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public boolean onClick(View v, IAdapter<CheckBoxSampleItem> adapter, CheckBoxSam
x++;
}
}
fastItemAdapter.add(items);
fastItemAdapter.items().add(items);

//restore selections (this has to be done after the items were added
fastItemAdapter.withSavedInstanceState(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public boolean onClick(View v, IAdapter<SimpleItem> adapter, SimpleItem item, in
});

//configure the itemAdapter
fastItemAdapter.withFilterPredicate(new IItemAdapter.Predicate<SimpleItem>() {
fastItemAdapter.items().withFilterPredicate(new IItemAdapter.Predicate<SimpleItem>() {
@Override
public boolean filter(SimpleItem item, CharSequence constraint) {
//return true if we should filter it out
Expand All @@ -87,7 +87,7 @@ public boolean filter(SimpleItem item, CharSequence constraint) {
}
});

fastItemAdapter.getItemAdapter().withItemFilterListener(this);
fastItemAdapter.items().withItemFilterListener(this);

//get our recyclerView and do basic setup
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv);
Expand All @@ -106,7 +106,7 @@ public void onLoadMore(final int currentPage) {
public void run() {
footerAdapter.clear();
for (int i = 1; i < 16; i++) {
fastItemAdapter.add(fastItemAdapter.getAdapterItemCount(), new SimpleItem().withName("Item " + i + " Page " + currentPage));
fastItemAdapter.items().add(fastItemAdapter.items().getAdapterItemCount(), new SimpleItem().withName("Item " + i + " Page " + currentPage));
}
}
}, 2000);
Expand All @@ -118,7 +118,7 @@ public void run() {
for (int i = 1; i < 16; i++) {
items.add(new SimpleItem().withName("Item " + i + " Page " + 1));
}
fastItemAdapter.add(items);
fastItemAdapter.items().add(items);

//add drag and drop for item
touchCallback = new SimpleDragCallback(this);
Expand Down Expand Up @@ -169,14 +169,14 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onQueryTextSubmit(String s) {
touchCallback.setIsDragEnabled(false);
fastItemAdapter.filter(s);
fastItemAdapter.items().filter(s);
return true;
}


@Override
public boolean onQueryTextChange(String s) {
fastItemAdapter.filter(s);
fastItemAdapter.items().filter(s);
touchCallback.setIsDragEnabled(TextUtils.isEmpty(s));
return true;
}
Expand All @@ -190,7 +190,7 @@ public boolean onQueryTextChange(String s) {

@Override
public boolean itemTouchOnMove(int oldPosition, int newPosition) {
Collections.swap(fastItemAdapter.getAdapterItems(), oldPosition, newPosition); // change position
Collections.swap(fastItemAdapter.items().getAdapterItems(), oldPosition, newPosition); // change position
fastItemAdapter.notifyAdapterItemMoved(oldPosition, newPosition);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public boolean onLongClick(View v, IAdapter<IItem> adapter, IItem item, int posi
.withTitleProvider(new ActionModeHelper.ActionModeTitleProvider() {
@Override
public String getTitle(int selected) {
return selected + "/" + SubItemUtil.countItems(fastItemAdapter.getItemAdapter(), false);
return selected + "/" + SubItemUtil.countItems(fastItemAdapter.items(), false);
}
})
// important so that the helper knows, that is should use the SubItemUtil for validating it's state
Expand Down Expand Up @@ -164,7 +164,7 @@ public int getSelectedSubItems() {
items.add(sampleItem);
}
}
fastItemAdapter.add(items);
fastItemAdapter.items().add(items);
fastItemAdapter.expand();

fastItemAdapter.withSelectionListener(new ISelectionListener() {
Expand All @@ -173,7 +173,7 @@ public void onSelectionChanged(IItem item, boolean selected) {
if (item instanceof SimpleSubItem) {
IItem headerItem = ((SimpleSubItem) item).getParent();
if (headerItem != null) {
int pos = fastItemAdapter.getAdapterPosition(headerItem);
int pos = fastItemAdapter.items().getAdapterPosition(headerItem);
// Important: notify the header directly, not via the notifyadapterItemChanged!
// we just want to update the view and we are sure, nothing else has to be done
fastItemAdapter.notifyItemChanged(pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected void onCreate(Bundle savedInstanceState) {
items.add(new SimpleSubItem().withName("Test " + i).withIdentifier(100 + i));
}
}
fastItemAdapter.add(items);
fastItemAdapter.items().add(items);

//restore selections (this has to be done after the items were added
fastItemAdapter.withSavedInstanceState(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
import android.view.MenuItem;
import android.view.View;

import com.mikepenz.fastadapter.IItem;
import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter;
import com.mikepenz.fastadapter.app.items.IconItem;
import com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem;
import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter;
import com.mikepenz.iconics.Iconics;
import com.mikepenz.iconics.context.IconicsLayoutInflater;
import com.mikepenz.iconics.typeface.ITypeface;
Expand All @@ -26,7 +25,7 @@

public class IconGridActivity extends AppCompatActivity {
//save our FastAdapter
private FastItemAdapter fastItemAdapter;
private FastItemAdapter<SimpleSubExpandableItem> fastItemAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -47,7 +46,7 @@ protected void onCreate(Bundle savedInstanceState) {
new MaterializeBuilder().withActivity(this).build();

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

//get our recyclerView and do basic setup
RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
Expand Down Expand Up @@ -91,7 +90,7 @@ public int compare(final ITypeface object1, final ITypeface object2) {
.withName(font.getFontName())
.withIdentifier(count);

ArrayList<IItem> icons = new ArrayList<>();
ArrayList<IconItem> icons = new ArrayList<>();
for (String icon : font.getIcons()) {
IconItem iconItem = new IconItem();
iconItem.withIcon(font.getIcon(icon));
Expand All @@ -104,7 +103,7 @@ public int compare(final ITypeface object1, final ITypeface object2) {
}

//fill with some sample data
fastItemAdapter.add(items);
fastItemAdapter.items().add(items);

//if first start we want to expand the item with ID 2
if (savedInstanceState != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public boolean onClick(View v, IAdapter<ImageItem> adapter, ImageItem item, int
rv.setAdapter(mFastItemAdapter);

//fill with some sample data
mFastItemAdapter.add(ImageDummyData.getImageItems());
mFastItemAdapter.items().add(ImageDummyData.getImageItems());

//restore selections (this has to be done after the items were added
mFastItemAdapter.withSavedInstanceState(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
mAdapter.withOnClickListener(this);

for (int i = 65; i <= 90; i++) {
mAdapter.add(new LetterItem(String.valueOf((char) i)));
mAdapter.items().add(new LetterItem(String.valueOf((char) i)));
}

ViewBinder viewBinder = new ViewBinder.Builder(R.layout.native_ad_item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import android.view.MenuItem;
import android.view.View;

import com.mikepenz.fastadapter.FastAdapter;
import com.mikepenz.fastadapter.adapters.GenericItemAdapter;
import com.mikepenz.fastadapter.app.generic.GenericIconItem;
import com.mikepenz.fastadapter.app.generic.IconModel;
import com.mikepenz.fastadapter.app.generic.RightGenericIconItem;
import com.mikepenz.fastadapter.app.generic.RightIconModel;
import com.mikepenz.fastadapter.commons.adapters.GenericFastItemAdapter;
import com.mikepenz.fastadapter.utils.Function;
import com.mikepenz.iconics.Iconics;
import com.mikepenz.iconics.typeface.ITypeface;
Expand All @@ -27,7 +26,7 @@

public class MultiTypeGenericItemActivity extends AppCompatActivity {
//save our FastAdapter
private FastAdapter fastAdapter;
private GenericFastItemAdapter<IconModel, GenericIconItem> genericFastItemAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -45,17 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {


//create our FastAdapter which will manage everything
fastAdapter = new FastAdapter();
fastAdapter.withSelectable(true);

//get our recyclerView and do basic setup
RecyclerView rv = (RecyclerView) findViewById(R.id.rv);

//init our gridLayoutManager and configure RV
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);

//if you need multiple items for different models you can also do this be defining a Function which get's the model object and returns the item (extends IItem)
GenericItemAdapter<IconModel, GenericIconItem> itemAdapter = new GenericItemAdapter<>(new Function<IconModel, GenericIconItem>() {
genericFastItemAdapter = new GenericFastItemAdapter<>(new Function<IconModel, GenericIconItem>() {
@Override
public GenericIconItem apply(IconModel o) {
if (o instanceof RightIconModel) {
Expand All @@ -65,10 +54,17 @@ public GenericIconItem apply(IconModel o) {
}
}
});
genericFastItemAdapter.withSelectable(true);

//get our recyclerView and do basic setup
RecyclerView rv = (RecyclerView) findViewById(R.id.rv);

//init our gridLayoutManager and configure RV
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);

rv.setLayoutManager(gridLayoutManager);
rv.setItemAnimator(new SlideDownAlphaAnimator());
rv.setAdapter(itemAdapter.wrap(fastAdapter));
rv.setAdapter(genericFastItemAdapter);

//order fonts by their name
List<ITypeface> mFonts = new ArrayList<>(Iconics.getRegisteredFonts(this));
Expand All @@ -94,10 +90,10 @@ public int compare(final ITypeface object1, final ITypeface object2) {
}

//fill with some sample data
itemAdapter.addModel(models);
genericFastItemAdapter.items().addModel(models);

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

//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Expand All @@ -107,7 +103,7 @@ public int compare(final ITypeface object1, final ITypeface object2) {
@Override
protected void onSaveInstanceState(Bundle outState) {
//add the values which need to be saved from the adapter to the bundel
outState = fastAdapter.saveInstanceState(outState);
outState = genericFastItemAdapter.saveInstanceState(outState);
super.onSaveInstanceState(outState);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class MultiselectSampleActivity extends AppCompatActivity {
//save our FastAdapter
private FastAdapter<SimpleItem> mFastAdapter;

private UndoHelper mUndoHelper;
private UndoHelper<SimpleItem> mUndoHelper;

private ActionModeHelper mActionModeHelper;

Expand All @@ -54,7 +54,7 @@ protected void onCreate(Bundle savedInstanceState) {
mFastAdapter = new FastAdapter<>();

//
mUndoHelper = new UndoHelper(mFastAdapter, new UndoHelper.UndoListener<SimpleItem>() {
mUndoHelper = new UndoHelper<>(mFastAdapter, new UndoHelper.UndoListener<SimpleItem>() {
@Override
public void commitRemove(Set<Integer> positions, ArrayList<FastAdapter.RelativeInfo<SimpleItem>> removed) {
Log.e("UndoHelper", "Positions: " + positions.toString() + " Removed: " + removed.size());
Expand Down Expand Up @@ -161,7 +161,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
/**
* Our ActionBarCallBack to showcase the CAB
*/
class ActionBarCallBack implements ActionMode.Callback {
private class ActionBarCallBack implements ActionMode.Callback {

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public boolean onClick(View v, IAdapter<RadioButtonSampleItem> adapter, RadioBut
x++;
}
}
fastItemAdapter.add(items);
fastItemAdapter.items().add(items);

//restore selections (this has to be done after the items were added
fastItemAdapter.withSavedInstanceState(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void onChange(RealmResults<RealmSampleUserItem> userItems) {
//This will call twice
//1.) from findAllAsync()
//2.) from createData()
mFastItemAdapter.setNewList(userItems);
mFastItemAdapter.items().setNewList(userItems);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public boolean onClick(View v, IAdapter<SimpleItem> adapter, SimpleItem item, in
});

//configure the itemAdapter
fastItemAdapter.withFilterPredicate(new IItemAdapter.Predicate<SimpleItem>() {
fastItemAdapter.items().withFilterPredicate(new IItemAdapter.Predicate<SimpleItem>() {
@Override
public boolean filter(SimpleItem item, CharSequence constraint) {
//return true if we should filter it out
Expand All @@ -85,7 +85,7 @@ public boolean filter(SimpleItem item, CharSequence constraint) {
}
});

fastItemAdapter.getItemAdapter().withItemFilterListener(this);
fastItemAdapter.items().withItemFilterListener(this);

//get our recyclerView and do basic setup
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv);
Expand All @@ -109,7 +109,7 @@ public boolean filter(SimpleItem item, CharSequence constraint) {
x++;
}
}
fastItemAdapter.add(items);
fastItemAdapter.items().add(items);

//add drag and drop for item
touchCallback = new SimpleDragCallback(this);
Expand Down Expand Up @@ -160,14 +160,14 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onQueryTextSubmit(String s) {
touchCallback.setIsDragEnabled(false);
fastItemAdapter.filter(s);
fastItemAdapter.items().filter(s);
return true;
}


@Override
public boolean onQueryTextChange(String s) {
fastItemAdapter.filter(s);
fastItemAdapter.items().filter(s);
touchCallback.setIsDragEnabled(TextUtils.isEmpty(s));
return true;
}
Expand All @@ -181,7 +181,7 @@ public boolean onQueryTextChange(String s) {

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