Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added library-kotlin module for Kotlin support #198

Merged
merged 4 commits into from
Feb 11, 2018
Merged
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
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/

buildscript {
ext.kotlin_version = '1.2.21'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Expand Down
1 change: 1 addition & 0 deletions library-kotlin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
51 changes: 51 additions & 0 deletions library-kotlin/build.gradle
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()
}
123 changes: 123 additions & 0 deletions library-kotlin/gradle-mvn-push.gradle
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
}
}
33 changes: 33 additions & 0 deletions library-kotlin/gradle.properties
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
21 changes: 21 additions & 0 deletions library-kotlin/proguard-rules.pro
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
17 changes: 17 additions & 0 deletions library-kotlin/src/main/AndroidManifest.xml
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 library-kotlin/src/main/java/me/drakeet/multitype/KClassLinker.kt
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 library-kotlin/src/main/java/me/drakeet/multitype/MultiType.kt
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 }
}
Loading