diff --git a/orion-viewer/src/main/java/com/artifex/mupdf/viewer/MuPDFCore.java b/orion-viewer/src/main/java/com/artifex/mupdf/viewer/MuPDFCore.java index ad20a4683..1d090d6fd 100644 --- a/orion-viewer/src/main/java/com/artifex/mupdf/viewer/MuPDFCore.java +++ b/orion-viewer/src/main/java/com/artifex/mupdf/viewer/MuPDFCore.java @@ -16,10 +16,14 @@ import com.artifex.mupdf.fitz.StructuredText; import com.artifex.mupdf.fitz.android.AndroidDrawDevice; +import kotlin.jvm.Volatile; + public class MuPDFCore { public Document doc; private Outline[] outline; + + @Volatile private int pageCount = -1; private int currentPage; private Page page; @@ -231,7 +235,11 @@ public synchronized boolean needsPassword() { } public synchronized boolean authenticatePassword(String password) { - return doc.authenticatePassword(password); + boolean res = doc.authenticatePassword(password); + if (res) { + pageCount = doc.countPages(); + } + return res; } /** diff --git a/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionViewerActivity.kt b/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionViewerActivity.kt index d1a8f1fdd..09f7a3752 100644 --- a/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionViewerActivity.kt +++ b/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionViewerActivity.kt @@ -28,6 +28,7 @@ import universe.constellation.orion.viewer.device.Device import universe.constellation.orion.viewer.dialog.SearchDialog import universe.constellation.orion.viewer.dialog.TapHelpDialog import universe.constellation.orion.viewer.dialog.create +import universe.constellation.orion.viewer.document.Document import universe.constellation.orion.viewer.layout.SimpleLayoutStrategy import universe.constellation.orion.viewer.prefs.GlobalOptions import universe.constellation.orion.viewer.prefs.initalizer @@ -280,6 +281,14 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT } try { + if (!askPassword(newDocument)) { + showErrorOrFallbackPanel( + getString(R.string.crash_on_book_opening_encrypted), + intent + ) + return@launch + } + if (newDocument.pageCount == 0) { showErrorAndErrorPanel( getString(R.string.crash_on_book_opening_title), @@ -297,9 +306,6 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT val layoutStrategy = SimpleLayoutStrategy.create() val controller1 = Controller(this@OrionViewerActivity, newDocument, layoutStrategy, rootJob, context = executor) - if (!askPassword(controller1)) { - return@launch - } val lastPageInfo1 = loadBookParameters(rootJob, file) log("Read LastPageInfo for page ${lastPageInfo1.pageNumber}") @@ -891,13 +897,13 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT } } - private suspend fun askPassword(controller: Controller): Boolean { + private suspend fun askPassword(controller: Document): Boolean { if (controller.needPassword()) { val view = layoutInflater.inflate(R.layout.password, null) val builder = createThemedAlertBuilder() builder.setView(view) - .setNegativeButton(R.string.string_cancel) { dialog, _ -> dialog.dismiss() } + .setNegativeButton(R.string.string_cancel) { dialog, _ -> dialog.cancel() } .setPositiveButton(R.string.string_apply) { _, _ -> } @@ -917,6 +923,7 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT } } } + dialog.setOnCancelListener { continuation.resume(false) } diff --git a/orion-viewer/src/main/res/values-ru/fileopen.xml b/orion-viewer/src/main/res/values-ru/fileopen.xml index 165422000..659f6ca81 100644 --- a/orion-viewer/src/main/res/values-ru/fileopen.xml +++ b/orion-viewer/src/main/res/values-ru/fileopen.xml @@ -22,6 +22,7 @@ Ошибка при обработке интента Ошибка при открытии \`%1$s\` файла. Пожалуйста, отправьте сообщение об ошибке: Ошибка при открытии \`%1$s\` файла: + Зашифрованный документ Отправить… [Пожалуйста, укажите дополнительную информацию (как воспроизвести проблему)] diff --git a/orion-viewer/src/main/res/values/fileopen.xml b/orion-viewer/src/main/res/values/fileopen.xml index b682da61b..b7f9f76b4 100644 --- a/orion-viewer/src/main/res/values/fileopen.xml +++ b/orion-viewer/src/main/res/values/fileopen.xml @@ -24,6 +24,8 @@ Error during file \`%1$s\` opening. Please report an issue: Error during file \`%1$s\` opening: + Encrypted document + Send… [Please provide additional details (steps to reproduce issue)]