From b8d34e7157105b7e71e09f9d4b9d23df62f6a41b Mon Sep 17 00:00:00 2001 From: Jieyi Date: Tue, 22 Jan 2019 19:26:20 +0900 Subject: [PATCH] Feature: added the compare replace whole list for changing the list. --- README.md | 2 +- .../devrapid/adaptiverecyclerview/AdaptiveAdapter.kt | 10 ++++++++-- .../adaptiverecyclerview/AdaptiveViewHolder.kt | 4 ++-- build.gradle | 4 ++-- gradle.properties | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 54a5034..8b75e09 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/adaptiverecyclerview/src/main/java/com/devrapid/adaptiverecyclerview/AdaptiveAdapter.kt b/adaptiverecyclerview/src/main/java/com/devrapid/adaptiverecyclerview/AdaptiveAdapter.kt index 2c7331e..0c914f5 100644 --- a/adaptiverecyclerview/src/main/java/com/devrapid/adaptiverecyclerview/AdaptiveAdapter.kt +++ b/adaptiverecyclerview/src/main/java/com/devrapid/adaptiverecyclerview/AdaptiveAdapter.kt @@ -57,9 +57,9 @@ abstract class AdaptiveAdapter, 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).initView(dataList[position], position, this) @@ -72,6 +72,8 @@ abstract class AdaptiveAdapter, 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) { val startIndex = dataList.size @@ -133,6 +135,10 @@ abstract class AdaptiveAdapter, VH : Re return true } + open fun replaceWholeList(newList: MutableList) { + updateList { newList } + } + private fun updateList(getNewListBlock: () -> MutableList) { val newList = getNewListBlock() val res = DiffUtil.calculateDiff(diffUtil.apply { diff --git a/adaptiverecyclerview/src/main/java/com/devrapid/adaptiverecyclerview/AdaptiveViewHolder.kt b/adaptiverecyclerview/src/main/java/com/devrapid/adaptiverecyclerview/AdaptiveViewHolder.kt index c1f369d..d682a4e 100644 --- a/adaptiverecyclerview/src/main/java/com/devrapid/adaptiverecyclerview/AdaptiveViewHolder.kt +++ b/adaptiverecyclerview/src/main/java/com/devrapid/adaptiverecyclerview/AdaptiveViewHolder.kt @@ -13,7 +13,7 @@ import androidx.recyclerview.widget.RecyclerView abstract class AdaptiveViewHolder>( view: View ) : RecyclerView.ViewHolder(view) { - protected val mContext: Context = view.context + protected val mContext: Context = itemView.context /** * Set the views' properties. @@ -22,5 +22,5 @@ abstract class AdaptiveViewHolder * @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<*, *, *>) } diff --git a/build.gradle b/build.gradle index d440c1a..8b0b86d 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } } diff --git a/gradle.properties b/gradle.properties index b7a767f..5bf2434 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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