Skip to content

Commit 72dbd01

Browse files
authored
Update Kotlin and Gradle (#114)
1 parent 39f527d commit 72dbd01

File tree

10 files changed

+26
-22
lines changed

10 files changed

+26
-22
lines changed

readium/lcp/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
**Warning:** Features marked as *alpha* may change or be removed in a future release without notice. Use with caution.
66

7-
<!-- ## [Unreleased] -->
7+
## [Unreleased]
8+
9+
### Changed
10+
11+
* Upgraded to Kotlin 1.5.20.
12+
813

914
## [2.0.0]
1015

readium/lcp/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.4.31'
4+
ext.kotlin_version = '1.5.20'
55

66
repositories {
77
google()
88
jcenter()
99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:4.1.2'
11+
classpath 'com.android.tools.build:gradle:4.2.2'
1212

1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1414

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Oct 29 14:00:53 CET 2020
1+
#Fri Jun 25 13:42:26 CEST 2021
22
distributionBase=GRADLE_USER_HOME
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
34
distributionPath=wrapper/dists
4-
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
6+
zipStoreBase=GRADLE_USER_HOME

readium/lcp/r2-lcp/build.gradle

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
/*
2-
* Module: r2-lcp-kotlin
3-
* Developers: Aferdita Muriqi, Clément Baumann
4-
*
5-
* Copyright (c) 2018. Readium Foundation. All rights reserved.
6-
* Use of this source code is governed by a BSD-style license which is detailed in the
7-
* LICENSE file present in the project repository where this source code is maintained.
2+
* Copyright 2018 Readium Foundation. All rights reserved.
3+
* Use of this source code is governed by the BSD-style license
4+
* available in the top-level LICENSE file of the project.
85
*/
96

107
apply plugin: 'com.android.library'
@@ -40,7 +37,7 @@ android {
4037

4138
dependencies {
4239
implementation fileTree(include: ['*.jar'], dir: 'libs')
43-
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3"
40+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0-native-mt"
4441

4542
if (findProject(':r2-shared')) {
4643
implementation project(':r2-shared')

readium/lcp/r2-lcp/src/main/java/org/readium/r2/lcp/LcpDecryptor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ private suspend fun LcpLicense.decryptFully(data: ResourceTry<ByteArray>, isDef
180180
}
181181

182182
private val Link.isDeflated: Boolean get() =
183-
properties.encryption?.compression?.toLowerCase(java.util.Locale.ROOT) == "deflate"
183+
properties.encryption?.compression?.lowercase(java.util.Locale.ROOT) == "deflate"
184184

185185
private val Link.isCbcEncrypted: Boolean get() =
186186
properties.encryption?.algorithm == "http://www.w3.org/2001/04/xmlenc#aes256-cbc"

readium/lcp/r2-lcp/src/main/java/org/readium/r2/lcp/LcpLicense.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package org.readium.r2.lcp
88

9+
import kotlinx.coroutines.DelicateCoroutinesApi
910
import kotlinx.coroutines.GlobalScope
1011
import kotlinx.coroutines.launch
1112
import kotlinx.coroutines.runBlocking
@@ -123,6 +124,7 @@ interface LcpLicense : ContentProtectionService.UserRights {
123124
fun renewLoan(end: DateTime?, present: (URL, dismissed: () -> Unit) -> Unit, completion: (LcpException?) -> Unit) {}
124125

125126
@Deprecated("Use `returnPublication()` with coroutines instead", ReplaceWith("returnPublication"))
127+
@DelicateCoroutinesApi
126128
fun returnPublication(completion: (LcpException?) -> Unit) {
127129
GlobalScope.launch {
128130
completion(returnPublication().exceptionOrNull())

readium/lcp/r2-lcp/src/main/java/org/readium/r2/lcp/LcpService.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
package org.readium.r2.lcp
1111

1212
import android.content.Context
13-
import kotlinx.coroutines.Dispatchers
14-
import kotlinx.coroutines.GlobalScope
15-
import kotlinx.coroutines.launch
16-
import kotlinx.coroutines.withContext
13+
import kotlinx.coroutines.*
1714
import org.readium.r2.lcp.auth.LcpDialogAuthentication
1815
import org.readium.r2.lcp.persistence.Database
1916
import org.readium.r2.lcp.service.*
@@ -125,6 +122,7 @@ interface LcpService {
125122

126123

127124
@Deprecated("Use `acquirePublication()` with coroutines instead", ReplaceWith("acquirePublication(lcpl)"))
125+
@DelicateCoroutinesApi
128126
fun importPublication(lcpl: ByteArray, authentication: LcpAuthenticating?, completion: (AcquiredPublication?, LcpException?) -> Unit) {
129127
GlobalScope.launch {
130128
acquirePublication(lcpl)
@@ -134,6 +132,7 @@ interface LcpService {
134132
}
135133

136134
@Deprecated("Use `retrieveLicense()` with coroutines instead", ReplaceWith("retrieveLicense(File(publication), authentication, allowUserInteraction = true)"))
135+
@DelicateCoroutinesApi
137136
fun retrieveLicense(publication: String, authentication: LcpAuthenticating?, completion: (LcpLicense?, LcpException?) -> Unit) {
138137
GlobalScope.launch {
139138
val result = retrieveLicense(File(publication), authentication ?: LcpDialogAuthentication(), allowUserInteraction = true)

readium/lcp/r2-lcp/src/main/java/org/readium/r2/lcp/auth/LcpDialogAuthentication.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class LcpDialogAuthentication : LcpAuthenticating {
145145
private fun Context.startActivityForLink(link: Link) {
146146
val url = tryOrNull { Uri.parse(link.href) } ?: return
147147

148-
val action = when (url.scheme?.toLowerCase(Locale.ROOT)) {
148+
val action = when (url.scheme?.lowercase(Locale.ROOT)) {
149149
"http", "https" -> Intent(Intent.ACTION_VIEW)
150150
"tel" -> Intent(Intent.ACTION_CALL)
151151
"mailto" -> Intent(Intent.ACTION_SEND)

readium/lcp/r2-lcp/src/main/java/org/readium/r2/lcp/license/LicenseValidation.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import org.readium.r2.shared.util.getOrElse
2121
import org.readium.r2.shared.util.mediatype.MediaType
2222
import timber.log.Timber
2323
import java.util.*
24+
import kotlin.time.Duration
2425
import kotlin.time.ExperimentalTime
2526
import kotlin.time.seconds
2627

@@ -315,7 +316,7 @@ internal class LicenseValidation(
315316
private suspend fun fetchStatus(license: LicenseDocument) {
316317
val url = license.url(LicenseDocument.Rel.status, preferredType = MediaType.LCP_STATUS_DOCUMENT).toString()
317318
// Short timeout to avoid blocking the License, since the LSD is optional.
318-
val data = network.fetch(url, timeout = 5.seconds)
319+
val data = network.fetch(url, timeout = Duration.seconds(5))
319320
.getOrElse { throw LcpException.Network(it) }
320321

321322
raise(Event.retrievedStatusData(data))
@@ -329,7 +330,7 @@ internal class LicenseValidation(
329330
private suspend fun fetchLicense(status: StatusDocument) {
330331
val url = status.url(StatusDocument.Rel.license, preferredType = MediaType.LCP_LICENSE_DOCUMENT).toString()
331332
// Short timeout to avoid blocking the License, since it can be updated next time.
332-
val data = network.fetch(url, timeout = 5.seconds)
333+
val data = network.fetch(url, timeout = Duration.seconds(5))
333334
.getOrElse { throw LcpException.Network(it) }
334335

335336
raise(Event.retrievedLicenseData(data))

readium/lcp/r2-lcp/src/main/java/org/readium/r2/lcp/service/NetworkService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ internal class NetworkService {
5050
val connection = url.openConnection() as HttpURLConnection
5151
connection.requestMethod = method.rawValue
5252
if (timeout != null) {
53-
connection.connectTimeout = timeout.toLongMilliseconds().toInt()
53+
connection.connectTimeout = timeout.inWholeMilliseconds.toInt()
5454
}
5555

5656
val status = connection.responseCode

0 commit comments

Comments
 (0)