Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: CymChad/BaseRecyclerViewAdapterHelper
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4.1.3
Choose a base ref
...
head repository: CymChad/BaseRecyclerViewAdapterHelper
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 14 commits
  • 10 files changed
  • 2 contributors

Commits on Dec 8, 2023

  1. Update README.md

    limuyang2 authored Dec 8, 2023
    Copy the full SHA
    68aff16 View commit details
  2. Update README.md

    limuyang2 authored Dec 8, 2023
    Copy the full SHA
    7e1b9d7 View commit details

Commits on Jan 4, 2024

  1. Copy the full SHA
    dfd0445 View commit details
  2. Copy the full SHA
    b30978a View commit details
  3. Copy the full SHA
    837b908 View commit details
  4. build: 4.1.4

    limuyang2 committed Jan 4, 2024
    Copy the full SHA
    d28a8f1 View commit details
  5. Update README.md

    limuyang2 authored Jan 4, 2024
    Copy the full SHA
    c7419ef View commit details

Commits on Jun 2, 2024

  1. Copy the full SHA
    4467fab View commit details
  2. Copy the full SHA
    057f3ca View commit details
  3. feat: 整理 gradle

    limuyang2 committed Jun 2, 2024
    Copy the full SHA
    fa46d74 View commit details

Commits on Jun 3, 2024

  1. feat: update gradle

    limuyang2 committed Jun 3, 2024
    Copy the full SHA
    3b8c5f7 View commit details
  2. feat: update gradle

    limuyang2 committed Jun 3, 2024
    Copy the full SHA
    321c3ac View commit details

