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 #119 from readium/2.0.0-alpha.1
Browse files Browse the repository at this point in the history
2.0.0-alpha.1
  • Loading branch information
mickael-menu authored Aug 11, 2020
2 parents 4de5021 + f062047 commit 809b3c5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS

This file was deleted.

9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ All notable changes to this project will be documented in this file.

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

[unreleased]: https://github.com/readium/r2-shared-kotlin/compare/master...HEAD
[1.2.0]: https://github.com/readium/r2-shared-kotlin/compare/1.1.6...1.2.0

## [Unreleased]

## [1.2.0]
## [2.0.0-alpha.1]

### Added

Expand Down Expand Up @@ -42,3 +39,7 @@ All notable changes to this project will be documented in this file.
* [The local HTTP server was broken](https://github.com/readium/r2-testapp-kotlin/pull/306) when provided with publication filenames containing invalid characters.
* XML namespace prefixes are now properly supported when an author chooses unusual ones (contributed by [@qnga](https://github.com/readium/r2-shared-kotlin/pull/85)).
* The `AndroidManifest.xml` is not forcing anymore `allowBackup` and `supportsRtl`, to let reading apps manage these features themselves (contributed by [@twaddington](https://github.com/readium/r2-shared-kotlin/pull/93)).


[unreleased]: https://github.com/readium/r2-shared-kotlin/compare/master...HEAD
[2.0.0-alpha.1]: https://github.com/readium/r2-shared-kotlin/compare/1.1.6...2.0.0-alpha.1
Original file line number Diff line number Diff line change
Expand Up @@ -243,26 +243,29 @@ data class Publication(
* Returns whether all the resources in the reading order are bitmaps.
*/
internal val allReadingOrderIsBitmap: Boolean get() =
readingOrder.all {
allReadingOrderMatches {
it.mediaType?.isBitmap == true
}

/**
* Returns whether all the resources in the reading order are audio clips.
*/
internal val allReadingOrderIsAudio: Boolean get() =
readingOrder.all {
allReadingOrderMatches {
it.mediaType?.isAudio == true
}

/**
* Returns whether all the resources in the reading order are contained in any of the given media types.
*/
internal fun allReadingOrderMatchesAnyOf(vararg mediaTypes: MediaType): Boolean =
readingOrder.all { link ->
allReadingOrderMatches { link ->
mediaTypes.any { link.mediaType?.matches(it) == true }
}

private fun allReadingOrderMatches(predicate: (Link) -> Boolean): Boolean =
readingOrder.isNotEmpty() && readingOrder.all(predicate)

companion object {

fun fromJSON(json: JSONObject?, normalizeHref: LinkHrefNormalizer = LinkHrefNormalizerIdentity): Publication? =
Expand Down Expand Up @@ -313,7 +316,13 @@ data class Publication(
resources = resources,
tableOfContents = tableOfContents,
otherCollections = otherCollections
)
).apply {
type = when {
metadata.type == "http://schema.org/Audiobook" || allReadingOrderIsAudio -> TYPE.AUDIO
allReadingOrderIsBitmap -> TYPE.DiViNa
else -> TYPE.WEBPUB
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import org.readium.r2.shared.Fixtures
import org.readium.r2.shared.assertJSONEquals
import org.readium.r2.shared.publication.Publication.TYPE.WEBPUB
import org.readium.r2.shared.publication.services.positions
import org.readium.r2.shared.publication.services.positionsByReadingOrder
import java.net.URL
Expand Down Expand Up @@ -47,7 +49,7 @@ class PublicationTest {
metadata = Metadata(localizedTitle = LocalizedString("Title")),
links = emptyList(),
readingOrder = emptyList()
),
).apply { type = WEBPUB },
Publication.fromJSON(JSONObject("""{
"metadata": {"title": "Title"},
"links": [],
Expand All @@ -66,7 +68,7 @@ class PublicationTest {
resources = listOf(Link(href = "/image.png", type = "image/png")),
tableOfContents = listOf(Link(href = "/cover.html"), Link(href = "/chap1.html")),
otherCollections = listOf(PublicationCollection(role = "sub", links = listOf(Link(href = "/sublink"))))
),
).apply { type = WEBPUB },
Publication.fromJSON(JSONObject("""{
"@context": "https://readium.org/webpub-manifest/context.jsonld",
"metadata": {"title": "Title"},
Expand Down Expand Up @@ -99,7 +101,7 @@ class PublicationTest {
metadata = Metadata(localizedTitle = LocalizedString("Title")),
links = listOf(Link(href = "/manifest.json", rels = setOf("self"))),
readingOrder = listOf(Link(href = "/chap1.html", type = "text/html"))
),
).apply { type = WEBPUB },
Publication.fromJSON(JSONObject("""{
"@context": ["context1", "context2"],
"metadata": {"title": "Title"},
Expand Down Expand Up @@ -131,7 +133,7 @@ class PublicationTest {
metadata = Metadata(localizedTitle = LocalizedString("Title")),
links = listOf(Link(href = "/manifest.json", rels = setOf("self"))),
readingOrder = listOf(Link(href = "/chap1.html", type = "text/html"))
),
).apply { type = WEBPUB },
Publication.fromJSON(JSONObject("""{
"metadata": {"title": "Title"},
"links": [
Expand All @@ -150,7 +152,7 @@ class PublicationTest {
metadata = Metadata(localizedTitle = LocalizedString("Title")),
links = listOf(Link(href = "/manifest.json", rels = setOf("self"))),
readingOrder = listOf(Link(href = "/chap1.html", type = "text/html"))
),
).apply { type = WEBPUB },
Publication.fromJSON(JSONObject("""{
"metadata": {"title": "Title"},
"links": [
Expand All @@ -171,7 +173,7 @@ class PublicationTest {
links = listOf(Link(href = "/manifest.json", rels = setOf("self"))),
readingOrder = listOf(Link(href = "/chap1.html", type = "text/html")),
resources = listOf(Link(href = "/withtype", type = "text/html"))
),
).apply { type = WEBPUB },
Publication.fromJSON(JSONObject("""{
"metadata": {"title": "Title"},
"links": [
Expand All @@ -188,6 +190,17 @@ class PublicationTest {
)
}

@Test fun `parse JSON computes the Publication {type} from the manifest content`() {
val fixtures = Fixtures("format")
fun parseAt(path: String): Publication =
Publication.fromJSON(JSONObject(fixtures.fileAt(path).readText()))!!

assertEquals(Publication.TYPE.AUDIO, parseAt("audiobook.json").type)
assertEquals(Publication.TYPE.DiViNa, parseAt("divina.json").type)
assertEquals(WEBPUB, parseAt("webpub.json").type)
assertEquals(WEBPUB, parseAt("opds2-publication.json").type)
}

@Test fun `get minimal JSON`() {
assertJSONEquals(
JSONObject("""{
Expand Down

0 comments on commit 809b3c5

Please sign in to comment.