Skip to content

Commit c90faa5

Browse files
committed
更新SDK
1 parent ba87210 commit c90faa5

6 files changed

Lines changed: 50 additions & 27 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# RecyclerArrayAdapter
22

33
###### `Java 8.0`
4-
###### `Kotlin 1.7.0`
5-
###### `SDk 31`
4+
###### `Kotlin 1.7.10`
5+
###### `SDk 33`
66
###### `Androidx`
77

88
* 方便快捷的 `ArrayAdapter`
@@ -37,5 +37,5 @@
3737
#### 使用
3838

3939
```
40-
implementation 'com.github.xiaoxiaoying:Page-RecyclerView-ArrayAdpter:1.4.1'
40+
implementation 'com.github.xiaoxiaoying:Page-RecyclerView-ArrayAdpter:1.4.2'
4141
```

app/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ apply plugin: 'kotlin-android'
55
apply plugin: 'kotlin-android-extensions'
66

77
android {
8-
compileSdkVersion 31
8+
compileSdkVersion 33
99
defaultConfig {
1010
applicationId "com.xiaoxiaoying.recyclerarrayadapter.demo"
1111
minSdkVersion 15
12-
targetSdkVersion 31
12+
targetSdkVersion 33
1313
versionCode 1
1414
versionName "1.0"
1515
}
@@ -31,10 +31,10 @@ android {
3131
dependencies {
3232
implementation fileTree(dir: 'libs', include: ['*.jar'])
3333
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
34-
implementation 'androidx.core:core-ktx:1.7.0'
35-
implementation 'androidx.appcompat:appcompat:1.4.1'
34+
implementation 'androidx.core:core-ktx:1.9.0'
35+
implementation 'androidx.appcompat:appcompat:1.5.1'
3636
implementation 'androidx.recyclerview:recyclerview:1.2.1'
3737
implementation project(path: ':recyclerarrayadapter')
3838
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
39-
testImplementation 'junit:junit:4.12'
39+
testImplementation 'junit:junit:4.13.2'
4040
}

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.7.0'
4+
ext.kotlin_version = '1.7.10'
55
repositories {
66
google()
77
jcenter()
88
}
99
dependencies {
10-
classpath "com.android.tools.build:gradle:7.1.2"
10+
classpath "com.android.tools.build:gradle:7.3.0"
1111
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1212
// classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1313
// classpath 'com.novoda:bintray-release:0.9.2'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Thu Jan 14 12:10:13 CST 2021
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

recyclerarrayadapter/build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ apply plugin: 'kotlin-android'
88
apply plugin: 'kotlin-android-extensions'
99
//apply plugin: 'com.github.dcendents.android-maven'
1010
android {
11-
compileSdkVersion 31
11+
compileSdkVersion 33
1212

1313
defaultConfig {
1414
minSdkVersion 15
15-
targetSdkVersion 31
16-
versionCode 21
17-
versionName "1.4.1"
15+
targetSdkVersion 33
16+
versionCode 22
17+
versionName "1.4.2"
1818

1919
}
2020
compileOptions {
@@ -42,11 +42,11 @@ android {
4242
dependencies {
4343
implementation fileTree(dir: 'libs', include: ['*.jar'])
4444
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
45-
implementation 'androidx.core:core-ktx:1.7.0'
46-
implementation 'androidx.appcompat:appcompat:1.4.1'
45+
implementation 'androidx.core:core-ktx:1.9.0'
46+
implementation 'androidx.appcompat:appcompat:1.5.1'
4747
implementation 'androidx.recyclerview:recyclerview:1.2.1'
4848

4949

50-
testImplementation 'junit:junit:4.12'
50+
testImplementation 'junit:junit:4.13.2'
5151
}
5252

recyclerarrayadapter/src/main/java/com/xiaoxiaoying/recyclerarrayadapter/adapter/ArrayAdapter.kt

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ import java.util.*
1616
* create by xiaoxiaoying on 2019-06-21
1717
* @author xiaoxiaoying
1818
*/
19-
abstract class ArrayAdapter<T, H : ArrayAdapter.ViewHolder<T>>(
19+
abstract class ArrayAdapter<T, H : ArrayAdapter.ViewHolder<T>> @JvmOverloads constructor(
2020
private val context: Context,
2121
@LayoutRes private val resId: Int = 0,
22-
private val arrays: MutableList<T>
22+
private val arrays: MutableList<T> = mutableListOf()
2323
) : RecyclerView.Adapter<H>() {
24-
constructor(context: Context) : this(context, 0)
25-
constructor(context: Context, resource: Int) : this(context, resource, ArrayList<T>())
26-
2724

2825
companion object {
2926
private val mLock = Any()
@@ -73,6 +70,26 @@ abstract class ArrayAdapter<T, H : ArrayAdapter.ViewHolder<T>>(
7370
notifyItemRangeInserted(index, 1)
7471
}
7572

73+
fun insert(vararg objects: T, startIndex: Int) {
74+
if (startIndex > arrays.size) return
75+
synchronized(mLock)
76+
{
77+
objects.forEachIndexed { index, t ->
78+
insert(t, index + startIndex)
79+
}
80+
}
81+
}
82+
83+
fun insert(collection: Collection<T>, startIndex: Int) {
84+
if (startIndex > arrays.size) return
85+
synchronized(mLock)
86+
{
87+
collection.forEachIndexed { index, t ->
88+
insert(t, index + startIndex)
89+
}
90+
}
91+
}
92+
7693
/**
7794
* Removes the specified object from the array.
7895
*
@@ -114,12 +131,14 @@ abstract class ArrayAdapter<T, H : ArrayAdapter.ViewHolder<T>>(
114131
fun removeItem(count: Int, startPosition: Int) {
115132
synchronized(mLock)
116133
{
117-
for (position in 0 until count) {
118-
val deletePosition = position + startPosition
119-
if (arrays.size <= deletePosition) return
120-
arrays.removeAt(deletePosition)
134+
repeat(count) {
135+
val deletePosition = it - 1 + startPosition
136+
if (arrays.size > deletePosition) {
137+
arrays.removeAt(deletePosition)
138+
}
121139

122140
}
141+
123142
notifyItemRangeRemoved(startPosition, count)
124143
}
125144
}
@@ -132,6 +151,10 @@ abstract class ArrayAdapter<T, H : ArrayAdapter.ViewHolder<T>>(
132151
*/
133152
fun findItemPosition(item: T): Int = arrays.indexOf(item)
134153

154+
fun find(predicate: (T) -> Boolean) {
155+
arrays.find(predicate)
156+
}
157+
135158
fun clean() {
136159
synchronized(mLock)
137160
{

0 commit comments

Comments
 (0)