-
Notifications
You must be signed in to change notification settings - Fork 752
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added library-kotlin module for Kotlin support (#198)
* Added library-kotlin module for Kotlin support * Supplied MultiTypeTest & implementation instead of compileOnly * Supplied some extensions and test for TypePool * Added register(binder), withKClassLinker, more tests, and repackage
- Loading branch information
Showing
17 changed files
with
531 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2016 drakeet. https://github.com/drakeet | ||
* | ||
* 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. | ||
*/ | ||
|
||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
apply from: 'gradle-mvn-push.gradle' | ||
|
||
android { | ||
compileSdkVersion gradle.compileSdkVersion | ||
buildToolsVersion gradle.buildToolsVersion | ||
|
||
defaultConfig { | ||
minSdkVersion gradle.minSdkVersion | ||
targetSdkVersion gradle.targetSdkVersion | ||
versionCode gradle.versionCode | ||
versionName gradle.versionName | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'org.jetbrains.kotlin:kotlin-stdlib:' + kotlin_version | ||
implementation 'me.drakeet.multitype:multitype:3.4.2' | ||
|
||
testImplementation 'junit:junit:4.12' | ||
testImplementation 'me.drakeet.multitype:multitype:3.4.2' | ||
testImplementation 'org.jetbrains.kotlin:kotlin-stdlib:' + kotlin_version | ||
testImplementation 'com.android.support:recyclerview-v7:' + gradle.supportLibraryVersion | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Copyright 2013 Chris Banes | ||
* Copyright 2016 drakeet | ||
* | ||
* 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. | ||
*/ | ||
|
||
apply plugin: 'maven' | ||
apply plugin: 'signing' | ||
|
||
def isReleaseBuild() { | ||
return gradle.versionName.contains("SNAPSHOT") == false | ||
} | ||
|
||
def getReleaseRepositoryUrl() { | ||
return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" | ||
} | ||
|
||
def getSnapshotRepositoryUrl() { | ||
return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL : "https://oss.sonatype.org/content/repositories/snapshots/" | ||
} | ||
|
||
def getRepositoryUsername() { | ||
return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" | ||
} | ||
|
||
def getRepositoryPassword() { | ||
return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" | ||
} | ||
|
||
afterEvaluate { project -> | ||
uploadArchives { | ||
repositories { | ||
mavenDeployer { | ||
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } | ||
|
||
pom.groupId = GROUP | ||
pom.artifactId = POM_ARTIFACT_ID | ||
pom.version = gradle.versionName | ||
|
||
repository(url: getReleaseRepositoryUrl()) { | ||
authentication(userName: getRepositoryUsername(), | ||
password: getRepositoryPassword()) | ||
} | ||
snapshotRepository(url: getSnapshotRepositoryUrl()) { | ||
authentication(userName: getRepositoryUsername(), | ||
password: getRepositoryPassword()) | ||
} | ||
|
||
pom.project { | ||
name POM_NAME | ||
packaging POM_PACKAGING | ||
description POM_DESCRIPTION | ||
url POM_URL | ||
|
||
scm { | ||
url POM_SCM_URL | ||
connection POM_SCM_CONNECTION | ||
developerConnection POM_SCM_DEV_CONNECTION | ||
} | ||
|
||
licenses { | ||
license { | ||
name POM_LICENCE_NAME | ||
url POM_LICENCE_URL | ||
distribution POM_LICENCE_DIST | ||
} | ||
} | ||
|
||
developers { | ||
developer { | ||
id POM_DEVELOPER_ID | ||
name POM_DEVELOPER_NAME | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
signing { | ||
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } | ||
sign configurations.archives | ||
} | ||
|
||
android.libraryVariants.all { variant -> | ||
task("${variant.name}Javadoc", type: Javadoc) { | ||
description "Generates Javadoc for $variant.name." | ||
source = variant.javaCompile.source | ||
classpath = files(variant.javaCompile.classpath.files, | ||
project.android.getBootClasspath()) | ||
exclude '**/BuildConfig.java' | ||
exclude '**/R.java' | ||
} | ||
} | ||
|
||
task javadocJar(type: Jar, dependsOn: 'releaseJavadoc') { | ||
classifier = 'javadoc' | ||
from { | ||
releaseJavadoc.destinationDir | ||
} | ||
} | ||
|
||
task androidSourcesJar(type: Jar) { | ||
classifier = 'sources' | ||
from android.sourceSets.main.java.sourceFiles | ||
} | ||
|
||
artifacts { | ||
archives androidSourcesJar | ||
archives javadocJar | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# | ||
# Copyright 2016 drakeet. https://github.com/drakeet | ||
# | ||
# 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. | ||
# | ||
|
||
POM_NAME=MultiType-Kotlin | ||
POM_ARTIFACT_ID=multitype-kotlin | ||
POM_PACKAGING=aar | ||
|
||
GROUP=me.drakeet.multitype | ||
|
||
POM_DESCRIPTION=An Android library to create multiple item types list views easily and flexibly. | ||
POM_URL=https://github.com/drakeet/MultiType | ||
POM_SCM_URL=https://github.com/drakeet/MultiType | ||
POM_SCM_CONNECTION=scm:[email protected]:drakeet/MultiType.git | ||
POM_SCM_DEV_CONNECTION=scm:[email protected]:drakeet/MultiType.git | ||
POM_LICENCE_NAME=The Apache Software License, Version 2.0 | ||
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt | ||
POM_LICENCE_DIST=repo | ||
POM_DEVELOPER_ID=drakeet | ||
POM_DEVELOPER_NAME=drakeet | ||
POM_DEVELOPER_URL=http://drakeet.me |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# 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 *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!-- | ||
~ Copyright 2016 drakeet. https://github.com/drakeet | ||
~ | ||
~ 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. | ||
--> | ||
|
||
<manifest package="me.drakeet.multitype.kotlin"/> |
37 changes: 37 additions & 0 deletions
37
library-kotlin/src/main/java/me/drakeet/multitype/KClassLinker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2016 drakeet. https://github.com/drakeet | ||
* | ||
* 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 me.drakeet.multitype | ||
|
||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* An interface to link the items and binders by the classes of binders. | ||
* | ||
* @author drakeet | ||
*/ | ||
interface KClassLinker<T> { | ||
|
||
/** | ||
* Returns the class of your registered binders for your item. | ||
* | ||
* @param position The position in items | ||
* @param t The item | ||
* @return The index of your registered binders | ||
* @see OneToManyEndpoint.withClassLinker | ||
*/ | ||
fun index(position: Int, t: T): KClass<out ItemViewBinder<T, *>> | ||
} |
63 changes: 63 additions & 0 deletions
63
library-kotlin/src/main/java/me/drakeet/multitype/MultiType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2016 drakeet. https://github.com/drakeet | ||
* | ||
* 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 me.drakeet.multitype | ||
|
||
import android.support.annotation.CheckResult | ||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* @author drakeet | ||
*/ | ||
fun <T : Any> MultiTypeAdapter.register(clazz: KClass<out T>, binder: ItemViewBinder<T, *>) { | ||
register(clazz.java, binder) | ||
} | ||
|
||
|
||
inline fun <reified T : Any> MultiTypeAdapter.register(binder: ItemViewBinder<T, *>) { | ||
register(T::class.java, binder) | ||
} | ||
|
||
|
||
@CheckResult | ||
fun <T : Any> MultiTypeAdapter.register(clazz: KClass<out T>): OneToManyFlow<T> { | ||
return register(clazz.java) | ||
} | ||
|
||
|
||
fun <T : Any> TypePool.register(clazz: KClass<out T>, binder: ItemViewBinder<T, *>, linker: Linker<T>) { | ||
register(clazz.java, binder, linker) | ||
} | ||
|
||
|
||
fun <T : Any> TypePool.unregister(clazz: KClass<out T>): Boolean { | ||
return unregister(clazz.java) | ||
} | ||
|
||
|
||
fun <T : Any> TypePool.firstIndexOf(clazz: KClass<out T>): Int { | ||
return firstIndexOf(clazz.java) | ||
} | ||
|
||
|
||
fun <T> OneToManyEndpoint<T>.withKClassLinker(classLinker: KClassLinker<T>) { | ||
withClassLinker { position, t -> classLinker.index(position, t).java } | ||
} | ||
|
||
|
||
fun <T> OneToManyEndpoint<T>.withKClassLinker(classLinker: (position: Int, t: T) -> KClass<out ItemViewBinder<T, *>>) { | ||
withClassLinker { position, t -> classLinker(position, t).java } | ||
} |
Oops, something went wrong.