From 43423b10a55995ca2122b99950c0ef13d2f84354 Mon Sep 17 00:00:00 2001 From: mostapha Date: Mon, 30 Jul 2018 14:08:28 +0200 Subject: [PATCH 01/52] Creation of the Locator model --- .../java/org/readium/r2/shared/Locator.kt | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 r2-shared/src/main/java/org/readium/r2/shared/Locator.kt 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 new file mode 100644 index 00000000..019b5f65 --- /dev/null +++ b/r2-shared/src/main/java/org/readium/r2/shared/Locator.kt @@ -0,0 +1,46 @@ +/* + * Copyright 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.shared + + +import org.joda.time.DateTime +import java.net.URI + +class Locator(val publicationId: String, val spineIndex: Integer, val created: DateTime, val title: URI, val locations: MutableList, val text: LocatorText) { + fun toJson(): String{ + var jsonString = """{ "publicationId": "$publicationId", "spineIndex": "$spineIndex", "created": "$created", "title": "$title", "locations" : [ """ + if (locations.size > 1) { + locations.forEach { jsonString = jsonString + it.toJson() + """, """ } + } else { + locations.firstOrNull().let { jsonString += """ "${it!!.toJson()}" """ } + } + jsonString += """ ], "text" : "${text.toJson()}" }""" + return jsonString + } +} + +class Location(val id: String, val cfi: String, val css: String, val progression: Double, val position: Integer){ + fun toJson(): String { + var jsonString = """{""" + id.let { jsonString += """ "id": "$id" """ } + cfi.let { jsonString += """, "cfi": "$cfi" """ } + css.let { jsonString += """, "css": "$css" """ } + progression.let { jsonString += """ "p": "$id" """ } + id.let { jsonString += """ "id": "$id" """ } + jsonString += """}""" + } +} + +class LocatorText(val after: String?, val before: String?, val highlight: String?){ + fun toJson(): String{ + var jsonString = """{""" + after.let { jsonString += """ "after": "$after" """ } + before.let { jsonString += """, "before": "$before" """ } + highlight.let { jsonString += """, "highlight": "$highlight" """ } + jsonString += """}""" + } +} \ No newline at end of file From 7a993d00f945e889c44d32cc3ed8bd1316c9c109 Mon Sep 17 00:00:00 2001 From: mostapha Date: Mon, 30 Jul 2018 14:50:28 +0200 Subject: [PATCH 02/52] Making Locator and Location an JSONable class + Turning LocatorText into a inner class to Locator --- .../java/org/readium/r2/shared/Locator.kt | 70 ++++++++++++++++--- 1 file changed, 59 insertions(+), 11 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 019b5f65..5def0103 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 @@ -8,22 +8,44 @@ package org.readium.r2.shared import org.joda.time.DateTime +import org.json.JSONObject import java.net.URI -class Locator(val publicationId: String, val spineIndex: Integer, val created: DateTime, val title: URI, val locations: MutableList, val text: LocatorText) { - fun toJson(): String{ - var jsonString = """{ "publicationId": "$publicationId", "spineIndex": "$spineIndex", "created": "$created", "title": "$title", "locations" : [ """ - if (locations.size > 1) { - locations.forEach { jsonString = jsonString + it.toJson() + """, """ } - } else { - locations.firstOrNull().let { jsonString += """ "${it!!.toJson()}" """ } +class Locator(val publicationId: String, val spineIndex: Integer, val created: DateTime, val title: URI, val locations: Location, val text: LocatorText?): JSONable { + + override fun getJSON(): JSONObject { + val json = JSONObject() + json.putOpt("publicationId", publicationId) + json.putOpt("spineIndex", spineIndex) + json.putOpt("created", created) + json.putOpt("title", title) + json.putOpt("location", locations.toJson()) + if (text != null) { + json.putOpt("text", text) } - jsonString += """ ], "text" : "${text.toJson()}" }""" + return json + } + + fun toJsonString(): String{ + var jsonString = """{ "publicationId": "$publicationId", "spineIndex": "$spineIndex", "created": "$created", "title": "$title", "locations" : ${locations.toJson()} """ + if (text != null) { jsonString += """, "text" : "${text.toJson()}"""" } + jsonString += """ }""" return jsonString } } -class Location(val id: String, val cfi: String, val css: String, val progression: Double, val position: Integer){ +class Location(val id: String, val cfi: String, val css: String, val progression: Double, val position: Integer): JSONable{ + + override fun getJSON(): JSONObject { + val json = JSONObject() + json.putOpt("id", id) + json.putOpt("cfi", cfi) + json.putOpt("css", css) + json.putOpt("progression", progression) + json.putOpt("position", position) + return json + } + fun toJson(): String { var jsonString = """{""" id.let { jsonString += """ "id": "$id" """ } @@ -35,7 +57,16 @@ class Location(val id: String, val cfi: String, val css: String, val progression } } -class LocatorText(val after: String?, val before: String?, val highlight: String?){ +class LocatorText(val after: String?, val before: String?, val highlight: String?): JSONable{ + + override fun getJSON(): JSONObject { + val json = JSONObject() + json.putOpt("after", after) + json.putOpt("before", before) + json.putOpt("highlight", highlight) + return json + } + fun toJson(): String{ var jsonString = """{""" after.let { jsonString += """ "after": "$after" """ } @@ -43,4 +74,21 @@ class LocatorText(val after: String?, val before: String?, val highlight: String highlight.let { jsonString += """, "highlight": "$highlight" """ } jsonString += """}""" } -} \ No newline at end of file +} +/* + override fun getJSON(): JSONObject { + val json = JSONObject() + json.putOpt("title", title) + json.putOpt("type", typeLink) + json.putOpt("href", href) + if (rel.isNotEmpty()) + json.put("rel", getStringArray(rel)) + json.putOpt("properties", properties) + if (height != 0) + json.putOpt("height", height) + if (width != 0) + json.putOpt("width", width) + json.putOpt("duration", duration) + return json + } + */ \ No newline at end of file From f143841e1c6750b6e154e67635610fbcb191bd66 Mon Sep 17 00:00:00 2001 From: mostapha Date: Mon, 30 Jul 2018 15:10:42 +0200 Subject: [PATCH 03/52] Commenting the Locator and Location --- .../java/org/readium/r2/shared/Locator.kt | 111 +++++++++++------- 1 file changed, 69 insertions(+), 42 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 5def0103..0109b935 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 @@ -11,7 +11,22 @@ import org.joda.time.DateTime import org.json.JSONObject import java.net.URI -class Locator(val publicationId: String, val spineIndex: Integer, val created: DateTime, val title: URI, val locations: Location, val text: LocatorText?): JSONable { +/** + * Locator : Class that's used to define a precise location in a Publication + * + * @param publicationId: String - Identifier of a Publication + * @param spineIndex: Integer - Index at a spine element + * @param created: DateTime - Date when the Locator has been created ( unique ) + * @param title: URI - Title of the spine element + * @param locations: Location - Object that's used to locate the target + * + * @var text: LocatorText? - If there's one, describe the Locator's context + * + */ +class Locator(val publicationId: String, val spineIndex: Integer, val created: DateTime, val title: URI, val locations: Location): JSONable { + + var text = LocatorText(null, null, null) + get override fun getJSON(): JSONObject { val json = JSONObject() @@ -32,15 +47,61 @@ class Locator(val publicationId: String, val spineIndex: Integer, val created: D jsonString += """ }""" return jsonString } + + fun setText(after: String? = null, before: String? = null, highlight: String? = null){ + if (after != null) { + text.after = after + } + if (before != null) { + text.before = before + } + if (highlight != null) { + text.highlight = highlight + } + } + + inner class LocatorText(var after: String?, var before: String?, var highlight: String?): JSONable{ + + override fun getJSON(): JSONObject { + val json = JSONObject() + json.putOpt("after", after) + json.putOpt("before", before) + json.putOpt("highlight", highlight) + return json + } + + fun toJson(): String{ + var jsonString = """{""" + after.let { jsonString += """ "after": "$after" """ } + before.let { jsonString += """, "before": "$before" """ } + highlight.let { jsonString += """, "highlight": "$highlight" """ } + jsonString += """}""" + return jsonString + } + } } -class Location(val id: String, val cfi: String, val css: String, val progression: Double, val position: Integer): JSONable{ +/** + * Location : Class that contain the different variables needed to localize a particular position + * + * @param id: String - Identifier of a Publication + * @param cfi: String? - String formatted to design a place in a EPUB + * @param css: String? - Css selector + * @param progression: Float - A percentage ( between 0 and 1 ) of the progression in a Publication + * @param position: integer - Index of a segment in the resource. + * + */ +class Location(val id: String, val cfi: String?, val css: String?, val progression: Float, val position: Integer): JSONable{ override fun getJSON(): JSONObject { val json = JSONObject() json.putOpt("id", id) - json.putOpt("cfi", cfi) - json.putOpt("css", css) + if (cfi != null) { + json.putOpt("cfi", cfi) + } + if (css != null) { + json.putOpt("css", css) + } json.putOpt("progression", progression) json.putOpt("position", position) return json @@ -51,44 +112,10 @@ class Location(val id: String, val cfi: String, val css: String, val progression id.let { jsonString += """ "id": "$id" """ } cfi.let { jsonString += """, "cfi": "$cfi" """ } css.let { jsonString += """, "css": "$css" """ } - progression.let { jsonString += """ "p": "$id" """ } + progression.let { jsonString += """ "progression": "$id" """ } + position.let { jsonString += """ "position": "$id" """ } id.let { jsonString += """ "id": "$id" """ } jsonString += """}""" + return jsonString } -} - -class LocatorText(val after: String?, val before: String?, val highlight: String?): JSONable{ - - override fun getJSON(): JSONObject { - val json = JSONObject() - json.putOpt("after", after) - json.putOpt("before", before) - json.putOpt("highlight", highlight) - return json - } - - fun toJson(): String{ - var jsonString = """{""" - after.let { jsonString += """ "after": "$after" """ } - before.let { jsonString += """, "before": "$before" """ } - highlight.let { jsonString += """, "highlight": "$highlight" """ } - jsonString += """}""" - } -} -/* - override fun getJSON(): JSONObject { - val json = JSONObject() - json.putOpt("title", title) - json.putOpt("type", typeLink) - json.putOpt("href", href) - if (rel.isNotEmpty()) - json.put("rel", getStringArray(rel)) - json.putOpt("properties", properties) - if (height != 0) - json.putOpt("height", height) - if (width != 0) - json.putOpt("width", width) - json.putOpt("duration", duration) - return json - } - */ \ No newline at end of file +} \ No newline at end of file From 3b87314a3eb13de096d433b76bdf9a52a976567b Mon Sep 17 00:00:00 2001 From: mostapha Date: Fri, 3 Aug 2018 11:54:12 +0200 Subject: [PATCH 04/52] Changing the toJsonString() methods to toString() methods --- .../src/main/java/org/readium/r2/shared/Locator.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 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 0109b935..1990c2db 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 @@ -20,13 +20,13 @@ import java.net.URI * @param title: URI - Title of the spine element * @param locations: Location - Object that's used to locate the target * + * * @var text: LocatorText? - If there's one, describe the Locator's context * */ class Locator(val publicationId: String, val spineIndex: Integer, val created: DateTime, val title: URI, val locations: Location): JSONable { var text = LocatorText(null, null, null) - get override fun getJSON(): JSONObject { val json = JSONObject() @@ -34,16 +34,16 @@ class Locator(val publicationId: String, val spineIndex: Integer, val created: D json.putOpt("spineIndex", spineIndex) json.putOpt("created", created) json.putOpt("title", title) - json.putOpt("location", locations.toJson()) + json.putOpt("location", locations.toString()) if (text != null) { json.putOpt("text", text) } return json } - fun toJsonString(): String{ - var jsonString = """{ "publicationId": "$publicationId", "spineIndex": "$spineIndex", "created": "$created", "title": "$title", "locations" : ${locations.toJson()} """ - if (text != null) { jsonString += """, "text" : "${text.toJson()}"""" } + override fun toString(): String{ + var jsonString = """{ "publicationId": "$publicationId", "spineIndex": "$spineIndex", "created": "$created", "title": "$title", "locations" : ${locations} """ + if (text != null) { jsonString += """, "text" : "${text}"""" } jsonString += """ }""" return jsonString } @@ -70,7 +70,7 @@ class Locator(val publicationId: String, val spineIndex: Integer, val created: D return json } - fun toJson(): String{ + override fun toString(): String{ var jsonString = """{""" after.let { jsonString += """ "after": "$after" """ } before.let { jsonString += """, "before": "$before" """ } @@ -107,7 +107,7 @@ class Location(val id: String, val cfi: String?, val css: String?, val progressi return json } - fun toJson(): String { + override fun toString(): String { var jsonString = """{""" id.let { jsonString += """ "id": "$id" """ } cfi.let { jsonString += """, "cfi": "$cfi" """ } From 4d223c0a5d2016d241efb78d1333eff9bc4ab39a Mon Sep 17 00:00:00 2001 From: mostapha Date: Fri, 3 Aug 2018 15:21:05 +0200 Subject: [PATCH 05/52] updating the comments + fixing Location.toString() --- r2-shared/src/main/java/org/readium/r2/shared/Locator.kt | 9 ++++----- 1 file changed, 4 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 1990c2db..ad890377 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 @@ -12,7 +12,7 @@ import org.json.JSONObject import java.net.URI /** - * Locator : Class that's used to define a precise location in a Publication + * Locator : That class is used to define a precise location in a Publication * * @param publicationId: String - Identifier of a Publication * @param spineIndex: Integer - Index at a spine element @@ -85,7 +85,7 @@ class Locator(val publicationId: String, val spineIndex: Integer, val created: D * Location : Class that contain the different variables needed to localize a particular position * * @param id: String - Identifier of a Publication - * @param cfi: String? - String formatted to design a place in a EPUB + * @param cfi: String? - String formatted to designed a particular place in an EPUB * @param css: String? - Css selector * @param progression: Float - A percentage ( between 0 and 1 ) of the progression in a Publication * @param position: integer - Index of a segment in the resource. @@ -112,9 +112,8 @@ class Location(val id: String, val cfi: String?, val css: String?, val progressi id.let { jsonString += """ "id": "$id" """ } cfi.let { jsonString += """, "cfi": "$cfi" """ } css.let { jsonString += """, "css": "$css" """ } - progression.let { jsonString += """ "progression": "$id" """ } - position.let { jsonString += """ "position": "$id" """ } - id.let { jsonString += """ "id": "$id" """ } + progression.let { jsonString += """ "progression": "$progression" """ } + position.let { jsonString += """ "position": "$position" """ } jsonString += """}""" return jsonString } From 55c913d69315a5a21707c58927a13cde40c53780 Mon Sep 17 00:00:00 2001 From: mostapha Date: Fri, 3 Aug 2018 18:03:33 +0200 Subject: [PATCH 06/52] Changing id for pubId for more perspicacity --- .../java/org/readium/r2/shared/Locator.kt | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 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 ad890377..7d99cfb0 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 @@ -24,7 +24,7 @@ import java.net.URI * @var text: LocatorText? - If there's one, describe the Locator's context * */ -class Locator(val publicationId: String, val spineIndex: Integer, val created: DateTime, val title: URI, val locations: Location): JSONable { +class Locator(val publicationId: String, val spineIndex: Int, val created: DateTime, val title: URI, val locations: Location): JSONable { var text = LocatorText(null, null, null) @@ -35,17 +35,12 @@ class Locator(val publicationId: String, val spineIndex: Integer, val created: D json.putOpt("created", created) json.putOpt("title", title) json.putOpt("location", locations.toString()) - if (text != null) { - json.putOpt("text", text) - } + json.putOpt("text", text) return json } override fun toString(): String{ - var jsonString = """{ "publicationId": "$publicationId", "spineIndex": "$spineIndex", "created": "$created", "title": "$title", "locations" : ${locations} """ - if (text != null) { jsonString += """, "text" : "${text}"""" } - jsonString += """ }""" - return jsonString + return """{ "publicationId": "$publicationId", "spineIndex": "$spineIndex", "created": "$created", "title": "$title", "locations" : ${locations} "text" : "${text}" """ } fun setText(after: String? = null, before: String? = null, highlight: String? = null){ @@ -84,18 +79,18 @@ class Locator(val publicationId: String, val spineIndex: Integer, val created: D /** * Location : Class that contain the different variables needed to localize a particular position * - * @param id: String - Identifier of a Publication + * @param pubId: String - Identifier of a Publication * @param cfi: String? - String formatted to designed a particular place in an EPUB * @param css: String? - Css selector * @param progression: Float - A percentage ( between 0 and 1 ) of the progression in a Publication * @param position: integer - Index of a segment in the resource. * */ -class Location(val id: String, val cfi: String?, val css: String?, val progression: Float, val position: Integer): JSONable{ +class Location(val pubId: String, val cfi: String?, val css: String?, val progression: Float, val position: Integer): JSONable{ override fun getJSON(): JSONObject { val json = JSONObject() - json.putOpt("id", id) + json.putOpt("pubId", pubId) if (cfi != null) { json.putOpt("cfi", cfi) } @@ -109,11 +104,11 @@ class Location(val id: String, val cfi: String?, val css: String?, val progressi override fun toString(): String { var jsonString = """{""" - id.let { jsonString += """ "id": "$id" """ } + pubId.let { jsonString += """ "id": "$pubId" """ } cfi.let { jsonString += """, "cfi": "$cfi" """ } css.let { jsonString += """, "css": "$css" """ } - progression.let { jsonString += """ "progression": "$progression" """ } - position.let { jsonString += """ "position": "$position" """ } + progression.let { jsonString += """, "progression": "$progression" """ } + position.let { jsonString += """, "position": "$position" """ } jsonString += """}""" return jsonString } From 45684dd1b2941a0f43ca9226c419d59fc0823593 Mon Sep 17 00:00:00 2001 From: mostapha Date: Thu, 9 Aug 2018 12:23:59 +0200 Subject: [PATCH 07/52] Adding of spineHref to Locator + verification on the position / progression --- .../java/org/readium/r2/shared/Locator.kt | 62 ++++++++++--------- 1 file changed, 34 insertions(+), 28 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 7d99cfb0..b645c4e4 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 @@ -1,5 +1,8 @@ /* - * Copyright 2018 Readium Foundation. All rights reserved. + * 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. */ @@ -14,24 +17,27 @@ import java.net.URI /** * Locator : That class is used to define a precise location in a Publication * - * @param publicationId: String - Identifier of a Publication - * @param spineIndex: Integer - Index at a spine element - * @param created: DateTime - Date when the Locator has been created ( unique ) - * @param title: URI - Title of the spine element - * @param locations: Location - Object that's used to locate the target + * @var publicationId: String - Identifier of a Publication + * @var spineIndex: Integer - Index at a spine element + * @var spineHref: String? - ( Optional ) String reference to the spine element + * @var created: DateTime - Date when the Locator has been created + * @var title: URI - Title of the spine element + * @var locations: Location - Object that's used to locate the target * * - * @var text: LocatorText? - If there's one, describe the Locator's context + * @var text: LocatorText? - ( Optional ) Describe the Locator's context * */ -class Locator(val publicationId: String, val spineIndex: Int, val created: DateTime, val title: URI, val locations: Location): JSONable { +class Locator(val publicationId: String, val spineIndex: Int, val spineHref: String?, val title: URI, val locations: Location): JSONable { + var created: DateTime = DateTime.now() var text = LocatorText(null, null, null) override fun getJSON(): JSONObject { val json = JSONObject() json.putOpt("publicationId", publicationId) json.putOpt("spineIndex", spineIndex) + json.putOpt("spineHref", spineHref) json.putOpt("created", created) json.putOpt("title", title) json.putOpt("location", locations.toString()) @@ -40,36 +46,30 @@ class Locator(val publicationId: String, val spineIndex: Int, val created: DateT } override fun toString(): String{ - return """{ "publicationId": "$publicationId", "spineIndex": "$spineIndex", "created": "$created", "title": "$title", "locations" : ${locations} "text" : "${text}" """ + return """{ "publicationId": "$publicationId", "spineIndex": "$spineIndex", "spineHref": "$spineHref", "created": "$created", "title": "$title", "locations" : ${locations} "text" : "${text}" """ } - fun setText(after: String? = null, before: String? = null, highlight: String? = null){ - if (after != null) { - text.after = after - } - if (before != null) { - text.before = before - } - if (highlight != null) { - text.highlight = highlight - } + fun setText(before: String? = null, highlight: String? = null, after: String? = null){ + text.before = before + text.highlight = highlight + text.after = after } - inner class LocatorText(var after: String?, var before: String?, var highlight: String?): JSONable{ + inner class LocatorText(var before: String?, var highlight: String?, var after: String?): JSONable{ override fun getJSON(): JSONObject { val json = JSONObject() - json.putOpt("after", after) json.putOpt("before", before) json.putOpt("highlight", highlight) + json.putOpt("after", after) return json } override fun toString(): String{ var jsonString = """{""" - after.let { jsonString += """ "after": "$after" """ } before.let { jsonString += """, "before": "$before" """ } highlight.let { jsonString += """, "highlight": "$highlight" """ } + after.let { jsonString += """ "after": "$after" """ } jsonString += """}""" return jsonString } @@ -79,14 +79,20 @@ class Locator(val publicationId: String, val spineIndex: Int, val created: DateT /** * Location : Class that contain the different variables needed to localize a particular position * - * @param pubId: String - Identifier of a Publication - * @param cfi: String? - String formatted to designed a particular place in an EPUB - * @param css: String? - Css selector - * @param progression: Float - A percentage ( between 0 and 1 ) of the progression in a Publication - * @param position: integer - Index of a segment in the resource. + * @var pubId: String - Identifier of a Publication + * @var cfi: String? - String formatted to designed a particular place in an EPUB + * @var css: String? - Css selector + * @var progression: Float - A percentage ( between 0 and 1 ) of the progression in a Publication + * @var position: integer - Index of a segment in the resource. * */ -class Location(val pubId: String, val cfi: String?, val css: String?, val progression: Float, val position: Integer): JSONable{ +class Location(val pubId: String, val cfi: String?, val css: String?, val progression: Float, val position: Int): JSONable{ + + init { + if (position < 0 || !(progression in 0..1)) { + throw Throwable("Error : invalid arguments.") + } + } override fun getJSON(): JSONObject { val json = JSONObject() From 2450b4d0c8812570095aaa44eeac1e041a6f3721 Mon Sep 17 00:00:00 2001 From: mostapha Date: Thu, 9 Aug 2018 15:51:14 +0200 Subject: [PATCH 08/52] Timestamp is now handled by Locator directly --- .../java/org/readium/r2/shared/Locator.kt | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 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 b645c4e4..ff0ac369 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 @@ -9,7 +9,6 @@ package org.readium.r2.shared - import org.joda.time.DateTime import org.json.JSONObject import java.net.URI @@ -18,9 +17,9 @@ import java.net.URI * Locator : That class is used to define a precise location in a Publication * * @var publicationId: String - Identifier of a Publication - * @var spineIndex: Integer - Index at a spine element + * @var spineIndex: Long - Index at a spine element * @var spineHref: String? - ( Optional ) String reference to the spine element - * @var created: DateTime - Date when the Locator has been created + * @var timestamp: DateTime - Date when the Locator has been timestamp * @var title: URI - Title of the spine element * @var locations: Location - Object that's used to locate the target * @@ -28,17 +27,28 @@ import java.net.URI * @var text: LocatorText? - ( Optional ) Describe the Locator's context * */ -class Locator(val publicationId: String, val spineIndex: Int, val spineHref: String?, val title: URI, val locations: Location): JSONable { +open class Locator(val publicationId: String, + val spineIndex: Long, + val spineHref: String?, + val title: String, + location: Location? = null): JSONable { - var created: DateTime = DateTime.now() + val locations = mutableListOf() + var timestamp = DateTime.now().toDate().time var text = LocatorText(null, null, null) + init { + if(location != null){ + locations.add(location) + } + } + override fun getJSON(): JSONObject { val json = JSONObject() json.putOpt("publicationId", publicationId) json.putOpt("spineIndex", spineIndex) json.putOpt("spineHref", spineHref) - json.putOpt("created", created) + json.putOpt("timestamp", timestamp) json.putOpt("title", title) json.putOpt("location", locations.toString()) json.putOpt("text", text) @@ -46,7 +56,7 @@ class Locator(val publicationId: String, val spineIndex: Int, val spineHref: Str } override fun toString(): String{ - return """{ "publicationId": "$publicationId", "spineIndex": "$spineIndex", "spineHref": "$spineHref", "created": "$created", "title": "$title", "locations" : ${locations} "text" : "${text}" """ + return """{ "publicationId": "$publicationId", "spineIndex": "$spineIndex", "spineHref": "$spineHref", "timestamp": "$timestamp", "title": "$title", "locations" : ${locations} "text" : "${text}" """ } fun setText(before: String? = null, highlight: String? = null, after: String? = null){ @@ -67,9 +77,9 @@ class Locator(val publicationId: String, val spineIndex: Int, val spineHref: Str override fun toString(): String{ var jsonString = """{""" - before.let { jsonString += """, "before": "$before" """ } + before.let { jsonString += """ "before": "$before" """ } highlight.let { jsonString += """, "highlight": "$highlight" """ } - after.let { jsonString += """ "after": "$after" """ } + after.let { jsonString += """, "after": "$after" """ } jsonString += """}""" return jsonString } @@ -86,13 +96,7 @@ class Locator(val publicationId: String, val spineIndex: Int, val spineHref: Str * @var position: integer - Index of a segment in the resource. * */ -class Location(val pubId: String, val cfi: String?, val css: String?, val progression: Float, val position: Int): JSONable{ - - init { - if (position < 0 || !(progression in 0..1)) { - throw Throwable("Error : invalid arguments.") - } - } +class Location(val pubId: String, val cfi: String?, val css: String?, val progression: Double, val position: Long): JSONable{ override fun getJSON(): JSONObject { val json = JSONObject() From 77484568ece54525c0d5741b35d4a165b2fa88ec Mon Sep 17 00:00:00 2001 From: mostapha Date: Thu, 9 Aug 2018 17:21:12 +0200 Subject: [PATCH 09/52] Add of xpath variable to Location --- .../main/java/org/readium/r2/shared/Locator.kt | 15 ++++++++++----- 1 file changed, 10 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 ff0ac369..5cb65b8d 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 @@ -91,12 +91,13 @@ open class Locator(val publicationId: String, * * @var pubId: String - Identifier of a Publication * @var cfi: String? - String formatted to designed a particular place in an EPUB - * @var css: String? - Css selector + * @var cssSelector: String? - Css selector + * @var xpath: String? - An xpath in the resource * @var progression: Float - A percentage ( between 0 and 1 ) of the progression in a Publication * @var position: integer - Index of a segment in the resource. * */ -class Location(val pubId: String, val cfi: String?, val css: String?, val progression: Double, val position: Long): JSONable{ +class Location(val pubId: String, val cfi: String?, val cssSelector: String?, val xpath: String?, val progression: Double, val position: Long): JSONable{ override fun getJSON(): JSONObject { val json = JSONObject() @@ -104,8 +105,11 @@ class Location(val pubId: String, val cfi: String?, val css: String?, val progre if (cfi != null) { json.putOpt("cfi", cfi) } - if (css != null) { - json.putOpt("css", css) + if (cssSelector != null) { + json.putOpt("cssSelector", cssSelector) + } + if (xpath != null) { + json.putOpt("xpath", xpath) } json.putOpt("progression", progression) json.putOpt("position", position) @@ -116,7 +120,8 @@ class Location(val pubId: String, val cfi: String?, val css: String?, val progre var jsonString = """{""" pubId.let { jsonString += """ "id": "$pubId" """ } cfi.let { jsonString += """, "cfi": "$cfi" """ } - css.let { jsonString += """, "css": "$css" """ } + cssSelector.let { jsonString += """, "cssSelector": "$cssSelector" """ } + xpath.let { jsonString += """, "xpath": "$xpath" """ } progression.let { jsonString += """, "progression": "$progression" """ } position.let { jsonString += """, "position": "$position" """ } jsonString += """}""" From 50eb04b6c1027f4ba0ce435e02621051fdb78e18 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Thu, 9 Aug 2018 17:42:59 +0200 Subject: [PATCH 10/52] as publicationId is inferred, it has been removed from the JSONObject (and spineIndex commented out for now) --- r2-shared/src/main/java/org/readium/r2/shared/Locator.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 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 5cb65b8d..8585416e 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 @@ -45,11 +45,10 @@ open class Locator(val publicationId: String, override fun getJSON(): JSONObject { val json = JSONObject() - json.putOpt("publicationId", publicationId) - json.putOpt("spineIndex", spineIndex) - json.putOpt("spineHref", spineHref) - json.putOpt("timestamp", timestamp) +// json.putOpt("spineIndex", spineIndex) + json.putOpt("href", spineHref) json.putOpt("title", title) + json.putOpt("timestamp", timestamp) json.putOpt("location", locations.toString()) json.putOpt("text", text) return json From d83e479494511b90b6c2d66ef444d3a8e1c8a5a0 Mon Sep 17 00:00:00 2001 From: mostapha Date: Thu, 9 Aug 2018 18:05:43 +0200 Subject: [PATCH 11/52] Draft of locators unit test --- .../org/readium/r2/shared/LocatorsUnitTest.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 r2-shared/src/main/java/org/readium/r2/shared/LocatorsUnitTest.kt diff --git a/r2-shared/src/main/java/org/readium/r2/shared/LocatorsUnitTest.kt b/r2-shared/src/main/java/org/readium/r2/shared/LocatorsUnitTest.kt new file mode 100644 index 00000000..e9df8521 --- /dev/null +++ b/r2-shared/src/main/java/org/readium/r2/shared/LocatorsUnitTest.kt @@ -0,0 +1,33 @@ +/* + * // Copyright 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.shared + +import java.net.URI + +/* +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 f3fe178e9dd9f056bbfe76d476af738297a180a0 Mon Sep 17 00:00:00 2001 From: mostapha Date: Fri, 10 Aug 2018 17:58:29 +0200 Subject: [PATCH 12/52] Use of Gson library to turn the object into a Json --- .../java/org/readium/r2/shared/Locator.kt | 83 ++++++++++++------- 1 file changed, 54 insertions(+), 29 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 8585416e..04b72ad4 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 @@ -9,9 +9,9 @@ package org.readium.r2.shared +import com.google.gson.Gson import org.joda.time.DateTime import org.json.JSONObject -import java.net.URI /** * Locator : That class is used to define a precise location in a Publication @@ -19,43 +19,39 @@ import java.net.URI * @var publicationId: String - Identifier of a Publication * @var spineIndex: Long - Index at a spine element * @var spineHref: String? - ( Optional ) String reference to the spine element - * @var timestamp: DateTime - Date when the Locator has been timestamp - * @var title: URI - Title of the spine element - * @var locations: Location - Object that's used to locate the target + * @var title: String - Title of the spine element * + * @var location: Location - List of objects used to locate the target + * @var timestamp: DateTime - Date when the Locator has been timestamp * * @var text: LocatorText? - ( Optional ) Describe the Locator's context * */ open class Locator(val publicationId: String, - val spineIndex: Long, val spineHref: String?, + val spineIndex: Long, val title: String, - location: Location? = null): JSONable { + val location: Location? = null): JSONable { - val locations = mutableListOf() var timestamp = DateTime.now().toDate().time var text = LocatorText(null, null, null) - init { - if(location != null){ - locations.add(location) - } + fun toJson(): String{ + return Gson().toJson(this) } override fun getJSON(): JSONObject { val json = JSONObject() -// json.putOpt("spineIndex", spineIndex) json.putOpt("href", spineHref) json.putOpt("title", title) json.putOpt("timestamp", timestamp) - json.putOpt("location", locations.toString()) + json.putOpt("location", location.toString()) json.putOpt("text", text) return json } override fun toString(): String{ - return """{ "publicationId": "$publicationId", "spineIndex": "$spineIndex", "spineHref": "$spineHref", "timestamp": "$timestamp", "title": "$title", "locations" : ${locations} "text" : "${text}" """ + return """{ "href": "$spineHref", "title": "$title", "timestamp": "$timestamp", "locations" : $location "text" : "$text" """ } fun setText(before: String? = null, highlight: String? = null, after: String? = null){ @@ -66,6 +62,10 @@ open class Locator(val publicationId: String, inner class LocatorText(var before: String?, var highlight: String?, var after: String?): JSONable{ + fun toJson(): String{ + return Gson().toJson(this) + } + override fun getJSON(): JSONObject { val json = JSONObject() json.putOpt("before", before) @@ -76,9 +76,21 @@ open class Locator(val publicationId: String, override fun toString(): String{ var jsonString = """{""" - before.let { jsonString += """ "before": "$before" """ } - highlight.let { jsonString += """, "highlight": "$highlight" """ } - after.let { jsonString += """, "after": "$after" """ } + if (before != null) { + before.let { jsonString += """ "before": "$before" """ } + if (highlight != null) { + jsonString += """,""" + } + } + if (highlight != null) { + highlight.let { jsonString += """ "highlight": "$highlight" """ } + if (after != null) { + jsonString += """,""" + } + } + if (after != null) { + after.let { jsonString += """ "after": "$after" """ } + } jsonString += """}""" return jsonString } @@ -88,19 +100,24 @@ open class Locator(val publicationId: String, /** * Location : Class that contain the different variables needed to localize a particular position * - * @var pubId: String - Identifier of a Publication - * @var cfi: String? - String formatted to designed a particular place in an EPUB + * @var id: Long? - Identifier of a specific fragment in the publication + * @var cfi: String? - String formatted to designed a particular place in an Publication * @var cssSelector: String? - Css selector * @var xpath: String? - An xpath in the resource - * @var progression: Float - A percentage ( between 0 and 1 ) of the progression in a Publication - * @var position: integer - Index of a segment in the resource. + * @var progression: Double - A percentage ( between 0 and 1 ) of the progression in a Publication + * @var position: Long - Index of a segment in the resource * */ -class Location(val pubId: String, val cfi: String?, val cssSelector: String?, val xpath: String?, val progression: Double, val position: Long): JSONable{ +class Location(val id: Long?, val cfi: String?, val cssSelector: String?, val xpath: String?, val progression: Double, val position: Long): JSONable{ + + + fun toJson(): String{ + return Gson().toJson(this) + } override fun getJSON(): JSONObject { val json = JSONObject() - json.putOpt("pubId", pubId) + json.putOpt("id", id) if (cfi != null) { json.putOpt("cfi", cfi) } @@ -117,12 +134,20 @@ class Location(val pubId: String, val cfi: String?, val cssSelector: String?, va override fun toString(): String { var jsonString = """{""" - pubId.let { jsonString += """ "id": "$pubId" """ } - cfi.let { jsonString += """, "cfi": "$cfi" """ } - cssSelector.let { jsonString += """, "cssSelector": "$cssSelector" """ } - xpath.let { jsonString += """, "xpath": "$xpath" """ } - progression.let { jsonString += """, "progression": "$progression" """ } - position.let { jsonString += """, "position": "$position" """ } + if (id != null) { + id.let { jsonString += """ "id": "$id" ,""" } + } + if (cfi != null) { + cfi.let { jsonString += """ "cfi": "$cfi" ,""" } + } + if (cssSelector != null) { + cssSelector.let { jsonString += """ "cssSelector": "$cssSelector" ,""" } + } + if (xpath != null) { + xpath.let { jsonString += """ "xpath": "$xpath" ,""" } + } + progression.let { jsonString += """ "progression": "$progression" ,""" } + position.let { jsonString += """ "position": "$position" """ } jsonString += """}""" return jsonString } From 22731bc58e40ac042c97606be056d56ae93c81ee Mon Sep 17 00:00:00 2001 From: mostapha Date: Fri, 10 Aug 2018 18:00:02 +0200 Subject: [PATCH 13/52] Introducing to LocatorUtils, meant to hold all the functions related to Locators ( getCurrentLocator, goToLocator, .. ) --- .../org/readium/r2/shared/LocatorUtils.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 r2-shared/src/main/java/org/readium/r2/shared/LocatorUtils.kt diff --git a/r2-shared/src/main/java/org/readium/r2/shared/LocatorUtils.kt b/r2-shared/src/main/java/org/readium/r2/shared/LocatorUtils.kt new file mode 100644 index 00000000..89705f15 --- /dev/null +++ b/r2-shared/src/main/java/org/readium/r2/shared/LocatorUtils.kt @@ -0,0 +1,33 @@ +/* + * 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.shared + +import android.content.Context +import android.content.ContextWrapper + + +/** + * LocatorUtils : API used to get the current location as a Locator object + * or to reach a Locator place in a publication + */ + +class LocatorUtils { + + // Size of a segment in a publication, expressed in characters + val SEGMENT = 1024 + + fun getCurrentLocator(){ + + } + fun goToLocator(){ + + } + +} \ No newline at end of file From a9ccae0b8e7970f99afd8b7afb1211a0135cb7cd Mon Sep 17 00:00:00 2001 From: mostapha Date: Fri, 10 Aug 2018 18:00:34 +0200 Subject: [PATCH 14/52] Update of the copyright --- .../main/java/org/readium/r2/shared/LocatorsUnitTest.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/LocatorsUnitTest.kt b/r2-shared/src/main/java/org/readium/r2/shared/LocatorsUnitTest.kt index e9df8521..80c916f0 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/LocatorsUnitTest.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/LocatorsUnitTest.kt @@ -1,7 +1,10 @@ /* - * // Copyright 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. + * 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.shared From 7ea59e1818383e40c2ec27a5ed46bbe14471eb88 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Fri, 17 Aug 2018 18:13:06 +0200 Subject: [PATCH 15/52] inverted parameters in locators constructor --- r2-shared/src/main/java/org/readium/r2/shared/Locator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 04b72ad4..87914a22 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 @@ -28,8 +28,8 @@ import org.json.JSONObject * */ open class Locator(val publicationId: String, - val spineHref: String?, val spineIndex: Long, + val spineHref: String?, val title: String, val location: Location? = null): JSONable { From 500f9edfa9a94e934cf1c4ab67fd227438d82841 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Wed, 22 Aug 2018 11:29:47 +0200 Subject: [PATCH 16/52] change 'timestamp' parameter to 'created' --- .../src/main/java/org/readium/r2/shared/Locator.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 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 87914a22..780aaf91 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 @@ -17,23 +17,23 @@ import org.json.JSONObject * Locator : That class is used to define a precise location in a Publication * * @var publicationId: String - Identifier of a Publication - * @var spineIndex: Long - Index at a spine element + * @var spineIndex: Long - Index of a spine element * @var spineHref: String? - ( Optional ) String reference to the spine element * @var title: String - Title of the spine element * * @var location: Location - List of objects used to locate the target - * @var timestamp: DateTime - Date when the Locator has been timestamp + * @var created: DateTime - Date when the Locator has been created * * @var text: LocatorText? - ( Optional ) Describe the Locator's context * */ open class Locator(val publicationId: String, - val spineIndex: Long, - val spineHref: String?, + val spineIndex: Long?, + val spineHref: String, val title: String, val location: Location? = null): JSONable { - var timestamp = DateTime.now().toDate().time + var created = DateTime.now().toDate().time var text = LocatorText(null, null, null) fun toJson(): String{ @@ -44,14 +44,14 @@ open class Locator(val publicationId: String, val json = JSONObject() json.putOpt("href", spineHref) json.putOpt("title", title) - json.putOpt("timestamp", timestamp) + json.putOpt("created", created) json.putOpt("location", location.toString()) json.putOpt("text", text) return json } override fun toString(): String{ - return """{ "href": "$spineHref", "title": "$title", "timestamp": "$timestamp", "locations" : $location "text" : "$text" """ + return """{ "href": "$spineHref", "title": "$title", "created": "$created", "locations" : $location "text" : "$text" """ } fun setText(before: String? = null, highlight: String? = null, after: String? = null){ From 12bc7b0acfc6f20adca3b71ba2e6f374704d5ad6 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Wed, 22 Aug 2018 11:30:00 +0200 Subject: [PATCH 17/52] moved file to testapp --- .../org/readium/r2/shared/LocatorUtils.kt | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 r2-shared/src/main/java/org/readium/r2/shared/LocatorUtils.kt diff --git a/r2-shared/src/main/java/org/readium/r2/shared/LocatorUtils.kt b/r2-shared/src/main/java/org/readium/r2/shared/LocatorUtils.kt deleted file mode 100644 index 89705f15..00000000 --- a/r2-shared/src/main/java/org/readium/r2/shared/LocatorUtils.kt +++ /dev/null @@ -1,33 +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.shared - -import android.content.Context -import android.content.ContextWrapper - - -/** - * LocatorUtils : API used to get the current location as a Locator object - * or to reach a Locator place in a publication - */ - -class LocatorUtils { - - // Size of a segment in a publication, expressed in characters - val SEGMENT = 1024 - - fun getCurrentLocator(){ - - } - fun goToLocator(){ - - } - -} \ No newline at end of file From 7c16dce79470e771b7ec05292623196b6cca8a88 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Mon, 27 Aug 2018 12:21:30 +0200 Subject: [PATCH 18/52] refactored spineHref into resourceHref --- r2-shared/src/main/java/org/readium/r2/shared/Locator.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 780aaf91..9054981f 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 @@ -18,7 +18,7 @@ import org.json.JSONObject * * @var publicationId: String - Identifier of a Publication * @var spineIndex: Long - Index of a spine element - * @var spineHref: String? - ( Optional ) String reference to the spine element + * @var resourceHref: String? - ( Optional ) String reference to the spine element * @var title: String - Title of the spine element * * @var location: Location - List of objects used to locate the target @@ -29,7 +29,7 @@ import org.json.JSONObject */ open class Locator(val publicationId: String, val spineIndex: Long?, - val spineHref: String, + open val resourceHref: String, val title: String, val location: Location? = null): JSONable { @@ -42,7 +42,7 @@ open class Locator(val publicationId: String, override fun getJSON(): JSONObject { val json = JSONObject() - json.putOpt("href", spineHref) + json.putOpt("href", resourceHref) json.putOpt("title", title) json.putOpt("created", created) json.putOpt("location", location.toString()) @@ -51,7 +51,7 @@ open class Locator(val publicationId: String, } override fun toString(): String{ - return """{ "href": "$spineHref", "title": "$title", "created": "$created", "locations" : $location "text" : "$text" """ + return """{ "href": "$resourceHref", "title": "$title", "created": "$created", "locations" : $location "text" : "$text" """ } fun setText(before: String? = null, highlight: String? = null, after: String? = null){ From ca3519a56e42cf08d237fce07473a4244e1c2772 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Mon, 27 Aug 2018 20:08:46 -0400 Subject: [PATCH 19/52] gradle config update --- build.gradle | 4 +- r2-shared/build.gradle | 16 ++-- r2-shared/r2-shared.iml | 157 ++++++++++++++++++++-------------------- 3 files changed, 87 insertions(+), 90 deletions(-) diff --git a/build.gradle b/build.gradle index 872bf9c8..48490da4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,9 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.2.50' + ext.kotlin_version = '1.2.61' + ext.support_version = '27.1.1' + repositories { google() jcenter() diff --git a/r2-shared/build.gradle b/r2-shared/build.gradle index 4f94c51c..ea4e1ba0 100644 --- a/r2-shared/build.gradle +++ b/r2-shared/build.gradle @@ -17,8 +17,6 @@ android { flavorDimensions "testapp" compileSdkVersion 27 - buildToolsVersion "27.0.3" - defaultConfig { minSdkVersion 21 targetSdkVersion 27 @@ -52,14 +50,13 @@ android { } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation fileTree(include: ['*.jar'], dir: 'libs') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation 'com.jakewharton.timber:timber:4.7.0' - - implementation 'com.android.support:appcompat-v7:27.1.1' + implementation 'com.jakewharton.timber:timber:4.7.1' + implementation "com.android.support:appcompat-v7:$support_version" implementation 'com.google.code.gson:gson:2.8.2' - implementation 'com.github.kittinunf.fuel:fuel:1.15.0' //for JVM - implementation 'com.github.kittinunf.fuel:fuel-android:1.15.0' //for Android + implementation 'com.github.kittinunf.fuel:fuel:1.15.0' + implementation 'com.github.kittinunf.fuel:fuel-android:1.15.0' implementation 'nl.komponents.kovenant:kovenant:3.3.0' implementation 'nl.komponents.kovenant:kovenant-core:3.3.0' implementation 'nl.komponents.kovenant:kovenant-android:3.3.0' @@ -67,9 +64,8 @@ dependencies { implementation 'nl.komponents.kovenant:kovenant-jvm:3.3.0' implementation 'nl.komponents.kovenant:kovenant-functional:3.3.0' implementation 'joda-time:joda-time:2.9.9' - testImplementation 'junit:junit:4.12' - testImplementation "org.mockito:mockito-core:2.12.0" + testImplementation 'org.mockito:mockito-core:2.12.0' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" diff --git a/r2-shared/r2-shared.iml b/r2-shared/r2-shared.iml index 4778cf66..ad7cc07a 100644 --- a/r2-shared/r2-shared.iml +++ b/r2-shared/r2-shared.iml @@ -8,11 +8,11 @@ - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -161,7 +161,6 @@ - @@ -178,15 +177,13 @@ - - + - + - @@ -194,40 +191,42 @@ + - + - + - - + + + - - + + \ No newline at end of file From cc942c8f65344d1a19ca2abde30937316f81d536 Mon Sep 17 00:00:00 2001 From: Aferdita Date: Tue, 28 Aug 2018 09:29:49 -0400 Subject: [PATCH 20/52] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1389c7c2..224d825f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ local.properties /.idea/workspace.xml /.idea/libraries +/.idea .DS_Store /build /captures From 0fce0d81e811c5a2cdcaeacaecc052200d00fcdb Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Sat, 1 Sep 2018 11:00:49 -0400 Subject: [PATCH 21/52] updated enum classes to access enum by value --- .../java/org/readium/r2/shared/Rendition.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Rendition.kt b/r2-shared/src/main/java/org/readium/r2/shared/Rendition.kt index 2606d2b2..e1d4e698 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Rendition.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Rendition.kt @@ -12,30 +12,34 @@ package org.readium.r2.shared import org.json.JSONObject import java.io.Serializable -enum class RenditionLayout(val ini: String) : Serializable { +enum class RenditionLayout(val value: String) : Serializable { Reflowable("reflowable"), - Fixed("fixed") + Fixed("pre-paginated"); + companion object : Publication.EnumCompanion(RenditionLayout.values().associateBy(RenditionLayout::value)) } -enum class RenditionFlow(val ini: String) : Serializable { +enum class RenditionFlow(val value: String) : Serializable { Paginated("paginated"), Continuous("continuous"), Document("document"), - Fixed("Fixed") + Fixed("fixed"); + companion object : Publication.EnumCompanion(RenditionFlow.values().associateBy(RenditionFlow::value)) } -enum class RenditionOrientation(val ini: String) : Serializable { +enum class RenditionOrientation(val value: String) : Serializable { Auto("auto"), Landscape("landscape"), - Portrait("portrait") + Portrait("portrait"); + companion object : Publication.EnumCompanion(RenditionOrientation.values().associateBy(RenditionOrientation::value)) } -enum class RenditionSpread(val ini: String) : Serializable { +enum class RenditionSpread(val value: String) : Serializable { Auto("auto"), Landscape("landscape"), Portrait("portrait"), Both("both"), - None("none") + None("none"); + companion object : Publication.EnumCompanion(RenditionSpread.values().associateBy(RenditionSpread::value)) } class Rendition : Serializable { From d40d85a39d3d5d9a77b56696f4c94cfd9019cc7f Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Sat, 1 Sep 2018 16:11:58 -0400 Subject: [PATCH 22/52] modified drm model and renew / return method signatures --- r2-shared/src/main/java/org/readium/r2/shared/drm/DRMModel.kt | 3 ++- .../src/main/java/org/readium/r2/shared/drm/DrmLicense.kt | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/drm/DRMModel.kt b/r2-shared/src/main/java/org/readium/r2/shared/drm/DRMModel.kt index 27af7674..4f7155e3 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/drm/DRMModel.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/drm/DRMModel.kt @@ -10,5 +10,6 @@ package org.readium.r2.shared.drm import java.io.Serializable +import java.net.URL -data class DRMModel(val type: String, val state: String, val provider: String, val issued: String, val updated: String, val start: String?, val end: String?, val prints: String, val copies: String) : Serializable \ No newline at end of file +data class DRMModel(val type: String, val licensePath: URL) : Serializable \ No newline at end of file diff --git a/r2-shared/src/main/java/org/readium/r2/shared/drm/DrmLicense.kt b/r2-shared/src/main/java/org/readium/r2/shared/drm/DrmLicense.kt index 3f0560f3..ae40db69 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/drm/DrmLicense.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/drm/DrmLicense.kt @@ -17,8 +17,8 @@ interface DrmLicense : Serializable { fun decipher(data: ByteArray): ByteArray? fun areRightsValid() fun register() - fun renew(endDate: Date?, completion: (String) -> Void) - fun ret(completion: (String) -> Void) + fun renewLicense (endDate: Date? = null, callback: (Any) -> Unit) + fun returnLicense(callback: (Any) -> Unit) fun currentStatus(): String fun lastUpdate(): Date fun issued(): Date From 5076d4b929e47b2ffd4ffa77b75b3500b96c8881 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Sat, 1 Sep 2018 19:16:09 -0400 Subject: [PATCH 23/52] renamed json function --- .../src/main/java/org/readium/r2/shared/Contributor.kt | 2 +- r2-shared/src/main/java/org/readium/r2/shared/JSONable.kt | 2 +- r2-shared/src/main/java/org/readium/r2/shared/Link.kt | 2 +- r2-shared/src/main/java/org/readium/r2/shared/Properties.kt | 2 +- .../src/main/java/org/readium/r2/shared/Publication.kt | 6 +++--- r2-shared/src/main/java/org/readium/r2/shared/Subject.kt | 2 +- 6 files changed, 8 insertions(+), 8 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 4e519f19..358fb805 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 @@ -24,7 +24,7 @@ class Contributor : JSONable, Serializable { var name: String? = null get() = multilanguageName.singleString - override fun getJSON(): JSONObject { + override fun toJSON(): JSONObject { val obj = JSONObject() obj.put("name", name) if (roles.isNotEmpty()) { diff --git a/r2-shared/src/main/java/org/readium/r2/shared/JSONable.kt b/r2-shared/src/main/java/org/readium/r2/shared/JSONable.kt index f1c3792c..afc1d2d6 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/JSONable.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/JSONable.kt @@ -13,6 +13,6 @@ import org.json.JSONObject interface JSONable { - fun getJSON(): JSONObject + fun toJSON(): JSONObject } \ No newline at end of file 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 2aa2e771..b6086b17 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 @@ -48,7 +48,7 @@ class Link : JSONable, Serializable { return properties.encryption != null } - override fun getJSON(): JSONObject { + override fun toJSON(): JSONObject { val json = JSONObject() json.putOpt("title", title) json.putOpt("type", typeLink) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/Properties.kt b/r2-shared/src/main/java/org/readium/r2/shared/Properties.kt index 9b94d777..b6d56a9f 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/Properties.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/Properties.kt @@ -42,7 +42,7 @@ class Properties : JSONable, Serializable { /// var indirectAcquisition: MutableList = mutableListOf() - override fun getJSON(): JSONObject { + override fun toJSON(): JSONObject { val json = JSONObject() if (contains.isNotEmpty()) json.put("contains", getStringArray(contains)) json.putOpt("mediaOverlay", mediaOverlay) 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 114e5e3d..a6b5f28a 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 @@ -26,7 +26,7 @@ fun URL.removeLastComponent(): URL { fun getJSONArray(list: List): JSONArray { val array = JSONArray() for (i in list) { - array.put(i.getJSON()) + array.put(i.toJSON()) } return array } @@ -46,8 +46,8 @@ fun tryPut(obj: JSONObject, list: List, tag: String) { class TocElement(val link: Link, val children: List) : JSONable { - override fun getJSON(): JSONObject { - val json = link.getJSON() + override fun toJSON(): JSONObject { + val json = link.toJSON() tryPut(json, children, "children") return json } 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 520f63cc..10bb6990 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,7 +22,7 @@ class Subject : JSONable, Serializable { // Epub 3.1 "code" (opf:term) var code: String? = null - override fun getJSON(): JSONObject { + override fun toJSON(): JSONObject { val json = JSONObject() json.putOpt("name", name) json.putOpt("sortAs", sortAs) From 6a135cc486cda9a154f9357c123050d795edfb37 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Sat, 1 Sep 2018 19:16:27 -0400 Subject: [PATCH 24/52] refactored Locator Model --- .../java/org/readium/r2/shared/Locator.kt | 240 +++++++++++------- 1 file changed, 154 insertions(+), 86 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 9054981f..bc8fdab7 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 @@ -9,93 +9,126 @@ package org.readium.r2.shared -import com.google.gson.Gson import org.joda.time.DateTime import org.json.JSONObject + + /** - * Locator : That class is used to define a precise location in a Publication - * - * @var publicationId: String - Identifier of a Publication - * @var spineIndex: Long - Index of a spine element - * @var resourceHref: String? - ( Optional ) String reference to the spine element - * @var title: String - Title of the spine element + * Locator model * - * @var location: Location - List of objects used to locate the target - * @var created: DateTime - Date when the Locator has been created - * - * @var text: LocatorText? - ( Optional ) Describe the Locator's context + * @var bookId: Long? - Book index in the database + * @val publicationID: String - Publication identifier + * @val resourceIndex: Long - Index to the spine element of the book + * @val resourceHref: String - Reference to the spine element + * @val resourceTitle: String - Title to the spine element of the book + * @val location: Location - Location in the spine element + * @val creationDate: Long - Datetime when the bookmark has been created + * @var id: Long? - ID of the bookmark in database * + * @fun toString(): String - Return a String description of the Locator */ -open class Locator(val publicationId: String, - val spineIndex: Long?, - open val resourceHref: String, - val title: String, - val location: Location? = null): JSONable { - - var created = DateTime.now().toDate().time - var text = LocatorText(null, null, null) - - fun toJson(): String{ - return Gson().toJson(this) - } - - override fun getJSON(): JSONObject { - val json = JSONObject() - json.putOpt("href", resourceHref) - json.putOpt("title", title) - json.putOpt("created", created) - json.putOpt("location", location.toString()) - json.putOpt("text", text) - return json - } - override fun toString(): String{ - return """{ "href": "$resourceHref", "title": "$title", "created": "$created", "locations" : $location "text" : "$text" """ - } +class Locator(val bookID: Long, + val publicationID: String, + val resourceIndex: Long, + val resourceHref: String, + val resourceTitle: String, + val location: Location, + var creationDate: Long = DateTime().toDate().time, + var id: Long? = null) { - fun setText(before: String? = null, highlight: String? = null, after: String? = null){ - text.before = before - text.highlight = highlight - text.after = after - } + //TODO update this +// override fun toString(): String { +// return "Locator id : ${this.id}, book id : ${this.bookID}, resource href selected ${this.resourceHref}, progression saved ${this.location.progression} and created the ${this.creationDate}." +// } - inner class LocatorText(var before: String?, var highlight: String?, var after: String?): JSONable{ +} - fun toJson(): String{ - return Gson().toJson(this) - } - override fun getJSON(): JSONObject { - val json = JSONObject() - json.putOpt("before", before) - json.putOpt("highlight", highlight) - json.putOpt("after", after) - return json - } - - override fun toString(): String{ - var jsonString = """{""" - if (before != null) { - before.let { jsonString += """ "before": "$before" """ } - if (highlight != null) { - jsonString += """,""" - } - } - if (highlight != null) { - highlight.let { jsonString += """ "highlight": "$highlight" """ } - if (after != null) { - jsonString += """,""" - } - } - if (after != null) { - after.let { jsonString += """ "after": "$after" """ } - } - jsonString += """}""" - return jsonString - } - } -} +///** +// * Locator : That class is used to define a precise location in a Publication +// * +// * @var publicationId: String - Identifier of a Publication +// * @var spineIndex: Long - Index of a spine element +// * @var resourceHref: String? - ( Optional ) String reference to the spine element +// * @var title: String - Title of the spine element +// * +// * @var location: Location - List of objects used to locate the target +// * @var created: DateTime - Date when the Locator has been created +// * +// * @var text: LocatorText? - ( Optional ) Describe the Locator's context +// * +// */ +//open class Locator(val publicationId: String, +// val spineIndex: Long?, +// open val resourceHref: String, +// val title: String, +// val location: Location? = null): JSONable { +// +// var created = DateTime.now().toDate().time +// var text = LocatorText(null, null, null) +// +// fun toJson(): String{ +// return Gson().toJson(this) +// } +// +// override fun toJSON(): JSONObject { +// val json = JSONObject() +// json.putOpt("href", resourceHref) +// json.putOpt("title", title) +// json.putOpt("created", created) +// json.putOpt("location", location.toString()) +// json.putOpt("text", text) +// return json +// } +// +// override fun toString(): String{ +// return """{ "href": "$resourceHref", "title": "$title", "created": "$created", "locations" : $location "text" : "$text" """ +// } +// +// fun setText(before: String? = null, highlight: String? = null, after: String? = null){ +// text.before = before +// text.highlight = highlight +// text.after = after +// } +// +// inner class LocatorText(var before: String?, var highlight: String?, var after: String?): JSONable{ +// +// fun toJson(): String{ +// return Gson().toJson(this) +// } +// +// override fun toJSON(): JSONObject { +// val json = JSONObject() +// json.putOpt("before", before) +// json.putOpt("highlight", highlight) +// json.putOpt("after", after) +// return json +// } +// +// override fun toString(): String{ +// var jsonString = """{""" +// if (before != null) { +// before.let { jsonString += """ "before": "$before" """ } +// if (highlight != null) { +// jsonString += """,""" +// } +// } +// if (highlight != null) { +// highlight.let { jsonString += """ "highlight": "$highlight" """ } +// if (after != null) { +// jsonString += """,""" +// } +// } +// if (after != null) { +// after.let { jsonString += """ "after": "$after" """ } +// } +// jsonString += """}""" +// return jsonString +// } +// } +//} /** * Location : Class that contain the different variables needed to localize a particular position @@ -108,27 +141,62 @@ open class Locator(val publicationId: String, * @var position: Long - Index of a segment in the resource * */ -class Location(val id: Long?, val cfi: String?, val cssSelector: String?, val xpath: String?, val progression: Double, val position: Long): JSONable{ - +class Location(var id: Long? = null, + var cfi: String? = null, + var cssSelector: String? = null, + var xpath: String? = null, + var progression: Double? = null, + var position: Long? = null) : JSONable { + + companion object { + fun fromJSON(json: JSONObject): Location { + + val location = Location() + if (json.has("id")) { + location.id = json.getLong("id") + } + if (json.has("cfi")) { + location.cfi = json.getString("cfi") + } + if (json.has("cssSelector")) { + location.cssSelector = json.getString("cssSelector") + } + if (json.has("xpath")) { + location.xpath = json.getString("xpath") + } + if (json.has("progression")) { + location.progression = json.getDouble("progression") + } + if (json.has("position")) { + location.position = json.getLong("position") + } - fun toJson(): String{ - return Gson().toJson(this) + return location + } } - override fun getJSON(): JSONObject { + override fun toJSON(): JSONObject { val json = JSONObject() - json.putOpt("id", id) - if (cfi != null) { + + id?.let { + json.putOpt("id", id) + } + cfi?.let { json.putOpt("cfi", cfi) } - if (cssSelector != null) { + cssSelector?.let { json.putOpt("cssSelector", cssSelector) } - if (xpath != null) { + xpath?.let { json.putOpt("xpath", xpath) } - json.putOpt("progression", progression) - json.putOpt("position", position) + progression?.let { + json.putOpt("progression", progression) + } + position?.let { + json.putOpt("position", position) + } + return json } From 42474a8f6b807ed5a271d4f7aab85979a7c2a7bc Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Sat, 1 Sep 2018 19:18:49 -0400 Subject: [PATCH 25/52] moved test into test package --- .../r2/shared => test/java/org/readium/r2}/LocatorsUnitTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename r2-shared/src/{main/java/org/readium/r2/shared => test/java/org/readium/r2}/LocatorsUnitTest.kt (98%) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/LocatorsUnitTest.kt b/r2-shared/src/test/java/org/readium/r2/LocatorsUnitTest.kt similarity index 98% rename from r2-shared/src/main/java/org/readium/r2/shared/LocatorsUnitTest.kt rename to r2-shared/src/test/java/org/readium/r2/LocatorsUnitTest.kt index 80c916f0..1e420ee6 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/LocatorsUnitTest.kt +++ b/r2-shared/src/test/java/org/readium/r2/LocatorsUnitTest.kt @@ -7,7 +7,7 @@ * LICENSE file present in the project repository where this source code is maintained. */ -package org.readium.r2.shared +package org.readium.r2 import java.net.URI From 4bc6ab5ada3185c53b5831e473c77046851144ca Mon Sep 17 00:00:00 2001 From: Hrishikesh Kadam Date: Tue, 11 Sep 2018 20:46:32 +0530 Subject: [PATCH 26/52] Print nested childrens of TOC in manifest json --- r2-shared/src/main/java/org/readium/r2/shared/Link.kt | 4 +++- .../src/main/java/org/readium/r2/shared/Publication.kt | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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 2aa2e771..0ed2ba1a 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 @@ -55,12 +55,14 @@ class Link : JSONable, Serializable { json.putOpt("href", href) if (rel.isNotEmpty()) json.put("rel", getStringArray(rel)) - json.putOpt("properties", properties) + tryPut(json, properties, "properties") if (height != 0) json.putOpt("height", height) if (width != 0) json.putOpt("width", width) json.putOpt("duration", duration) + if (children.isNotEmpty()) + json.put("children", getJSONArray(children)) return json } 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 114e5e3d..d30631a4 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 @@ -44,6 +44,13 @@ fun tryPut(obj: JSONObject, list: List, tag: String) { obj.putOpt(tag, getJSONArray(list)) } +// Try to put class which implements JSONable only if not empty +fun tryPut(jsonObject: JSONObject, jsonable: JSONable, tag: String) { + val tempJsonObject = jsonable.getJSON() + if (tempJsonObject.length() != 0) + jsonObject.put(tag, tempJsonObject) +} + class TocElement(val link: Link, val children: List) : JSONable { override fun getJSON(): JSONObject { From cb25704ec60fba7be98cf766c07c9654d3c2b29d Mon Sep 17 00:00:00 2001 From: mostapha Date: Fri, 14 Sep 2018 16:16:36 +0200 Subject: [PATCH 27/52] fixed endDate type --- .../src/main/java/org/readium/r2/shared/drm/DrmLicense.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/drm/DrmLicense.kt b/r2-shared/src/main/java/org/readium/r2/shared/drm/DrmLicense.kt index ae40db69..2b02a5a4 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/drm/DrmLicense.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/drm/DrmLicense.kt @@ -9,6 +9,7 @@ package org.readium.r2.shared.drm +import org.joda.time.DateTime import java.io.Serializable import java.net.URL import java.util.* @@ -17,7 +18,7 @@ interface DrmLicense : Serializable { fun decipher(data: ByteArray): ByteArray? fun areRightsValid() fun register() - fun renewLicense (endDate: Date? = null, callback: (Any) -> Unit) + fun renewLicense (endDate: DateTime? = null, callback: (Any) -> Unit) fun returnLicense(callback: (Any) -> Unit) fun currentStatus(): String fun lastUpdate(): Date From 83785fb2940788021de1d0b9f90d5941dd164794 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Fri, 14 Sep 2018 17:25:52 +0200 Subject: [PATCH 28/52] contributor links processed as JSONArray --- .../main/java/org/readium/r2/shared/Contributor.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 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 4e519f19..cbff32ae 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 @@ -79,8 +79,15 @@ fun parseContributor(cDict: JSONObject): Contributor { c.roles.add(cDict.getString("role")) } if (cDict.has("links")) { - val linkDict = cDict.getJSONObject("links") - c.links.add(parseLink(linkDict)) + cDict.get("links")?.let { + val links = it as? JSONArray + ?: throw Exception() + for (i in 0..(links.length() - 1)) { + val linkDict = links.getJSONObject(i) + val link = parseLink(linkDict) + c.links.add(link) + } + } } return c } From 86bc2355f7ff74525205625b5e5f52e8f2ced768 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Fri, 14 Sep 2018 17:51:56 +0200 Subject: [PATCH 29/52] added String and Array case for subject --- .../java/org/readium/r2/shared/Metadata.kt | 47 +++++++++++++------ 1 file changed, 33 insertions(+), 14 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 20288e7e..de1b7433 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 @@ -155,24 +155,43 @@ fun parseMetadata(metadataDict: JSONObject): Metadata { m.rights = metadataDict.getString("rights") } if (metadataDict.has("subject")) { - val subjDict = metadataDict.getJSONArray("subject") - for (i in 0..(subjDict.length() - 1)) { - val sub = subjDict.getJSONObject(i) - val subject = Subject() - if (sub.has("name")) { - subject.name = sub.getString("name") - } - if (sub.has("sort_as")) { - subject.sortAs = sub.getString("sort_as") + val subjectDictUntyped = metadataDict.get("subject") + + when(subjectDictUntyped) { + is String -> { + val subject = Subject() + subject.name = subjectDictUntyped + m.subjects.add(subject) } - if (sub.has("scheme")) { - subject.scheme = sub.getString("scheme") + is Array<*> -> { + for(i in 0 until subjectDictUntyped.size - 1) { + val subject = Subject() + subject.name = subjectDictUntyped[i] as String + } } - if (sub.has("code")) { - subject.code = sub.getString("code") + is JSONArray -> { + val subjDict = metadataDict.getJSONArray("subject") + for (i in 0..(subjDict.length() - 1)) { + val sub = subjDict.getJSONObject(i) + val subject = Subject() + if (sub.has("name")) { + subject.name = sub.getString("name") + } + if (sub.has("sort_as")) { + subject.sortAs = sub.getString("sort_as") + } + if (sub.has("scheme")) { + subject.scheme = sub.getString("scheme") + } + if (sub.has("code")) { + subject.code = sub.getString("code") + } + m.subjects.add(subject) + } } - m.subjects.add(subject) } + + } if (metadataDict.has("belongs_to")) { val belongsDict = metadataDict.getJSONObject("belongs_to") From b20bd2c823d3e3f3a5ffcbaca3d20cce04a7fa2c Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Fri, 14 Sep 2018 17:58:01 +0200 Subject: [PATCH 30/52] forgot to add subject --- r2-shared/src/main/java/org/readium/r2/shared/Metadata.kt | 1 + 1 file changed, 1 insertion(+) 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 de1b7433..0b347f9d 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 @@ -167,6 +167,7 @@ fun parseMetadata(metadataDict: JSONObject): Metadata { for(i in 0 until subjectDictUntyped.size - 1) { val subject = Subject() subject.name = subjectDictUntyped[i] as String + m.subjects.add(subject) } } is JSONArray -> { From 50638dfb63d3858358624073b74dc232066a31e6 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Fri, 14 Sep 2018 17:59:44 +0200 Subject: [PATCH 31/52] added array of strings parsing to parseContributors --- .../src/main/java/org/readium/r2/shared/Contributor.kt | 7 +++++++ 1 file changed, 7 insertions(+) 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 cbff32ae..cc4c0595 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 @@ -44,6 +44,13 @@ fun parseContributors(contributors: Any): List { c.multilanguageName.singleString = contributors result.add(c) } + is Array<*> -> { + for(i in 0 until contributors.size - 1) { + val c = Contributor() + c.multilanguageName.singleString = contributors[i] as String + result.add(c) + } + } is JSONObject -> { val c = parseContributor(contributors) result.add(c) From 5309bc425f0093c1cdee8e53e4e1cde97ff3563a Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Mon, 17 Sep 2018 12:09:40 +0200 Subject: [PATCH 32/52] creating default object instead of throwing exception --- r2-shared/src/main/java/org/readium/r2/shared/Contributor.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 cc4c0595..aad9b4c2 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 @@ -88,7 +88,7 @@ fun parseContributor(cDict: JSONObject): Contributor { if (cDict.has("links")) { cDict.get("links")?.let { val links = it as? JSONArray - ?: throw Exception() + ?: JSONArray() for (i in 0..(links.length() - 1)) { val linkDict = links.getJSONObject(i) val link = parseLink(linkDict) From 8ad63827489b89b9c3c02b14f8b1b7b98cace670 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Thu, 20 Sep 2018 11:23:49 +0200 Subject: [PATCH 33/52] to be able to get rid of "/" --- 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 d30631a4..0b469542 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 @@ -149,7 +149,7 @@ class Publication : Serializable { return str } - fun resource(relativePath: String): Link? = (spine + resources).first { it.href == relativePath } + fun resource(relativePath: String): Link? = (spine + resources).first { (it.href == relativePath) || (it.href == "/$relativePath") } fun linkWithRel(rel: String): Link? { val findLinkWithRel: (Link) -> Boolean = { it.rel.contains(rel) } From ce2260fba0238dbc5f4e5bbbd3a08cd9f1856206 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Tue, 25 Sep 2018 15:10:23 +0200 Subject: [PATCH 34/52] renamed function --- 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 874c35bc..68efe627 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 @@ -46,7 +46,7 @@ fun tryPut(obj: JSONObject, list: List, tag: String) { // Try to put class which implements JSONable only if not empty fun tryPut(jsonObject: JSONObject, jsonable: JSONable, tag: String) { - val tempJsonObject = jsonable.getJSON() + val tempJsonObject = jsonable.toJSON() if (tempJsonObject.length() != 0) jsonObject.put(tag, tempJsonObject) } From 0af775da43f16694adb1dea0cb2d90d8c9ea1328 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Tue, 25 Sep 2018 15:58:31 +0200 Subject: [PATCH 35/52] refactored locators --- r2-shared/r2-shared.iml | 4 + .../java/org/readium/r2/shared/Locator.kt | 176 +++++++----------- 2 files changed, 74 insertions(+), 106 deletions(-) diff --git a/r2-shared/r2-shared.iml b/r2-shared/r2-shared.iml index ad7cc07a..2b0985e7 100644 --- a/r2-shared/r2-shared.iml +++ b/r2-shared/r2-shared.iml @@ -154,15 +154,19 @@ + + + + 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 bc8fdab7..b2eee662 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 @@ -29,106 +29,69 @@ import org.json.JSONObject * @fun toString(): String - Return a String description of the Locator */ -class Locator(val bookID: Long, - val publicationID: String, - val resourceIndex: Long, - val resourceHref: String, - val resourceTitle: String, - val location: Location, - var creationDate: Long = DateTime().toDate().time, - var id: Long? = null) { - - //TODO update this -// override fun toString(): String { -// return "Locator id : ${this.id}, book id : ${this.bookID}, resource href selected ${this.resourceHref}, progression saved ${this.location.progression} and created the ${this.creationDate}." -// } -} +open class Locator(val href:String, + val created:Long, + val title:String, + val locations:Locations, + val text:LocatorText?) {} + +class LocatorText(var after:String? = null, + var before:String? = null, + var hightlight:String? = null) + : JSONable { + + companion object { + fun fromJSON(json: JSONObject): LocatorText { + + val location = LocatorText() + if (json.has("before")) { + location.before = json.getString("before") + } + if (json.has("hightlight")) { + location.hightlight = json.getString("hightlight") + } + if (json.has("after")) { + location.after = json.getString("after") + } + + return location + } + } + + override fun toJSON(): JSONObject { + val json = JSONObject() + + before?.let { + json.putOpt("before", before) + } + hightlight?.let { + json.putOpt("hightlight", hightlight) + } + after?.let { + json.putOpt("after", after) + } + return json + } + + override fun toString(): String { + var jsonString = """{""" + + if (before != null) { + before.let { jsonString += """ "before": "$before" ,""" } + } + if (hightlight != null) { + hightlight.let { jsonString += """ "before": "$hightlight" ,""" } + } + if (after != null) { + after.let { jsonString += """ "after": "$after" ,""" } + } + jsonString += """}""" + return jsonString + } +} -///** -// * Locator : That class is used to define a precise location in a Publication -// * -// * @var publicationId: String - Identifier of a Publication -// * @var spineIndex: Long - Index of a spine element -// * @var resourceHref: String? - ( Optional ) String reference to the spine element -// * @var title: String - Title of the spine element -// * -// * @var location: Location - List of objects used to locate the target -// * @var created: DateTime - Date when the Locator has been created -// * -// * @var text: LocatorText? - ( Optional ) Describe the Locator's context -// * -// */ -//open class Locator(val publicationId: String, -// val spineIndex: Long?, -// open val resourceHref: String, -// val title: String, -// val location: Location? = null): JSONable { -// -// var created = DateTime.now().toDate().time -// var text = LocatorText(null, null, null) -// -// fun toJson(): String{ -// return Gson().toJson(this) -// } -// -// override fun toJSON(): JSONObject { -// val json = JSONObject() -// json.putOpt("href", resourceHref) -// json.putOpt("title", title) -// json.putOpt("created", created) -// json.putOpt("location", location.toString()) -// json.putOpt("text", text) -// return json -// } -// -// override fun toString(): String{ -// return """{ "href": "$resourceHref", "title": "$title", "created": "$created", "locations" : $location "text" : "$text" """ -// } -// -// fun setText(before: String? = null, highlight: String? = null, after: String? = null){ -// text.before = before -// text.highlight = highlight -// text.after = after -// } -// -// inner class LocatorText(var before: String?, var highlight: String?, var after: String?): JSONable{ -// -// fun toJson(): String{ -// return Gson().toJson(this) -// } -// -// override fun toJSON(): JSONObject { -// val json = JSONObject() -// json.putOpt("before", before) -// json.putOpt("highlight", highlight) -// json.putOpt("after", after) -// return json -// } -// -// override fun toString(): String{ -// var jsonString = """{""" -// if (before != null) { -// before.let { jsonString += """ "before": "$before" """ } -// if (highlight != null) { -// jsonString += """,""" -// } -// } -// if (highlight != null) { -// highlight.let { jsonString += """ "highlight": "$highlight" """ } -// if (after != null) { -// jsonString += """,""" -// } -// } -// if (after != null) { -// after.let { jsonString += """ "after": "$after" """ } -// } -// jsonString += """}""" -// return jsonString -// } -// } -//} /** * Location : Class that contain the different variables needed to localize a particular position @@ -138,20 +101,21 @@ class Locator(val bookID: Long, * @var cssSelector: String? - Css selector * @var xpath: String? - An xpath in the resource * @var progression: Double - A percentage ( between 0 and 1 ) of the progression in a Publication - * @var position: Long - Index of a segment in the resource + * @var position: Long - Index of a segment in the resource / synthetic page number!!?? * */ -class Location(var id: Long? = null, - var cfi: String? = null, - var cssSelector: String? = null, - var xpath: String? = null, - var progression: Double? = null, - var position: Long? = null) : JSONable { +class Locations(var id: Long? = null, + var cfi: String? = null, // 1 = highlight, annotation etc = priority 3 + var cssSelector: String? = null, // 2 = + var xpath: String? = null, // 2 = + var progression: Double? = null, // 3 = bookmark = priority 1 (done) + var position: Long? = null // 4 = got page = priority 2 +) : JSONable { companion object { - fun fromJSON(json: JSONObject): Location { + fun fromJSON(json: JSONObject): Locations { - val location = Location() + val location = Locations() if (json.has("id")) { location.id = json.getLong("id") } From 64c372b6e5a87a01e49cbe2b23cbde19c18d31ea Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Wed, 26 Sep 2018 12:50:33 +0200 Subject: [PATCH 36/52] added computation of the style that should be used --- .../java/org/readium/r2/shared/Metadata.kt | 20 +++++++++++++++++++ 1 file changed, 20 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 0b347f9d..b44c6a0d 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 @@ -84,6 +84,26 @@ class Metadata : Serializable { return obj } + + fun contentLayoutStyle(langType: LangType, pageDirection: String?) : ContentLayoutStyle { + + when(langType) { + LangType.afh -> return ContentLayoutStyle.rtl + LangType.cjk -> { + if (pageDirection == ContentLayoutStyle.rtl.name) + return ContentLayoutStyle.cjkv + else + return ContentLayoutStyle.cjkh + } + else -> { + if (pageDirection == ContentLayoutStyle.rtl.name) + return ContentLayoutStyle.rtl + else + return ContentLayoutStyle.ltr + } + } + } + } fun parseMetadata(metadataDict: JSONObject): Metadata { From 11d191f2be3db2f63005f851e08f6ba42d3e6d03 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Wed, 26 Sep 2018 12:51:18 +0200 Subject: [PATCH 37/52] enum classes for css use --- .../java/org/readium/r2/shared/Metadata.kt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 b44c6a0d..26ad5341 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 @@ -37,7 +37,7 @@ class Metadata : Serializable { var inkers: MutableList = mutableListOf() var narrators: MutableList = mutableListOf() var imprints: MutableList = mutableListOf() - var direction: String = "default" + var direction: String = PageProgressionDirection.default.name var subjects: MutableList = mutableListOf() var publishers: MutableList = mutableListOf() var contributors: MutableList = mutableListOf() @@ -263,3 +263,19 @@ fun parseMetadata(metadataDict: JSONObject): Metadata { return m } + +enum class LangType { + cjk, afh, other +} + + +enum class PageProgressionDirection { + default, + ltr, + rtl +} + +enum class ContentLayoutStyle { + ltr, rtl, + cjkv, cjkh +} \ No newline at end of file From 1fd396fdaf9c92b0a9f87a4becbf46884c920bf2 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Wed, 17 Oct 2018 12:09:37 +0200 Subject: [PATCH 38/52] completed publication parsing --- .../java/org/readium/r2/shared/Publication.kt | 96 ++++++++++++++++++- 1 file changed, 95 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 68efe627..00300153 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 @@ -88,7 +88,8 @@ class Publication : Serializable { enum class EXTENSION(var value: String) { EPUB(".epub"), - CBZ(".cbz"); + CBZ(".cbz"), + JSON(".json"); companion object : EnumCompanion(EXTENSION.values().associateBy(EXTENSION::value)) } @@ -199,6 +200,7 @@ fun parsePublication(pubDict: JSONObject): Publication { } } + if (pubDict.has("links")) { pubDict.get("links")?.let { val links = it as? JSONArray @@ -210,6 +212,7 @@ fun parsePublication(pubDict: JSONObject): Publication { } } } + if (pubDict.has("images")) { pubDict.get("images")?.let { val links = it as? JSONArray @@ -221,5 +224,96 @@ fun parsePublication(pubDict: JSONObject): Publication { } } } + + if (pubDict.has("spine")) { + pubDict.get("spine")?.let { + val spine = it as? JSONArray + ?: throw Exception(Publication.PublicationError.InvalidPublication.name) + for (i in 0..(spine.length() - 1)) { + val linkDict = spine.getJSONObject(i) + val link = parseLink(linkDict) + p.spine.add(link) + } + } + } + + if (pubDict.has("readingOrder")) { + pubDict.get("readingOrder")?.let { + val readingOrder = it as? JSONArray + ?: throw Exception(Publication.PublicationError.InvalidPublication.name) + for (i in 0..(readingOrder.length() - 1)) { + val linkDict = readingOrder.getJSONObject(i) + val link = parseLink(linkDict) + p.spine.add(link) + } + } + } + + if (pubDict.has("resources")) { + pubDict.get("resources")?.let { + val resources = it as? JSONArray + ?: throw Exception(Publication.PublicationError.InvalidPublication.name) + for (i in 0..(resources.length() - 1)) { + val linkDict = resources.getJSONObject(i) + val link = parseLink(linkDict) + p.resources.add(link) + } + } + } + +// if (pubDict.has("toc")) { +// pubDict.get("toc")?.let { +// val toc = it as? JSONArray +// ?: throw Exception(Publication.PublicationError.InvalidPublication.name) +// for (i in 0..(toc.length() - 1)) { +// val linkDict = toc.getJSONObject(i) +// val link = parseLink(linkDict) +// p.tableOfContents.add(link) +// } +// } +// } + + if (pubDict.has("page-list")) { + pubDict.get("page-list")?.let { + val pageList = it as? JSONArray + ?: throw Exception(Publication.PublicationError.InvalidPublication.name) + for (i in 0..(pageList.length() - 1)) { + val linkDict = pageList.getJSONObject(i) + val link = parseLink(linkDict) + p.pageList.add(link) + } + } + } + + if (pubDict.has("landmarks")) { + pubDict.get("landmarks")?.let { + val landmarks = it as? JSONArray + ?: throw Exception(Publication.PublicationError.InvalidPublication.name) + for (i in 0..(landmarks.length() - 1)) { + val linkDict = landmarks.getJSONObject(i) + val link = parseLink(linkDict) + p.landmarks.add(link) + } + } + } + + +// var coverLink: Link? = null + +// /// The kind of publication it is ( Epub, Cbz, ... ) +// var type = Publication.TYPE.EPUB +// /// The version of the publication, if the type needs any. +// var version: Double = 0.0 + +// var listOfAudioFiles: MutableList = mutableListOf() +// var listOfIllustrations: MutableList = mutableListOf() +// var listOfTables: MutableList = mutableListOf() +// var listOfVideos: MutableList = mutableListOf() + +// /// Extension point for links that shouldn't show up in the manifest. +// var otherLinks: MutableList = mutableListOf() +// var internalData: MutableMap = mutableMapOf() +// + return p } From b506187d90af6944d6cf81e7c2896ceabf2012d9 Mon Sep 17 00:00:00 2001 From: Hrishikesh Kadam Date: Fri, 19 Oct 2018 20:37:33 +0530 Subject: [PATCH 39/52] Make Locator Serializable --- .../java/org/readium/r2/shared/Locator.kt | 133 ++++++++---------- 1 file changed, 62 insertions(+), 71 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 b2eee662..bff9f10f 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 @@ -9,89 +9,80 @@ package org.readium.r2.shared -import org.joda.time.DateTime import org.json.JSONObject - - +import java.io.Serializable /** - * Locator model + * Locator model - https://github.com/readium/architecture/tree/master/locators * - * @var bookId: Long? - Book index in the database - * @val publicationID: String - Publication identifier - * @val resourceIndex: Long - Index to the spine element of the book - * @val resourceHref: String - Reference to the spine element - * @val resourceTitle: String - Title to the spine element of the book - * @val location: Location - Location in the spine element - * @val creationDate: Long - Datetime when the bookmark has been created - * @var id: Long? - ID of the bookmark in database - * - * @fun toString(): String - Return a String description of the Locator + * @val href: String - The href of the resource the locator points at. + * @val created: Long - The datetime of creation of the locator. + * @val title: String - The title of the chapter or section which is more relevant in the context of this locator. + * @val location: Location - One or more alternative expressions of the location. + * @val text: LocatorText? - Textual context of the locator. */ +open class Locator(val href: String, + val created: Long, + val title: String, + val locations: Locations, + val text: LocatorText?) : Serializable -open class Locator(val href:String, - val created:Long, - val title:String, - val locations:Locations, - val text:LocatorText?) {} - -class LocatorText(var after:String? = null, - var before:String? = null, - var hightlight:String? = null) - : JSONable { - - companion object { - fun fromJSON(json: JSONObject): LocatorText { - - val location = LocatorText() - if (json.has("before")) { - location.before = json.getString("before") - } - if (json.has("hightlight")) { - location.hightlight = json.getString("hightlight") - } - if (json.has("after")) { - location.after = json.getString("after") - } - - return location - } - } +class LocatorText(var after: String? = null, + var before: String? = null, + var hightlight: String? = null) + : JSONable, Serializable { - override fun toJSON(): JSONObject { - val json = JSONObject() + companion object { + fun fromJSON(json: JSONObject): LocatorText { - before?.let { - json.putOpt("before", before) + val location = LocatorText() + if (json.has("before")) { + location.before = json.getString("before") } - hightlight?.let { - json.putOpt("hightlight", hightlight) + if (json.has("hightlight")) { + location.hightlight = json.getString("hightlight") } - after?.let { - json.putOpt("after", after) + if (json.has("after")) { + location.after = json.getString("after") } - return json + return location } + } - override fun toString(): String { - var jsonString = """{""" + override fun toJSON(): JSONObject { + val json = JSONObject() - if (before != null) { - before.let { jsonString += """ "before": "$before" ,""" } - } - if (hightlight != null) { - hightlight.let { jsonString += """ "before": "$hightlight" ,""" } - } - if (after != null) { - after.let { jsonString += """ "after": "$after" ,""" } - } - jsonString += """}""" - return jsonString + before?.let { + json.putOpt("before", before) } -} + hightlight?.let { + json.putOpt("hightlight", hightlight) + } + after?.let { + json.putOpt("after", after) + } + + return json + } + + override fun toString(): String { + var jsonString = """{""" + if (before != null) { + before.let { jsonString += """ "before": "$before" ,""" } + } + if (hightlight != null) { + hightlight.let { jsonString += """ "before": "$hightlight" ,""" } + } + if (after != null) { + after.let { jsonString += """ "after": "$after" ,""" } + } + jsonString += """}""" + return jsonString + } +} /** * Location : Class that contain the different variables needed to localize a particular position @@ -105,12 +96,12 @@ class LocatorText(var after:String? = null, * */ class Locations(var id: Long? = null, - var cfi: String? = null, // 1 = highlight, annotation etc = priority 3 - var cssSelector: String? = null, // 2 = - var xpath: String? = null, // 2 = - var progression: Double? = null, // 3 = bookmark = priority 1 (done) - var position: Long? = null // 4 = got page = priority 2 -) : JSONable { + var cfi: String? = null, // 1 = highlight, annotation etc = priority 3 + var cssSelector: String? = null, // 2 = + var xpath: String? = null, // 2 = + var progression: Double? = null, // 3 = bookmark = priority 1 (done) + var position: Long? = null // 4 = got page = priority 2 +) : JSONable, Serializable { companion object { fun fromJSON(json: JSONObject): Locations { From dbc29c0fa1e94ca4666cea27f1ebe7846fb309b0 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Mon, 22 Oct 2018 15:14:29 +0200 Subject: [PATCH 40/52] fixed default rendition mode --- .../src/main/java/org/readium/r2/shared/Publication.kt | 6 +++++- 1 file changed, 5 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 00300153..58c2bf61 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 @@ -196,8 +196,12 @@ fun parsePublication(pubDict: JSONObject): Publication { val metadataDict = it as? JSONObject ?: throw Exception(Publication.PublicationError.InvalidPublication.name) val metadata = parseMetadata(metadataDict) - p.metadata = metadata + if (metadata.rendition.isEmpty()) { + metadata.rendition.layout = RenditionLayout.Reflowable + } + + p.metadata = metadata } } From 41fe5d264de7862000d94dcf13fd4c49a6d49891 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Mon, 22 Oct 2018 15:15:12 +0200 Subject: [PATCH 41/52] fixed cast exception when discovering children in json --- .../main/java/org/readium/r2/shared/Link.kt | 18 +++++++++++---- .../java/org/readium/r2/shared/Publication.kt | 22 +++++++++---------- 2 files changed, 25 insertions(+), 15 deletions(-) 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 04209ab8..fa0783b9 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 @@ -137,10 +137,20 @@ fun parseLink(linkDict: JSONObject, feedUrl: URL? = null): Link { } } if (linkDict.has("children")) { - val childLinkDict = linkDict.getJSONObject("children") - ?: throw Exception(LinkError.InvalidLink.name) - val childLink = parseLink(childLinkDict) - link.children.add(childLink) +// val childLinkDict = linkDict.getJSONObject("children") +// ?: throw Exception(LinkError.InvalidLink.name) +// val childLink = parseLink(childLinkDict) +// link.children.add(childLink) + + linkDict.get("children")?.let { + val children = it as? JSONArray + ?: throw Exception(LinkError.InvalidLink.name) + for (i in 0..(children.length() - 1)) { + val childLinkDict = children.getJSONObject(i) + val childLink = parseLink(childLinkDict) + link.children.add(childLink) + } + } } return link } 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 58c2bf61..adc4e051 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 @@ -265,17 +265,17 @@ fun parsePublication(pubDict: JSONObject): Publication { } } -// if (pubDict.has("toc")) { -// pubDict.get("toc")?.let { -// val toc = it as? JSONArray -// ?: throw Exception(Publication.PublicationError.InvalidPublication.name) -// for (i in 0..(toc.length() - 1)) { -// val linkDict = toc.getJSONObject(i) -// val link = parseLink(linkDict) -// p.tableOfContents.add(link) -// } -// } -// } + if (pubDict.has("toc")) { + pubDict.get("toc")?.let { + val toc = it as? JSONArray + ?: throw Exception(Publication.PublicationError.InvalidPublication.name) + for (i in 0..(toc.length() - 1)) { + val linkDict = toc.getJSONObject(i) + val link = parseLink(linkDict) + p.tableOfContents.add(link) + } + } + } if (pubDict.has("page-list")) { pubDict.get("page-list")?.let { From 4432e91c8a5a450d3247f856037fc6668eb5d733 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Tue, 23 Oct 2018 07:03:27 -0400 Subject: [PATCH 42/52] minor fix --- r2-shared/src/main/java/org/readium/r2/shared/Locator.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 bff9f10f..c149b0b2 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 @@ -95,12 +95,12 @@ class LocatorText(var after: String? = null, * @var position: Long - Index of a segment in the resource / synthetic page number!!?? * */ -class Locations(var id: Long? = null, - var cfi: String? = null, // 1 = highlight, annotation etc = priority 3 +class Locations(var cfi: String? = null, // 1 = highlight, annotation etc + var id: Long? = null, // 2 = fragment identifier (toc, page lists, landmarks) var cssSelector: String? = null, // 2 = var xpath: String? = null, // 2 = - var progression: Double? = null, // 3 = bookmark = priority 1 (done) - var position: Long? = null // 4 = got page = priority 2 + var progression: Double? = null, // 3 = bookmarks + var position: Long? = null // 4 = goto page ) : JSONable, Serializable { companion object { From 6a00295b7ce609d084a4b56733af77f47c2ef585 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Tue, 23 Oct 2018 17:46:54 +0200 Subject: [PATCH 43/52] added publications types for later use --- 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 adc4e051..29e2e5bc 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 @@ -79,7 +79,7 @@ class Publication : Serializable { * */ enum class TYPE { - EPUB, CBZ, FXL + EPUB, CBZ, FXL, WEBPUB, AUDIO } open class EnumCompanion(private val valueMap: Map) { From 4c4e1ac4356b3bf72d72dec3b5b575b1ed4572f4 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Tue, 23 Oct 2018 17:47:18 +0200 Subject: [PATCH 44/52] added coverLink retrieve --- r2-shared/src/main/java/org/readium/r2/shared/Publication.kt | 4 ++++ 1 file changed, 4 insertions(+) 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 29e2e5bc..aee8007f 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 @@ -301,6 +301,10 @@ fun parsePublication(pubDict: JSONObject): Publication { } } + p.linkWithRel("cover")?.let { + p.coverLink = it + } + // var coverLink: Link? = null From 4977c9984fcf8f778d932ebddb30ac3c9bf4ca7b Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Tue, 23 Oct 2018 18:16:15 -0400 Subject: [PATCH 45/52] id should be string not Long --- r2-shared/src/main/java/org/readium/r2/shared/Locator.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 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 c149b0b2..e8b150cd 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 @@ -96,7 +96,7 @@ class LocatorText(var after: String? = null, * */ class Locations(var cfi: String? = null, // 1 = highlight, annotation etc - var id: Long? = null, // 2 = fragment identifier (toc, page lists, landmarks) + var id: String? = null, // 2 = fragment identifier (toc, page lists, landmarks) var cssSelector: String? = null, // 2 = var xpath: String? = null, // 2 = var progression: Double? = null, // 3 = bookmarks @@ -108,7 +108,7 @@ class Locations(var cfi: String? = null, // 1 = highlight, annotatio val location = Locations() if (json.has("id")) { - location.id = json.getLong("id") + location.id = json.getString("id") } if (json.has("cfi")) { location.cfi = json.getString("cfi") From 528ba5bb5c86596a137366162983313e00be4a19 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Wed, 24 Oct 2018 16:19:32 +0200 Subject: [PATCH 46/52] added publication type when parsing --- .../src/main/java/org/readium/r2/shared/Publication.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 aee8007f..4bf93410 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 @@ -305,11 +305,12 @@ fun parsePublication(pubDict: JSONObject): Publication { p.coverLink = it } + p.linkWithRel("self")?.let { + if (it.typeLink == "application/webpub+json") p.type = Publication.TYPE.WEBPUB + if (it.typeLink == "application/audiobook+json") p.type = Publication.TYPE.AUDIO + } -// var coverLink: Link? = null -// /// The kind of publication it is ( Epub, Cbz, ... ) -// var type = Publication.TYPE.EPUB // /// The version of the publication, if the type needs any. // var version: Double = 0.0 @@ -321,7 +322,6 @@ fun parsePublication(pubDict: JSONObject): Publication { // /// Extension point for links that shouldn't show up in the manifest. // var otherLinks: MutableList = mutableListOf() // var internalData: MutableMap = mutableMapOf() -// return p } From 0fef45d03ba2b69521d56e688510f7e216932f86 Mon Sep 17 00:00:00 2001 From: Aferdita Date: Wed, 31 Oct 2018 10:23:33 -0400 Subject: [PATCH 47/52] Update Link.kt remove commented out code --- r2-shared/src/main/java/org/readium/r2/shared/Link.kt | 5 ----- 1 file changed, 5 deletions(-) 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 fa0783b9..e6f7d834 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 @@ -137,11 +137,6 @@ fun parseLink(linkDict: JSONObject, feedUrl: URL? = null): Link { } } if (linkDict.has("children")) { -// val childLinkDict = linkDict.getJSONObject("children") -// ?: throw Exception(LinkError.InvalidLink.name) -// val childLink = parseLink(childLinkDict) -// link.children.add(childLink) - linkDict.get("children")?.let { val children = it as? JSONArray ?: throw Exception(LinkError.InvalidLink.name) From fcb447a62fa34027e973238c5b2295843ceaea7c Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Wed, 14 Nov 2018 21:35:22 -0500 Subject: [PATCH 48/52] added function to normalize hrefs --- .../java/org/readium/r2/shared/URLHelper.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/r2-shared/src/main/java/org/readium/r2/shared/URLHelper.kt b/r2-shared/src/main/java/org/readium/r2/shared/URLHelper.kt index 36b98ef5..cfb9d14c 100644 --- a/r2-shared/src/main/java/org/readium/r2/shared/URLHelper.kt +++ b/r2-shared/src/main/java/org/readium/r2/shared/URLHelper.kt @@ -16,3 +16,29 @@ fun getAbsolute(href: String, base: String): String { val relative = baseURI.resolve(href) return relative.toString() } + + +internal fun normalize(base: String, in_href: String?) : String { + val href = in_href + if (href == null || href.isEmpty()) { + return "" + } + val hrefComponents = href.split( "/").filter({ !it.isEmpty() }) + var baseComponents = base.split( "/").filter({ !it.isEmpty() }) + baseComponents.dropLast(1) + + val replacementsNumber = hrefComponents.filter({ it == ".." }).count() + var normalizedComponents = hrefComponents.filter({ it != ".." }) + for (e in 0 until replacementsNumber) { + baseComponents.dropLast(1) + } + normalizedComponents = baseComponents + normalizedComponents + var normalizedString = "" + for (component in normalizedComponents) { + normalizedString += "/${component}" + } + return normalizedString +} + + + From 037893c5f12dffa7be236bceffa7939f9b1bdc01 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Thu, 15 Nov 2018 18:24:25 +0100 Subject: [PATCH 49/52] added presets management --- .../java/org/readium/r2/shared/Metadata.kt | 10 +++++-- .../java/org/readium/r2/shared/Publication.kt | 28 +++++++++++++++++++ 2 files changed, 36 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 26ad5341..065948ea 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 @@ -276,6 +276,12 @@ enum class PageProgressionDirection { } enum class ContentLayoutStyle { - ltr, rtl, - cjkv, cjkh + ltr, + rtl, + cjkv, + cjkh; + + companion object { + fun layout(name: String): ContentLayoutStyle = ContentLayoutStyle.valueOf(name) + } } \ No newline at end of file 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 4bf93410..ad0dc508 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 @@ -121,6 +121,8 @@ class Publication : Serializable { var otherLinks: MutableList = mutableListOf() var internalData: MutableMap = mutableMapOf() + var userSettingsUIPreset: MutableMap = mutableMapOf() + var coverLink: Link? = null get() = linkWithRel("cover") @@ -184,6 +186,32 @@ class Publication : Serializable { } +// List of strings that can identify the name of a CSS custom property +// Also used for storing UserSettings in UserDefaults +enum class ReadiumCSSName(val ref: String) { + fontSize("--USER__fontSize"), + fontFamily("--USER__fontFamily"), + fontOverride("--USER__fontOverride"), + appearance("--USER__appearance"), + scroll("--USER__scroll"), + publisherDefault("--USER__advancedSettings"), + textAlignment("--USER__textAlign"), + columnCount("--USER__colCount"), + wordSpacing("--USER__wordSpacing"), + letterSpacing("--USER__letterSpacing"), + pageMargins("--USER__pageMargins"), + lineHeight("--USER__lineHeight"), + paraIndent("--USER__paraIndent"), + hyphens("--USER__bodyHyphens"), + ligatures("--USER__ligatures"); + + companion object { + fun ref(name: String): ReadiumCSSName = ReadiumCSSName.valueOf(name) + } + +} + + /** * Parse a JSON dictionary of extra information into a publication * From 7442c41d384fe5c4087ccf0d29402fe0ea796824 Mon Sep 17 00:00:00 2001 From: Paul Stoica Date: Fri, 16 Nov 2018 11:06:10 +0100 Subject: [PATCH 50/52] added cssStyle field, needed for presets & direction (ltr, rtl, etc.) --- r2-shared/src/main/java/org/readium/r2/shared/Publication.kt | 2 ++ 1 file changed, 2 insertions(+) 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 ad0dc508..e9255db8 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 @@ -123,6 +123,8 @@ class Publication : Serializable { var userSettingsUIPreset: MutableMap = mutableMapOf() + var cssStyle: String? = null + var coverLink: Link? = null get() = linkWithRel("cover") From bdba21f75f569d9374b6546a3417b0db57617fa4 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Sun, 25 Nov 2018 17:24:35 +0100 Subject: [PATCH 51/52] added comments --- r2-shared/src/main/java/org/readium/r2/shared/Publication.kt | 3 +++ 1 file changed, 3 insertions(+) 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 4bf93410..49ac78a3 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 @@ -78,6 +78,8 @@ class Publication : Serializable { * use it to check the type on your implementation * */ + + // Navigator Type enum class TYPE { EPUB, CBZ, FXL, WEBPUB, AUDIO } @@ -86,6 +88,7 @@ class Publication : Serializable { fun fromString(type: T) = valueMap[type] } + // Parser Type enum class EXTENSION(var value: String) { EPUB(".epub"), CBZ(".cbz"), From 3eb39daf209b0ef992bbca173f53c369d9438b3b Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Sun, 25 Nov 2018 17:50:14 +0100 Subject: [PATCH 52/52] moved enum into separate kotlin file --- .../java/org/readium/r2/shared/Publication.kt | 25 -------- .../java/org/readium/r2/shared/ReadiumCSS.kt | 58 +++++++++++++++++++ 2 files changed, 58 insertions(+), 25 deletions(-) create mode 100644 r2-shared/src/main/java/org/readium/r2/shared/ReadiumCSS.kt 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 0d9b5475..f22ba431 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 @@ -191,31 +191,6 @@ class Publication : Serializable { } -// List of strings that can identify the name of a CSS custom property -// Also used for storing UserSettings in UserDefaults -enum class ReadiumCSSName(val ref: String) { - fontSize("--USER__fontSize"), - fontFamily("--USER__fontFamily"), - fontOverride("--USER__fontOverride"), - appearance("--USER__appearance"), - scroll("--USER__scroll"), - publisherDefault("--USER__advancedSettings"), - textAlignment("--USER__textAlign"), - columnCount("--USER__colCount"), - wordSpacing("--USER__wordSpacing"), - letterSpacing("--USER__letterSpacing"), - pageMargins("--USER__pageMargins"), - lineHeight("--USER__lineHeight"), - paraIndent("--USER__paraIndent"), - hyphens("--USER__bodyHyphens"), - ligatures("--USER__ligatures"); - - companion object { - fun ref(name: String): ReadiumCSSName = ReadiumCSSName.valueOf(name) - } - -} - /** * Parse a JSON dictionary of extra information into a publication diff --git a/r2-shared/src/main/java/org/readium/r2/shared/ReadiumCSS.kt b/r2-shared/src/main/java/org/readium/r2/shared/ReadiumCSS.kt new file mode 100644 index 00000000..cc83e6d0 --- /dev/null +++ b/r2-shared/src/main/java/org/readium/r2/shared/ReadiumCSS.kt @@ -0,0 +1,58 @@ +package org.readium.r2.shared + + + +const val FONT_SIZE_REF = "fontSize" +const val FONT_FAMILY_REF = "fontFamily" +const val FONT_OVERRIDE_REF = "fontOverride" +const val APPEARANCE_REF = "appearance" +const val SCROLL_REF = "scroll" +const val PUBLISHER_DEFAULT_REF = "advancedSettings" +const val TEXT_ALIGNMENT_REF = "textAlign" +const val COLUMN_COUNT_REF = "colCount" +const val WORD_SPACING_REF = "wordSpacing" +const val LETTER_SPACING_REF = "letterSpacing" +const val PAGE_MARGINS_REF = "pageMargins" +const val LINE_HEIGHT_REF = "lineHeight" + +const val FONT_SIZE_NAME = "--USER__$FONT_SIZE_REF" +const val FONT_FAMILY_NAME = "--USER__$FONT_FAMILY_REF" +const val FONT_OVERRIDE_NAME = "--USER__$FONT_OVERRIDE_REF" +const val APPEARANCE_NAME = "--USER__$APPEARANCE_REF" +const val SCROLL_NAME = "--USER__$SCROLL_REF" +const val PUBLISHER_DEFAULT_NAME = "--USER__$PUBLISHER_DEFAULT_REF" +const val TEXT_ALIGNMENT_NAME = "--USER__$TEXT_ALIGNMENT_REF" +const val COLUMN_COUNT_NAME = "--USER__$COLUMN_COUNT_REF" +const val WORD_SPACING_NAME = "--USER__$WORD_SPACING_REF" +const val LETTER_SPACING_NAME = "--USER__$LETTER_SPACING_REF" +const val PAGE_MARGINS_NAME = "--USER__$PAGE_MARGINS_REF" +const val LINE_HEIGHT_NAME = "--USER__$LINE_HEIGHT_REF" + + + +// List of strings that can identify the name of a CSS custom property +// Also used for storing UserSettings in UserDefaults +enum class ReadiumCSSName(val ref: String) { + fontSize("--USER__fontSize"), + fontFamily("--USER__fontFamily"), + fontOverride("--USER__fontOverride"), + appearance("--USER__appearance"), + scroll("--USER__scroll"), + publisherDefault("--USER__advancedSettings"), + textAlignment("--USER__textAlign"), + columnCount("--USER__colCount"), + wordSpacing("--USER__wordSpacing"), + letterSpacing("--USER__letterSpacing"), + pageMargins("--USER__pageMargins"), + lineHeight("--USER__lineHeight"), + paraIndent("--USER__paraIndent"), + hyphens("--USER__bodyHyphens"), + ligatures("--USER__ligatures"); + + companion object { + fun ref(name: String): ReadiumCSSName = ReadiumCSSName.valueOf(name) + } + +} + +