Skip to content

Commit

Permalink
Merge branch 'release/v1.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepenz committed Feb 6, 2016
2 parents de051a8 + 0d1b327 commit e5d2c91
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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:1.0.2@aar') {
compile('com.mikepenz:fastadapter:1.0.3@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 102
versionName '1.0.2'
versionCode 103
versionName '1.0.3'

applicationVariants.all { variant ->
variant.outputs.each { output ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* Created by mikepenz on 28.12.15.
*/
public class SimpleImageItem extends AbstractItem<ImageItem, SimpleImageItem.ViewHolder> {
public class SimpleImageItem extends AbstractItem<SimpleImageItem, SimpleImageItem.ViewHolder> {
//the static ViewHolderFactory which will be used to generate the ViewHolder for this Item
private static final ViewHolderFactory<? extends ViewHolder> FACTORY = new ItemFactory();

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha9'
classpath 'com.android.tools.build:gradle:2.0.0-beta2'
classpath 'com.novoda:bintray-release:0.3.4'
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Maven stuff
VERSION_NAME=1.0.2
VERSION_CODE=102
VERSION_NAME=1.0.3
VERSION_CODE=103
GROUP=com.mikepenz

POM_DESCRIPTION=FastAdapter Library
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 10
targetSdkVersion 23
versionCode 102
versionName '1.0.2'
versionCode 103
versionName '1.0.3'
}
buildTypes {
release {
Expand Down
35 changes: 27 additions & 8 deletions library/src/main/java/com/mikepenz/fastadapter/FastAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,16 @@ public List<Item> deleteAllSelectedItems() {
//-------------------------
//-------------------------

/**
* returns the expanded items this contains position and the count of items
* which are expanded by this position
*
* @return the expanded items
*/
public SparseIntArray getExpanded() {
return mExpanded;
}

/**
* @return a set with the global positions of all expanded items
*/
Expand Down Expand Up @@ -884,8 +894,8 @@ public void expand(int position) {
if (item != null && item instanceof IExpandable) {
IExpandable<?, Item> expandable = (IExpandable<?, Item>) item;

//if this item is not already callapsed and has sub items we go on
if (!expandable.isExpanded() && expandable.getSubItems() != null && expandable.getSubItems().size() > 0) {
//if this item is not already expanded and has sub items we go on
if (mExpanded.indexOfKey(position) < 0 && expandable.getSubItems() != null && expandable.getSubItems().size() > 0) {
IAdapter<Item> adapter = getAdapter(position);
if (adapter != null && adapter instanceof IItemAdapter) {
((IItemAdapter<Item>) adapter).add(position + 1, expandable.getSubItems());
Expand Down Expand Up @@ -913,6 +923,9 @@ public void notifyAdapterDataSetChanged() {
mExpanded.clear();
cacheSizes();
notifyDataSetChanged();

//we make sure the new items are displayed properly
AdapterUtil.handleStates(this, 0, getItemCount() - 1);
}

/**
Expand All @@ -926,6 +939,9 @@ public void notifyAdapterItemInserted(int position) {
mExpanded = AdapterUtil.adjustPosition(mExpanded, position, Integer.MAX_VALUE, 1);
cacheSizes();
notifyItemInserted(position);

//we make sure the new items are displayed properly
AdapterUtil.handleStates(this, position, position);
}

/**
Expand All @@ -940,6 +956,9 @@ public void notifyAdapterItemRangeInserted(int position, int itemCount) {
mExpanded = AdapterUtil.adjustPosition(mExpanded, position, Integer.MAX_VALUE, itemCount);
cacheSizes();
notifyItemRangeInserted(position, itemCount);

//we make sure the new items are displayed properly
AdapterUtil.handleStates(this, position, position + itemCount - 1);
}

/**
Expand Down Expand Up @@ -1022,6 +1041,9 @@ public void notifyAdapterItemChanged(int position, Object payload) {
} else {
notifyItemChanged(position, payload);
}

//we make sure the new items are displayed properly
AdapterUtil.handleStates(this, position, position);
}

/**
Expand All @@ -1046,19 +1068,16 @@ public void notifyAdapterItemRangeChanged(int position, int itemCount, Object pa
if (mExpanded.indexOfKey(i) >= 0) {
collapse(i);
}
Item updateItem = getItem(i);
if (updateItem.isSelected()) {
mSelections.add(i);
} else if (mSelections.contains(i)) {
mSelections.remove(i);
}
}

if (payload == null) {
notifyItemRangeChanged(position, itemCount);
} else {
notifyItemRangeChanged(position, itemCount, payload);
}

//we make sure the new items are displayed properly
AdapterUtil.handleStates(this, position, position + itemCount - 1);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import android.util.SparseIntArray;

import com.mikepenz.fastadapter.FastAdapter;
import com.mikepenz.fastadapter.IExpandable;
import com.mikepenz.fastadapter.IItem;

import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
Expand All @@ -11,6 +15,29 @@
*/
public class AdapterUtil {

/**
* internal method which correctly set the selected state and expandable state on the newly added items
*
* @param fastAdapter the fastAdapter which manages everything
* @param startPosition the position of the first item to handle
* @param endPosition the position of the last item to handle
*/
public static void handleStates(FastAdapter fastAdapter, int startPosition, int endPosition) {
for (int i = endPosition; i >= startPosition; i--) {
IItem updateItem = fastAdapter.getItem(i);
if (updateItem.isSelected()) {
fastAdapter.getSelections().add(i);
} else if (fastAdapter.getSelections().contains(i)) {
fastAdapter.getSelections().remove(i);
}
if (updateItem instanceof IExpandable) {
if (((IExpandable) updateItem).isExpanded() && fastAdapter.getExpanded().indexOfKey(i) < 0) {
fastAdapter.expand(i);
}
}
}
}

/**
* internal method to handle the selections if items are added / removed
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<b>FastAdapter</b>, the bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
]]>
</string>
<string name="library_fastadapter_libraryVersion">1.0.2</string>
<string name="library_fastadapter_libraryVersion">1.0.3</string>
<string name="library_fastadapter_libraryWebsite">https://github.com/mikepenz/FastAdapter</string>
<string name="library_fastadapter_licenseId">apache_2_0</string>
<string name="library_fastadapter_isOpenSource">true</string>
Expand Down

0 comments on commit e5d2c91

Please sign in to comment.