Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #83 from readium/develop
Browse files Browse the repository at this point in the history
1.1.16
  • Loading branch information
aferditamuriqi authored Jan 11, 2020
2 parents 5a62331 + 577fc67 commit 0b1d597
Show file tree
Hide file tree
Showing 14 changed files with 272 additions and 380 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @aferditamuriqi
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.31'
ext.r2branch = 'develop'
ext.kotlin_version = '1.3.61'

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
// NOTE: Do not place your application dependencies here; they belong
Expand Down
30 changes: 8 additions & 22 deletions r2-shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,33 @@ apply plugin: 'com.github.dcendents.android-maven'
group='com.github.readium'

android {
flavorDimensions "testapp"

compileSdkVersion 28
compileSdkVersion 29
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
targetSdkVersion 29

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
intTestapp {
dimension "testapp"
}
intTestappWithLcp {
dimension "testapp"
}
devTestapp {
dimension "testapp"
}
devTestappWithLcp {
dimension "testapp"
}
}

// default build flavour
defaultPublishConfig "intTestappDebug"
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation "androidx.appcompat:appcompat:1.1.0-beta01"
implementation 'com.google.code.gson:gson:2.8.2'
implementation "androidx.appcompat:appcompat:1.2.0-alpha01"
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.github.kittinunf.fuel:fuel:1.16.0'
implementation 'com.github.kittinunf.fuel:fuel-android:1.16.0'
implementation 'nl.komponents.kovenant:kovenant:3.3.0'
Expand Down
252 changes: 0 additions & 252 deletions r2-shared/r2-shared.iml

This file was deleted.

16 changes: 8 additions & 8 deletions r2-shared/src/main/java/org/readium/r2/shared/Contributor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ fun parseContributor(cDict: JSONObject): Contributor {
c.roles.add(cDict.getString("role"))
}
if (cDict.has("links")) {
cDict.get("links")?.let {
val links = it as? JSONArray
?: JSONArray()
for (i in 0 until links.length()) {
val linkDict = links.getJSONObject(i)
val link = parseLink(linkDict)
c.links.add(link)
cDict.get("links").let {
val links = it as? JSONArray
?: JSONArray()
for (i in 0 until links.length()) {
val linkDict = links.getJSONObject(i)
val link = parseLink(linkDict)
c.links.add(link)
}
}
}
}
return c
}
22 changes: 22 additions & 0 deletions r2-shared/src/main/java/org/readium/r2/shared/InjectableType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Module: r2-shared-kotlin
* Developers: Aferdita Muriqi
*
* Copyright (c) 2019. Readium Foundation. All rights reserved.
* Use of this source code is governed by a BSD-Style license which is detailed in the
* LICENSE file present in the project repository where this source code is maintained.
*/

package org.readium.r2.shared

import java.io.Serializable

