Merge pull request #719 from esensar/feature/712-password-protected-pdf

Support opening password protected PDF files
This commit is contained in:
Tibor Kaputa 2023-07-07 19:01:53 +02:00 committed by GitHub
commit 4d59b24be0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 59 additions and 26 deletions

View File

@ -64,7 +64,7 @@ android {
}
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:84c71fdcc1'
implementation 'com.github.SimpleMobileTools:Simple-Commons:a8693482e8'
implementation 'com.github.tibbi:AndroidPdfViewer:e6a533125b'
implementation 'com.github.Stericson:RootTools:df729dcb13'
implementation 'com.github.Stericson:RootShell:1.6'

View File

@ -3,12 +3,15 @@ package com.simplemobiletools.filemanager.pro.activities
import android.content.Context
import android.content.res.Configuration
import android.graphics.Color
import android.net.Uri
import android.os.Bundle
import android.print.PrintAttributes
import android.print.PrintManager
import android.view.WindowManager
import android.widget.RelativeLayout
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle
import com.shockwave.pdfium.PdfPasswordException
import com.simplemobiletools.commons.dialogs.EnterPasswordDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
import com.simplemobiletools.commons.helpers.isPiePlus
@ -16,11 +19,15 @@ import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.extensions.hideSystemUI
import com.simplemobiletools.filemanager.pro.extensions.showSystemUI
import com.simplemobiletools.filemanager.pro.helpers.PdfDocumentAdapter
import kotlinx.android.synthetic.main.activity_pdf_viewer.*
import kotlinx.android.synthetic.main.activity_pdf_viewer.pdf_viewer
import kotlinx.android.synthetic.main.activity_pdf_viewer.pdf_viewer_appbar
import kotlinx.android.synthetic.main.activity_pdf_viewer.pdf_viewer_toolbar
import kotlinx.android.synthetic.main.activity_pdf_viewer.top_shadow
class PDFViewerActivity : SimpleActivity() {
private var realFilePath = ""
private var isFullScreen = false
private var passwordDialog: EnterPasswordDialog? = null
override fun onCreate(savedInstanceState: Bundle?) {
showTransparentTop = true
@ -91,15 +98,41 @@ class PDFViewerActivity : SimpleActivity() {
return
}
loadPdfViewer(uri)
}
private fun loadPdfViewer(uri: Uri, filePassword: String? = null) {
val primaryColor = getProperPrimaryColor()
pdf_viewer.setBackgroundColor(getProperBackgroundColor())
pdf_viewer.fromUri(uri)
.password(filePassword)
.scrollHandle(DefaultScrollHandle(this, primaryColor.getContrastColor(), primaryColor))
.spacing(15)
.onTap { toggleFullScreen() }
.onError {
showErrorToast(it.localizedMessage?.toString() ?: getString(R.string.unknown_error_occurred))
finish()
if (it is PdfPasswordException) {
// already entered a password and it was wrong
if (filePassword != null) {
toast(getString(R.string.invalid_password))
passwordDialog?.clearPassword()
} else {
passwordDialog = EnterPasswordDialog(
this,
callback = { password ->
loadPdfViewer(uri, password)
},
cancelCallback = {
finish()
}
)
}
} else {
showErrorToast(it.localizedMessage?.toString() ?: getString(R.string.unknown_error_occurred))
finish()
}
}
.onLoad {
passwordDialog?.dismiss(notify = false)
}
.load()

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Non atopou todas as cadeas que debería traducir? Existen algunhas máis en
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -53,4 +53,4 @@
<!-- Settings -->
<string name="enable_root_access">روٹ دی پہنچ چالو کرو</string>
<string name="press_back_twice">بند کرن لئی دو وار پچھلے دباؤݨ دی لوڑ اے</string>
</resources>
</resources>

View File

@ -55,7 +55,7 @@
<string name="others">Outros</string>
<string name="storage_free">Livre</string>
<string name="total_storage">Armazenamento total: %s</string>
<!-- Settings -->
<string name="enable_root_access">Ativar o acesso ao root</string>
<string name="press_back_twice">Pressione o botão "voltar" duas vezes para sair do app</string>

View File

@ -57,4 +57,4 @@
Não encontrou todas as cadeias a traduzir? Existem mais algumas em
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -53,4 +53,4 @@
<!-- Settings -->
<string name="enable_root_access">Omogoči root (korenski) dostop</string>
<string name="press_back_twice">Dvakratni pritisk nazaj za izhod iz aplikacije</string>
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>

View File

@ -57,4 +57,4 @@
Haven't found some strings? There's more at
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
-->
</resources>
</resources>