Skip to content

Commit

Permalink
Feature: added the compare replace whole list for changing the list.
Browse files Browse the repository at this point in the history
  • Loading branch information
pokk committed Jan 22, 2019
1 parent 30bbe97 commit b8d34e7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ please. There is a simple sample for this library. 😄
It's very easy to import, you just put them into your gradle file.

```gradle
compile "com.devrapid.jieyi:adaptiverecyclerview:1.0.6"
compile "com.devrapid.jieyi:adaptiverecyclerview:1.0.7"
```

## Maven
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ abstract class AdaptiveAdapter<VT : ViewTypeFactory, M : IVisitable<VT>, VH : Re
}

//region Necessary override methods.
override fun getItemCount(): Int = dataList.size
override fun getItemCount() = dataList.size

override fun getItemViewType(position: Int): Int = dataList[position].type(typeFactory)
override fun getItemViewType(position: Int) = dataList[position].type(typeFactory)

override fun onBindViewHolder(holder: VH, position: Int) =
(holder as AdaptiveViewHolder<VT, M>).initView(dataList[position], position, this)
Expand All @@ -72,6 +72,8 @@ abstract class AdaptiveAdapter<VT : ViewTypeFactory, M : IVisitable<VT>, VH : Re
}
//endregion

fun listDescription() = dataList.joinToString("\n") { it.toString() }

// OPTIMIZE(jieyi): 2018/12/04 There's no checking bounding.
open fun appendList(list: MutableList<M>) {
val startIndex = dataList.size
Expand Down Expand Up @@ -133,6 +135,10 @@ abstract class AdaptiveAdapter<VT : ViewTypeFactory, M : IVisitable<VT>, VH : Re
return true
}

open fun replaceWholeList(newList: MutableList<M>) {
updateList { newList }
}

private fun updateList(getNewListBlock: () -> MutableList<M>) {
val newList = getNewListBlock()
val res = DiffUtil.calculateDiff(diffUtil.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import androidx.recyclerview.widget.RecyclerView
abstract class AdaptiveViewHolder<in VT : ViewTypeFactory, in M : IVisitable<VT>>(
view: View
) : RecyclerView.ViewHolder(view) {
protected val mContext: Context = view.context
protected val mContext: Context = itemView.context

/**
* Set the views' properties.
Expand All @@ -22,5 +22,5 @@ abstract class AdaptiveViewHolder<in VT : ViewTypeFactory, in M : IVisitable<VT>
* @param position the index of a list.
* @param adapter parent adapter.
*/
abstract fun initView(model: M, position: Int, adapter: Any)
abstract fun initView(model: M, position: Int, adapter: AdaptiveAdapter<*, *, *>)
}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ buildscript {

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ proj_name=adaptiverecyclerview
proj_libname=AdaptiveRecyclerview
proj_group=com.devrapid.jieyi
proj_artifactid=adaptiverecyclerview
proj_version=1.0.6
proj_version=1.0.7
proj_description=Create an adaptive recycler view for each of type view.
proj_websiteurl=https://github.com/pokk/AdaptiveRecyclerView
proj_issuetrackerurl=https://github.com/pokk/AdaptiveRecyclerView/issues
Expand Down

0 comments on commit b8d34e7

Please sign in to comment.