enum class Injectable(val rawValue: String): Serializable {
Script("scripts"),
Font("fonts"),
Style("styles");

companion object {
operator fun invoke(rawValue: String) = values().firstOrNull { it.rawValue == rawValue }
}
}
6 changes: 3 additions & 3 deletions r2-shared/src/main/java/org/readium/r2/shared/Link.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ fun parseLink(linkDict: JSONObject, feedUrl: URL? = null): Link {
}
if (linkDict.has("href")) {
feedUrl?.let {
link.href = getAbsolute(linkDict.getString("href")!!, feedUrl.toString())
link.href = getAbsolute(linkDict.getString("href"), feedUrl.toString())
} ?: run {
link.href = linkDict.getString("href")!!
link.href = linkDict.getString("href")
}
}
if (linkDict.has("type")) {
Expand Down Expand Up @@ -138,7 +138,7 @@ fun parseLink(linkDict: JSONObject, feedUrl: URL? = null): Link {
link.properties = properties
}
if (linkDict.has("children")) {
linkDict.get("children")?.let {
linkDict.get("children").let {
val children = it as? JSONArray
?: throw Exception(LinkError.InvalidLink.name)
for (i in 0 until children.length()) {
Expand Down
192 changes: 167 additions & 25 deletions r2-shared/src/main/java/org/readium/r2/shared/Locator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,59 @@ import java.io.Serializable
* @val text: LocatorText? - Textual context of the locator.
*/

open class Locator(val href: String,
val type: String,
val title: String? = null,
val locations: Locations? = null,
val text: LocatorText?) : Serializable
open class Locator(var href: String? = null,
var type: String? = null,
var title: String? = null,
var locations: Locations? = null,
var text: LocatorText? = null) : JSONable, Serializable {


companion object {
fun fromJSON(json: JSONObject): Locator {

val locator = Locator()
if (json.has("href")) {
locator.href = json.getString("href")
}
if (json.has("type")) {
locator.type = json.getString("type")
}
if (json.has("title")) {
locator.title = json.getString("title")
}
if (json.has("locations")) {
locator.locations = Locations.fromJSON(JSONObject(json.getString("locations")))
}
if (json.has("text")) {
locator.text = LocatorText.fromJSON(JSONObject(json.getString("text")))
}

return locator
}
}

override fun toJSON(): JSONObject {
val json = JSONObject()

href.let {
json.putOpt("href", href)
}
type.let {
json.putOpt("type", type)
}
title.let {
json.putOpt("title", title)
}
locations?.let {
json.putOpt("locations", it.toJSON())
}
text?.let {
json.putOpt("text", it.toJSON())
}
return json
}

}

class LocatorText(var after: String? = null,
var before: String? = null,
Expand Down Expand Up @@ -67,14 +115,6 @@ class LocatorText(var after: String? = null,
return json
}

override fun toString(): String {
var jsonString = """{"""
before.let { jsonString += """ "before": "$before" ,""" }
highlight.let { jsonString += """ "before": "$highlight" ,""" }
after.let { jsonString += """ "after": "$after" ,""" }
jsonString += """}"""
return jsonString
}
}

/**
Expand All @@ -87,7 +127,10 @@ class LocatorText(var after: String? = null,
*/
class Locations(var fragment: String? = null, // 1 = fragment identifier (toc, page lists, landmarks)
var progression: Double? = null, // 2 = bookmarks
var position: Long? = null // 3 = goto page
var position: Long? = null, // 3 = goto page
var cssSelector: String? = null,
var partialCfi: String? = null,
var domRange: DomRange? = null
) : JSONable, Serializable {

companion object {
Expand All @@ -103,12 +146,20 @@ class Locations(var fragment: String? = null, // 1 = fragment identifier
if (json.has("position")) {
location.position = json.getLong("position")
}

if (json.has("cssSelector")) {
location.cssSelector = json.getString("cssSelector")
}
if (json.has("partialCfi")) {
location.partialCfi = json.getString("partialCfi")
}
if (json.has("domRange")) {
location.domRange = DomRange.fromJSON(JSONObject(json.getString("domRange")))
}
return location
}

fun isEmpty(locations: Locations):Boolean {
if (locations.fragment == null && locations.position == null && locations.progression == null) {
fun isEmpty(locations: Locations): Boolean {
if (locations.fragment == null && locations.position == null && locations.progression == null && locations.cssSelector == null && locations.partialCfi == null && locations.domRange == null) {
return true
}
return false
Expand All @@ -128,16 +179,107 @@ class Locations(var fragment: String? = null, // 1 = fragment identifier
position?.let {
json.putOpt("position", position)
}
cssSelector?.let {
json.putOpt("cssSelector", cssSelector)
}
partialCfi?.let {
json.putOpt("partialCfi", partialCfi)
}
domRange?.let {
json.putOpt("domRange", it.toJSON())
}

return json
}
}

class Range(var cssSelector: String? = null,
var textNodeIndex: Long? = null,
var offset: Long? = null
) : JSONable, Serializable {

companion object {
fun fromJSON(json: JSONObject): Range {

val range = Range()
if (json.has("cssSelector")) {
range.cssSelector = json.getString("cssSelector")
}
if (json.has("textNodeIndex")) {
range.textNodeIndex = json.getLong("textNodeIndex")
}
if (json.has("offset")) {
range.offset = json.getLong("offset")
}
return range
}

fun isEmpty(locations: Range): Boolean {
if (locations.cssSelector == null && locations.textNodeIndex == null && locations.offset == null) {
return true
}
return false
}

}

override fun toJSON(): JSONObject {
val json = JSONObject()

cssSelector?.let {
json.putOpt("cssSelector", cssSelector)
}
textNodeIndex?.let {
json.putOpt("textNodeIndex", textNodeIndex)
}
offset?.let {
json.putOpt("offset", offset)
}

return json
}
}


class DomRange(var start: Range? = null,
var end: Range? = null
) : JSONable, Serializable {

companion object {
fun fromJSON(json: JSONObject): DomRange {

val domRange = DomRange()

if (json.has("start")) {
domRange.start = Range.fromJSON(JSONObject(json.getString("start")))
}
if (json.has("end")) {
domRange.end = Range.fromJSON(JSONObject(json.getString("end")))
}

return domRange
}

fun isEmpty(locations: DomRange): Boolean {
if (locations.start == null && locations.end == null) {
return true
}
return false
}

}

override fun toJSON(): JSONObject {
val json = JSONObject()

override fun toString(): String {
var jsonString = """{"""
fragment.let { jsonString += """ "fragment": "$fragment" ,""" }
progression.let { jsonString += """ "progression": "$progression" ,""" }
position.let { jsonString += """ "position": "$position" """ }
jsonString += """}"""
return jsonString
start?.let {
json.putOpt("start", it.toJSON())
}
end?.let {
json.putOpt("end", it.toJSON())
}

return json
}
}

}
Loading

0 comments on commit 0b1d597

Please sign in to comment.