From b6dca6d2ac9c1d63493744d6c45f03cd5b915cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Mon, 3 Feb 2020 16:41:55 +0100 Subject: [PATCH] Use the new Publication models and fix warnings --- .../r2/testapp/audiobook/AudiobookActivity.kt | 8 +++--- .../readium/r2/testapp/comic/ComicActivity.kt | 5 ++-- .../readium/r2/testapp/db/BooksDatabase.kt | 2 +- .../r2/testapp/db/HighlightsDatabase.kt | 1 - .../r2/testapp/drm/DRMLibraryService.kt | 2 +- .../readium/r2/testapp/epub/EpubActivity.kt | 27 ++++++++++--------- .../readium/r2/testapp/epub/R2ScreenReader.kt | 4 +-- .../r2/testapp/epub/R2SyntheticPageList.kt | 12 ++++----- .../r2/testapp/library/LibraryActivity.kt | 22 ++++++++------- .../r2/testapp/opds/OPDSCatalogActivity.kt | 1 + .../r2/testapp/opds/OPDSDetailActivity.kt | 17 ++++++------ .../r2/testapp/opds/RecyclerViewAdapter.kt | 3 ++- .../r2/testapp/outline/R2OutlineActivity.kt | 21 ++++++++------- .../r2/testapp/search/SearchInterface.kt | 4 +-- .../r2/testapp/utils/R2IntentHelper.java | 2 +- .../r2/testapp/utils/R2IntentMapper.kt | 3 +-- .../org/readium/r2/testapp/CatalogActivity.kt | 12 +++------ 17 files changed, 73 insertions(+), 73 deletions(-) diff --git a/r2-testapp/src/main/java/org/readium/r2/testapp/audiobook/AudiobookActivity.kt b/r2-testapp/src/main/java/org/readium/r2/testapp/audiobook/AudiobookActivity.kt index fca6bf2b..ab202bfe 100644 --- a/r2-testapp/src/main/java/org/readium/r2/testapp/audiobook/AudiobookActivity.kt +++ b/r2-testapp/src/main/java/org/readium/r2/testapp/audiobook/AudiobookActivity.kt @@ -35,8 +35,8 @@ class AudiobookActivity : R2AudiobookActivity(), NavigatorDelegate { it } ?: run { val resource = publication.readingOrder[currentResource] - val resourceHref = resource.href ?: "" - val resourceType = resource.typeLink ?: "" + val resourceHref = resource.href + val resourceType = resource.type ?: "" Locator(resourceHref, resourceType, publication.metadata.title, Locations(progression = 0.0)) } } @@ -119,8 +119,8 @@ class AudiobookActivity : R2AudiobookActivity(), NavigatorDelegate { val resourceIndex = currentResource.toLong() val resource = publication.readingOrder[currentResource] - val resourceHref = resource.href ?: "" - val resourceType = resource.typeLink ?: "" + val resourceHref = resource.href + val resourceType = resource.type ?: "" val resourceTitle = resource.title ?: "" val bookmark = Bookmark( diff --git a/r2-testapp/src/main/java/org/readium/r2/testapp/comic/ComicActivity.kt b/r2-testapp/src/main/java/org/readium/r2/testapp/comic/ComicActivity.kt index 4005a6fd..048d87ff 100644 --- a/r2-testapp/src/main/java/org/readium/r2/testapp/comic/ComicActivity.kt +++ b/r2-testapp/src/main/java/org/readium/r2/testapp/comic/ComicActivity.kt @@ -21,6 +21,7 @@ import org.readium.r2.navigator.NavigatorDelegate import org.readium.r2.navigator.cbz.R2CbzActivity import org.readium.r2.shared.Locations import org.readium.r2.shared.Locator +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 @@ -44,8 +45,8 @@ class ComicActivity : R2CbzActivity(), CoroutineScope, NavigatorDelegate { it } ?: run { val resource = publication.images[resourcePager.currentItem] - val resourceHref = resource.href ?: "" - val resourceType = resource.typeLink ?: "" + val resourceHref = resource.href + val resourceType = resource.type ?: "" Locator(resourceHref, resourceType, publication.metadata.title, Locations(progression = 0.0)) } } diff --git a/r2-testapp/src/main/java/org/readium/r2/testapp/db/BooksDatabase.kt b/r2-testapp/src/main/java/org/readium/r2/testapp/db/BooksDatabase.kt index f0ef7591..49c3f953 100644 --- a/r2-testapp/src/main/java/org/readium/r2/testapp/db/BooksDatabase.kt +++ b/r2-testapp/src/main/java/org/readium/r2/testapp/db/BooksDatabase.kt @@ -20,7 +20,7 @@ import org.jetbrains.anko.db.* import org.joda.time.DateTime import org.json.JSONObject import org.readium.r2.shared.Locator -import org.readium.r2.shared.Publication +import org.readium.r2.shared.publication.Publication import java.net.URI import java.nio.file.Paths diff --git a/r2-testapp/src/main/java/org/readium/r2/testapp/db/HighlightsDatabase.kt b/r2-testapp/src/main/java/org/readium/r2/testapp/db/HighlightsDatabase.kt index d13a6795..37b944b1 100644 --- a/r2-testapp/src/main/java/org/readium/r2/testapp/db/HighlightsDatabase.kt +++ b/r2-testapp/src/main/java/org/readium/r2/testapp/db/HighlightsDatabase.kt @@ -171,7 +171,6 @@ class HIGHLIGHTS(private var database: HighlightsDatabaseOpenHelper) { return@use null } } - return null } private fun has(highlight: Highlight): List { diff --git a/r2-testapp/src/main/java/org/readium/r2/testapp/drm/DRMLibraryService.kt b/r2-testapp/src/main/java/org/readium/r2/testapp/drm/DRMLibraryService.kt index 7e14a01c..dfaf15fd 100644 --- a/r2-testapp/src/main/java/org/readium/r2/testapp/drm/DRMLibraryService.kt +++ b/r2-testapp/src/main/java/org/readium/r2/testapp/drm/DRMLibraryService.kt @@ -12,8 +12,8 @@ package org.readium.r2.testapp.drm import android.app.ProgressDialog import android.net.Uri -import org.readium.r2.shared.Publication import org.readium.r2.shared.drm.DRM +import org.readium.r2.shared.publication.Publication import org.readium.r2.streamer.parser.epub.EpubParser import org.readium.r2.streamer.parser.PubBox import org.readium.r2.testapp.db.Book diff --git a/r2-testapp/src/main/java/org/readium/r2/testapp/epub/EpubActivity.kt b/r2-testapp/src/main/java/org/readium/r2/testapp/epub/EpubActivity.kt index 65746b0f..9111a307 100644 --- a/r2-testapp/src/main/java/org/readium/r2/testapp/epub/EpubActivity.kt +++ b/r2-testapp/src/main/java/org/readium/r2/testapp/epub/EpubActivity.kt @@ -48,6 +48,9 @@ import org.readium.r2.navigator.epub.Style import org.readium.r2.navigator.pager.R2EpubPageFragment import org.readium.r2.navigator.pager.R2PagerAdapter import org.readium.r2.shared.* +import org.readium.r2.shared.publication.ContentLayout +import org.readium.r2.shared.publication.epub.EpubLayout +import org.readium.r2.shared.publication.presentation.presentation import org.readium.r2.testapp.BuildConfig.DEBUG import org.readium.r2.testapp.DRMManagementActivity import org.readium.r2.testapp.R @@ -76,8 +79,8 @@ class EpubActivity : R2EpubActivity(), CoroutineScope, NavigatorDelegate/*, Visu it } ?: run { val resource = publication.readingOrder[resourcePager.currentItem] - val resourceHref = resource.href ?: "" - val resourceType = resource.typeLink ?: "" + val resourceHref = resource.href + val resourceType = resource.type ?: "" Locator(resourceHref, resourceType, publication.metadata.title, Locations(progression = 0.0)) } } @@ -340,7 +343,7 @@ class EpubActivity : R2EpubActivity(), CoroutineScope, NavigatorDelegate/*, Visu return false } }) - searchView.setOnQueryTextFocusChangeListener { view, b -> + searchView.setOnQueryTextFocusChangeListener { _, b -> if (!b) { search_overlay.visibility = View.INVISIBLE } else { @@ -495,8 +498,8 @@ class EpubActivity : R2EpubActivity(), CoroutineScope, NavigatorDelegate/*, Visu R.id.bookmark -> { val resourceIndex = resourcePager.currentItem.toLong() val resource = publication.readingOrder[resourcePager.currentItem] - val resourceHref = resource.href ?: "" - val resourceType = resource.typeLink ?: "" + val resourceHref = resource.href + val resourceType = resource.type ?: "" val resourceTitle = resource.title ?: "" val currentPage = positionsDB.positions.getCurrentPage(bookId, resourceHref, currentLocation?.locations?.progression!!)?.let { it @@ -574,11 +577,11 @@ class EpubActivity : R2EpubActivity(), CoroutineScope, NavigatorDelegate/*, Visu val index = fragments.getValue("i").toInt() val searchStorage = getSharedPreferences("org.readium.r2.search", Context.MODE_PRIVATE) Handler().postDelayed({ - if (publication.metadata.rendition.layout == RenditionLayout.Reflowable) { + if (publication.metadata.presentation.layout == EpubLayout.REFLOWABLE) { val currentFragment = (resourcePager.adapter as R2PagerAdapter).getCurrentFragment() as R2EpubPageFragment val resource = publication.readingOrder[resourcePager.currentItem] - val resourceHref = resource.href ?: "" - val resourceType = resource.typeLink ?: "" + val resourceHref = resource.href + val resourceType = resource.type ?: "" val resourceTitle = resource.title ?: "" currentFragment.webView.runJavaScript("markSearch('${searchStorage.getString("term", null)}', null, '$resourceHref', '$resourceType', '$resourceTitle', '$index')") { result -> @@ -752,7 +755,7 @@ class EpubActivity : R2EpubActivity(), CoroutineScope, NavigatorDelegate/*, Visu private fun drawHighlight() { val resource = publication.readingOrder[resourcePager.currentItem] - highlightDB.highlights.listAll(bookId, resource.href!!).forEach { + highlightDB.highlights.listAll(bookId, resource.href).forEach { val highlight = convertHighlight2NavigationHighlight(it) showHighlight(highlight) } @@ -822,8 +825,8 @@ class EpubActivity : R2EpubActivity(), CoroutineScope, NavigatorDelegate/*, Visu private fun convertNavigationHighlight2Highlight(highlight: org.readium.r2.navigator.epub.Highlight, annotation: String? = null, annotationMarkStyle: String? = null): Highlight { val resourceIndex = resourcePager.currentItem.toLong() val resource = publication.readingOrder[resourcePager.currentItem] - val resourceHref = resource.href ?: "" - val resourceType = resource.typeLink ?: "" + val resourceHref = resource.href + val resourceType = resource.type ?: "" val resourceTitle = resource.title ?: "" val currentPage = positionsDB.positions.getCurrentPage(bookId, resourceHref, currentLocation?.locations?.progression!!)?.let { it @@ -894,7 +897,7 @@ class EpubActivity : R2EpubActivity(), CoroutineScope, NavigatorDelegate/*, Visu userSettings.updateViewCSS(SCROLL_REF) }, 500) } else { - if (publication.cssStyle != ContentLayoutStyle.cjkv.name) { + if (publication.cssStyle != ContentLayout.CJK_VERTICAL.key) { publication.userSettingsUIPreset.remove(ReadiumCSSName.ref(SCROLL_REF)) } diff --git a/r2-testapp/src/main/java/org/readium/r2/testapp/epub/R2ScreenReader.kt b/r2-testapp/src/main/java/org/readium/r2/testapp/epub/R2ScreenReader.kt index 2f8f1548..61a16f66 100644 --- a/r2-testapp/src/main/java/org/readium/r2/testapp/epub/R2ScreenReader.kt +++ b/r2-testapp/src/main/java/org/readium/r2/testapp/epub/R2ScreenReader.kt @@ -19,7 +19,7 @@ import org.jsoup.select.Elements import org.readium.r2.navigator.BASE_URL import org.readium.r2.navigator.IR2TTS import org.readium.r2.navigator.VisualNavigator -import org.readium.r2.shared.Publication +import org.readium.r2.shared.publication.Publication import org.readium.r2.testapp.BuildConfig.DEBUG import timber.log.Timber import java.io.IOException @@ -169,7 +169,7 @@ class R2ScreenReader(var context: Context, var ttsCallbacks: IR2TTS, var navigat * Inner function that sets the Text To Speech language. */ private fun setTTSLanguage() { - val language = textToSpeech.setLanguage(Locale(publication.metadata.languages.firstOrNull())) + val language = textToSpeech.setLanguage(Locale(publication.metadata.languages.firstOrNull() ?: "")) if (language == TextToSpeech.LANG_MISSING_DATA || language == TextToSpeech.LANG_NOT_SUPPORTED) { Toast.makeText(context.applicationContext, "There was an error with the TTS language, switching " diff --git a/r2-testapp/src/main/java/org/readium/r2/testapp/epub/R2SyntheticPageList.kt b/r2-testapp/src/main/java/org/readium/r2/testapp/epub/R2SyntheticPageList.kt index 6161ce70..aeacb51a 100644 --- a/r2-testapp/src/main/java/org/readium/r2/testapp/epub/R2SyntheticPageList.kt +++ b/r2-testapp/src/main/java/org/readium/r2/testapp/epub/R2SyntheticPageList.kt @@ -14,13 +14,13 @@ import android.text.Html import org.json.JSONArray import org.json.JSONObject import org.readium.r2.shared.JSONable -import org.readium.r2.shared.Link +import org.readium.r2.shared.publication.Link import org.readium.r2.testapp.db.PositionsDatabase import java.net.URI import java.net.URL -class R2SyntheticPageList(private val positionsDB: PositionsDatabase, private val bookID: Long, private val publicationIdentifier: String) : AsyncTask>, String, MutableList>() { +class R2SyntheticPageList(private val positionsDB: PositionsDatabase, private val bookID: Long, private val publicationIdentifier: String) : AsyncTask>, String, MutableList>() { private val syntheticPageList = mutableListOf() private var pageNumber: Long = 0 @@ -29,13 +29,11 @@ class R2SyntheticPageList(private val positionsDB: PositionsDatabase, private va positionsDB.positions.init(bookID) } - override fun doInBackground(vararg p0: Triple>): MutableList { + override fun doInBackground(vararg p0: Triple>): MutableList { for (uri in p0) { for (i in 0 until uri.third.size) { - uri.third[i].href?.let { - createSyntheticPages(uri.first, uri.second, uri.third[i]) - } + createSyntheticPages(uri.first, uri.second, uri.third[i]) if (isCancelled) { positionsDB.positions.delete(bookID) @@ -55,7 +53,7 @@ class R2SyntheticPageList(private val positionsDB: PositionsDatabase, private va val resourceURL: URL val resourceHref = link.href - val resourceType = link.typeLink + val resourceType = link.type resourceURL = if (URI(resourceHref).isAbsolute) { URL(resourceHref) diff --git a/r2-testapp/src/main/java/org/readium/r2/testapp/library/LibraryActivity.kt b/r2-testapp/src/main/java/org/readium/r2/testapp/library/LibraryActivity.kt index 2f17598a..9bce9c0e 100644 --- a/r2-testapp/src/main/java/org/readium/r2/testapp/library/LibraryActivity.kt +++ b/r2-testapp/src/main/java/org/readium/r2/testapp/library/LibraryActivity.kt @@ -54,11 +54,14 @@ import org.json.JSONObject import org.readium.r2.opds.OPDS1Parser import org.readium.r2.opds.OPDS2Parser import org.readium.r2.shared.Injectable -import org.readium.r2.shared.Publication import org.readium.r2.shared.drm.DRM import org.readium.r2.shared.opds.ParseData import org.readium.r2.shared.parsePublication import org.readium.r2.shared.promise +import org.readium.r2.shared.publication.Publication +import org.readium.r2.shared.publication.Publication.Companion +import org.readium.r2.shared.publication.epub.pageList +import org.readium.r2.shared.publication.opds.images import org.readium.r2.streamer.container.ContainerError import org.readium.r2.streamer.parser.PubBox import org.readium.r2.streamer.parser.audio.AudioBookConstant @@ -363,7 +366,7 @@ open class LibraryActivity : AppCompatActivity(), BooksAdapter.RecyclerViewClick val publicationIdentifier = publication.metadata.identifier!! val author = authorName(publication) task { - getBitmapFromURL(publication.images.first().href!!) + getBitmapFromURL(publication.images.first().href) }.then { val bitmap = it val stream = ByteArrayOutputStream() @@ -538,11 +541,9 @@ open class LibraryActivity : AppCompatActivity(), BooksAdapter.RecyclerViewClick val links = publication.links for (link in links) { val href = link.href - if (href != null) { - if (href.contains(Publication.EXTENSION.EPUB.value) || href.contains(Publication.EXTENSION.LCPL.value)) { - url = URL(href) - break - } + if (href.contains(Publication.EXTENSION.EPUB.value) || href.contains(Publication.EXTENSION.LCPL.value)) { + url = URL(href) + break } } return url @@ -992,9 +993,10 @@ open class LibraryActivity : AppCompatActivity(), BooksAdapter.RecyclerViewClick } then { json -> json?.let { - val externalPub = parsePublication(json) - val externalURIBase = externalPub.linkWithRel("self")!!.href!!.substring(0, externalManifest.lastIndexOf("/") + 1) - val externalURIFileName = externalPub.linkWithRel("self")!!.href!!.substring(externalManifest.lastIndexOf("/") + 1) + val externalPub = Publication.fromJSON(json) + ?: throw Exception("Invalid Publication") + val externalURIBase = externalPub.linkWithRel("self")!!.href.substring(0, externalManifest.lastIndexOf("/") + 1) + val externalURIFileName = externalPub.linkWithRel("self")!!.href.substring(externalManifest.lastIndexOf("/") + 1) var book: Book? = null diff --git a/r2-testapp/src/main/java/org/readium/r2/testapp/opds/OPDSCatalogActivity.kt b/r2-testapp/src/main/java/org/readium/r2/testapp/opds/OPDSCatalogActivity.kt index 47eed984..0f8c9f2a 100644 --- a/r2-testapp/src/main/java/org/readium/r2/testapp/opds/OPDSCatalogActivity.kt +++ b/r2-testapp/src/main/java/org/readium/r2/testapp/opds/OPDSCatalogActivity.kt @@ -41,6 +41,7 @@ import org.readium.r2.opds.OPDS2Parser import org.readium.r2.shared.Link import org.readium.r2.shared.opds.Facet import org.readium.r2.shared.opds.ParseData +import org.readium.r2.shared.publication.opds.numberOfItems import org.readium.r2.testapp.BuildConfig.DEBUG import org.readium.r2.testapp.R import timber.log.Timber diff --git a/r2-testapp/src/main/java/org/readium/r2/testapp/opds/OPDSDetailActivity.kt b/r2-testapp/src/main/java/org/readium/r2/testapp/opds/OPDSDetailActivity.kt index 6b5fd126..df9a8d5c 100644 --- a/r2-testapp/src/main/java/org/readium/r2/testapp/opds/OPDSDetailActivity.kt +++ b/r2-testapp/src/main/java/org/readium/r2/testapp/opds/OPDSDetailActivity.kt @@ -27,7 +27,8 @@ import org.jetbrains.anko.* import org.jetbrains.anko.appcompat.v7.Appcompat import org.jetbrains.anko.design.snackbar import org.jetbrains.anko.support.v4.nestedScrollView -import org.readium.r2.shared.Publication +import org.readium.r2.shared.publication.Publication +import org.readium.r2.shared.publication.opds.images import org.readium.r2.testapp.R import org.readium.r2.testapp.db.Book import org.readium.r2.testapp.db.BooksDatabase @@ -103,11 +104,11 @@ class OPDSDetailActivity : AppCompatActivity(), CoroutineScope { val stream = ByteArrayOutputStream() publication.coverLink?.let { link -> - val bitmap = getBitmapFromURL(link.href!!) + val bitmap = getBitmapFromURL(link.href) bitmap?.compress(Bitmap.CompressFormat.PNG, 100, stream) } ?: run { if (publication.images.isNotEmpty()) { - val bitmap = getBitmapFromURL(publication.images.first().href!!) + val bitmap = getBitmapFromURL(publication.images.first().href) bitmap?.compress(Bitmap.CompressFormat.PNG, 100, stream) } } @@ -142,7 +143,7 @@ class OPDSDetailActivity : AppCompatActivity(), CoroutineScope { } val bCancel = getButton(AlertDialog.BUTTON_NEGATIVE) bCancel.setOnClickListener { - File(book.url).delete() + File(book.url!!).delete() duplicateAlert.dismiss() } } @@ -166,11 +167,9 @@ class OPDSDetailActivity : AppCompatActivity(), CoroutineScope { val links = publication.links for (link in links) { val href = link.href - if (href != null) { - if (href.contains(Publication.EXTENSION.EPUB.value) || href.contains(Publication.EXTENSION.LCPL.value)) { - url = URL(href) - break - } + if (href.contains(Publication.EXTENSION.EPUB.value) || href.contains(Publication.EXTENSION.LCPL.value)) { + url = URL(href) + break } } return url diff --git a/r2-testapp/src/main/java/org/readium/r2/testapp/opds/RecyclerViewAdapter.kt b/r2-testapp/src/main/java/org/readium/r2/testapp/opds/RecyclerViewAdapter.kt index 26386c8f..f8f3fd63 100644 --- a/r2-testapp/src/main/java/org/readium/r2/testapp/opds/RecyclerViewAdapter.kt +++ b/r2-testapp/src/main/java/org/readium/r2/testapp/opds/RecyclerViewAdapter.kt @@ -19,7 +19,8 @@ import androidx.recyclerview.widget.RecyclerView import com.mcxiaoke.koi.ext.onClick import com.squareup.picasso.Picasso import org.jetbrains.anko.intentFor -import org.readium.r2.shared.Publication +import org.readium.r2.shared.publication.Publication +import org.readium.r2.shared.publication.opds.images import org.readium.r2.testapp.R class RecyclerViewAdapter(private val activity: Activity, private val strings: MutableList) : RecyclerView.Adapter() { diff --git a/r2-testapp/src/main/java/org/readium/r2/testapp/outline/R2OutlineActivity.kt b/r2-testapp/src/main/java/org/readium/r2/testapp/outline/R2OutlineActivity.kt index c737fff6..cb965f46 100644 --- a/r2-testapp/src/main/java/org/readium/r2/testapp/outline/R2OutlineActivity.kt +++ b/r2-testapp/src/main/java/org/readium/r2/testapp/outline/R2OutlineActivity.kt @@ -26,10 +26,13 @@ import kotlinx.android.synthetic.main.item_recycle_highlight.view.* import kotlinx.android.synthetic.main.item_recycle_outline.view.* import org.joda.time.DateTime import org.joda.time.format.DateTimeFormat -import org.readium.r2.shared.Link import org.readium.r2.shared.Locations import org.readium.r2.shared.Locator -import org.readium.r2.shared.Publication +import org.readium.r2.shared.publication.Link +import org.readium.r2.shared.publication.Publication +import org.readium.r2.shared.publication.epub.landmarks +import org.readium.r2.shared.publication.epub.pageList +import org.readium.r2.shared.publication.opds.images import org.readium.r2.testapp.R import org.readium.r2.testapp.db.* import org.readium.r2.testapp.epub.Position @@ -62,7 +65,7 @@ class R2OutlineActivity : AppCompatActivity() { */ val tableOfContext = mutableListOf>() - val contents: MutableList = when { + val contents: List = when { publication.tableOfContents.isNotEmpty() -> { publication.tableOfContents } @@ -92,9 +95,9 @@ class R2OutlineActivity : AppCompatActivity() { val resource = tableOfContext[position].second val resourceHref = resource.href - val resourceType = resource.typeLink?: "" + val resourceType = resource.type ?: "" - resourceHref?.let { + resourceHref.let { val intent = Intent() if (resourceHref.indexOf("#") > 0) { @@ -174,8 +177,8 @@ class R2OutlineActivity : AppCompatActivity() { //Link to the resource in the publication val link = pageList[position] - val resourceHref = link.href?: "" - val resourceType = link.typeLink?: "" + val resourceHref = link.href + val resourceType = link.type ?: "" val intent = Intent() @@ -224,8 +227,8 @@ class R2OutlineActivity : AppCompatActivity() { //Link to the resource in the publication val link = landmarks[position] - val resourceHref = link.href?: "" - val resourceType = link.typeLink?: "" + val resourceHref = link.href + val resourceType = link.type ?: "" val intent = Intent() intent.putExtra("locator", Locator(resourceHref, resourceType, publication.metadata.title, Locations(progression = 0.0),null)) diff --git a/r2-testapp/src/main/java/org/readium/r2/testapp/search/SearchInterface.kt b/r2-testapp/src/main/java/org/readium/r2/testapp/search/SearchInterface.kt index a3626885..4f047abc 100644 --- a/r2-testapp/src/main/java/org/readium/r2/testapp/search/SearchInterface.kt +++ b/r2-testapp/src/main/java/org/readium/r2/testapp/search/SearchInterface.kt @@ -30,8 +30,8 @@ class MarkJSSearchEngine(private var listener: IR2Activity) : SearchInterface { for (resourceIndex in 0 until listener.publication.readingOrder.size) { val fragment = ((listener.resourcePager?.adapter as R2PagerAdapter).mFragments.get((listener.resourcePager?.adapter as R2PagerAdapter).getItemId(resourceIndex))) as R2EpubPageFragment val resource = listener.publication.readingOrder[resourceIndex] - val resourceHref = resource.href ?: "" - val resourceType = resource.typeLink ?: "" + val resourceHref = resource.href + val resourceType = resource.type ?: "" val resourceTitle = resource.title ?: "" Handler().postDelayed({ fragment.webView.runJavaScript("markSearch('${keyword}', null, '$resourceHref', '$resourceType', '$resourceTitle')") { result -> diff --git a/r2-testapp/src/main/java/org/readium/r2/testapp/utils/R2IntentHelper.java b/r2-testapp/src/main/java/org/readium/r2/testapp/utils/R2IntentHelper.java index 5f3ac361..550fbcd5 100644 --- a/r2-testapp/src/main/java/org/readium/r2/testapp/utils/R2IntentHelper.java +++ b/r2-testapp/src/main/java/org/readium/r2/testapp/utils/R2IntentHelper.java @@ -14,7 +14,7 @@ import android.content.Intent; import android.net.Uri; -import org.readium.r2.shared.Publication; +import org.readium.r2.shared.publication.Publication; import org.readium.r2.testapp.CatalogActivity; /** diff --git a/r2-testapp/src/main/java/org/readium/r2/testapp/utils/R2IntentMapper.kt b/r2-testapp/src/main/java/org/readium/r2/testapp/utils/R2IntentMapper.kt index fedbff7e..d84e9023 100644 --- a/r2-testapp/src/main/java/org/readium/r2/testapp/utils/R2IntentMapper.kt +++ b/r2-testapp/src/main/java/org/readium/r2/testapp/utils/R2IntentMapper.kt @@ -13,7 +13,7 @@ package org.readium.r2.testapp.utils import android.content.Context import android.content.Intent import android.net.Uri -import org.readium.r2.shared.Publication +import org.readium.r2.shared.publication.Publication /** @@ -53,7 +53,6 @@ class R2IntentMapper(private val mContext: Context, private val mIntents: R2Inte if (uri.toString().contains(".")) { val extension = when (uri.toString().substring(uri.toString().lastIndexOf("."))) { - Publication.EXTENSION.EPUB.value -> Publication.EXTENSION.EPUB Publication.EXTENSION.JSON.value -> Publication.EXTENSION.JSON Publication.EXTENSION.AUDIO.value -> Publication.EXTENSION.AUDIO diff --git a/r2-testapp/src/withlcp/java/org/readium/r2/testapp/CatalogActivity.kt b/r2-testapp/src/withlcp/java/org/readium/r2/testapp/CatalogActivity.kt index 84055d3a..62753c66 100644 --- a/r2-testapp/src/withlcp/java/org/readium/r2/testapp/CatalogActivity.kt +++ b/r2-testapp/src/withlcp/java/org/readium/r2/testapp/CatalogActivity.kt @@ -34,8 +34,8 @@ import org.jetbrains.anko.design.longSnackbar import org.readium.r2.testapp.BuildConfig.DEBUG import org.readium.r2.lcp.public.* import org.readium.r2.shared.Injectable -import org.readium.r2.shared.Publication import org.readium.r2.shared.drm.DRM +import org.readium.r2.shared.publication.Publication import org.readium.r2.streamer.parser.PubBox import org.readium.r2.streamer.parser.epub.EpubParser import org.readium.r2.testapp.db.Book @@ -296,10 +296,7 @@ class CatalogActivity : LibraryActivity(), LCPLibraryActivityService, CoroutineS launch { val parser = EpubParser() val pub = parser.parse(publication.localURL) - pub?.let { - val pair = parser.fillEncryption(pub.container, pub.publication, pub.container.drm) - pub.container = pair.first - pub.publication = pair.second + if (pub != null) { prepareToServe(pub, file.name, file.absolutePath, add = true, lcp = true) progress.dismiss() catalogView.longSnackbar("publication added to your library") @@ -358,10 +355,7 @@ class CatalogActivity : LibraryActivity(), LCPLibraryActivityService, CoroutineS launch { val parser = EpubParser() val pub = parser.parse(result.localURL) - pub?.let { - val pair = parser.fillEncryption(pub.container, pub.publication, pub.container.drm) - pub.container = pair.first - pub.publication = pair.second + if (pub != null) { prepareToServe(pub, file.name, file.absolutePath, add = true, lcp = true) progress.dismiss() catalogView.longSnackbar("publication added to your library")