Skip to content

Commit

Permalink
change action when no view type matched
Browse files Browse the repository at this point in the history
  • Loading branch information
junixapp committed Aug 16, 2022
1 parent 2af287e commit a93b3e4
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 29 deletions.
15 changes: 5 additions & 10 deletions app/src/main/java/com/lxj/easyadapter/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class MainActivity : AppCompatActivity() {
multiItemTypeAdapter = MultiItemTypeAdapter<User>(userList)
.apply {
addItemDelegate(OneDelegate())
// addItemDelegate(TwoDelegate())
addItemDelegate(TwoDelegate())
// addHeaderView(createView("Multi Header view1111"))
// addHeaderView(createView("Multi Header view22222"))
// addFootView(createView("Multi Footer view"))
Expand All @@ -165,8 +165,7 @@ class MainActivity : AppCompatActivity() {
internal inner class OneDelegate : ItemDelegate<User> {

override fun isThisType(item: User, position: Int): Boolean {
return true
// return position % 2 != 0
return position < 2
}
override fun bind(holder: ViewHolder, user: User, position: Int) {
holder.setText(R.id.name, user.name)
Expand All @@ -179,12 +178,8 @@ class MainActivity : AppCompatActivity() {
}

//布局更新
override fun bindWithPayloads(
holder: ViewHolder,
t: User,
position: Int,
payloads: List<Any>
) {
override fun bindWithPayloads(holder: ViewHolder, t: User,
position: Int, payloads: List<Any>) {
if(payloads.isNullOrEmpty()) return
val bundle = payloads[0] as Bundle
val name = bundle.getString("name") ?: ""
Expand All @@ -200,7 +195,7 @@ class MainActivity : AppCompatActivity() {
override fun getLayoutId(): Int = android.R.layout.simple_list_item_1

override fun isThisType(item: User, position: Int): Boolean {
return position % 2 == 0
return position >=2
}
override fun bind(holder: ViewHolder, user: User, position: Int) {
holder.setText(android.R.id.text1, "age: " + user.age)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UserDiffCallback(var oldData: List<User>?, var newData: List<User>?) : Dif
return oldData!![oldItemPosition].name == newData!![newItemPosition].name
}

//局部更新 areItemsTheSame为true && areContentsTheSame==false 调用
//局部更新 areItemsTheSame==true && areContentsTheSame==false 调用
override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? {
val oldItem = oldData!![oldItemPosition]
val newItem = newData!![newItemPosition]
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.5.0'

repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:4.2.0'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
11 changes: 0 additions & 11 deletions easy-adapter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,3 @@ dependencies {
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

//publish {
// userOrg = 'li-xiaojun'
// groupId = 'com.lxj'
// artifactId = 'easyadapter'
// publishVersion = '1.2.3'
// repoName = 'jrepo'
// desc = 'An simpify version for hongyangAndroid baseAdapter!'
// website = 'https://github.com/li-xiaojun/EasyAdapter'
//}

Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ class ItemDelegateManager<T> {
return delegates.keyAt(i)
}
}
throw IllegalArgumentException(
"No ItemDelegate added that matches position=$position in data source")
return 0
// throw IllegalArgumentException(
// "No ItemDelegate added that matches position=$position in data source")
}

fun convert(holder: ViewHolder, item: T, position: Int, payloads: List<Any>? = null) {
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Apr 25 21:24:32 CST 2020
#Wed Dec 18 19:13:30 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip

0 comments on commit a93b3e4

Please sign in to comment.