From b79516ea329cc4f4f2bcfc721af617ea8bd8465a Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Fri, 3 May 2019 09:40:18 -0400 Subject: [PATCH 01/26] initial setup for DiViNa (WIP) --- r2-shared/src/main/java/org/readium/r2/shared/Publication.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt b/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt index 9371a24d..77eb790d 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt @@ -83,7 +83,7 @@ class Publication : Serializable { // Navigator Type enum class TYPE { - EPUB, CBZ, FXL, WEBPUB, AUDIO + EPUB, CBZ, FXL, WEBPUB, AUDIO, DiViNa } open class EnumCompanion(private val valueMap: Map) { @@ -94,7 +94,8 @@ class Publication : Serializable { enum class EXTENSION(var value: String) { EPUB(".epub"), CBZ(".cbz"), - JSON(".json"); + JSON(".json"), + ZIP(".zip"); companion object : EnumCompanion(EXTENSION.values().associateBy(EXTENSION::value)) } From 06d0f70811bc99d76be76b87768178da5260b2e2 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Fri, 26 Jul 2019 11:01:55 -0400 Subject: [PATCH 02/26] removed iml files --- r2-shared/r2-shared.iml | 252 ---------------------------------------- 1 file changed, 252 deletions(-) delete mode 100644 r2-shared/r2-shared.iml diff --git a/r2-shared/r2-shared.iml b/r2-shared/r2-shared.iml deleted file mode 100644 index 40e2bbc0..00000000 --- a/r2-shared/r2-shared.iml +++ /dev/null @@ -1,252 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 03d826380e37e7a180d292ef2ae177b45a0128ff Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Fri, 26 Jul 2019 11:02:11 -0400 Subject: [PATCH 03/26] updated gradle version --- build.gradle | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 7d71d5c7..6b161885 100644 --- a/build.gradle +++ b/build.gradle @@ -1,15 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.31' - ext.r2branch = 'develop' + ext.kotlin_version = '1.3.41' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:3.4.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' // NOTE: Do not place your application dependencies here; they belong From f248fc49ddfe9beff5691d9e822bd475baec4e2a Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Fri, 26 Jul 2019 11:02:36 -0400 Subject: [PATCH 04/26] removed product flavors --- r2-shared/build.gradle | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/r2-shared/build.gradle b/r2-shared/build.gradle index e6dc1a9f..23d3f5df 100644 --- a/r2-shared/build.gradle +++ b/r2-shared/build.gradle @@ -14,7 +14,6 @@ apply plugin: 'com.github.dcendents.android-maven' group='com.github.readium' android { - flavorDimensions "testapp" compileSdkVersion 28 defaultConfig { @@ -30,23 +29,6 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - productFlavors { - intTestapp { - dimension "testapp" - } - intTestappWithLcp { - dimension "testapp" - } - devTestapp { - dimension "testapp" - } - devTestappWithLcp { - dimension "testapp" - } - } - - // default build flavour - defaultPublishConfig "intTestappDebug" } dependencies { From 3d3672465b1c1e88b1ad6435ca89d1b357e846d1 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Fri, 26 Jul 2019 11:02:55 -0400 Subject: [PATCH 05/26] added Injectable type --- .../org/readium/r2/shared/InjectableType.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 r2-shared/src/main/java/org/readium/r2/shared/InjectableType.kt diff --git a/r2-shared/src/main/java/org/readium/r2/shared/InjectableType.kt b/r2-shared/src/main/java/org/readium/r2/shared/InjectableType.kt new file mode 100644 index 00000000..a6ece41f --- /dev/null +++ b/r2-shared/src/main/java/org/readium/r2/shared/InjectableType.kt @@ -0,0 +1,22 @@ +/* + * Module: r2-shared-kotlin + * Developers: Aferdita Muriqi + * + * Copyright (c) 2019. Readium Foundation. All rights reserved. + * Use of this source code is governed by a BSD-Style license which is detailed in the + * LICENSE file present in the project repository where this source code is maintained. + */ + +package org.readium.r2.shared + +import java.io.Serializable + +enum class Injectable(val rawValue: String): Serializable { + Script("scripts"), + Font("fonts"), + Style("styles"); + + companion object { + operator fun invoke(rawValue: String) = values().firstOrNull { it.rawValue == rawValue } + } +} From 43fa57dd0df0a16247af888db18e40da63197ed0 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Fri, 26 Jul 2019 11:03:15 -0400 Subject: [PATCH 06/26] removed obsolete unit test --- .../java/org/readium/r2/LocatorsUnitTest.kt | 34 ------------------- 1 file changed, 34 deletions(-) delete mode 100644 r2-shared/src/test/java/org/readium/r2/LocatorsUnitTest.kt diff --git a/r2-shared/src/test/java/org/readium/r2/LocatorsUnitTest.kt b/r2-shared/src/test/java/org/readium/r2/LocatorsUnitTest.kt deleted file mode 100644 index b7f0f881..00000000 --- a/r2-shared/src/test/java/org/readium/r2/LocatorsUnitTest.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Module: r2-shared-kotlin - * Developers: Aferdita Muriqi, Mostapha Idoubihi, Paul Stoica - * - * Copyright (c) 2018. Readium Foundation. All rights reserved. - * Use of this source code is governed by a BSD-style license which is detailed in the - * LICENSE file present in the project repository where this source code is maintained. - */ - -package org.readium.r2 - -/* -class LocatorsUnitTest { - - lateinit var locatorList: MutableList - - init { - locatorList.add(Locator("FirstPublication", 1, null, URI("FirstPublication"), Location("FirstPublication", null, null, 0.0f, 0))) - locatorList.add(Locator("FirstPublication", 1, null, URI("FirstPublication"), Location("FirstPublication", null, null, 0.0f, 0))) - locatorList.add(Locator("SecondPublication", 2, null, URI("SecondPublication"), Location("SecondPublication", null, null, 0.23931f, 3))) - locatorList.add(Locator("SixthPublication", 6, null, URI("SixthPublication"), Location("SixthPublication", null, null, 0.5f, 6))) - locatorList.add(Locator("ThirteenthPublication", 13, null, URI("ThirteenthPublication"), Location("ThirteenthPublication", null, null, 0.1578f, 13))) - locatorList.add(Locator("IsThatEvenAPub?!", -2, null, URI("IsThatEvenAPub?!"), Location("IsThatEvenAPub?!", null, null, 0.9239f, -2))) - locatorList.add(Locator("ComeOn..", 8, null, URI("ComeOn.."), Location("ComeOn..", null, null, -0.323f, 8))) - } - - fun addToList(newElem: Locator){ - locatorList.add(newElem) - } - - fun test(){ - - } -}*/ From 93cb266e1d741de49192f43367448ff50797ddaa Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Fri, 26 Jul 2019 12:53:36 -0400 Subject: [PATCH 07/26] updated dependencies --- r2-shared/build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/r2-shared/build.gradle b/r2-shared/build.gradle index 23d3f5df..b1f1a78a 100644 --- a/r2-shared/build.gradle +++ b/r2-shared/build.gradle @@ -15,10 +15,10 @@ group='com.github.readium' android { - compileSdkVersion 28 + compileSdkVersion 29 defaultConfig { minSdkVersion 21 - targetSdkVersion 28 + targetSdkVersion 29 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -35,8 +35,8 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation 'com.jakewharton.timber:timber:4.7.1' - implementation "androidx.appcompat:appcompat:1.1.0-beta01" - implementation 'com.google.code.gson:gson:2.8.2' + implementation "androidx.appcompat:appcompat:1.1.0-rc01" + implementation 'com.google.code.gson:gson:2.8.5' implementation 'com.github.kittinunf.fuel:fuel:1.16.0' implementation 'com.github.kittinunf.fuel:fuel-android:1.16.0' implementation 'nl.komponents.kovenant:kovenant:3.3.0' From 04a67af124a3ffab3419440ea2eb431427d2b1c8 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Fri, 26 Jul 2019 13:33:20 -0400 Subject: [PATCH 08/26] added course and target compatibility --- r2-shared/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/r2-shared/build.gradle b/r2-shared/build.gradle index b1f1a78a..8fc0b4f8 100644 --- a/r2-shared/build.gradle +++ b/r2-shared/build.gradle @@ -23,6 +23,10 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } + compileOptions { + sourceCompatibility 1.8 + targetCompatibility 1.8 + } buildTypes { release { minifyEnabled false From 7d0ad11e08ab438eed33bd3f80a319bdbcdeb339 Mon Sep 17 00:00:00 2001 From: Harry Date: Thu, 22 Aug 2019 10:31:54 +0800 Subject: [PATCH 09/26] Fixed issue Language isn't parsed as a string #69 --- r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt index 37659dcb..75b79311 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt @@ -266,6 +266,8 @@ fun parseMetadata(metadataDict: JSONObject): Metadata { val string = array.getString(i) m.languages.add(string) } + }else if (metadataDict.get("language") is String){ + m.languages.add(metadataDict.get("language") as String) } } From 73b11e629b3ff7f551b9110bbd2f2a6a71b97e0a Mon Sep 17 00:00:00 2001 From: Harry Date: Mon, 26 Aug 2019 15:16:19 +0800 Subject: [PATCH 10/26] Fixed issue:Missing links in subject #68 --- .../src/main/java/org/readium/r2/shared/Metadata.kt | 11 +++++++++++ .../src/main/java/org/readium/r2/shared/Subject.kt | 3 +++ 2 files changed, 14 insertions(+) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt index 37659dcb..f98044e5 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt @@ -213,6 +213,17 @@ fun parseMetadata(metadataDict: JSONObject): Metadata { if (sub.has("code")) { subject.code = sub.getString("code") } + if (sub.has("links")) { + sub.get("links")?.let { + val links = it as? JSONArray + ?: JSONArray() + for (i in 0 until links.length()) { + val linkDict = links.getJSONObject(i) + val link = parseLink(linkDict) + subject.links.add(link) + } + } + } m.subjects.add(subject) } } diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Subject.kt b/r2-shared/src/main/java/org/readium/r2/shared/Subject.kt index 10bb6990..ab04d8e7 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Subject.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Subject.kt @@ -22,12 +22,15 @@ class Subject : JSONable, Serializable { // Epub 3.1 "code" (opf:term) var code: String? = null + var links: MutableList = mutableListOf() + override fun toJSON(): JSONObject { val json = JSONObject() json.putOpt("name", name) json.putOpt("sortAs", sortAs) json.putOpt("scheme", scheme) json.putOpt("code", code) + json.putOpt("links", links) return json } From 334567e9197ea4d7b3723b99432ba93fc376dfe6 Mon Sep 17 00:00:00 2001 From: Harry Date: Mon, 26 Aug 2019 15:18:56 +0800 Subject: [PATCH 11/26] Fixed issue:Missing links in subject #68 --- .../src/main/java/org/readium/r2/shared/Metadata.kt | 11 +++++++++++ .../src/main/java/org/readium/r2/shared/Subject.kt | 3 +++ 2 files changed, 14 insertions(+) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt index 75b79311..4027e54c 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt @@ -213,6 +213,17 @@ fun parseMetadata(metadataDict: JSONObject): Metadata { if (sub.has("code")) { subject.code = sub.getString("code") } + if (sub.has("links")) { + sub.get("links")?.let { + val links = it as? JSONArray + ?: JSONArray() + for (i in 0 until links.length()) { + val linkDict = links.getJSONObject(i) + val link = parseLink(linkDict) + subject.links.add(link) + } + } + } m.subjects.add(subject) } } diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Subject.kt b/r2-shared/src/main/java/org/readium/r2/shared/Subject.kt index 10bb6990..ab04d8e7 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Subject.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Subject.kt @@ -22,12 +22,15 @@ class Subject : JSONable, Serializable { // Epub 3.1 "code" (opf:term) var code: String? = null + var links: MutableList = mutableListOf() + override fun toJSON(): JSONObject { val json = JSONObject() json.putOpt("name", name) json.putOpt("sortAs", sortAs) json.putOpt("scheme", scheme) json.putOpt("code", code) + json.putOpt("links", links) return json } From 4c6101fec2ed90ea494c76d35b99eb4b86c4bee6 Mon Sep 17 00:00:00 2001 From: Irteza Sheikh Date: Tue, 27 Aug 2019 11:17:47 -0700 Subject: [PATCH 12/26] .audibook files import OK --- r2-shared/src/main/java/org/readium/r2/shared/Publication.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt b/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt index 4661d3e3..f3b72a43 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt @@ -94,7 +94,8 @@ class Publication : Serializable { enum class EXTENSION(var value: String) { EPUB(".epub"), CBZ(".cbz"), - JSON(".json"); + JSON(".json"), + AUDIOBOOK(".audiobook"); companion object : EnumCompanion(values().associateBy(EXTENSION::value)) } From 4ef80e235bb9234454db2f78030cc5b194e01299 Mon Sep 17 00:00:00 2001 From: Aferdita Date: Thu, 29 Aug 2019 10:52:37 -0400 Subject: [PATCH 13/26] if statements with three or more branches is replaced with a when expression --- .../java/org/readium/r2/shared/Metadata.kt | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt index 4027e54c..8f23edd7 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt @@ -268,17 +268,18 @@ fun parseMetadata(metadataDict: JSONObject): Metadata { if (metadataDict.has("duration")) { m.duration = metadataDict.getInt("duration") } + if (metadataDict.has("language")) { - if (metadataDict.get("language") is JSONObject) { - m.languages.add(metadataDict.getString("language")) - } else if (metadataDict.get("language") is JSONArray) { - val array = metadataDict.getJSONArray("language") - for (i in 0 until array.length()) { - val string = array.getString(i) - m.languages.add(string) + when { + metadataDict.get("language") is JSONObject -> m.languages.add(metadataDict.getString("language")) + metadataDict.get("language") is JSONArray -> { + val array = metadataDict.getJSONArray("language") + for (i in 0 until array.length()) { + val string = array.getString(i) + m.languages.add(string) + } } - }else if (metadataDict.get("language") is String){ - m.languages.add(metadataDict.get("language") as String) + metadataDict.get("language") is String -> m.languages.add(metadataDict.get("language") as String) } } @@ -305,4 +306,4 @@ enum class ContentLayoutStyle { companion object { fun layout(name: String): ContentLayoutStyle = valueOf(name) } -} \ No newline at end of file +} From cd1444051d73bdf84eb44681fab60e94b97855fe Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Fri, 30 Aug 2019 22:11:56 -0400 Subject: [PATCH 14/26] minor change --- r2-shared/src/main/java/org/readium/r2/shared/Publication.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt b/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt index f3b72a43..b35f1303 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt @@ -95,7 +95,7 @@ class Publication : Serializable { EPUB(".epub"), CBZ(".cbz"), JSON(".json"), - AUDIOBOOK(".audiobook"); + AUDIO(".audiobook"); companion object : EnumCompanion(values().associateBy(EXTENSION::value)) } From 250e338bbc4a79f609d10616dad9ce62d763233d Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Thu, 5 Sep 2019 12:57:45 -0400 Subject: [PATCH 15/26] minor fix --- r2-shared/src/main/java/org/readium/r2/shared/Publication.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt b/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt index c1293479..157eb79b 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt @@ -95,7 +95,7 @@ class Publication : Serializable { EPUB(".epub"), CBZ(".cbz"), JSON(".json"), - ZIP(".zip"); + ZIP(".zip"), AUDIO(".audiobook"); companion object : EnumCompanion(values().associateBy(EXTENSION::value)) From c6069f28462bec38e6d0217ff853400747ac5014 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Fri, 6 Sep 2019 07:28:58 -0400 Subject: [PATCH 16/26] use divina extension --- r2-shared/src/main/java/org/readium/r2/shared/Publication.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt b/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt index 157eb79b..cf2457c5 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt @@ -95,7 +95,7 @@ class Publication : Serializable { EPUB(".epub"), CBZ(".cbz"), JSON(".json"), - ZIP(".zip"), + DIVINA(".divina"), AUDIO(".audiobook"); companion object : EnumCompanion(values().associateBy(EXTENSION::value)) From 4885423a11ad0c84179361230f9d8b8a7a4aa24a Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Mon, 9 Sep 2019 09:40:15 -0400 Subject: [PATCH 17/26] use random uuid if no identifier can be found --- r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt index 8f23edd7..0a49ed09 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt @@ -114,6 +114,8 @@ fun parseMetadata(metadataDict: JSONObject): Metadata { } if (metadataDict.has("identifier")) { m.identifier = metadataDict.getString("identifier") + } else { + m.identifier = UUID.randomUUID().toString() } if (metadataDict.has("@type")) { m.rdfType = metadataDict.getString("@type") From 112bdffe56064316ef6ea34eb23cfec035b71c0b Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Mon, 9 Sep 2019 13:06:44 -0400 Subject: [PATCH 18/26] Revert "use random uuid if no identifier can be found" This reverts commit 4885423a11ad0c84179361230f9d8b8a7a4aa24a. --- r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt index 0a49ed09..8f23edd7 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt @@ -114,8 +114,6 @@ fun parseMetadata(metadataDict: JSONObject): Metadata { } if (metadataDict.has("identifier")) { m.identifier = metadataDict.getString("identifier") - } else { - m.identifier = UUID.randomUUID().toString() } if (metadataDict.has("@type")) { m.rdfType = metadataDict.getString("@type") From e0be25bdd06e6c6f394f796b89f89f8d005835a3 Mon Sep 17 00:00:00 2001 From: Harry Date: Mon, 16 Sep 2019 18:56:58 +0800 Subject: [PATCH 19/26] Fixed collection/series parse issue --- .../main/java/org/readium/r2/shared/Metadata.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt index f98044e5..ec4d3fed 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt @@ -239,25 +239,27 @@ fun parseMetadata(metadataDict: JSONObject): Metadata { if (belongsDict.has("series")) { if (belongsDict.get("series") is JSONObject) { - m.belongsTo?.series?.add(Collection(belongsDict.getString("series"))) + belongs.series.add(parseCollection(belongsDict.getJSONObject("series"))) } else if (belongsDict.get("series") is JSONArray) { val array = belongsDict.getJSONArray("series") for (i in 0 until array.length()) { - val string = array.getString(i) - m.belongsTo?.series?.add(Collection(string)) + val seriesJsonObject = array.getJSONObject(i) + belongs.series.add(parseCollection(seriesJsonObject)) } + }else if (belongsDict.get("series") is String) { + belongs.series.add(Collection(belongsDict.getString("series"))) } } if (belongsDict.has("collection")) { when { - belongsDict.get("collection") is String -> m.belongsTo?.collection?.add(Collection(belongsDict.getString("collection"))) - belongsDict.get("collection") is JSONObject -> belongs.series.add(parseCollection(belongsDict.getJSONObject("collection"))) + belongsDict.get("collection") is String -> belongs.collection.add(Collection(belongsDict.getString("collection"))) + belongsDict.get("collection") is JSONObject -> belongs.collection.add(parseCollection(belongsDict.getJSONObject("collection"))) belongsDict.get("collection") is JSONArray -> { val array = belongsDict.getJSONArray("collection") for (i in 0 until array.length()) { val obj = array.getJSONObject(i) - belongs.series.add(parseCollection(obj)) + belongs.collection.add(parseCollection(obj)) } } } From bfb264b6bceb4b7cb75085dc7b9e875afdb69a29 Mon Sep 17 00:00:00 2001 From: trycatch Date: Mon, 14 Oct 2019 19:27:33 +0900 Subject: [PATCH 20/26] Initial commit for new functions for highlights and annotation on r2 reader --- .../java/org/readium/r2/shared/Locator.kt | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Locator.kt b/r2-shared/src/main/java/org/readium/r2/shared/Locator.kt index e57748a1..5c7e98cb 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Locator.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Locator.kt @@ -26,7 +26,17 @@ open class Locator(val href: String, val type: String, val title: String? = null, val locations: Locations? = null, - val text: LocatorText?) : Serializable + val text: LocatorText?) : Serializable { + override fun toString(): String { + var jsonString = """{""" + href.let { jsonString += """ "href": "$href" ,""" } + type.let { jsonString += """ "type": "$type" ,""" } + title.let { jsonString += """ "title": "$title" ,""" } + locations.let { jsonString += """ "locations": $locations """ } + jsonString += """}""" + return jsonString + } +} class LocatorText(var after: String? = null, var before: String? = null, @@ -87,7 +97,10 @@ class LocatorText(var after: String? = null, */ class Locations(var fragment: String? = null, // 1 = fragment identifier (toc, page lists, landmarks) var progression: Double? = null, // 2 = bookmarks - var position: Long? = null // 3 = goto page + var position: Long? = null, // 3 = goto page + var cssSelector: String? = null, + var partialCfi: String? = null, + var domRange: String? = null ) : JSONable, Serializable { companion object { @@ -103,12 +116,20 @@ class Locations(var fragment: String? = null, // 1 = fragment identifier if (json.has("position")) { location.position = json.getLong("position") } - + if (json.has("cssSelector")) { + location.cssSelector = json.getString("cssSelector") + } + if (json.has("partialCfi")) { + location.partialCfi = json.getString("partialCfi") + } + if (json.has("domRange")) { + location.domRange = json.getString("domRange") + } return location } fun isEmpty(locations: Locations):Boolean { - if (locations.fragment == null && locations.position == null && locations.progression == null) { + if (locations.fragment == null && locations.position == null && locations.progression == null && locations.cssSelector == null && locations.partialCfi == null && locations.domRange == null) { return true } return false @@ -128,6 +149,15 @@ class Locations(var fragment: String? = null, // 1 = fragment identifier position?.let { json.putOpt("position", position) } + cssSelector?.let { + json.putOpt("cssSelector", cssSelector) + } + partialCfi?.let { + json.putOpt("partialCfi", partialCfi) + } + domRange?.let { + json.putOpt("domRange", domRange) + } return json } @@ -136,7 +166,10 @@ class Locations(var fragment: String? = null, // 1 = fragment identifier var jsonString = """{""" fragment.let { jsonString += """ "fragment": "$fragment" ,""" } progression.let { jsonString += """ "progression": "$progression" ,""" } - position.let { jsonString += """ "position": "$position" """ } + position.let { jsonString += """ "position": "$position" ,""" } + cssSelector.let { jsonString += """ "cssSelector": "$cssSelector" ,""" } + partialCfi.let { jsonString += """ "partialCfi": "$partialCfi" ,""" } + domRange.let { jsonString += """ "domRange": $domRange """ } jsonString += """}""" return jsonString } From 1e2d74e996429db7854692e27d7725e3e29a4331 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Mon, 4 Nov 2019 12:53:27 +0100 Subject: [PATCH 21/26] extended enum with extensions lcpl and unknown --- r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt | 2 +- r2-shared/src/main/java/org/readium/r2/shared/Publication.kt | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt index 8f23edd7..135d6048 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt @@ -24,7 +24,7 @@ class Metadata : Serializable { get() = multilanguageTitle?.singleString ?: "" var languages: MutableList = mutableListOf() - lateinit var identifier: String + var identifier: String? = null // Contributors. var authors: MutableList = mutableListOf() var translators: MutableList = mutableListOf() diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt b/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt index cf2457c5..3bd544f6 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt @@ -96,7 +96,9 @@ class Publication : Serializable { CBZ(".cbz"), JSON(".json"), DIVINA(".divina"), - AUDIO(".audiobook"); + AUDIO(".audiobook"), + LCPL(".lcpl"), + UNKNOWN(""); companion object : EnumCompanion(values().associateBy(EXTENSION::value)) } @@ -208,6 +210,7 @@ class Publication : Serializable { private fun findLinkInPublicationLinks(closure: (Link) -> Boolean) = resources.firstOrNull(closure) ?: readingOrder.firstOrNull(closure) ?: links.firstOrNull(closure) ?: pageList.firstOrNull(closure) + ?: images.firstOrNull(closure) fun addSelfLink(endPoint: String, baseURL: URL) { val publicationUrl: URL From fc3c239d4c1d5cb069da4fd1155c823029dbfdf9 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Tue, 12 Nov 2019 17:11:43 +0100 Subject: [PATCH 22/26] jsonable locator --- .../java/org/readium/r2/shared/Locator.kt | 67 +++++++++++++++++-- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Locator.kt b/r2-shared/src/main/java/org/readium/r2/shared/Locator.kt index e57748a1..62d79929 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Locator.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Locator.kt @@ -22,11 +22,68 @@ import java.io.Serializable * @val text: LocatorText? - Textual context of the locator. */ -open class Locator(val href: String, - val type: String, - val title: String? = null, - val locations: Locations? = null, - val text: LocatorText?) : Serializable +open class Locator(var href: String? = null, + var type: String? = null, + var title: String? = null, + var locations: Locations? = null, + var text: LocatorText? = null) : JSONable, Serializable { + + + companion object { + fun fromJSON(json: JSONObject): Locator { + + val locator = Locator() + if (json.has("href")) { + locator.href = json.getString("href") + } + if (json.has("type")) { + locator.type = json.getString("type") + } + if (json.has("title")) { + locator.title = json.getString("title") + } + if (json.has("locations")) { + locator.locations = Locations.fromJSON(JSONObject(json.getString("locations"))) + } + if (json.has("text")) { + locator.text = LocatorText.fromJSON(JSONObject(json.getString("text"))) + } + + return locator + } + } + override fun toJSON(): JSONObject { + val json = JSONObject() + + href.let { + json.putOpt("href", href) + } + type.let { + json.putOpt("type", type) + } + title.let { + json.putOpt("title", title) + } + locations?.let { + json.putOpt("locations", it.toJSON()) + } + text?.let { + json.putOpt("text", it.toJSON()) + } + return json + } + + override fun toString(): String { + var jsonString = """{""" + href.let { jsonString += """ "href": "$href" ,""" } + type.let { jsonString += """ "type": "$type" ,""" } + title.let { jsonString += """ "title": "$title" ,""" } + locations.let { jsonString += """ "locations": "${locations.toString()}" ,""" } + text.let { jsonString += """ "text": "${text.toString()}" ,""" } + jsonString += """}""" + return jsonString + } +} class LocatorText(var after: String? = null, var before: String? = null, From c828805729caa8c0bcea72a0e7b467afc10f633d Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Fri, 22 Nov 2019 21:03:43 +0100 Subject: [PATCH 23/26] optimized locator model --- .../java/org/readium/r2/shared/Locator.kt | 128 +++++++++++++----- 1 file changed, 95 insertions(+), 33 deletions(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Locator.kt b/r2-shared/src/main/java/org/readium/r2/shared/Locator.kt index 7e499bf4..eb493b71 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Locator.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Locator.kt @@ -52,6 +52,7 @@ open class Locator(var href: String? = null, return locator } } + override fun toJSON(): JSONObject { val json = JSONObject() @@ -73,16 +74,6 @@ open class Locator(var href: String? = null, return json } - override fun toString(): String { - var jsonString = """{""" - href.let { jsonString += """ "href": "$href" ,""" } - type.let { jsonString += """ "type": "$type" ,""" } - title.let { jsonString += """ "title": "$title" ,""" } - locations.let { jsonString += """ "locations": "${locations.toString()}" ,""" } - text.let { jsonString += """ "text": "${text.toString()}" ,""" } - jsonString += """}""" - return jsonString - } } class LocatorText(var after: String? = null, @@ -124,14 +115,6 @@ class LocatorText(var after: String? = null, return json } - override fun toString(): String { - var jsonString = """{""" - before.let { jsonString += """ "before": "$before" ,""" } - highlight.let { jsonString += """ "before": "$highlight" ,""" } - after.let { jsonString += """ "after": "$after" ,""" } - jsonString += """}""" - return jsonString - } } /** @@ -147,7 +130,7 @@ class Locations(var fragment: String? = null, // 1 = fragment identifier var position: Long? = null, // 3 = goto page var cssSelector: String? = null, var partialCfi: String? = null, - var domRange: String? = null + var domRange: DomRange? = null ) : JSONable, Serializable { companion object { @@ -170,12 +153,12 @@ class Locations(var fragment: String? = null, // 1 = fragment identifier location.partialCfi = json.getString("partialCfi") } if (json.has("domRange")) { - location.domRange = json.getString("domRange") + location.domRange = DomRange.fromJSON(JSONObject(json.getString("domRange"))) } return location } - fun isEmpty(locations: Locations):Boolean { + fun isEmpty(locations: Locations): Boolean { if (locations.fragment == null && locations.position == null && locations.progression == null && locations.cssSelector == null && locations.partialCfi == null && locations.domRange == null) { return true } @@ -203,21 +186,100 @@ class Locations(var fragment: String? = null, // 1 = fragment identifier json.putOpt("partialCfi", partialCfi) } domRange?.let { - json.putOpt("domRange", domRange) + json.putOpt("domRange", it.toJSON()) } return json } +} + +class Range(var cssSelector: String? = null, + var textNodeIndex: Long? = null, + var offset: Long? = null +) : JSONable, Serializable { + + companion object { + fun fromJSON(json: JSONObject): Range { - override fun toString(): String { - var jsonString = """{""" - fragment.let { jsonString += """ "fragment": "$fragment" ,""" } - progression.let { jsonString += """ "progression": "$progression" ,""" } - position.let { jsonString += """ "position": "$position" ,""" } - cssSelector.let { jsonString += """ "cssSelector": "$cssSelector" ,""" } - partialCfi.let { jsonString += """ "partialCfi": "$partialCfi" ,""" } - domRange.let { jsonString += """ "domRange": $domRange """ } - jsonString += """}""" - return jsonString + val range = Range() + if (json.has("cssSelector")) { + range.cssSelector = json.getString("cssSelector") + } + if (json.has("textNodeIndex")) { + range.textNodeIndex = json.getLong("textNodeIndex") + } + if (json.has("offset")) { + range.offset = json.getLong("offset") + } + return range + } + + fun isEmpty(locations: Range): Boolean { + if (locations.cssSelector == null && locations.textNodeIndex == null && locations.offset == null) { + return true + } + return false + } + + } + + override fun toJSON(): JSONObject { + val json = JSONObject() + + cssSelector?.let { + json.putOpt("cssSelector", cssSelector) + } + textNodeIndex?.let { + json.putOpt("textNodeIndex", textNodeIndex) + } + offset?.let { + json.putOpt("offset", offset) + } + + return json } -} \ No newline at end of file +} + + +class DomRange(var start: Range? = null, + var end: Range? = null +) : JSONable, Serializable { + + companion object { + fun fromJSON(json: JSONObject): DomRange { + + val domRange = DomRange() + + if (json.has("start")) { + domRange.start = Range.fromJSON(JSONObject(json.getString("start"))) + } + if (json.has("end")) { + domRange.end = Range.fromJSON(JSONObject(json.getString("end"))) + } + + return domRange + } + + fun isEmpty(locations: DomRange): Boolean { + if (locations.start == null && locations.end == null) { + return true + } + return false + } + + } + + override fun toJSON(): JSONObject { + val json = JSONObject() + + start?.let { + json.putOpt("start", it.toJSON()) + } + end?.let { + json.putOpt("end", it.toJSON()) + } + + return json + } + +} From accc27dc49342106fedce9ffb88bcb8dbccf9e89 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Sun, 8 Dec 2019 20:45:56 +0100 Subject: [PATCH 24/26] version bump gradle & kotlin --- build.gradle | 4 ++-- r2-shared/build.gradle | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 6b161885..e7abc85e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.41' + ext.kotlin_version = '1.3.61' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.2' + classpath 'com.android.tools.build:gradle:3.5.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' // NOTE: Do not place your application dependencies here; they belong diff --git a/r2-shared/build.gradle b/r2-shared/build.gradle index 8fc0b4f8..8e496931 100644 --- a/r2-shared/build.gradle +++ b/r2-shared/build.gradle @@ -39,7 +39,7 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation 'com.jakewharton.timber:timber:4.7.1' - implementation "androidx.appcompat:appcompat:1.1.0-rc01" + implementation "androidx.appcompat:appcompat:1.2.0-alpha01" implementation 'com.google.code.gson:gson:2.8.5' implementation 'com.github.kittinunf.fuel:fuel:1.16.0' implementation 'com.github.kittinunf.fuel:fuel-android:1.16.0' From 3dcb4323d37ff7328c1e5100ee7c89a5ad2d3487 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Sun, 15 Dec 2019 18:13:37 +0100 Subject: [PATCH 25/26] added code owners --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..d9ce658a --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @aferditamuriqi From 778aa4c81f2cd1582c5d66c913a950f4eaadbde7 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Sat, 28 Dec 2019 20:25:59 +0100 Subject: [PATCH 26/26] source formatting --- .../java/org/readium/r2/shared/Contributor.kt | 16 ++++++------- .../main/java/org/readium/r2/shared/Link.kt | 6 ++--- .../java/org/readium/r2/shared/Metadata.kt | 24 +++++++++++-------- .../java/org/readium/r2/shared/Publication.kt | 18 +++++++------- .../org/readium/r2/shared/UserProperties.kt | 2 +- .../java/org/readium/r2/shared/drm/DRM.kt | 4 ++-- 6 files changed, 37 insertions(+), 33 deletions(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Contributor.kt b/r2-shared/src/main/java/org/readium/r2/shared/Contributor.kt index a28da03c..0a3d5396 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Contributor.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Contributor.kt @@ -95,15 +95,15 @@ fun parseContributor(cDict: JSONObject): Contributor { c.roles.add(cDict.getString("role")) } if (cDict.has("links")) { - cDict.get("links")?.let { - val links = it as? JSONArray - ?: JSONArray() - for (i in 0 until links.length()) { - val linkDict = links.getJSONObject(i) - val link = parseLink(linkDict) - c.links.add(link) + cDict.get("links").let { + val links = it as? JSONArray + ?: JSONArray() + for (i in 0 until links.length()) { + val linkDict = links.getJSONObject(i) + val link = parseLink(linkDict) + c.links.add(link) + } } } - } return c } diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Link.kt b/r2-shared/src/main/java/org/readium/r2/shared/Link.kt index fdd21095..9a76566a 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Link.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Link.kt @@ -79,9 +79,9 @@ fun parseLink(linkDict: JSONObject, feedUrl: URL? = null): Link { } if (linkDict.has("href")) { feedUrl?.let { - link.href = getAbsolute(linkDict.getString("href")!!, feedUrl.toString()) + link.href = getAbsolute(linkDict.getString("href"), feedUrl.toString()) } ?: run { - link.href = linkDict.getString("href")!! + link.href = linkDict.getString("href") } } if (linkDict.has("type")) { @@ -138,7 +138,7 @@ fun parseLink(linkDict: JSONObject, feedUrl: URL? = null): Link { link.properties = properties } if (linkDict.has("children")) { - linkDict.get("children")?.let { + linkDict.get("children").let { val children = it as? JSONArray ?: throw Exception(LinkError.InvalidLink.name) for (i in 0 until children.length()) { diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt index f7f393f8..5866d306 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt @@ -214,7 +214,7 @@ fun parseMetadata(metadataDict: JSONObject): Metadata { subject.code = sub.getString("code") } if (sub.has("links")) { - sub.get("links")?.let { + sub.get("links").let { val links = it as? JSONArray ?: JSONArray() for (i in 0 until links.length()) { @@ -238,16 +238,20 @@ fun parseMetadata(metadataDict: JSONObject): Metadata { val belongs = BelongsTo() if (belongsDict.has("series")) { - if (belongsDict.get("series") is JSONObject) { - belongs.series.add(parseCollection(belongsDict.getJSONObject("series"))) - } else if (belongsDict.get("series") is JSONArray) { - val array = belongsDict.getJSONArray("series") - for (i in 0 until array.length()) { - val seriesJsonObject = array.getJSONObject(i) - belongs.series.add(parseCollection(seriesJsonObject)) + when { + belongsDict.get("series") is JSONObject -> { + belongs.series.add(parseCollection(belongsDict.getJSONObject("series"))) + } + belongsDict.get("series") is JSONArray -> { + val array = belongsDict.getJSONArray("series") + for (i in 0 until array.length()) { + val seriesJsonObject = array.getJSONObject(i) + belongs.series.add(parseCollection(seriesJsonObject)) + } + } + belongsDict.get("series") is String -> { + belongs.series.add(Collection(belongsDict.getString("series"))) } - }else if (belongsDict.get("series") is String) { - belongs.series.add(Collection(belongsDict.getString("series"))) } } diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt b/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt index 3bd544f6..3f180d3a 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Publication.kt @@ -238,7 +238,7 @@ fun parsePublication(pubDict: JSONObject): Publication { val p = Publication() if (pubDict.has("metadata")) { - pubDict.get("metadata")?.let { + pubDict.get("metadata").let { val metadataDict = it as? JSONObject ?: throw Exception(Publication.PublicationError.InvalidPublication.name) val metadata = parseMetadata(metadataDict) @@ -252,7 +252,7 @@ fun parsePublication(pubDict: JSONObject): Publication { } if (pubDict.has("links")) { - pubDict.get("links")?.let { + pubDict.get("links").let { val links = it as? JSONArray ?: throw Exception(Publication.PublicationError.InvalidPublication.name) for (i in 0 until links.length()) { @@ -264,7 +264,7 @@ fun parsePublication(pubDict: JSONObject): Publication { } if (pubDict.has("images")) { - pubDict.get("images")?.let { + pubDict.get("images").let { val links = it as? JSONArray ?: throw Exception(Publication.PublicationError.InvalidPublication.name) for (i in 0 until links.length()) { @@ -276,7 +276,7 @@ fun parsePublication(pubDict: JSONObject): Publication { } if (pubDict.has("spine")) { - pubDict.get("spine")?.let { + pubDict.get("spine").let { val spine = it as? JSONArray ?: throw Exception(Publication.PublicationError.InvalidPublication.name) for (i in 0 until spine.length()) { @@ -288,7 +288,7 @@ fun parsePublication(pubDict: JSONObject): Publication { } if (pubDict.has("readingOrder")) { - pubDict.get("readingOrder")?.let { + pubDict.get("readingOrder").let { val readingOrder = it as? JSONArray ?: throw Exception(Publication.PublicationError.InvalidPublication.name) for (i in 0 until readingOrder.length()) { @@ -300,7 +300,7 @@ fun parsePublication(pubDict: JSONObject): Publication { } if (pubDict.has("resources")) { - pubDict.get("resources")?.let { + pubDict.get("resources").let { val resources = it as? JSONArray ?: throw Exception(Publication.PublicationError.InvalidPublication.name) for (i in 0 until resources.length()) { @@ -312,7 +312,7 @@ fun parsePublication(pubDict: JSONObject): Publication { } if (pubDict.has("toc")) { - pubDict.get("toc")?.let { + pubDict.get("toc").let { val toc = it as? JSONArray ?: throw Exception(Publication.PublicationError.InvalidPublication.name) for (i in 0 until toc.length()) { @@ -324,7 +324,7 @@ fun parsePublication(pubDict: JSONObject): Publication { } if (pubDict.has("page-list")) { - pubDict.get("page-list")?.let { + pubDict.get("page-list").let { val pageList = it as? JSONArray ?: throw Exception(Publication.PublicationError.InvalidPublication.name) for (i in 0 until pageList.length()) { @@ -336,7 +336,7 @@ fun parsePublication(pubDict: JSONObject): Publication { } if (pubDict.has("landmarks")) { - pubDict.get("landmarks")?.let { + pubDict.get("landmarks").let { val landmarks = it as? JSONArray ?: throw Exception(Publication.PublicationError.InvalidPublication.name) for (i in 0 until landmarks.length()) { diff --git a/r2-shared/src/main/java/org/readium/r2/shared/UserProperties.kt b/r2-shared/src/main/java/org/readium/r2/shared/UserProperties.kt index cf91e7c2..9deb40bb 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/UserProperties.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/UserProperties.kt @@ -18,7 +18,7 @@ sealed class UserProperty(var ref: String, var name: String) { abstract override fun toString(): String fun getJson(): String { - return """{name:"$name",value:"${this}"}""" + return """{name:"$name",value:"$this"}""" } } diff --git a/r2-shared/src/main/java/org/readium/r2/shared/drm/DRM.kt b/r2-shared/src/main/java/org/readium/r2/shared/drm/DRM.kt index 40196514..3f4f0cb4 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/drm/DRM.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/drm/DRM.kt @@ -19,7 +19,7 @@ data class DRM(val brand: Brand): Serializable { lcp("lcp"); companion object { - operator fun invoke(rawValue: String) = Brand.values().firstOrNull { it.rawValue == rawValue } + operator fun invoke(rawValue: String) = values().firstOrNull { it.rawValue == rawValue } } } @@ -27,7 +27,7 @@ data class DRM(val brand: Brand): Serializable { lcp("http://readium.org/2014/01/lcp"); companion object { - operator fun invoke(rawValue: String) = Scheme.values().firstOrNull { it.rawValue == rawValue } + operator fun invoke(rawValue: String) = values().firstOrNull { it.rawValue == rawValue } } }