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

Commit

Permalink
Use the new Publication models and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu committed Feb 3, 2020
1 parent 46c20ee commit b6dca6d
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ class HIGHLIGHTS(private var database: HighlightsDatabaseOpenHelper) {
return@use null
}
}
return null
}

private fun has(highlight: Highlight): List<Highlight> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Triple<String, String, MutableList<Link>>, String, MutableList<Position>>() {
class R2SyntheticPageList(private val positionsDB: PositionsDatabase, private val bookID: Long, private val publicationIdentifier: String) : AsyncTask<Triple<String, String, List<Link>>, String, MutableList<Position>>() {

private val syntheticPageList = mutableListOf<Position>()
private var pageNumber: Long = 0
Expand All @@ -29,13 +29,11 @@ class R2SyntheticPageList(private val positionsDB: PositionsDatabase, private va
positionsDB.positions.init(bookID)
}

override fun doInBackground(vararg p0: Triple<String, String, MutableList<Link>>): MutableList<Position> {
override fun doInBackground(vararg p0: Triple<String, String, List<Link>>): MutableList<Position> {

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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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()
}
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Publication>) : RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,7 +65,7 @@ class R2OutlineActivity : AppCompatActivity() {
*/
val tableOfContext = mutableListOf<Pair<Int,Link>>()

val contents: MutableList<Link> = when {
val contents: List<Link> = when {
publication.tableOfContents.isNotEmpty() -> {
publication.tableOfContents
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))
Expand Down
Loading

0 comments on commit b6dca6d

Please sign in to comment.