Skip to content

Commit

Permalink
Merge pull request #7 from netcosports/dev
Browse files Browse the repository at this point in the history
1.0.1
  • Loading branch information
Woffkaa authored Dec 7, 2021
2 parents afbbaa2 + 3b7f6fa commit 584af1b
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 33 deletions.
19 changes: 7 additions & 12 deletions buildSrc/src/main/kotlin/Deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ import org.gradle.api.JavaVersion
object Config {

object Build {
const val kotlinVersion = "1.5.20"
const val kotlinVersion = "1.6.0"

const val compileSdk = 30
const val buildTools = "30.0.2"
const val compileSdk = 31
const val minSdk = 17
const val sampleMinSdk = 21
const val targetSdk = compileSdk

val javaVersion = JavaVersion.VERSION_1_8

const val repoName = "CompositeAdapter_Android"
const val packageNameDev = "io.github.netcosports.compositeadapter.sample"
const val packageNameProd = "io.github.netcosports.compositeadapter.sample"

const val versionName = "1.0.0"
const val versionName = "1.0.1"
const val versionOffset = 0
}

Expand All @@ -29,29 +27,26 @@ object Config {
}

object Plugins {
const val buildGradle = "com.android.tools.build:gradle:4.2.0"
const val buildGradle = "com.android.tools.build:gradle:7.0.3"
const val kotlinGradle = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Build.kotlinVersion}"
const val androidApp = "com.android.application"
const val androidLibrary = "com.android.library"
const val android = "android"
const val kapt = "kapt"
const val mavenPublish = "maven-publish"
const val jfrogArtifactory = "com.jfrog.artifactory"
const val jfrogArtifactoryVersion = "4.21.0"
}

object Deps {
object AndroidX {
const val appcompat = "androidx.appcompat:appcompat:1.3.0"
const val appcompat = "androidx.appcompat:appcompat:1.4.0"
const val swipeRefresh = "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
const val recycler = "androidx.recyclerview:recyclerview:1.2.1"
const val lifecycleVersion = "2.3.1"
const val lifecycleVersion = "2.4.0"
const val lifecycleViewModelKtx = "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
const val lifecycleLiveDataKtx = "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
}

object Coroutines {
const val version = "1.5.0"
const val version = "1.5.2"
const val android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"
}

Expand Down
12 changes: 7 additions & 5 deletions composite-adapter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ plugins {
}

android {
compileSdkVersion(Config.Build.compileSdk)
buildToolsVersion(Config.Build.buildTools)
compileSdk = Config.Build.compileSdk

defaultConfig {
minSdkVersion(Config.Build.minSdk)
targetSdkVersion(Config.Build.targetSdk)
minSdk = Config.Build.minSdk
targetSdk = Config.Build.targetSdk
}

buildTypes {
Expand All @@ -25,14 +24,17 @@ android {
sourceCompatibility = Config.Build.javaVersion
targetCompatibility = Config.Build.javaVersion
}

kotlinOptions {
jvmTarget = Config.Build.javaVersion.toString()
}
}

dependencies {
compileOnly(Config.Deps.Kotlin.kotlinJdk8)

implementation(Config.Deps.AndroidX.appcompat)
compileOnly(Config.Deps.AndroidX.recycler)
compileOnly(Config.Deps.AndroidX.swipeRefresh)
}

val androidSourcesJar by tasks.registering(Jar::class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ abstract class BaseCompositeAdapter<DATA : Cell<*>>(
return item.onCreateViewHolder(inflater, parent, item.viewType)
}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int, payloads: MutableList<Any>) {
if (payloads.isNotEmpty() && payloads.all { it == Cell.CELL_DECORATION_PAYLOAD }) {
storeCellInHolder(holder, position)
override fun onBindViewHolder(
holder: RecyclerView.ViewHolder,
position: Int,
payloads: MutableList<Any>
) {
if (payloads.isNotEmpty() && payloads.all { it == Cell.CELL_INTERNAL_PAYLOAD }) {
handleInternalPayload(holder, position, payloads)
} else {
if (!getItem(position).onBindViewHolder(holder, position, payloads)) {
super.onBindViewHolder(holder, position, payloads)
Expand All @@ -61,9 +65,18 @@ abstract class BaseCompositeAdapter<DATA : Cell<*>>(

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
storeHolderInView(holder, position)
onBind(holder, position)
storeCellInHolder(holder, position)
onBindClickListener(holder, position)
onBind(holder, position)
}

protected open fun handleInternalPayload(
holder: RecyclerView.ViewHolder,
position: Int,
payloads: MutableList<Any>
) {
storeCellInHolder(holder, position)
onBindClickListener(holder, position)
}

protected open fun storeHolderInView(holder: RecyclerView.ViewHolder, position: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ interface Cell<T> {
fun areContentsTheSame(newItem: Cell<*>): Boolean = data == newItem.data
fun getChangePayload(newItem: Cell<*>): Any? = null
fun areDecorationsTheSame(newItem: Cell<*>): Boolean = decoration == newItem.decoration
fun areOnClickListenersTheSame(newItem: Cell<*>): Boolean = onClickListener == newItem.onClickListener

fun onClicked(context: Context, holder: RecyclerView.ViewHolder, position: Int) {
onClickListener?.invoke(ClickItem(context, holder, position, data))
}

companion object {
const val CELL_DECORATION_PAYLOAD = "CELL_DECORATION"
const val CELL_INTERNAL_PAYLOAD = "CELL_INTERNAL_PAYLOAD"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ open class CellItemCallback<CELL : Cell<*>> : DiffUtil.ItemCallback<CELL>() {
}

override fun areContentsTheSame(oldItem: CELL, newItem: CELL): Boolean {
return oldItem.areContentsTheSame(newItem) && oldItem.areDecorationsTheSame(newItem)
return oldItem.areContentsTheSame(newItem)
&& oldItem.areDecorationsTheSame(newItem)
&& oldItem.areOnClickListenersTheSame(newItem)
}

override fun getChangePayload(oldItem: CELL, newItem: CELL): Any? {
val payload = oldItem.getChangePayload(newItem)
return if (payload == null && oldItem.areContentsTheSame(newItem)) {
Cell.CELL_DECORATION_PAYLOAD
Cell.CELL_INTERNAL_PAYLOAD
} else {
payload
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-all.zip
17 changes: 10 additions & 7 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ plugins {
}

android {
compileSdkVersion(Config.Build.compileSdk)
buildToolsVersion(Config.Build.buildTools)
compileSdk = Config.Build.compileSdk

defaultConfig {
minSdkVersion(Config.Build.sampleMinSdk)
targetSdkVersion(Config.Build.targetSdk)
minSdk = Config.Build.minSdk
targetSdk = Config.Build.targetSdk

versionCode = getCustomVersionCode()
versionName = getCustomVersionName()
Expand All @@ -25,15 +24,15 @@ android {
}
}

flavorDimensions("env")
flavorDimensions.add("env")
productFlavors {
create("development") {
dimension("env")
dimension = "env"
applicationId = Config.Build.packageNameDev
}

create("production") {
dimension("env")
dimension = "env"
applicationId = Config.Build.packageNameProd
}
}
Expand All @@ -43,6 +42,10 @@ android {
targetCompatibility = Config.Build.javaVersion
}

kotlinOptions {
jvmTarget = Config.Build.javaVersion.toString()
}

buildFeatures {
dataBinding = true
viewBinding = true
Expand Down
4 changes: 3 additions & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".ui.sample.SampleActivity">
<activity
android:name=".ui.sample.SampleActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down

0 comments on commit 584af1b

Please sign in to comment.