Skip to content

Commit

Permalink
Fix: fixed the adding function with header and footer.
Browse files Browse the repository at this point in the history
  • Loading branch information
pokk committed Feb 28, 2019
1 parent a73b39d commit df81e9e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,18 @@ abstract class AdaptiveAdapter<VT : ViewTypeFactory, M : IVisitable<VT>, VH : Re
updateList { newList }
}

@Deprecated("There's some bugs with index of header and footer")
open fun add(position: Int, item: M) {
if (dataItemCount <= 0) throw IndexOutOfBoundsException()

val newList = dataList.toMutableList().apply {
add(position + (if (headerEntity == null) 0 else 1) + (if (footerEntity == null) 0 else -1), item)
add(position + (if (headerEntity == null) 0 else 1), item)
}
updateList { newList }
}

@Deprecated("There's some bugs with index of header and footer")
open fun add(position: Int, list: MutableList<M>) {
val newList = dataList.toMutableList().apply {
addAll(position + (if (headerEntity == null) 0 else 1) + (if (footerEntity == null) 0 else -1), list)
addAll(position + (if (headerEntity == null) 0 else 1), list)
}
updateList { newList }
}
Expand Down
4 changes: 4 additions & 0 deletions sample/src/main/java/com/devrapid/example/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class MainActivity : AppCompatActivity() {
adapter.footerEntity = Person("Google !!!!!!!!")

btn_add.setOnClickListener {
adapter.add(0, mutableListOf<IExpandVisitor>(Person("BBBBBBBB ${a++}"),
Person("BBBBBBBB ${a++}"),
Person("BBBBBBBB ${a++}"),
Person("BBBBBBBB ${a++}")))
}
btn_minus.setOnClickListener {
// adapter.appendList(mutableListOf(Person("BBBBBBBB ${a++}"),
Expand Down

0 comments on commit df81e9e

Please sign in to comment.