Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu committed Jul 24, 2023
1 parent 9a45585 commit b674582
Show file tree
Hide file tree
Showing 33 changed files with 125 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

package org.readium.adapters.pdfium.document

import com.shockwave.pdfium.PdfDocument as _PdfiumDocument
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import org.readium.r2.shared.publication.Publication
import org.readium.r2.shared.publication.protection.ContentProtection
import org.readium.r2.shared.publication.services.ContentProtectionService

public class LcpContentProtectionService(public val license: LcpLicense?, override val error: LcpException?) : ContentProtectionService {
public class LcpContentProtectionService(
public val license: LcpLicense?,
override val error: LcpException?
) : ContentProtectionService {

override val isRestricted: Boolean = license == null

Expand All @@ -26,7 +29,9 @@ public class LcpContentProtectionService(public val license: LcpLicense?, overri

public companion object {

public fun createFactory(license: LcpLicense?, error: LcpException?): (Publication.Service.Context) -> LcpContentProtectionService =
public fun createFactory(license: LcpLicense?, error: LcpException?): (
Publication.Service.Context
) -> LcpContentProtectionService =
{ LcpContentProtectionService(license, error) }
}
}
Expand Down
4 changes: 3 additions & 1 deletion readium/lcp/src/main/java/org/readium/r2/lcp/LcpException.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ public sealed class LcpException(
/**
* Errors while parsing the License or Status JSON Documents.
*/
public sealed class Parsing(@StringRes userMessageId: Int = R.string.readium_lcp_exception_parsing) : LcpException(userMessageId) {
public sealed class Parsing(
@StringRes userMessageId: Int = R.string.readium_lcp_exception_parsing
) : LcpException(userMessageId) {

/** The JSON is malformed and can't be parsed. */
public object MalformedJSON : Parsing(R.string.readium_lcp_exception_parsing_malformed_json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ public class LicenseDocument(public val data: ByteArray) {
public fun links(rel: Rel, type: MediaType? = null): List<Link> =
links.allWithRel(rel.rawValue, type)

public fun url(rel: Rel, preferredType: MediaType? = null, parameters: URLParameters = emptyMap()): URL {
public fun url(
rel: Rel,
preferredType: MediaType? = null,
parameters: URLParameters = emptyMap()
): URL {
val link = link(rel, preferredType)
?: links.firstWithRelAndNoType(rel.rawValue)
?: throw LcpException.Parsing.Url(rel = rel.rawValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ public class StatusDocument(public val data: ByteArray) {
internal fun linkWithNoType(rel: Rel): Link? =
links.firstWithRelAndNoType(rel.rawValue)

public fun url(rel: Rel, preferredType: MediaType? = null, parameters: URLParameters = emptyMap()): URL {
public fun url(
rel: Rel,
preferredType: MediaType? = null,
parameters: URLParameters = emptyMap()
): URL {
val link = link(rel, preferredType)
?: linkWithNoType(rel)
?: throw LcpException.Parsing.Url(rel = rel.rawValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,21 @@ public data class HtmlDecorationTemplate(
public companion object {

/** Creates a new decoration template for the highlight style. */
public fun highlight(@ColorInt defaultTint: Int, lineWeight: Int, cornerRadius: Int, alpha: Double): HtmlDecorationTemplate =
public fun highlight(
@ColorInt defaultTint: Int,
lineWeight: Int,
cornerRadius: Int,
alpha: Double
): HtmlDecorationTemplate =
createTemplate(asHighlight = true, defaultTint = defaultTint, lineWeight = lineWeight, cornerRadius = cornerRadius, alpha = alpha)

/** Creates a new decoration template for the underline style. */
public fun underline(@ColorInt defaultTint: Int, lineWeight: Int, cornerRadius: Int, alpha: Double): HtmlDecorationTemplate =
public fun underline(
@ColorInt defaultTint: Int,
lineWeight: Int,
cornerRadius: Int,
alpha: Double
): HtmlDecorationTemplate =
createTemplate(asHighlight = false, defaultTint = defaultTint, lineWeight = lineWeight, cornerRadius = cornerRadius, alpha = alpha)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package org.readium.r2.navigator.media

import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import org.readium.r2.navigator.ExperimentalAudiobook

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public interface MediaPlayer {

public fun locatorFromMediaId(mediaId: String, extras: Bundle?): Locator?

public suspend fun coverOfPublication(publication: Publication, publicationId: PublicationId): Bitmap?
public suspend fun coverOfPublication(
publication: Publication,
publicationId: PublicationId
): Bitmap?

public fun onNotificationPosted(notificationId: Int, notification: Notification)
public fun onNotificationCancelled(notificationId: Int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ public open class MediaService : MediaBrowserServiceCompat(), CoroutineScope by
/**
* Returns the cover for the given [publication] which should be used in media notifications.
*/
public open suspend fun coverOfPublication(publicationId: PublicationId, publication: Publication): Bitmap? =
public open suspend fun coverOfPublication(
publicationId: PublicationId,
publication: Publication
): Bitmap? =
publication.cover()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.readium.r2.navigator.preferences.Configurable
import org.readium.r2.navigator.preferences.PreferencesEditor
import org.readium.r2.shared.ExperimentalReadiumApi
import org.readium.r2.shared.publication.Locator
import org.readium.r2.shared.publication.Metadata
import org.readium.r2.shared.publication.Publication

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import org.readium.r2.navigator.media3.api.MediaMetadataProvider
import org.readium.r2.navigator.media3.audio.AudioEngineProvider
import org.readium.r2.shared.ExperimentalReadiumApi
import org.readium.r2.shared.publication.Locator
import org.readium.r2.shared.publication.Metadata
import org.readium.r2.shared.publication.Publication
import org.readium.r2.shared.publication.indexOfFirstWithHref

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public interface TtsEngineProvider<S : TtsEngine.Settings, P : TtsEngine.Prefere
/**
* Updates [previousPreferences] to honor the given Media3 [playbackParameters].
*/
public fun updatePlaybackParameters(previousPreferences: P, playbackParameters: PlaybackParameters): P
public fun updatePlaybackParameters(
previousPreferences: P,
playbackParameters: PlaybackParameters
): P

/**
* Maps an engine-specific error to Media3 [PlaybackException].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.media3.common.PlaybackException.*
import androidx.media3.common.PlaybackParameters
import org.readium.r2.navigator.media3.tts.TtsEngineProvider
import org.readium.r2.shared.ExperimentalReadiumApi
import org.readium.r2.shared.publication.Metadata
import org.readium.r2.shared.publication.Publication

@ExperimentalReadiumApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public class OPDS1Parser {
}
}

public suspend fun parseRequest(request: HttpRequest, client: HttpClient = DefaultHttpClient()): Try<ParseData, Exception> {
public suspend fun parseRequest(
request: HttpRequest,
client: HttpClient = DefaultHttpClient()
): Try<ParseData, Exception> {
return client.fetchWithDecoder(request) {
this.parse(it.body, URL(request.url))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public class OPDS2Parser {
}
}

public suspend fun parseRequest(request: HttpRequest, client: HttpClient = DefaultHttpClient()): Try<ParseData, Exception> {
public suspend fun parseRequest(
request: HttpRequest,
client: HttpClient = DefaultHttpClient()
): Try<ParseData, Exception> {
return client.fetchWithDecoder(request) {
this.parse(it.body, URL(request.url))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ public open class UserException protected constructor(
public companion object {
public operator fun invoke(@StringRes userMessageId: Int, vararg args: Any?): Content =
LocalizedString(userMessageId, args, null)
public operator fun invoke(@PluralsRes userMessageId: Int, quantity: Int?, vararg args: Any?): Content =
public operator fun invoke(
@PluralsRes userMessageId: Int,
quantity: Int?,
vararg args: Any?
): Content =
LocalizedString(userMessageId, args, quantity)
public operator fun invoke(cause: UserException): Content =
Exception(cause)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import java.io.Serializable
public sealed class UserProperty(public var ref: String, public var name: String)

@Deprecated("Migrate to the new Settings API (see migration guide)", level = DeprecationLevel.ERROR)
public class Enumerable(public var index: Int, private val values: List<String>, ref: String, name: String)
public class Enumerable(
public var index: Int,
private val values: List<String>,
ref: String,
name: String
)

@Deprecated("Migrate to the new Settings API (see migration guide)", level = DeprecationLevel.ERROR)
public class Incremental(
Expand All @@ -31,7 +36,13 @@ public class Incremental(
)

@Deprecated("Migrate to the new Settings API (see migration guide)", level = DeprecationLevel.ERROR)
public class Switchable(onValue: String, offValue: String, public var on: Boolean, ref: String, name: String)
public class Switchable(
onValue: String,
offValue: String,
public var on: Boolean,
ref: String,
name: String
)

@Deprecated("Migrate to the new Settings API (see migration guide)", level = DeprecationLevel.ERROR)
public class UserProperties : Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public sealed class Try<out Success, out Failure> {
* Returns the result of [onSuccess] for the encapsulated value if this instance represents success or
* the result of [onFailure] function for the encapsulated value if it is failure.
*/
public inline fun <R> fold(onSuccess: (value: Success) -> R, onFailure: (exception: Failure) -> R): R =
public inline fun <R> fold(
onSuccess: (value: Success) -> R,
onFailure: (exception: Failure) -> R
): R =
when (this) {
is Try.Success -> onSuccess(value)
is Try.Failure -> onFailure(failureOrNull()!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ public fun JSONObject.optPositiveInt(name: String, fallback: Int = -1, remove: B
* If [remove] is true, then the mapping will be removed from the [JSONObject].
*/
@InternalReadiumApi
public fun JSONObject.optPositiveDouble(name: String, fallback: Double = -1.0, remove: Boolean = false): Double? {
public fun JSONObject.optPositiveDouble(
name: String,
fallback: Double = -1.0,
remove: Boolean = false
): Double? {
val double = optDouble(name, fallback)
val value = if (double >= 0) double else null
if (remove) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public class FallbackResource(
/**
* Falls back to alternative resources when the receiver fails.
*/
public fun Fetcher.Resource.fallback(fallbackResourceFactory: (Resource.Exception) -> Fetcher.Resource): Fetcher.Resource =
public fun Fetcher.Resource.fallback(
fallbackResourceFactory: (Resource.Exception) -> Fetcher.Resource
): Fetcher.Resource =
FallbackResource(this, fallbackResourceFactory)

/**
Expand Down Expand Up @@ -133,7 +135,10 @@ public abstract class TransformingResource(
/**
* Creates a [TransformingResource] using the given [transform] function.
*/
public operator fun invoke(resource: Fetcher.Resource, transform: suspend (ByteArray) -> ByteArray): TransformingResource =
public operator fun invoke(
resource: Fetcher.Resource,
transform: suspend (ByteArray) -> ByteArray
): TransformingResource =
object : TransformingResource(resource) {
override suspend fun transform(data: ResourceTry<ByteArray>): ResourceTry<ByteArray> =
data.mapCatching { transform(it) }
Expand Down Expand Up @@ -384,7 +389,7 @@ public class BufferingResource(
public fun Fetcher.Resource.buffered(
resourceLength: Long? = null,
size: Long = BufferingResource.DEFAULT_BUFFER_SIZE
) : BufferingResource =
): BufferingResource =
BufferingResource(resource = this, resourceLength = resourceLength, bufferSize = size)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import kotlinx.coroutines.withContext
import org.jsoup.Jsoup
import org.jsoup.parser.Parser
import org.readium.r2.shared.ExperimentalReadiumApi
import org.readium.r2.shared.Search
import org.readium.r2.shared.error.Try
import org.readium.r2.shared.resource.ResourceTry
import org.readium.r2.shared.resource.readAsString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public class RoutingFetcher(private val routes: List<Route>) : Fetcher {
*
* The default value for [accepts] means that the fetcher will accept any link.
*/
public class Route(public val fetcher: Fetcher, public val accepts: (Link) -> Boolean = { true })
public class Route(
public val fetcher: Fetcher,
public val accepts: (Link) -> Boolean = { true }
)

public constructor(local: Fetcher, remote: Fetcher) :
this(listOf(Route(local, Link::isLocal), Route(remote)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import org.xmlpull.v1.XmlPullParserFactory
* If [isCaseSensitive] is false, attribute and tag names are lowercased during the parsing
*/
@InternalReadiumApi
public class XmlParser(private val isNamespaceAware: Boolean = true, private val isCaseSensitive: Boolean = true) {
public class XmlParser(
private val isNamespaceAware: Boolean = true,
private val isCaseSensitive: Boolean = true
) {

private val parser: XmlPullParser = XmlPullParserFactory.newInstance().let {
it.isNamespaceAware = isNamespaceAware
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ package org.readium.r2.shared.publication

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import org.readium.r2.shared.util.MapWithDefaultCompanion

/**
* The [ContentLayout] defines how a [Publication] should be laid out, based on the declared
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ public interface ContentProtection {
quantity: Int? = null,
cause: Throwable? = null
) : UserException(userMessageId, quantity, *args, cause = cause) {
protected constructor(@StringRes userMessageId: Int, vararg args: Any?, cause: Throwable? = null) : this(userMessageId, *args, quantity = null, cause = cause)
protected constructor(
@StringRes userMessageId: Int,
vararg args: Any?,
cause: Throwable? = null
) : this(userMessageId, *args, quantity = null, cause = cause)

/**
* Exception returned when the given Content Protection [scheme] is not supported by the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ public class TextContentTokenizer(
/**
* A [ContentTokenizer] using the default [TextTokenizer] to split the text of the [Content.Element].
*/
public constructor(language: Language?, unit: TextUnit, overrideContentLanguage: Boolean = false) : this(
public constructor(
language: Language?,
unit: TextUnit,
overrideContentLanguage: Boolean = false
) : this(
language = language,
textTokenizerFactory = { contentLanguage -> DefaultTextContentTokenizer(unit, contentLanguage) },
overrideContentLanguage = overrideContentLanguage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import java.util.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.readium.r2.shared.ExperimentalReadiumApi
import org.readium.r2.shared.Search
import org.readium.r2.shared.error.Try
import org.readium.r2.shared.error.getOrThrow
import org.readium.r2.shared.fetcher.DefaultResourceContentExtractorFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public interface Resource : SuspendingCloseable {
public sealed class Exception(@StringRes userMessageId: Int, cause: Throwable? = null) : UserException(userMessageId, cause = cause) {

/** Equivalent to a 400 HTTP error. */
public class BadRequest(public val parameters: Map<String, String> = emptyMap(), cause: Throwable? = null) :
public class BadRequest(
public val parameters: Map<String, String> = emptyMap(),
cause: Throwable? = null
) :
Exception(R.string.readium_shared_resource_exception_bad_request, cause)

/** Equivalent to a 404 HTTP error. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public interface HttpClient {
*
* If the decoder fails, a MalformedResponse error is returned.
*/
public suspend fun <T> HttpClient.fetchWithDecoder(request: HttpRequest, decoder: (HttpFetchResponse) -> T): HttpTry<T> =
public suspend fun <T> HttpClient.fetchWithDecoder(
request: HttpRequest,
decoder: (HttpFetchResponse) -> T
): HttpTry<T> =
fetch(request)
.flatMap {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ public class HttpException(
*
* Returns null if the status code is a success.
*/
public operator fun invoke(statusCode: Int, mediaType: MediaType? = null, body: ByteArray? = null): HttpException? =
public operator fun invoke(
statusCode: Int,
mediaType: MediaType? = null,
body: ByteArray? = null
): HttpException? =
Kind.ofStatusCode(statusCode)?.let { kind ->
HttpException(kind, mediaType, body)
}
Expand Down
Loading

0 comments on commit b674582

Please sign in to comment.