Skip to content

Commit

Permalink
Merge branch 'feature/pp-871'
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed Feb 26, 2024
2 parents b866f96 + ee17527 commit 7c904f2
Show file tree
Hide file tree
Showing 79 changed files with 1,338 additions and 1,506 deletions.
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ the project and functionality that must be provided by the hosting application.

The [org.librarysimplified.r2.api](org.librarysimplified.r2.api) module defines a _controller API_ that accepts
commands and publishes events in response to those commands. A _controller_ encapsulates
a Readium [Publication](https://readium.org/webpub-manifest/) and an internal server
used to expose resources from that `Publication`. A single _controller_ instance has
a Readium [Publication](https://readium.org/webpub-manifest/). A single _controller_ instance has
a lifetime matching that of the `Publication`; when the user wants to open a book,
a new _controller_ instance is created for that book, and then destroyed when the
user closes the book.
Expand Down Expand Up @@ -70,9 +69,7 @@ restoring this state each time a `WebView` is (re)connected.
The [org.librarysimplified.r2.views](org.librarysimplified.r2.views) module defines a set of Android [Fragments](https://developer.android.com/guide/fragments)
that implement a simple user interface for displaying a book and allowing the user to
manage bookmarks and choose items from the book's table of contents. The fragments are
conceptually stateless views that simply respond to events published by the current
_controller_ instance. The fragments communicate by a shared, public [ViewModel](https://developer.android.com/topic/libraries/architecture/viewmodel),
with the _controller_ instance being stored in this `ViewModel`.
stateless views that simply respond to events published by the current _controller_ instance.

### Usage

Expand All @@ -85,11 +82,10 @@ The user's application has the following responsibilities:
database. Failing to handle events will merely result in bookmarks not being saved.

* The application _must_ respond to requests from the fragments to instantiate other
fragments, and to pop the backstack as necessary. For example, when the user clicks
the _table of contents_ button in the `SR2ReaderFragment`, the `ViewModel` will
publish an event indicating that the user's application should now instantiate and
attach a `SR2TOCFragment` in order to show the table of contents. Failing to handle
these events will merely result in a UI that does nothing when the user selects
fragments. For example, when the user clicks the _table of contents_ button in the
`SR2ReaderFragment`, an event will be published indicating that the user's application
should now instantiate and attach a `SR2TOCFragment` in order to show the table of contents.
Failing to handle these events will merely result in a UI that does nothing when the user selects
various menu items.

An extremely minimal [demo application](org.librarysimplified.r2.demo) is included that
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ POM_SCM_CONNECTION=scm:git:git://github.com/ThePalaceProject/android-r2
POM_SCM_DEV_CONNECTION=scm:git:ssh://[email protected]/ThePalaceProject/android-r2
POM_SCM_URL=http://github.com/ThePalaceProject/android-r2
POM_URL=http://github.com/ThePalaceProject/android-r2
VERSION_NAME=2.6.0-SNAPSHOT
VERSION_NAME=3.0.0-SNAPSHOT
VERSION_PREVIOUS=2.5.0

android.useAndroidX=true
Expand Down
2 changes: 1 addition & 1 deletion org.librarysimplified.r2.api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
dependencies {
implementation(libs.google.guava)
implementation(libs.joda.time)
implementation(libs.kotlin.stdlib)
implementation(libs.r2.shared)
implementation(libs.r2.streamer)
implementation(libs.rxjava2)
implementation(libs.slf4j)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.librarysimplified.r2.api

import android.content.Context
import com.google.common.util.concurrent.ListeningExecutorService
import org.readium.r2.shared.publication.ContentProtection
import org.readium.r2.shared.publication.asset.PublicationAsset
import org.readium.r2.shared.publication.protection.ContentProtection
import org.readium.r2.shared.util.asset.Asset

/**
* Configuration values for an R2 controller.
Expand All @@ -15,7 +14,7 @@ data class SR2ControllerConfiguration(
* A publication asset containing a book.
*/

val bookFile: PublicationAsset,
val bookFile: Asset,

/**
* An identifier used to uniquely identify a publication. Unfortunately, identifier are optional
Expand All @@ -42,12 +41,6 @@ data class SR2ControllerConfiguration(

val contentProtections: List<ContentProtection>,

/**
* An executor service used to execute I/O code on one or more background threads.
*/

val ioExecutor: ListeningExecutorService,

/**
* A function that executes `f` on the Android UI thread.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
package org.librarysimplified.r2.api

import com.google.common.util.concurrent.ListenableFuture
import java.util.concurrent.Callable
import android.app.Application

/**
* A provider of R2 controllers.
*/

interface SR2ControllerProviderType {

/**
* Create a new R2 controller on a thread provided by the given I/O executor.
*/

fun create(
configuration: SR2ControllerConfiguration,
): ListenableFuture<SR2ControllerType> {
return configuration.ioExecutor.submit(
Callable {
this.createHere(configuration)
},
)
}

/**
* Create a new controller on the current thread.
*
* Note that, as most implementations will perform I/O upon initialization, this method
* should _not_ be called on the Android UI thread.
*/

fun createHere(
fun create(
context: Application,
configuration: SR2ControllerConfiguration,
): SR2ControllerType
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.librarysimplified.r2.api

import org.readium.r2.shared.Search
import org.readium.r2.shared.publication.Href
import org.readium.r2.shared.publication.services.search.SearchIterator

/**
Expand Down Expand Up @@ -51,7 +52,7 @@ sealed class SR2Event {
*/

data class SR2ReadingPositionChanged(
val chapterHref: String,
val chapterHref: Href,
val chapterProgress: Double,
val chapterTitle: String?,
val currentPage: Int?,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.librarysimplified.r2.api

import org.slf4j.LoggerFactory
import java.util.concurrent.Executor
import java.util.concurrent.Executors

object SR2Executors {

private val logger =
LoggerFactory.getLogger(SR2Executors::class.java)

val ioExecutor: Executor =
Executors.newSingleThreadExecutor { r ->
val thread = Thread(r)
thread.name = "org.librarysimplified.r2.io"
thread.setUncaughtExceptionHandler { t, e ->
logger.error("Uncaught exception: ", e)
}
thread
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package org.librarysimplified.r2.api

import org.readium.r2.shared.publication.Href

/**
* A location within a book.
*/

sealed class SR2Locator : Comparable<SR2Locator> {

abstract val chapterHref: String
abstract val chapterHref: Href

data class SR2LocatorPercent(
override val chapterHref: String,
override val chapterHref: Href,
val chapterProgress: Double,
) : SR2Locator() {

Expand All @@ -20,13 +22,13 @@ sealed class SR2Locator : Comparable<SR2Locator> {
}

companion object {
fun start(href: String): SR2LocatorPercent {
fun start(href: Href): SR2LocatorPercent {
return SR2LocatorPercent(chapterProgress = 0.0, chapterHref = href)
}
}

override fun compareTo(other: SR2Locator): Int {
val indexCmp = this.chapterHref.compareTo(other.chapterHref)
val indexCmp = this.chapterHref.toString().compareTo(other.chapterHref.toString())
return if (indexCmp == 0) {
when (other) {
is SR2LocatorPercent ->
Expand All @@ -41,10 +43,10 @@ sealed class SR2Locator : Comparable<SR2Locator> {
}

data class SR2LocatorChapterEnd(
override val chapterHref: String,
override val chapterHref: Href,
) : SR2Locator() {
override fun compareTo(other: SR2Locator): Int {
val indexCmp = this.chapterHref.compareTo(other.chapterHref)
val indexCmp = this.chapterHref.toString().compareTo(other.chapterHref.toString())
return if (indexCmp == 0) {
when (other) {
is SR2LocatorPercent ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.librarysimplified.r2.api

import org.readium.r2.shared.publication.Href

/**
* A flattened entry from the table of contents.
*/

data class SR2TOCEntry(
val title: String,
val href: String,
val href: Href,
val depth: Int,
) {
init {
Expand Down
2 changes: 0 additions & 2 deletions org.librarysimplified.r2.demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ dependencies {
implementation(libs.androidx.vectordrawable.animated)
implementation(libs.androidx.viewpager)
implementation(libs.androidx.viewpager2)
implementation(libs.google.failureaccess)
implementation(libs.google.guava)
implementation(libs.google.material)
implementation(libs.joda.time)
implementation(libs.jsoup)
Expand Down
Loading

0 comments on commit 7c904f2

Please sign in to comment.