Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
buildscript {
ext.versions = [
sdkMin : 14,
sdkTarget : 27,
buildTools : '27.0.1',
gradlePlugin : '3.0.1',
kotlin : '1.2.0',
support : '27.0.2'
sdkTarget : 28,
buildTools : '28.0.0',
gradlePlugin : '3.2.0-beta05',
kotlin : '1.2.60',
support : '27.1.1',
androidX : '1.0.0-beta01'
]
repositories {
google()
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-4.3.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import android.view.ViewGroup

class LastAdapter(private val list: List<Any>,
private val variable: Int? = null,
stableIds: Boolean = false) : RecyclerView.Adapter<Holder<ViewDataBinding>>() {
stableIds: Boolean = false
) : RecyclerView.Adapter<Holder<ViewDataBinding>>() {

constructor(list: List<Any>) : this(list, null, false)
constructor(list: List<Any>, variable: Int) : this(list, variable, false)
Expand All @@ -35,7 +36,6 @@ class LastAdapter(private val list: List<Any>,
private val DATA_INVALIDATION = Any()
private val callback = ObservableListCallback(this)
private var recyclerView: RecyclerView? = null
private var inflater: LayoutInflater? = null

private val map = mutableMapOf<Class<*>, BaseType>()
private var layoutHandler: LayoutHandler? = null
Expand Down Expand Up @@ -85,15 +85,14 @@ class LastAdapter(private val list: List<Any>,

fun into(recyclerView: RecyclerView) = apply { recyclerView.adapter = this }



override fun onCreateViewHolder(view: ViewGroup, viewType: Int): Holder<ViewDataBinding> {
val inflater = LayoutInflater.from(view.context)
val binding = DataBindingUtil.inflate<ViewDataBinding>(inflater, viewType, view, false)
val holder = Holder(binding)
binding.addOnRebindCallback(object : OnRebindCallback<ViewDataBinding>() {
override fun onPreBind(binding: ViewDataBinding) = recyclerView?.isComputingLayout ?: false
override fun onCanceled(binding: ViewDataBinding) {
if (recyclerView?.isComputingLayout ?: true) {
if (recyclerView?.isComputingLayout != false) {
return
}
val position = holder.adapterPosition
Expand Down Expand Up @@ -157,7 +156,6 @@ class LastAdapter(private val list: List<Any>,
list.addOnListChangedCallback(callback)
}
recyclerView = rv
inflater = LayoutInflater.from(rv.context)
}

override fun onDetachedFromRecyclerView(rv: RecyclerView) {
Expand Down
1 change: 1 addition & 0 deletions lastadapterx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
18 changes: 18 additions & 0 deletions lastadapterx/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
}

android {
compileSdkVersion versions.sdkTarget
buildToolsVersion versions.buildTools
defaultConfig.minSdkVersion versions.sdkMin
dataBinding.enabled true
}

dependencies {
implementation "androidx.recyclerview:recyclerview:$versions.androidX"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlin"
}

apply from: 'publish.gradle'
21 changes: 21 additions & 0 deletions lastadapterx/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

android.useAndroidX=true
android.enableJetifier=true
17 changes: 17 additions & 0 deletions lastadapterx/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Android\SDK/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
74 changes: 74 additions & 0 deletions lastadapterx/publish.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

def libName = 'lastadapter'
def libGroup = 'com.github.nitrico.' + libName
def libSite = 'https://github.com/nitrico/' + libName
def libGit = libSite + '.git'
def libTracker = libSite + '/issues'
def libDesc = "Don't write any other RecyclerView adapter again. Not even a Holder!"
def libTags = ['android', 'recyclerview', 'adapter', 'data binding', 'kotlin']

group libGroup
version '2.3.0'

Properties properties = new Properties()
properties.load(rootProject.file('local.properties').newDataInputStream())

bintray {
user properties.getProperty('bintray_user')
key properties.getProperty('bintray_key')
configurations = ['archives']
pkg {
repo = 'maven'
name = libName
desc = libDesc
websiteUrl = libSite
issueTrackerUrl = libTracker
vcsUrl = libGit
labels = libTags
licenses = ['Apache-2.0']
publish = true
publicDownloadNumbers = true
}
}

install {
repositories.mavenInstaller {
pom.project {
packaging 'aar'
groupId libGroup
artifactId libName
name libName
description libDesc
url libSite
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'moreno'
name 'Miguel Ángel Moreno'
email 'nitrico@gmail.com'
}
}
scm {
connection libGit
developerConnection libGit
url libSite
}
}
}
}

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier 'sources'
}

artifacts {
archives sourcesJar
}
1 change: 1 addition & 0 deletions lastadapterx/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest package="com.github.nitrico.lastadapterx"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2016 Miguel Ángel Moreno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.github.nitrico.lastadapterx

import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView

open class Holder<B : ViewDataBinding>(val binding: B) : RecyclerView.ViewHolder(binding.root) {
internal var created = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2016 Miguel Ángel Moreno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.github.nitrico.lastadapterx

interface Handler

interface TypeHandler : Handler {
fun getItemType(item: Any, position: Int): BaseType?
}

interface LayoutHandler : Handler {
fun getItemLayout(item: Any, position: Int): Int
}

interface StableId {
val stableId: Long
}
Loading