Skip to content

Commit

Permalink
Various changes for v3 (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
qnga authored Jul 21, 2023
1 parent 6a489f7 commit f911a2c
Show file tree
Hide file tree
Showing 139 changed files with 839 additions and 5,185 deletions.
1 change: 1 addition & 0 deletions readium/lcp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ plugins {
}

android {
resourcePrefix = "readium_"

compileSdk = 33
defaultConfig {
Expand Down
11 changes: 4 additions & 7 deletions readium/lcp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<!--
~ Module: r2-lcp-kotlin
~ Developers: Aferdita Muriqi, Clément Baumann
~
~ Copyright (c) 2018. Readium Foundation. All rights reserved.
~ Use of this source code is governed by a BSD-style license which is detailed in the
~ LICENSE file present in the project repository where this source code is maintained.
-->
Copyright 2023 Readium Foundation. All rights reserved.
Use of this source code is governed by the BSD-style license
available in the top-level LICENSE file of the project.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

Expand Down
64 changes: 32 additions & 32 deletions readium/lcp/src/main/java/org/readium/r2/lcp/LcpException.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ sealed class LcpException(
) : this(userMessageId, *args, quantity = quantity, cause = cause)

/** The interaction is not available with this License. */
object LicenseInteractionNotAvailable : LcpException(R.string.r2_lcp_exception_license_interaction_not_available)
object LicenseInteractionNotAvailable : LcpException(R.string.readium_lcp_exception_license_interaction_not_available)

/** This License's profile is not supported by liblcp. */
object LicenseProfileNotSupported : LcpException(R.string.r2_lcp_exception_license_profile_not_supported)
object LicenseProfileNotSupported : LcpException(R.string.readium_lcp_exception_license_profile_not_supported)

/** Failed to retrieve the Certificate Revocation List. */
object CrlFetching : LcpException(R.string.r2_lcp_exception_crl_fetching)
object CrlFetching : LcpException(R.string.readium_lcp_exception_crl_fetching)

/** A network request failed with the given exception. */
class Network(override val cause: Throwable?) : LcpException(R.string.r2_lcp_exception_network, cause = cause)
class Network(override val cause: Throwable?) : LcpException(R.string.readium_lcp_exception_network, cause = cause)

/**
* An unexpected LCP exception occurred. Please post an issue on r2-lcp-kotlin with the error
* message and how to reproduce it.
*/
class Runtime(override val message: String) : LcpException(R.string.r2_lcp_exception_runtime)
class Runtime(override val message: String) : LcpException(R.string.readium_lcp_exception_runtime)

/** An unknown low-level exception was reported. */
class Unknown(override val cause: Throwable?) : LcpException(R.string.r2_lcp_exception_unknown)
class Unknown(override val cause: Throwable?) : LcpException(R.string.readium_lcp_exception_unknown)

/**
* Errors while checking the status of the License, using the Status Document.
Expand All @@ -59,13 +59,13 @@ sealed class LcpException(
constructor(@StringRes userMessageId: Int, vararg args: Any) : this(userMessageId, *args, quantity = null)
constructor(@PluralsRes userMessageId: Int, quantity: Int, vararg args: Any) : this(userMessageId, *args, quantity = quantity)

class Cancelled(val date: Date) : LicenseStatus(R.string.r2_lcp_exception_license_status_cancelled, date)
class Cancelled(val date: Date) : LicenseStatus(R.string.readium_lcp_exception_license_status_cancelled, date)

class Returned(val date: Date) : LicenseStatus(R.string.r2_lcp_exception_license_status_returned, date)
class Returned(val date: Date) : LicenseStatus(R.string.readium_lcp_exception_license_status_returned, date)

class NotStarted(val start: Date) : LicenseStatus(R.string.r2_lcp_exception_license_status_not_started, start)
class NotStarted(val start: Date) : LicenseStatus(R.string.readium_lcp_exception_license_status_not_started, start)

class Expired(val end: Date) : LicenseStatus(R.string.r2_lcp_exception_license_status_expired, end)
class Expired(val end: Date) : LicenseStatus(R.string.readium_lcp_exception_license_status_expired, end)

/**
* If the license has been revoked, the user message should display the number of devices which
Expand All @@ -74,7 +74,7 @@ sealed class LcpException(
* appear (certainly not "The license was registered by 0 devices").
*/
class Revoked(val date: Date, val devicesCount: Int) :
LicenseStatus(R.plurals.r2_lcp_exception_license_status_revoked, devicesCount, date, devicesCount)
LicenseStatus(R.plurals.readium_lcp_exception_license_status_revoked, devicesCount, date, devicesCount)
}

/**
Expand All @@ -83,13 +83,13 @@ sealed class LcpException(
sealed class Renew(@StringRes userMessageId: Int) : LcpException(userMessageId) {

/** Your publication could not be renewed properly. */
object RenewFailed : Renew(R.string.r2_lcp_exception_renew_renew_failed)
object RenewFailed : Renew(R.string.readium_lcp_exception_renew_renew_failed)

/** Incorrect renewal period, your publication could not be renewed. */
class InvalidRenewalPeriod(val maxRenewDate: Date?) : Renew(R.string.r2_lcp_exception_renew_invalid_renewal_period)
class InvalidRenewalPeriod(val maxRenewDate: Date?) : Renew(R.string.readium_lcp_exception_renew_invalid_renewal_period)

/** An unexpected error has occurred on the licensing server. */
object UnexpectedServerError : Renew(R.string.r2_lcp_exception_renew_unexpected_server_error)
object UnexpectedServerError : Renew(R.string.readium_lcp_exception_renew_unexpected_server_error)
}

/**
Expand All @@ -98,29 +98,29 @@ sealed class LcpException(
sealed class Return(@StringRes userMessageId: Int) : LcpException(userMessageId) {

/** Your publication could not be returned properly. */
object ReturnFailed : Return(R.string.r2_lcp_exception_return_return_failed)
object ReturnFailed : Return(R.string.readium_lcp_exception_return_return_failed)

/** Your publication has already been returned before or is expired. */

object AlreadyReturnedOrExpired : Return(R.string.r2_lcp_exception_return_already_returned_or_expired)
object AlreadyReturnedOrExpired : Return(R.string.readium_lcp_exception_return_already_returned_or_expired)

/** An unexpected error has occurred on the licensing server. */
object UnexpectedServerError : Return(R.string.r2_lcp_exception_return_unexpected_server_error)
object UnexpectedServerError : Return(R.string.readium_lcp_exception_return_unexpected_server_error)
}

