diff --git a/README.md b/README.md index debae880b..ff6108763 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ 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.0@aar') { +compile('com.mikepenz:fastadapter:1.1.1@aar') { transitive = true } ``` diff --git a/app/build.gradle b/app/build.gradle index 2ed34ebe8..b0a28b445 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { defaultConfig { minSdkVersion 11 targetSdkVersion 23 - versionCode 110 - versionName '1.1.0' + versionCode 111 + versionName '1.1.1' applicationVariants.all { variant -> variant.outputs.each { output -> diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java index f94d3f04e..b9edd0c52 100755 --- a/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java @@ -83,7 +83,7 @@ public boolean filter(SampleItem item, CharSequence constraint) { } }); - fastItemAdapter.getItemAdapter().setItemFilterListener(this); + fastItemAdapter.getItemAdapter().withItemFilterListener(this); //get our recyclerView and do basic setup RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv); diff --git a/build.gradle b/build.gradle index 64eb0f2f2..933011522 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.0.0-beta4' + classpath 'com.android.tools.build:gradle:2.0.0-beta5' classpath 'com.novoda:bintray-release:0.3.4' } } @@ -26,5 +26,5 @@ allprojects { } task wrapper(type: Wrapper) { - gradleVersion = '2.10' + gradleVersion = '2.11' } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1e2a35c64..02f331b95 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Dec 28 13:17:13 CET 2015 +#Tue Feb 23 21:51:53 CET 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-all.zip diff --git a/library/build.gradle b/library/build.gradle index 4be3be31b..bcd6de035 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 10 targetSdkVersion 23 - versionCode 110 - versionName '1.1.0' + versionCode 111 + versionName '1.1.1' } buildTypes { release { diff --git a/library/gradle.properties b/library/gradle.properties index 48a600d6d..7a5c73fab 100755 --- a/library/gradle.properties +++ b/library/gradle.properties @@ -2,5 +2,5 @@ POM_NAME=FastAdapter Library POM_ARTIFACT_ID=fastadapter POM_PACKAGING=aar -VERSION_NAME=1.1.0 -VERSION_CODE=110 \ No newline at end of file +VERSION_NAME=1.1.1 +VERSION_CODE=111 \ No newline at end of file diff --git a/library/src/main/java/com/mikepenz/fastadapter/FastAdapter.java b/library/src/main/java/com/mikepenz/fastadapter/FastAdapter.java index abd8f4075..98ab64eaf 100644 --- a/library/src/main/java/com/mikepenz/fastadapter/FastAdapter.java +++ b/library/src/main/java/com/mikepenz/fastadapter/FastAdapter.java @@ -551,6 +551,29 @@ public int getPreItemCount(int position) { return mAdapterSizes.floorKey(position); } + /** + * calculates the count of expandable items before a given position + * + * @param from the global start position you should pass here the count of items of the previous adapters (or 0 if you want to start from the beginning) + * @param position the global position + * @return the count of expandable items before a given position + */ + public int getExpandedItemsCount(int from, int position) { + int totalAddedItems = 0; + int length = mExpanded.size(); + for (int i = 0; i < length; i++) { + //now we count the amount of expanded items within our range we check + if (mExpanded.keyAt(i) >= from && mExpanded.keyAt(i) < position) { + totalAddedItems = totalAddedItems + mExpanded.get(mExpanded.keyAt(i)); + } else if (mExpanded.keyAt(i) >= position) { + //we do not care about all expanded items which are outside our range + break; + } + } + return totalAddedItems; + } + + /** * add the values to the bundle for saveInstanceState * diff --git a/library/src/main/java/com/mikepenz/fastadapter/IItemAdapter.java b/library/src/main/java/com/mikepenz/fastadapter/IItemAdapter.java index ee1ef0a11..ee7008a9d 100644 --- a/library/src/main/java/com/mikepenz/fastadapter/IItemAdapter.java +++ b/library/src/main/java/com/mikepenz/fastadapter/IItemAdapter.java @@ -47,7 +47,7 @@ public interface IItemAdapter extends IAdapter { /** * add an array of items at the given position within the existing items * - * @param position the relative position (position of this adapter) + * @param position the global position * @param items */ void add(int position, Item... items); @@ -55,7 +55,7 @@ public interface IItemAdapter extends IAdapter { /** * add a list of items at the given position within the existing items * - * @param position the relative position (position of this adapter) + * @param position the global position * @param items */ void add(int position, List items); @@ -63,7 +63,7 @@ public interface IItemAdapter extends IAdapter { /** * sets an item at the given position, overwriting the previous item * - * @param position the relative position (position of this adapter) + * @param position the global position * @param item */ void set(int position, Item item); @@ -71,14 +71,14 @@ public interface IItemAdapter extends IAdapter { /** * removes an item at the given position within the existing icons * - * @param position the relative position (position of this adapter) + * @param position the global position */ void remove(int position); /** * removes a range of items starting with the given position within the existing icons * - * @param position the relative position (position of this adapter) + * @param position the global position * @param itemCount */ void removeRange(int position, int itemCount); diff --git a/library/src/main/java/com/mikepenz/fastadapter/adapters/ItemAdapter.java b/library/src/main/java/com/mikepenz/fastadapter/adapters/ItemAdapter.java index 7508f021a..7cfd98385 100644 --- a/library/src/main/java/com/mikepenz/fastadapter/adapters/ItemAdapter.java +++ b/library/src/main/java/com/mikepenz/fastadapter/adapters/ItemAdapter.java @@ -9,6 +9,8 @@ import com.mikepenz.fastadapter.utils.IdDistributor; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import static java.util.Arrays.asList; @@ -69,14 +71,40 @@ public void filter(CharSequence constraint) { mItemFilter.filter(constraint); } - public void setItemFilterListener(ItemFilterListener listener) { + /** + * @param listener which will be called after the items were filtered + * @return this + */ + public ItemAdapter withItemFilterListener(ItemFilterListener listener) { mItemFilterListener = listener; + return this; } + + //the listener which will be called after the items were filtered protected ItemFilterListener mItemFilterListener; + + /** + * interface for the ItemFilterListener + */ public interface ItemFilterListener { void itemsFiltered(); } + // + public Comparator mComparator; + + /** + * define a comparator which will be used to sort the list "everytime" it is altered + * NOTE this will only sort if you "set" a new list or "add" new items (not if you provide a position for the add function) + * + * @param comparator used to sort the list + * @return this + */ + public ItemAdapter withComparator(Comparator comparator) { + this.mComparator = comparator; + return this; + } + /** * @return the order of the items within the FastAdapter */ @@ -153,7 +181,8 @@ public T setSubItems(IExpandable collapsible, List subItems) /** * set a new list of items and apply it to the existing list (clear - add) for this adapter - * Note may consider using setNewList if the items list is a reference to the list which is used inside the adapter + * NOTE may consider using setNewList if the items list is a reference to the list which is used inside the adapter + * NOTE this will not sort * * @param items the items to set */ @@ -211,6 +240,11 @@ public void setNewList(List items) { } mItems = new ArrayList<>(items); mapPossibleTypes(mItems); + + if (mComparator != null) { + Collections.sort(mItems, mComparator); + } + getFastAdapter().notifyAdapterDataSetChanged(); } @@ -235,7 +269,13 @@ public void add(List items) { } mItems.addAll(items); mapPossibleTypes(items); - getFastAdapter().notifyAdapterItemRangeInserted(getFastAdapter().getPreItemCountByOrder(getOrder()), items.size()); + + if (mComparator == null) { + getFastAdapter().notifyAdapterItemRangeInserted(getFastAdapter().getPreItemCountByOrder(getOrder()), items.size()); + } else { + Collections.sort(mItems, mComparator); + getFastAdapter().notifyAdapterDataSetChanged(); + } } /** @@ -262,6 +302,7 @@ public void add(int position, List items) { if (items != null) { mItems.addAll(position - getFastAdapter().getPreItemCount(position), items); mapPossibleTypes(items); + getFastAdapter().notifyAdapterItemRangeInserted(position, items.size()); } } @@ -278,6 +319,7 @@ public void set(int position, Item item) { } mItems.set(position - getFastAdapter().getPreItemCount(position), item); mapPossibleType(item); + getFastAdapter().notifyAdapterItemChanged(position); } diff --git a/library/src/main/res/values/library_fastadapter_strings.xml b/library/src/main/res/values/library_fastadapter_strings.xml index cf28a5763..c1a666c43 100755 --- a/library/src/main/res/values/library_fastadapter_strings.xml +++ b/library/src/main/res/values/library_fastadapter_strings.xml @@ -10,7 +10,7 @@ FastAdapter, the bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction... ]]> - 1.1.0 + 1.1.1 https://github.com/mikepenz/FastAdapter apache_2_0 true