Commit a48cf652 authored by wanglei's avatar wanglei

...

parent 4ca8c937
......@@ -23,6 +23,8 @@ object ConstObject {
const val DO_SPLIT_PDF = "do_split_pdf"
const val DO_SAVE_PDF = "do_save_pdf"
const val DO_MERGE_PDF = "do_merge_pdf"
const val DO_LOCK_PDF = "do_lock_pdf"
const val DO_UNLOCK_PDF = "do_unlock_pdf"
var ifAgreePrivacy = false
get() {
......
......@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.content.Intent
import android.view.View
import androidx.lifecycle.lifecycleScope
import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_LOCK_PDF
import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_MERGE_PDF
import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_SPLIT_PDF
import com.base.pdfviewerscannerwhite.bean.DocumentBean
......@@ -12,6 +13,7 @@ import com.base.pdfviewerscannerwhite.helper.BaseActivity
import com.base.pdfviewerscannerwhite.ui.adapter.DocumentAdapter
import com.base.pdfviewerscannerwhite.ui.main.DocumentPresenter
import com.base.pdfviewerscannerwhite.ui.main.DocumentView
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showPdfPwdDialog
class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView {
......@@ -29,12 +31,23 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView
override fun initView() {
doWhat = intent.extras?.getString("doWhat", "") ?: ""
documentPresenter = DocumentPresenter(this, this, DocumentBean.TYPE_PDF, lifecycleScope)
if (doWhat == DO_SPLIT_PDF) {
binding.tvBtnNext.visibility = View.GONE
binding.tvSelectTip.text = "Select a project"
}
initAdapter()
documentPresenter.initData()
when (doWhat) {
DO_SPLIT_PDF -> {
binding.tvBtnNext.visibility = View.GONE
binding.tvSelectTip.text = "Select a project"
documentPresenter.initData()
}
DO_LOCK_PDF -> {
binding.tvBtnNext.visibility = View.GONE
binding.tvSelectTip.text = "Select a project"
documentPresenter.initUnLoadData()
}
}
}
override fun initListener() {
......@@ -59,6 +72,12 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView
putExtra("path", it.path)
})
}
if (doWhat == DO_LOCK_PDF) {
showPdfPwdDialog(it, null, false, encryptionAction = {
adapter.remove(it)
})
}
}
adapter.selectAction = {
if (it == 0) {
......
......@@ -55,7 +55,7 @@ class DocumentFragment() : BaseFragment<FragmentDocumentBinding>(), DocumentView
})
}
if (item.state == 1) {
requireContext().showPdfPwdDialog(null, item, true, verificationAction = { pwd ->
requireContext().showPdfPwdDialog(item, null, true, verificationAction = { pwd ->
startActivity(Intent(requireContext(), PdfActivity::class.java).apply {
putExtra("path", item.path)
putExtra("pwd", pwd)
......
......@@ -41,6 +41,17 @@ class DocumentPresenter(
}
fun initUnLoadData() = lifecycleScope.launch(Dispatchers.IO) {
val documentList = getDocumentBeanList()
documentList.forEach {
it.state = PdfBoxUtils.checkPdfEncryption(it.path)
}
val list = documentList.filter { it.state == 0 }
launch(Dispatchers.Main) {
documentView.refreshDocumentRv(list, true)
}
}
fun saveBookmarkChange(addRemove: Boolean, path: String) {
if (addRemove) {
SpStringUtils.addSpString(SpStringUtils.BOOKMARK_KEY, path)
......
package com.base.pdfviewerscannerwhite.ui.main
import android.content.Intent
import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_LOCK_PDF
import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_MERGE_PDF
import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_SPLIT_PDF
import com.base.pdfviewerscannerwhite.databinding.FragmentToolBinding
import com.base.pdfviewerscannerwhite.helper.BaseFragment
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfSelectActivity
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfSplitActivity
class ToolFragment : BaseFragment<FragmentToolBinding>() {
......@@ -30,6 +30,11 @@ class ToolFragment : BaseFragment<FragmentToolBinding>() {
putExtra("doWhat", DO_SPLIT_PDF)
})
}
binding.llLock.setOnClickListener {
startActivity(Intent(requireContext(), PdfSelectActivity::class.java).apply {
putExtra("doWhat", DO_LOCK_PDF)
})
}
}
}
\ No newline at end of file
......@@ -129,7 +129,7 @@ object DialogView {
binding.tvLock.text = "Lock PDF"
}
binding.llLock.setOnClickListener {
showPdfPwdDialog(dialog, item)
showPdfPwdDialog(item, dialog)
}
dialog.setOnDismissListener {
dismissAction.invoke()
......@@ -188,10 +188,11 @@ object DialogView {
@SuppressLint("SetTextI18n")
fun Context.showPdfPwdDialog(
firstDialog: Dialog?,
item: DocumentBean,
firstDialog: Dialog?,
isCheckPwd: Boolean = false,
verificationAction: ((pwd: String) -> Unit)? = null
verificationAction: ((pwd: String) -> Unit)? = null,
encryptionAction: (() -> Unit)? = null
) {
val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
val binding = DialogPdfPasswordBinding.inflate(LayoutInflater.from(this))
......@@ -243,6 +244,7 @@ object DialogView {
if (item.state == 0) {
PdfBoxUtils.setPassword(item.path, pwd, pwd)
toast("Success Encryption")
encryptionAction?.invoke()
}
if (item.state == 1) {
PdfBoxUtils.clearPassword(item.path, pwd)
......
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