Skip to content

Commit

Permalink
target kotlin 1.5.0 (#70)
Browse files Browse the repository at this point in the history
* prepare for kotlin 1.5.0-RC

* breakout capitalize first letter logic to extension function

* fix typo

* bump coroutine 1.5.0, turbine 0.5.0, room 2.2.6
  • Loading branch information
sphrak authored May 20, 2021
1 parent 0d9bc2f commit e423d98
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 21 deletions.
11 changes: 10 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ group='com.github.ivanisidrowu'

android {
compileSdkVersion 30
buildToolsVersion "30.0.0"
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 23
Expand All @@ -20,6 +20,11 @@ android {
consumerProguardFiles "consumer-rules.pro"
}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -33,6 +38,10 @@ android {
'-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi',
]
}

lintOptions {
abortOnError false
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package tw.ktrssreader.config

import java.nio.charset.Charset
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.days

Expand All @@ -28,5 +29,5 @@ class KtRssReaderConfig {
var flushCache: Boolean = false

@ExperimentalTime
var expiredTimeMillis: Long = 1.days.toLongMilliseconds()
var expiredTimeMillis: Long = Duration.days(1).inWholeMilliseconds
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ abstract class AndroidParserBase<out T : RssStandardChannel> : tw.ktrssreader.ko
}

protected fun String.toBoolOrNull(): Boolean? {
return when (toLowerCase()) {
return when (lowercase()) {
"yes", "true" -> true
"no", "false" -> false
else -> null
Expand Down
7 changes: 6 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 30
buildToolsVersion "30.0.0"
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "tw.ktrssreader"
Expand All @@ -17,6 +17,11 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}

buildTypes {
release {
minifyEnabled false
Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
buildscript {

ext {
def coroutines_version = '1.3.9'
def coroutines_version = '1.5.0'
def okhttp_version = '4.9.0'
def room_version = '2.2.5'
def room_version = '2.2.6'
def startup_version = '1.0.0'

def mockk_version = '1.10.0'
def turbine_version = '0.2.1'
def turbine_version = '0.5.0'

deps = [
'kotlinxCoroutinesCore' : "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version",
Expand All @@ -24,15 +24,15 @@ buildscript {
'turbine': "app.cash.turbine:turbine:$turbine_version"
]

kotlin_version = "1.4.0"
kotlin_version = "1.5.0"
}

repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
classpath "com.android.tools.build:gradle:4.1.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'

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.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ abstract class ParserBase<out T : RssStandardChannel> : Parser<T> {
}

protected fun String.toBoolOrNull(): Boolean? {
return when (toLowerCase()) {
return when (lowercase()) {
"yes", "true" -> true
"no", "false" -> false
else -> null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,30 @@ fun String.isPrimitive(): Boolean = primitiveJavaPaths.any { this.contains(other
fun String.getFuncName(): String {
return when {
this.startsWith(GOOGLE_PREFIX) || this.startsWith(ITUNES_PREFIX) ->
"get${this.substringAfterLast(':').capitalize(Locale.ROOT)}"
else -> "get${this.capitalize(Locale.ROOT)}"
"get${this.substringAfterLast(':').capitalize()}"
else -> "get${this.capitalize()}"
}
}

fun String.getListFuncName(): String {
val tagCapitalized = substringAfterLast(':').capitalize(Locale.ROOT)
val tagCapitalized = substringAfterLast(':').capitalize()
return when {
startsWith(GOOGLE_PREFIX) -> "get${GOOGLE_PREFIX.capitalize(Locale.ROOT)}${tagCapitalized}List"
startsWith(ITUNES_PREFIX) -> "get${ITUNES_PREFIX.capitalize(Locale.ROOT)}${tagCapitalized}List"
startsWith(GOOGLE_PREFIX) -> "get${GOOGLE_PREFIX.capitalize()}${tagCapitalized}List"
startsWith(ITUNES_PREFIX) -> "get${ITUNES_PREFIX.capitalize()}${tagCapitalized}List"
else -> "get${tagCapitalized}List"
}
}

internal fun String.capitalize(): String = replaceFirstChar {
if (it.isLowerCase()) {
it.titlecase(Locale.ROOT)
} else {
it.toString()
}
}

fun String.getGeneratedClassPath() =
"${GENERATOR_PACKAGE}.${this.capitalize(Locale.ROOT)}${PARSER_SUFFIX}"
"${GENERATOR_PACKAGE}.${this.capitalize()}${PARSER_SUFFIX}"

fun String.extractListType() =
this.substringAfter('<')
Expand Down Expand Up @@ -95,10 +103,10 @@ fun Element.getPackage(): String {
}

fun String.getVariableName(tag: String): String {
val tagCapitalized = tag.substringAfterLast(':').capitalize(Locale.ROOT)
val tagCapitalized = tag.substringAfterLast(':').capitalize()
return when {
tag.startsWith(GOOGLE_PREFIX) -> "$this${GOOGLE_PREFIX.capitalize(Locale.ROOT)}$tagCapitalized"
tag.startsWith(ITUNES_PREFIX) -> "$this${ITUNES_PREFIX.capitalize(Locale.ROOT)}$tagCapitalized"
tag.startsWith(GOOGLE_PREFIX) -> "$this${GOOGLE_PREFIX.capitalize()}$tagCapitalized"
tag.startsWith(ITUNES_PREFIX) -> "$this${ITUNES_PREFIX.capitalize()}$tagCapitalized"
else -> "$this$tagCapitalized"
}
}
Expand Down Expand Up @@ -126,7 +134,7 @@ fun Name.extractNameFromMethod(): String {
}

return withoutPrefix
.decapitalize(Locale.ROOT)
.replaceFirstChar { it.lowercase(Locale.ROOT) }
.substringBeforeLast('$')
}

Expand Down

0 comments on commit e423d98

Please sign in to comment.