Commits on Jun 26, 2024

  1. Update README.md

    CymChad authored Jun 26, 2024
    Copy the full SHA
    a010a4e View commit details
  2. Update README.md

    CymChad authored Jun 26, 2024
    1
    Copy the full SHA
    afa7a11 View commit details
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
![](https://user-images.githubusercontent.com/7698209/33198075-ef8f2230-d123-11e7-85a3-4cb9b22f877d.png)
[![](https://img.shields.io/maven-central/v/io.github.cymchad/BaseRecyclerViewAdapterHelper4)](https://repo.maven.apache.org/maven2/io/github/cymchad/BaseRecyclerViewAdapterHelper4/) [![API](https://img.shields.io/badge/API-16%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=16) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-BaseRecyclerViewAdapterHelper-green.svg?style=true)](https://android-arsenal.com/details/1/3644) [![CircleCI](https://circleci.com/gh/CymChad/BaseRecyclerViewAdapterHelper/tree/master.svg?style=svg)](https://circleci.com/gh/CymChad/BaseRecyclerViewAdapterHelper/tree/master) [![](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-%E9%99%88%E5%AE%87%E6%98%8E-7AD6FD.svg)](https://mp.weixin.qq.com/s/5UlMx9HDgEcvxJb4w5-gBA) [![](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-limuyang2-7AD6FD)](https://github.com/limuyang2)
[![](https://img.shields.io/maven-central/v/io.github.cymchad/BaseRecyclerViewAdapterHelper4)](https://repo.maven.apache.org/maven2/io/github/cymchad/BaseRecyclerViewAdapterHelper4/) [![API](https://img.shields.io/badge/API-16%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=16) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-BaseRecyclerViewAdapterHelper-green.svg?style=true)](https://android-arsenal.com/details/1/3644) [![CircleCI](https://circleci.com/gh/CymChad/BaseRecyclerViewAdapterHelper/tree/master.svg?style=svg)](https://circleci.com/gh/CymChad/BaseRecyclerViewAdapterHelper/tree/master) [![](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-%E9%99%88%E5%AE%87%E6%98%8E-7AD6FD.svg)](https://mp.weixin.qq.com/s/U4QAPlu5WDm8U5Ljc7TuAQ) [![](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-limuyang2-7AD6FD)](https://github.com/limuyang2)
# BRVAH
http://www.recyclerview.org/

Powerful and flexible RecyclerView Adapter,
Please feel free to use this. (Welcome to **Star** and **Fork**)

强大而灵活的RecyclerView Adapter(欢迎 **Star****Fork**

新版4.x.x已发布 alpha 版本,完美兼容`ConcatAdapter`,解决了许多遗留问题,拆分了功能模块,BaseAdapter更加简洁干净。“多类型布局”更加灵活。向上、向下加载得到极大加强。
新版4.x.x已发布,完美兼容`ConcatAdapter`,解决了许多遗留问题,拆分了功能模块,BaseAdapter更加简洁干净。“多类型布局”更加灵活。向上、向下加载得到极大加强。
v4版本已经上传 maven 中央仓库,不需要再引入三方仓库配置了。欢迎尝试。
**注意,4.0为非兼容升级,建议在新项目尝试**
```
implementation "io.github.cymchad:BaseRecyclerViewAdapterHelper4:4.1.2"
implementation "io.github.cymchad:BaseRecyclerViewAdapterHelper4:4.1.4"
```


18 changes: 9 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -6,12 +6,12 @@ plugins {
}

android {
compileSdkVersion 33
compileSdk 34

defaultConfig {
applicationId "com.chad.baserecyclerviewadapterhelper"
minSdkVersion 19
targetSdkVersion 33
minSdk 21
targetSdk 34
versionCode 10
versionName "4.0"
}
@@ -46,17 +46,17 @@ android {
dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
implementation project(path: ':library')
implementation 'com.google.android.material:material:1.8.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation "androidx.core:core-ktx:1.10.1"
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation "androidx.core:core-ktx:1.13.1"

implementation 'com.kyleduo.switchbutton:library:2.1.0'
implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"

implementation("com.squareup.moshi:moshi:1.14.0")
ksp("com.squareup.moshi:moshi-kotlin-codegen:1.14.0")
implementation("com.squareup.moshi:moshi:1.15.1")
ksp("com.squareup.moshi:moshi-kotlin-codegen:1.15.1")

implementation 'com.jaredrummler:material-spinner:1.3.1'
}
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ class EmptyViewUseActivity : BaseViewBindingActivity<ActivityEmptyViewUseBinding

// 打开空布局功能
mAdapter.isStateViewEnable = true
mAdapter.isUseStateViewSize = true

onRefresh()
}
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

plugins {
id 'com.android.application' version '8.0.1' apply false
id 'com.android.library' version '8.0.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.21' apply false
id 'com.google.devtools.ksp' version '1.8.21-1.0.11' apply false
id 'com.android.application' version '8.2.0' apply false
id 'com.android.library' version '8.2.0' apply false
id 'org.jetbrains.kotlin.android' version '2.0.0' apply false
id 'com.google.devtools.ksp' version '2.0.0-1.0.21' apply false
}

task clean(type: Delete) {
tasks.register('clean', Delete) {
delete rootProject.buildDir
}

1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -17,5 +17,4 @@ android.enableJetifier=false
android.injected.testOnly=false

android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon May 29 14:19:55 CST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 6 additions & 6 deletions library/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ plugins {
signing
}

val versionName = "4.1.3"
val versionName = "4.1.6"


android {
@@ -33,11 +33,11 @@ android {
add("com.github.CymChad.brvah")
add("-Xjvm-default=all")
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "11"
}
namespace = "com.chad.library.adapter4"

@@ -53,9 +53,9 @@ android {


dependencies {
implementation("androidx.annotation:annotation:1.6.0")
implementation("androidx.annotation:annotation:1.8.0")

implementation("androidx.recyclerview:recyclerview:1.3.0")
implementation("androidx.recyclerview:recyclerview:1.3.2")

implementation("androidx.databinding:databinding-runtime:8.0.0")
}
Original file line number Diff line number Diff line change
@@ -91,67 +91,111 @@ abstract class BaseDifferAdapter<T : Any, VH : RecyclerView.ViewHolder>(
}

override operator fun set(position: Int, data: T) {
set(position, data, null)
}

override fun add(data: T) {
add(data, null)
}

override fun add(position: Int, data: T) {
add(position, data, null)
}

override fun addAll(collection: Collection<T>) {
addAll(collection, null)
}

override fun addAll(position: Int, collection: Collection<T>) {
addAll(position, collection, null)
}

override fun removeAt(position: Int) {
removeAt(position, null)
}

override fun remove(data: T) {
remove(data, null)
}

override fun removeAtRange(range: IntRange) {
removeAtRange(range, null)
}

override fun swap(fromPosition: Int, toPosition: Int) {
swap(fromPosition, toPosition, null)
}

override fun move(fromPosition: Int, toPosition: Int) {
move(fromPosition, toPosition, null)
}


/**
* 带 Runnable
*/
open fun set(position: Int, data: T, commitCallback: Runnable?) {
items.toMutableList().also {
it[position] = data
submitList(it)
submitList(it, commitCallback)
}
}

override fun add(data: T) {
open fun add(data: T, commitCallback: Runnable?) {
items.toMutableList().also {
it.add(data)
submitList(it)
submitList(it, commitCallback)
}
}

override fun add(position: Int, data: T) {
open fun add(position: Int, data: T, commitCallback: Runnable?) {
if (position > items.size || position < 0) {
throw IndexOutOfBoundsException("position: ${position}. size:${items.size}")
}

items.toMutableList().also {
it.add(position, data)
submitList(it)
submitList(it, commitCallback)
}
}

override fun addAll(collection: Collection<T>) {
open fun addAll(collection: Collection<T>, commitCallback: Runnable?) {
items.toMutableList().also {
it.addAll(collection)
submitList(it)
submitList(it, commitCallback)
}
}

override fun addAll(position: Int, collection: Collection<T>) {
open fun addAll(position: Int, collection: Collection<T>, commitCallback: Runnable?) {
if (position > items.size || position < 0) {
throw IndexOutOfBoundsException("position: ${position}. size:${items.size}")
}

items.toMutableList().also {
it.addAll(position, collection)
submitList(it)
submitList(it, commitCallback)
}
}

override fun removeAt(position: Int) {
open fun removeAt(position: Int, commitCallback: Runnable?) {
if (position >= items.size) {
throw IndexOutOfBoundsException("position: ${position}. size:${items.size}")
}

items.toMutableList().also {
it.removeAt(position)
submitList(it)
submitList(it, commitCallback)
}
}

override fun remove(data: T) {
open fun remove(data: T, commitCallback: Runnable?) {
items.toMutableList().also {
it.remove(data)
submitList(it)
submitList(it, commitCallback)
}
}

override fun removeAtRange(range: kotlin.ranges.IntRange) {
open fun removeAtRange(range: IntRange, commitCallback: Runnable?) {
if (range.isEmpty()) {
return
}
@@ -169,25 +213,29 @@ abstract class BaseDifferAdapter<T : Any, VH : RecyclerView.ViewHolder>(
for (it in last downTo range.first) {
list.removeAt(it)
}
submitList(list)
submitList(list, commitCallback)
}

override fun swap(fromPosition: Int, toPosition: Int) {
open fun swap(fromPosition: Int, toPosition: Int, commitCallback: Runnable?) {
if (fromPosition in items.indices || toPosition in items.indices) {
items.toMutableList().also {
Collections.swap(it, fromPosition, toPosition)
submitList(it)
submitList(it, commitCallback)
}
}
}

override fun move(fromPosition: Int, toPosition: Int) {
open fun move(fromPosition: Int, toPosition: Int, commitCallback: Runnable?) {
if (fromPosition in items.indices || toPosition in items.indices) {
items.toMutableList().also {
val e = it.removeAt(fromPosition)
it.add(toPosition, e)
submitList(it)
submitList(it, commitCallback)
}
}
}




}
Original file line number Diff line number Diff line change
@@ -124,6 +124,13 @@ abstract class BaseQuickAdapter<T : Any, VH : RecyclerView.ViewHolder>(
}
}

/**
* 是否使用状态布局的尺寸。
*
* Whether to use the dimensions of the state layout.
*/
var isUseStateViewSize = false

/**
* Empty view. Attention please: take effect when [items] is empty array.
* 空视图,注意:[items]为空数组才会生效
@@ -232,7 +239,7 @@ abstract class BaseQuickAdapter<T : Any, VH : RecyclerView.ViewHolder>(
parent: ViewGroup, viewType: Int
): RecyclerView.ViewHolder {
if (viewType == EMPTY_VIEW) {
return StateLayoutVH(parent, stateView)
return StateLayoutVH(parent, stateView, isUseStateViewSize)
}

return onCreateViewHolder(parent.context, parent, viewType).apply {
@@ -242,7 +249,7 @@ abstract class BaseQuickAdapter<T : Any, VH : RecyclerView.ViewHolder>(

final override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is StateLayoutVH) {
holder.changeStateView(stateView)
holder.changeStateView(stateView, isUseStateViewSize)
return
}

@@ -258,7 +265,7 @@ abstract class BaseQuickAdapter<T : Any, VH : RecyclerView.ViewHolder>(
}

if (holder is StateLayoutVH) {
holder.changeStateView(stateView)
holder.changeStateView(stateView, isUseStateViewSize)
return
}

Original file line number Diff line number Diff line change
@@ -17,21 +17,22 @@ import com.chad.library.adapter4.fullspan.FullSpanAdapterType
internal class StateLayoutVH(
parent: ViewGroup,
stateView: View?,
isUseStateViewSize: Boolean,
private val stateLayout: FrameLayout = FrameLayout(parent.context).apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT
)
setStateView(this, stateView)
setStateView(this, stateView, isUseStateViewSize)
}
) : RecyclerView.ViewHolder(stateLayout), FullSpanAdapterType {


fun changeStateView(stateView: View?) {
setStateView(stateLayout, stateView)
fun changeStateView(stateView: View?, isUseStateViewSize: Boolean) {
setStateView(stateLayout, stateView, isUseStateViewSize)
}

companion object {
private fun setStateView(rootView: ViewGroup, stateView: View?) {
private fun setStateView(rootView: ViewGroup, stateView: View?, isUseStateViewSize: Boolean) {
if (stateView == null) {
rootView.removeAllViews()
return
@@ -59,6 +60,13 @@ internal class StateLayoutVH(
}
}

if (isUseStateViewSize) {
val lp = rootView.layoutParams
lp.height = stateView.layoutParams.height
lp.width = stateView.layoutParams.width
rootView.layoutParams = lp
}

rootView.removeAllViews()
rootView.addView(stateView)
}