/**
* Errors while parsing the License or Status JSON Documents.
*/
sealed class Parsing(@StringRes userMessageId: Int = R.string.r2_lcp_exception_parsing) : LcpException(userMessageId) {
sealed class Parsing(@StringRes userMessageId: Int = R.string.readium_lcp_exception_parsing) : LcpException(userMessageId) {

/** The JSON is malformed and can't be parsed. */
object MalformedJSON : Parsing(R.string.r2_lcp_exception_parsing_malformed_json)
object MalformedJSON : Parsing(R.string.readium_lcp_exception_parsing_malformed_json)

/** The JSON is not representing a valid License Document. */
object LicenseDocument : Parsing(R.string.r2_lcp_exception_parsing_license_document)
object LicenseDocument : Parsing(R.string.readium_lcp_exception_parsing_license_document)

/** The JSON is not representing a valid Status Document. */
object StatusDocument : Parsing(R.string.r2_lcp_exception_parsing_status_document)
object StatusDocument : Parsing(R.string.readium_lcp_exception_parsing_status_document)

/** Invalid Link. */
object Link : Parsing()
Expand All @@ -141,39 +141,39 @@ sealed class LcpException(
sealed class Container(@StringRes userMessageId: Int) : LcpException(userMessageId) {

/** Can't access the container, it's format is wrong. */
object OpenFailed : Container(R.string.r2_lcp_exception_container_open_failed)
object OpenFailed : Container(R.string.readium_lcp_exception_container_open_failed)

/** The file at given relative path is not found in the Container. */
class FileNotFound(val path: String) : Container(R.string.r2_lcp_exception_container_file_not_found)
class FileNotFound(val path: String) : Container(R.string.readium_lcp_exception_container_file_not_found)

/** Can't read the file at given relative path in the Container. */
class ReadFailed(val path: String) : Container(R.string.r2_lcp_exception_container_read_failed)
class ReadFailed(val path: String) : Container(R.string.readium_lcp_exception_container_read_failed)

/** Can't write the file at given relative path in the Container. */
class WriteFailed(val path: String) : Container(R.string.r2_lcp_exception_container_write_failed)
class WriteFailed(val path: String) : Container(R.string.readium_lcp_exception_container_write_failed)
}

/**
* An error occurred while checking the integrity of the License, it can't be retrieved.
*/
sealed class LicenseIntegrity(@StringRes userMessageId: Int) : LcpException(userMessageId) {

object CertificateRevoked : LicenseIntegrity(R.string.r2_lcp_exception_license_integrity_certificate_revoked)
object CertificateRevoked : LicenseIntegrity(R.string.readium_lcp_exception_license_integrity_certificate_revoked)

object InvalidCertificateSignature : LicenseIntegrity(R.string.r2_lcp_exception_license_integrity_invalid_certificate_signature)
object InvalidCertificateSignature : LicenseIntegrity(R.string.readium_lcp_exception_license_integrity_invalid_certificate_signature)

object InvalidLicenseSignatureDate : LicenseIntegrity(R.string.r2_lcp_exception_license_integrity_invalid_license_signature_date)
object InvalidLicenseSignatureDate : LicenseIntegrity(R.string.readium_lcp_exception_license_integrity_invalid_license_signature_date)

object InvalidLicenseSignature : LicenseIntegrity(R.string.r2_lcp_exception_license_integrity_invalid_license_signature)
object InvalidLicenseSignature : LicenseIntegrity(R.string.readium_lcp_exception_license_integrity_invalid_license_signature)

object InvalidUserKeyCheck : LicenseIntegrity(R.string.r2_lcp_exception_license_integrity_invalid_user_key_check)
object InvalidUserKeyCheck : LicenseIntegrity(R.string.readium_lcp_exception_license_integrity_invalid_user_key_check)
}

sealed class Decryption(@StringRes userMessageId: Int) : LcpException(userMessageId) {

object ContentKeyDecryptError : Decryption(R.string.r2_lcp_exception_decryption_content_key_decrypt_error)
object ContentKeyDecryptError : Decryption(R.string.readium_lcp_exception_decryption_content_key_decrypt_error)

object ContentDecryptError : Decryption(R.string.r2_lcp_exception_decryption_content_decrypt_error)
object ContentDecryptError : Decryption(R.string.readium_lcp_exception_decryption_content_decrypt_error)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class LcpDialogAuthentication : LcpAuthenticating {

val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
@SuppressLint("InflateParams") // https://stackoverflow.com/q/26404951/1474476
val dialogView = inflater.inflate(R.layout.r2_lcp_auth_dialog, null)
val dialogView = inflater.inflate(R.layout.readium_lcp_auth_dialog, null)

val title = dialogView.findViewById(R.id.r2_title) as TextView
val description = dialogView.findViewById(R.id.r2_description) as TextView
Expand All @@ -85,16 +85,16 @@ class LcpDialogAuthentication : LcpAuthenticating {

when (reason) {
LcpAuthenticating.AuthenticationReason.PassphraseNotFound -> {
title.text = context.getString(R.string.r2_lcp_dialog_reason_passphraseNotFound)
title.text = context.getString(R.string.readium_lcp_dialog_reason_passphraseNotFound)
}
LcpAuthenticating.AuthenticationReason.InvalidPassphrase -> {
title.text = context.getString(R.string.r2_lcp_dialog_reason_invalidPassphrase)
passwordLayout.error = context.getString(R.string.r2_lcp_dialog_reason_invalidPassphrase)
title.text = context.getString(R.string.readium_lcp_dialog_reason_invalidPassphrase)
passwordLayout.error = context.getString(R.string.readium_lcp_dialog_reason_invalidPassphrase)
}
}

val provider = tryOr(license.provider) { Uri.parse(license.provider).host }
description.text = context.getString(R.string.r2_lcp_dialog_prompt, provider)
description.text = context.getString(R.string.readium_lcp_dialog_prompt, provider)

hint.text = license.hint

Expand Down Expand Up @@ -129,12 +129,12 @@ class LcpDialogAuthentication : LcpAuthenticating {

private fun showHelpDialog(context: Context, links: List<Link>) {
val titles = links.map {
it.title ?: tryOr(context.getString(R.string.r2_lcp_dialog_support)) {
it.title ?: tryOr(context.getString(R.string.readium_lcp_dialog_support)) {
when (Uri.parse(it.href).scheme) {
"http", "https" -> context.getString(R.string.r2_lcp_dialog_support_web)
"tel" -> context.getString(R.string.r2_lcp_dialog_support_phone)
"mailto" -> context.getString(R.string.r2_lcp_dialog_support_mail)
else -> context.getString(R.string.r2_lcp_dialog_support)
"http", "https" -> context.getString(R.string.readium_lcp_dialog_support_web)
"tel" -> context.getString(R.string.readium_lcp_dialog_support_phone)
"mailto" -> context.getString(R.string.readium_lcp_dialog_support_mail)
else -> context.getString(R.string.readium_lcp_dialog_support)
}
}
}.toTypedArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="@string/r2_lcp_dialog_cancel"
android:text="@string/readium_lcp_dialog_cancel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

Expand Down Expand Up @@ -85,7 +85,7 @@
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="@string/r2_lcp_dialog_continue"
android:text="@string/readium_lcp_dialog_continue"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/r2_passwordLayout" />
Expand All @@ -98,7 +98,7 @@
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:background="@android:color/transparent"
android:text="@string/r2_lcp_dialog_forgotPassphrase"
android:text="@string/readium_lcp_dialog_forgotPassphrase"
android:textAlignment="viewStart"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -112,7 +112,7 @@
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:background="@android:color/transparent"
android:text="@string/r2_lcp_dialog_help"
android:text="@string/readium_lcp_dialog_help"
android:textAlignment="viewStart"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
Expand Down
Loading

0 comments on commit f911a2c

Please sign in to comment.