Commit 6698b57f authored by 周文华's avatar 周文华

【修复】修复pdf加锁问题

parent 0005e831
...@@ -121,11 +121,11 @@ class PdfActivity : BaseActivity<ActivityPdfBinding>(), PdfView { ...@@ -121,11 +121,11 @@ class PdfActivity : BaseActivity<ActivityPdfBinding>(), PdfView {
SearchTaskResult.set(null) SearchTaskResult.set(null)
if (muPDFCore?.needsPassword() == true) { if (muPDFCore?.needsPassword() == true) {
val pwd = intent.extras?.getString("pwd") ?: "" //val pwd = intent.extras?.getString("pwd") ?: ""
val flag = muPDFCore?.authenticatePassword(pwd) ?: false val flag = muPDFCore?.authenticatePassword(pwd) ?: false
if (flag) { if (flag) {
pdfPresenter.password = pwd pdfPresenter.password = pwd
pdfPageAdapter.setPassword(pwd) // pdfPageAdapter.setPassword(pwd)
createPdfUI() createPdfUI()
muPDFCore?.countPages()?.let { muPDFCore?.countPages()?.let {
//pdfPresenter.iniPdfPage(it) //pdfPresenter.iniPdfPage(it)
...@@ -351,7 +351,7 @@ class PdfActivity : BaseActivity<ActivityPdfBinding>(), PdfView { ...@@ -351,7 +351,7 @@ class PdfActivity : BaseActivity<ActivityPdfBinding>(), PdfView {
} }
private fun initAdapter() { private fun initAdapter() {
pdfPageAdapter = PdfPagerAdapter(path, uri){ pdfPageAdapter = PdfPagerAdapter(path, uri, mPassword = pwd){
iniSetVerticalSeekbar(it) iniSetVerticalSeekbar(it)
} }
pdfPageAdapter.clickAction = { pageIndex -> pdfPageAdapter.clickAction = { pageIndex ->
......
...@@ -15,6 +15,7 @@ import com.tom_roush.pdfbox.pdmodel.PDPage ...@@ -15,6 +15,7 @@ import com.tom_roush.pdfbox.pdmodel.PDPage
import com.tom_roush.pdfbox.pdmodel.PDPageContentStream import com.tom_roush.pdfbox.pdmodel.PDPageContentStream
import com.tom_roush.pdfbox.pdmodel.common.PDRectangle import com.tom_roush.pdfbox.pdmodel.common.PDRectangle
import com.tom_roush.pdfbox.pdmodel.encryption.AccessPermission import com.tom_roush.pdfbox.pdmodel.encryption.AccessPermission
import com.tom_roush.pdfbox.pdmodel.encryption.InvalidPasswordException
import com.tom_roush.pdfbox.pdmodel.encryption.StandardProtectionPolicy import com.tom_roush.pdfbox.pdmodel.encryption.StandardProtectionPolicy
import com.tom_roush.pdfbox.pdmodel.graphics.image.PDImageXObject import com.tom_roush.pdfbox.pdmodel.graphics.image.PDImageXObject
import com.tom_roush.pdfbox.rendering.ImageType import com.tom_roush.pdfbox.rendering.ImageType
...@@ -90,6 +91,9 @@ object PdfBoxUtils { ...@@ -90,6 +91,9 @@ object PdfBoxUtils {
state = 0 state = 0
} }
} }
}catch (e: InvalidPasswordException){
e.printStackTrace()
state = 1
} catch (e: IOException) { } catch (e: IOException) {
e.printStackTrace() e.printStackTrace()
state = -1 state = -1
......
...@@ -27,10 +27,10 @@ class PdfPagerAdapter( ...@@ -27,10 +27,10 @@ class PdfPagerAdapter(
val uri: String? = null, val uri: String? = null,
val itemLayout: Int = R.layout.item_pdf_pager, val itemLayout: Int = R.layout.item_pdf_pager,
private val previewScale: Float = 1f, private val previewScale: Float = 1f,
private val mPassword: String? = null,
initCallBack: ((itemCount: Int) -> Unit)? = null initCallBack: ((itemCount: Int) -> Unit)? = null
) : BaseQuickAdapter<PdfPageBean, PdfPagerAdapter.PdfPagerViewHolder>() { ) : BaseQuickAdapter<PdfPageBean, PdfPagerAdapter.PdfPagerViewHolder>() {
var mPassword: String? = null
var selectAction: ((enable: Boolean, allSelect: Boolean) -> Unit)? = null var selectAction: ((enable: Boolean, allSelect: Boolean) -> Unit)? = null
var clickAction: ((pageIndex: Int) -> Unit)? = null var clickAction: ((pageIndex: Int) -> Unit)? = null
...@@ -183,12 +183,6 @@ class PdfPagerAdapter( ...@@ -183,12 +183,6 @@ class PdfPagerAdapter(
notifyDataSetChanged() notifyDataSetChanged()
} }
@SuppressLint("NotifyDataSetChanged")
fun setPassword(password: String) {
mPassword = password
notifyDataSetChanged()
}
fun release() { fun release() {
scope.cancel() scope.cancel()
pdfRender = null pdfRender = null
......
...@@ -70,8 +70,7 @@ class PdfSplitActivity : BaseActivity<ActivityPdfSplitBinding>(), PdfView { ...@@ -70,8 +70,7 @@ class PdfSplitActivity : BaseActivity<ActivityPdfSplitBinding>(), PdfView {
} }
private fun initAdapter() { private fun initAdapter() {
pdfPagerAdapter = PdfPagerAdapter(path, null, R.layout.item_pdf_pager_split, 1.5f) pdfPagerAdapter = PdfPagerAdapter(path, null, R.layout.item_pdf_pager_split, 1.5f, mPassword = pwd)
pdfPagerAdapter.mPassword = pwd
pdfPagerAdapter.selectAction = { enable, allSelect -> pdfPagerAdapter.selectAction = { enable, allSelect ->
binding.tvBtnSplit.isEnabled = enable binding.tvBtnSplit.isEnabled = enable
binding.ivSelector.isSelected = allSelect binding.ivSelector.isSelected = allSelect
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment