Skip to content

Commit 1a9b228

Browse files
authored
Add an Audiobook navigator based on MediaSession (#155)
1 parent eb10465 commit 1a9b228

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

readium/shared/r2-shared/src/main/java/org/readium/r2/shared/Experimental.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ package org.readium.r2.shared
1111

1212
@RequiresOptIn(message = "Support for PDF is still experimental. The API may be changed in the future without notice.")
1313
@Retention(AnnotationRetention.BINARY)
14-
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.TYPEALIAS)
14+
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.TYPEALIAS, AnnotationTarget.PROPERTY)
1515
annotation class PdfSupport
1616

1717
@RequiresOptIn(message = "Support for SearchService is still experimental. The API may be changed in the future without notice.")

readium/shared/r2-shared/src/main/java/org/readium/r2/shared/fetcher/Resource.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ interface Resource : SuspendingCloseable {
141141
class Unavailable(cause: Throwable? = null)
142142
: Exception(R.string.r2_shared_resource_exception_unavailable, cause)
143143

144+
/**
145+
* The Internet connection appears to be offline.
146+
*/
147+
object Offline : Exception(R.string.r2_shared_resource_exception_offline)
148+
144149
/**
145150
* Equivalent to a 507 HTTP error.
146151
*

readium/shared/r2-shared/src/main/java/org/readium/r2/shared/fetcher/ResourceInputStream.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import java.io.InputStream
1616
/**
1717
* Input stream reading a [Resource]'s content.
1818
*
19-
* The underlying resource will be automatically closed at the same time that this stream is.
20-
* */
19+
* If you experience bad performances, consider wrapping the stream in a BufferedInputStream. This
20+
* is particularly useful when streaming deflated ZIP entries.
21+
*/
2122
class ResourceInputStream(
2223
private val resource: Resource,
2324
val range: LongRange? = null

readium/shared/r2-shared/src/main/java/org/readium/r2/shared/publication/Manifest.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
package org.readium.r2.shared.publication
1111

1212
import android.os.Parcelable
13+
import kotlinx.coroutines.Dispatchers
14+
import kotlinx.coroutines.withContext
1315
import kotlinx.parcelize.Parcelize
1416
import org.json.JSONArray
1517
import org.json.JSONObject
@@ -22,6 +24,7 @@ import org.readium.r2.shared.toJSON
2224
import org.readium.r2.shared.util.Href
2325
import org.readium.r2.shared.util.logging.WarningLogger
2426
import org.readium.r2.shared.util.logging.log
27+
import java.io.File
2528

2629
/**
2730
* Holds the metadata of a Readium publication, as described in the Readium Web Publication Manifest.
@@ -75,7 +78,7 @@ data class Manifest(
7578
companion object {
7679

7780
/**
78-
* Parses a [Publication] from its RWPM JSON representation.
81+
* Parses a [Manifest] from its RWPM JSON representation.
7982
*
8083
* If the publication can't be parsed, a warning will be logged with [warnings].
8184
* https://readium.org/webpub-manifest/
@@ -106,7 +109,7 @@ data class Manifest(
106109

107110
val metadata = Metadata.fromJSON(json.remove("metadata") as? JSONObject, normalizeHref, warnings)
108111
if (metadata == null) {
109-
warnings?.log(Publication::class.java, "[metadata] is required", json)
112+
warnings?.log(Manifest::class.java, "[metadata] is required", json)
110113
return null
111114
}
112115

readium/shared/r2-shared/src/main/java/org/readium/r2/shared/publication/Publication.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ import kotlin.reflect.KClass
3737

3838
internal typealias ServiceFactory = (Publication.Service.Context) -> Publication.Service?
3939

40+
/**
41+
* A reference uniquely identifying a publication in the reading app.
42+
*
43+
* For example, a database primary key for a local publication, or a source URL for a remote one.
44+
*
45+
* We can't use publication.metadata.identifier directly because it might be null or not really
46+
* unique in the reading app. That's why sometimes we require an ID provided by the app.
47+
*/
48+
typealias PublicationId = String
49+
4050
/**
4151
* The Publication shared model is the entry-point for all the metadata and services
4252
* related to a Readium publication.

readium/shared/r2-shared/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<string name="r2.shared.resource.exception.not_found">Resource not found</string>
2121
<string name="r2.shared.resource.exception.forbidden">You are not allowed to access the resource</string>
2222
<string name="r2.shared.resource.exception.unavailable">The resource is currently unavailable, please try again later</string>
23+
<string name="r2_shared_resource_exception_offline">The Internet connection appears to be offline</string>
2324
<string name="r2.shared.resource.exception.out_of_memory">The resource is too large to be read on this device</string>
2425
<string name="r2.shared.resource.exception.cancelled">The request was cancelled</string>
2526
<string name="r2.shared.resource.exception.other">A service error occurred</string>

0 commit comments

Comments
 (0)