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
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.mikepenz.fastadapter.commons.utils;

import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;

import com.mikepenz.fastadapter.IItem;

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

/**
Expand Down Expand Up @@ -35,28 +34,28 @@ public RecyclerViewCacheUtil withCacheSize(int cacheSize) {
public void apply(RecyclerView recyclerView, Iterable<Item> items) {
if (items != null) {
//we pre-create the views for our cache
HashMap<Integer, Stack<RecyclerView.ViewHolder>> cache = new HashMap<>();
SparseArray<Stack<RecyclerView.ViewHolder>> cache = new SparseArray<>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"SparseArrays map integers to Objects. Unlike a normal array of Objects, there can be gaps in the indices. It is intended to be more memory efficient than using a HashMap to map Integers to Objects, both because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping." https://developer.android.com/reference/android/util/SparseArray.html

for (Item d : items) {
if (!cache.containsKey(d.getType())) {
Stack<RecyclerView.ViewHolder> holders = cache.get(d.getType());
if (holders == null) {
cache.put(d.getType(), new Stack<RecyclerView.ViewHolder>());
}

if (mCacheSize == -1 || cache.get(d.getType()).size() <= mCacheSize) {
cache.get(d.getType()).push(d.getViewHolder(recyclerView));
} else if (mCacheSize == -1 || holders.size() <= mCacheSize) {
holders.push(d.getViewHolder(recyclerView));
}

RecyclerView.RecycledViewPool recyclerViewPool = new RecyclerView.RecycledViewPool();

//we fill the pool
for (Map.Entry<Integer, Stack<RecyclerView.ViewHolder>> entry : cache.entrySet()) {
recyclerViewPool.setMaxRecycledViews(entry.getKey(), mCacheSize);

for (RecyclerView.ViewHolder holder : entry.getValue()) {
for (int i = 0, length = cache.size(); i < length; i++) {
int key = cache.keyAt(i);
Stack<RecyclerView.ViewHolder> entry = cache.get(key);
recyclerViewPool.setMaxRecycledViews(key, mCacheSize);
for (RecyclerView.ViewHolder holder : entry) {
recyclerViewPool.putRecycledView(holder);
}

//make sure to clear the stack
entry.getValue().clear();
entry.clear();

}

//make sure to clear the cache
Expand Down