Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[*.{kt,kts}]

ktlint_disabled_rules=no-wildcard-imports,max-line-length

# Imports must be ordered in lexicographic order without any empty lines in-between.
# https://github.com/pinterest/ktlint/issues/1236
ij_kotlin_imports_layout=*
9 changes: 9 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
id("com.android.library") apply false
id("org.jetbrains.kotlin.android") apply false
id("org.jetbrains.dokka") apply true
id("org.jlleitschuh.gradle.ktlint") apply true
}

allprojects {
Expand All @@ -26,6 +27,14 @@ subprojects {
archiveClassifier.set("sources")
from("src/main/java", "src/main/resources")
}

apply(plugin = "org.jlleitschuh.gradle.ktlint")

ktlint {
android.set(true)
disabledRules.add("no-wildcard-imports")
disabledRules.add("max-line-length")
}
}

tasks.register("clean", Delete::class).configure {
Expand Down
7 changes: 0 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
[versions]

android-gradle-plugin = "7.3.1"

androidx-activity = "1.6.1"
androidx-appcompat = "1.5.1"
androidx-browser = "1.4.0"
Expand Down Expand Up @@ -146,8 +144,3 @@ navigation = ["androidx-navigation-fragment", "androidx-navigation-ui"]
room = ["androidx-room-runtime", "androidx-room-ktx"]
test-frameworks = ["junit", "androidx-ext-junit", "androidx-expresso-core", "robolectric", "kotlin-junit", "assertj", "kotlinx-coroutines-test"]

[plugins]
agpapp = { id = "com.android.application", version.ref = "android-gradle-plugin" }
agplib = { id = "com.android.library", version.ref = "android-gradle-plugin" }
kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ package org.readium.adapters.pdfium.document
import android.content.Context
import android.graphics.Bitmap
import android.os.ParcelFileDescriptor
import com.shockwave.pdfium.PdfDocument as _PdfiumDocument
import com.shockwave.pdfium.PdfiumCore
import java.io.File
import kotlin.reflect.KClass
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.readium.r2.shared.PdfSupport
Expand All @@ -20,9 +23,6 @@ import org.readium.r2.shared.util.pdf.PdfDocument
import org.readium.r2.shared.util.pdf.PdfDocumentFactory
import org.readium.r2.shared.util.use
import timber.log.Timber
import java.io.File
import kotlin.reflect.KClass
import com.shockwave.pdfium.PdfDocument as _PdfiumDocument

@OptIn(PdfSupport::class)
class PdfiumDocument(
Expand Down Expand Up @@ -84,7 +84,7 @@ class PdfiumDocumentFactory(context: Context) : PdfDocumentFactory<PdfiumDocumen

override val documentType: KClass<PdfiumDocument> = PdfiumDocument::class

private val core by lazy { PdfiumCore(context.applicationContext ) }
private val core by lazy { PdfiumCore(context.applicationContext) }

override suspend fun open(file: File, password: String?): PdfiumDocument =
core.fromFile(file, password)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

package org.readium.adapters.pdfium.navigator

import org.readium.r2.shared.ExperimentalReadiumApi
import org.readium.r2.navigator.preferences.ReadingProgression
import org.readium.r2.shared.ExperimentalReadiumApi

/**
* Default values for the PDF navigator with the PDFium adapter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import com.github.barteksc.pdfviewer.PDFView
import kotlin.math.roundToInt
import kotlinx.coroutines.launch
import org.readium.adapters.pdfium.document.PdfiumDocumentFactory
import org.readium.r2.navigator.pdf.PdfDocumentFragment
Expand All @@ -24,7 +25,6 @@ import org.readium.r2.shared.fetcher.Resource
import org.readium.r2.shared.publication.Link
import org.readium.r2.shared.publication.Publication
import timber.log.Timber
import kotlin.math.roundToInt

@ExperimentalReadiumApi
class PdfiumDocumentFragment internal constructor(
Expand Down Expand Up @@ -55,7 +55,11 @@ class PdfiumDocumentFragment internal constructor(
private var isReloading: Boolean = false
private var hasToReload: Int? = null

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View =
PDFView(inflater.context, null)
.also { pdfView = it }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class PdfiumPreferencesEditor internal constructor(

val scrollAxis: EnumPreference<Axis> =
EnumPreferenceDelegate(
getValue = { preferences.scrollAxis},
getValue = { preferences.scrollAxis },
getEffectiveValue = { state.settings.scrollAxis },
getIsEffective = { true },
updateValue = { value -> updateValues { it.copy(scrollAxis = value) } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

package org.readium.adapters.pdfium.navigator

import org.readium.r2.shared.publication.ReadingProgression as PublicationReadingProgression
import org.readium.r2.navigator.preferences.Axis
import org.readium.r2.navigator.preferences.Fit
import org.readium.r2.navigator.preferences.ReadingProgression
import org.readium.r2.shared.ExperimentalReadiumApi
import org.readium.r2.shared.publication.Metadata
import org.readium.r2.shared.publication.ReadingProgression as PublicationReadingProgression

@ExperimentalReadiumApi
internal class PdfiumSettingsResolver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import com.pspdfkit.annotations.actions.GoToAction
import com.pspdfkit.document.DocumentSource
import com.pspdfkit.document.OutlineElement
import com.pspdfkit.document.PageBinding
import com.pspdfkit.document.PdfDocument as _PsPdfKitDocument
import com.pspdfkit.document.PdfDocumentLoader
import java.io.File
import kotlin.reflect.KClass
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.readium.r2.shared.fetcher.Resource
import org.readium.r2.shared.publication.ReadingProgression
import org.readium.r2.shared.util.pdf.PdfDocument
import org.readium.r2.shared.util.pdf.PdfDocumentFactory
import timber.log.Timber
import java.io.File
import kotlin.reflect.KClass
import com.pspdfkit.document.PdfDocument as _PsPdfKitDocument

class PsPdfKitDocumentFactory(context: Context) : PdfDocumentFactory<PsPdfKitDocument> {
private val context = context.applicationContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
package org.readium.adapters.pspdfkit.document

import com.pspdfkit.document.providers.DataProvider
import java.util.*
import kotlinx.coroutines.runBlocking
import org.readium.r2.shared.fetcher.Resource
import org.readium.r2.shared.fetcher.synchronized
import org.readium.r2.shared.util.getOrElse
import org.readium.r2.shared.util.isLazyInitialized
import timber.log.Timber
import java.util.*

class ResourceDataProvider(
resource: Resource,
Expand Down Expand Up @@ -57,4 +57,4 @@ class ResourceDataProvider(
runBlocking { resource.close() }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.pspdfkit.listeners.DocumentListener
import com.pspdfkit.listeners.OnPreparePopupToolbarListener
import com.pspdfkit.ui.PdfFragment
import com.pspdfkit.ui.toolbar.popup.PdfTextSelectionPopupToolbar
import kotlin.math.roundToInt
import org.readium.adapters.pspdfkit.document.PsPdfKitDocument
import org.readium.r2.navigator.pdf.PdfDocumentFragment
import org.readium.r2.navigator.preferences.Axis
Expand All @@ -39,7 +40,6 @@ import org.readium.r2.navigator.preferences.Spread
import org.readium.r2.shared.ExperimentalReadiumApi
import org.readium.r2.shared.publication.Publication
import org.readium.r2.shared.publication.services.isProtected
import kotlin.math.roundToInt

@ExperimentalReadiumApi
internal class PsPdfKitDocumentFragment(
Expand All @@ -61,7 +61,11 @@ internal class PsPdfKitDocumentFragment(
private lateinit var pdfFragment: PdfFragment
private val psPdfKitListener = PsPdfKitListener()

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View =
FragmentContainerView(inflater.context)
.apply {
id = R.id.readium_pspdfkit_fragment
Expand Down Expand Up @@ -171,7 +175,13 @@ internal class PsPdfKitDocumentFragment(
return center?.let { listener.onTap(it) } ?: false
}

override fun onPageClick(document: PdfDocument, pageIndex: Int, event: MotionEvent?, pagePosition: PointF?, clickedAnnotation: Annotation?): Boolean {
override fun onPageClick(
document: PdfDocument,
pageIndex: Int,
event: MotionEvent?,
pagePosition: PointF?,
clickedAnnotation: Annotation?
): Boolean {
if (
pagePosition == null || clickedAnnotation is LinkAnnotation ||
clickedAnnotation is SoundAnnotation
Expand Down Expand Up @@ -227,7 +237,7 @@ internal class PsPdfKitDocumentFragment(
private val Spread.pageLayout: PageLayoutMode
get() = when (this) {
Spread.AUTO -> PageLayoutMode.AUTO
Spread.ALWAYS-> PageLayoutMode.DOUBLE
Spread.ALWAYS -> PageLayoutMode.DOUBLE
Spread.NEVER -> PageLayoutMode.SINGLE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class PsPdfKitEngineProvider(
SimplePresentation(
readingProgression = settings.readingProgression,
scroll = settings.scroll,
axis = if (settings.scroll) settings.scrollAxis else Axis.HORIZONTAL
axis = if (settings.scroll) settings.scrollAxis else Axis.HORIZONTAL
)

override fun createPreferenceEditor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PsPdfKitPreferencesEditor internal constructor(
val pageSpacingRange: ClosedRange<Double> = 0.0..50.0,
val pageSpacingProgression: ProgressionStrategy<Double> = DoubleIncrement(5.0),
)

private data class State(
val preferences: PsPdfKitPreferences,
val settings: PsPdfKitSettings
Expand Down Expand Up @@ -68,7 +68,7 @@ class PsPdfKitPreferencesEditor internal constructor(
SwitchPreferenceDelegate(
getValue = { preferences.offsetFirstPage },
getEffectiveValue = { state.settings.offsetFirstPage },
getIsEffective = { !state.settings.scroll && state.settings.spread != Spread.NEVER},
getIsEffective = { !state.settings.scroll && state.settings.spread != Spread.NEVER },
updateValue = { value -> updateValues { it.copy(offsetFirstPage = value) } },
)

Expand Down Expand Up @@ -122,7 +122,7 @@ class PsPdfKitPreferencesEditor internal constructor(
val newPreferences = updater(preferences)
state = newPreferences.toState()
}

private fun PsPdfKitPreferences.toState() =
State(preferences = this, settings = settingsResolver.settings(this))
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package org.readium.adapters.pspdfkit.navigator

import org.readium.r2.navigator.preferences.Axis
import org.readium.r2.navigator.preferences.Fit
import org.readium.r2.navigator.preferences.Spread
import org.readium.r2.navigator.preferences.ReadingProgression
import org.readium.r2.navigator.preferences.Spread
import org.readium.r2.shared.ExperimentalReadiumApi
import org.readium.r2.shared.publication.Metadata
import org.readium.r2.shared.publication.ReadingProgression as PublicationReadingProgression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ interface LcpAuthenticating {
* @param sender Free object that can be used by reading apps to give some UX context when
* presenting dialogs.
*/
suspend fun retrievePassphrase(license: AuthenticatedLicense, reason: AuthenticationReason, allowUserInteraction: Boolean, sender: Any? = null): String?

suspend fun retrievePassphrase(
license: AuthenticatedLicense,
reason: AuthenticationReason,
allowUserInteraction: Boolean,
sender: Any? = null
): String?

enum class AuthenticationReason {

Expand Down Expand Up @@ -94,10 +98,8 @@ interface LcpAuthenticating {
val user: User?
get() = document.user
}

}


@Deprecated("Renamed to `LcpAuthenticating`", replaceWith = ReplaceWith("LcpAuthenticating"))
typealias LCPAuthenticating = LcpAuthenticating

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal class LcpContentProtection(
?: this.authentication

val license = lcpService
.retrieveLicense(asset.file, authentication, allowUserInteraction, sender)
.retrieveLicense(asset.file, authentication, allowUserInteraction, sender)

val serviceFactory = LcpContentProtectionService
.createFactory(license?.getOrNull(), license?.exceptionOrNull())
Expand All @@ -55,5 +55,4 @@ internal class LcpContentProtection(

return Try.success(protectedFile)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ class LcpContentProtectionService(val license: LcpLicense?, override val error:

companion object {

fun createFactory(license: LcpLicense?, error: LcpException?): (Publication.Service.Context) -> LcpContentProtectionService =
fun createFactory(license: LcpLicense?, error: LcpException?): (Publication.Service.Context) -> LcpContentProtectionService =
{ LcpContentProtectionService(license, error) }

}

}

/**
Expand Down
Loading