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

Commit

Permalink
Fix current location
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu committed Feb 10, 2020
1 parent 3da6f9c commit e79e9aa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,20 @@ import org.readium.r2.navigator.Navigator
import org.readium.r2.navigator.NavigatorDelegate
import org.readium.r2.navigator.audiobook.R2AudiobookActivity
import org.readium.r2.shared.publication.Locator
import org.readium.r2.shared.publication.indexOfFirstWithHref
import org.readium.r2.testapp.R
import org.readium.r2.testapp.db.Bookmark
import org.readium.r2.testapp.db.BookmarksDatabase
import org.readium.r2.testapp.db.BooksDatabase
import org.readium.r2.testapp.library.activitiesLaunched
import org.readium.r2.testapp.outline.R2OutlineActivity
import timber.log.Timber


class AudiobookActivity : R2AudiobookActivity(), NavigatorDelegate {

override val currentLocation: Locator?
get() {
return booksDB.books.currentLocator(bookId)?.let {
it
} ?: run {
val resource = publication.readingOrder[currentResource]
val resourceHref = resource.href
val resourceType = resource.type ?: ""
Locator(resourceHref, resourceType, publication.metadata.title, Locator.Locations(progression = 0.0))
}
}

override fun locationDidChange(navigator: Navigator?, locator: Locator) {
Timber.d("locationDidChange $locator")
booksDB.books.saveProgression(locator, bookId)
}

Expand All @@ -61,7 +52,9 @@ class AudiobookActivity : R2AudiobookActivity(), NavigatorDelegate {

progressDialog = indeterminateProgressDialog(getString(R.string.progress_wait_while_preparing_audiobook))

currentResource = publication.readingOrder.indexOfFirst { it.href == currentLocation?.href }
currentResource = booksDB.books.currentLocator(bookId)
?.let { publication.readingOrder.indexOfFirstWithHref(it.href) }
?: 0

Handler().postDelayed({
//Setting cover
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import org.readium.r2.navigator.Navigator
import org.readium.r2.navigator.NavigatorDelegate
import org.readium.r2.navigator.cbz.R2CbzActivity
import org.readium.r2.shared.publication.Locator
import org.readium.r2.shared.publication.indexOfFirstWithHref
import org.readium.r2.shared.publication.opds.images
import org.readium.r2.testapp.R
import org.readium.r2.testapp.db.BooksDatabase
import org.readium.r2.testapp.library.activitiesLaunched
import org.readium.r2.testapp.outline.R2OutlineActivity
import timber.log.Timber
import kotlin.coroutines.CoroutineContext


Expand All @@ -37,20 +39,8 @@ import kotlin.coroutines.CoroutineContext
*/
class ComicActivity : R2CbzActivity(), CoroutineScope, NavigatorDelegate {


override val currentLocation: Locator?
get() {
return booksDB.books.currentLocator(bookId)?.let {
it
} ?: run {
val resource = publication.readingOrder[resourcePager.currentItem]
val resourceHref = resource.href
val resourceType = resource.type ?: ""
Locator(resourceHref, resourceType, publication.metadata.title, Locator.Locations(progression = 0.0))
}
}

override fun locationDidChange(navigator: Navigator?, locator: Locator) {
Timber.d("locationDidChange $locator")
booksDB.books.saveProgression(locator, bookId)
}

Expand All @@ -73,7 +63,10 @@ class ComicActivity : R2CbzActivity(), CoroutineScope, NavigatorDelegate {
navigatorDelegate = this
bookId = intent.getLongExtra("bookId", -1)

currentPagerPosition = publication.readingOrder.indexOfFirst { it.href == currentLocation?.href }
currentPagerPosition = booksDB.books.currentLocator(bookId)
?.let { publication.readingOrder.indexOfFirstWithHref(it.href) }
?: 0

resourcePager.currentItem = currentPagerPosition

toggleActionBar()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import org.readium.r2.shared.*
import org.readium.r2.shared.publication.ContentLayout
import org.readium.r2.shared.publication.Locator
import org.readium.r2.shared.publication.epub.EpubLayout
import org.readium.r2.shared.publication.indexOfFirstWithHref
import org.readium.r2.shared.publication.presentation.presentation
import org.readium.r2.testapp.BuildConfig.DEBUG
import org.readium.r2.testapp.DRMManagementActivity
Expand All @@ -73,22 +74,11 @@ import kotlin.coroutines.CoroutineContext
*/
class EpubActivity : R2EpubActivity(), CoroutineScope, NavigatorDelegate/*, VisualNavigatorDelegate, OutlineTableViewControllerDelegate*/ {

override val currentLocation: Locator?
get() {
return booksDB.books.currentLocator(bookId)?.let {
it
} ?: run {
val resource = publication.readingOrder[resourcePager.currentItem]
val resourceHref = resource.href
val resourceType = resource.type ?: ""
Locator(resourceHref, resourceType, publication.metadata.title, Locator.Locations(progression = 0.0))
}
}

override fun locationDidChange(navigator: Navigator?, locator: Locator) {
Timber.d("locationDidChange $locator")
booksDB.books.saveProgression(locator, bookId)

if (locator.locations.progression == 0.0) {
if (this::screenReader.isInitialized && locator.locations.progression == 0.0) {
screenReader.currentUtterance = 0
}
}
Expand Down Expand Up @@ -166,7 +156,9 @@ class EpubActivity : R2EpubActivity(), CoroutineScope, NavigatorDelegate/*, Visu

resourcePager.offscreenPageLimit = 1

currentPagerPosition = publication.readingOrder.indexOfFirst { it.href == currentLocation?.href }
currentPagerPosition = booksDB.books.currentLocator(bookId)
?.let { publication.readingOrder.indexOfFirstWithHref(it.href) }
?: 0
resourcePager.currentItem = currentPagerPosition

titleView.text = publication.metadata.title
Expand Down

0 comments on commit e79e9aa

Please sign in to comment.