Merge pull request #719 from esensar/feature/712-password-protected-pdf
Support opening password protected PDF files
This commit is contained in:
commit
4d59b24be0
|
@ -64,7 +64,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:84c71fdcc1'
|
implementation 'com.github.SimpleMobileTools:Simple-Commons:a8693482e8'
|
||||||
implementation 'com.github.tibbi:AndroidPdfViewer:e6a533125b'
|
implementation 'com.github.tibbi:AndroidPdfViewer:e6a533125b'
|
||||||
implementation 'com.github.Stericson:RootTools:df729dcb13'
|
implementation 'com.github.Stericson:RootTools:df729dcb13'
|
||||||
implementation 'com.github.Stericson:RootShell:1.6'
|
implementation 'com.github.Stericson:RootShell:1.6'
|
||||||
|
|
|
@ -3,12 +3,15 @@ package com.simplemobiletools.filemanager.pro.activities
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.print.PrintAttributes
|
import android.print.PrintAttributes
|
||||||
import android.print.PrintManager
|
import android.print.PrintManager
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle
|
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.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
|
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
|
||||||
import com.simplemobiletools.commons.helpers.isPiePlus
|
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.hideSystemUI
|
||||||
import com.simplemobiletools.filemanager.pro.extensions.showSystemUI
|
import com.simplemobiletools.filemanager.pro.extensions.showSystemUI
|
||||||
import com.simplemobiletools.filemanager.pro.helpers.PdfDocumentAdapter
|
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() {
|
class PDFViewerActivity : SimpleActivity() {
|
||||||
private var realFilePath = ""
|
private var realFilePath = ""
|
||||||
private var isFullScreen = false
|
private var isFullScreen = false
|
||||||
|
private var passwordDialog: EnterPasswordDialog? = null
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
showTransparentTop = true
|
showTransparentTop = true
|
||||||
|
@ -91,16 +98,42 @@ class PDFViewerActivity : SimpleActivity() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadPdfViewer(uri)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadPdfViewer(uri: Uri, filePassword: String? = null) {
|
||||||
val primaryColor = getProperPrimaryColor()
|
val primaryColor = getProperPrimaryColor()
|
||||||
pdf_viewer.setBackgroundColor(getProperBackgroundColor())
|
pdf_viewer.setBackgroundColor(getProperBackgroundColor())
|
||||||
pdf_viewer.fromUri(uri)
|
pdf_viewer.fromUri(uri)
|
||||||
|
.password(filePassword)
|
||||||
.scrollHandle(DefaultScrollHandle(this, primaryColor.getContrastColor(), primaryColor))
|
.scrollHandle(DefaultScrollHandle(this, primaryColor.getContrastColor(), primaryColor))
|
||||||
.spacing(15)
|
.spacing(15)
|
||||||
.onTap { toggleFullScreen() }
|
.onTap { toggleFullScreen() }
|
||||||
.onError {
|
.onError {
|
||||||
|
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))
|
showErrorToast(it.localizedMessage?.toString() ?: getString(R.string.unknown_error_occurred))
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
.onLoad {
|
||||||
|
passwordDialog?.dismiss(notify = false)
|
||||||
|
}
|
||||||
.load()
|
.load()
|
||||||
|
|
||||||
showSystemUI(true)
|
showSystemUI(true)
|
||||||
|
|
Loading…
Reference in New Issue