Commit 6d575f28 authored by wanglei's avatar wanglei

...

parent a48cf652
...@@ -8,9 +8,9 @@ data class DocumentBean( ...@@ -8,9 +8,9 @@ data class DocumentBean(
val type: String = "", val type: String = "",
var isBookmarked: Boolean = false var isBookmarked: Boolean = false
) { ) {
var uiType: Int = 0//0首页模式 1合并选择模式 2拆分模式 var uiType: Int = 0//0首页模式 1合并选择模式 2拆分模式 3解锁加锁模式
var isSelect: Boolean = false var isSelect: Boolean = false
var state: Int = 0//0正常状态 1 锁定 var state: Int = -1//0正常状态 1 锁定
companion object { companion object {
const val TYPE_PDF = "type_pdf" const val TYPE_PDF = "type_pdf"
......
...@@ -49,7 +49,16 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV ...@@ -49,7 +49,16 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV
if (item == null) return if (item == null) return
val binding = ItemDocumentBinding.bind(holder.itemView) val binding = ItemDocumentBinding.bind(holder.itemView)
if (item.type == TYPE_PDF) { if (item.type == TYPE_PDF) {
checkPwd(item, binding.iv) if (item.state == -1) {
checkPwd(item, binding.iv)
} else {
var res = R.mipmap.h_pdfiocn
when (item.state) {
0 -> res = R.mipmap.h_pdfiocn
1 -> res = R.mipmap.suoding
}
binding.iv.setImageResource(res)
}
} }
val file = File(item.path) val file = File(item.path)
...@@ -99,6 +108,11 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV ...@@ -99,6 +108,11 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV
binding.flBookmark.visibility = View.GONE binding.flBookmark.visibility = View.GONE
binding.flMore.visibility = View.INVISIBLE binding.flMore.visibility = View.INVISIBLE
} }
3 -> {
binding.flBookmark.visibility = View.GONE
binding.flMore.visibility = View.INVISIBLE
}
} }
binding.root.setOnClickListener { binding.root.setOnClickListener {
...@@ -119,7 +133,6 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV ...@@ -119,7 +133,6 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV
iv.setImageResource(res) iv.setImageResource(res)
} }
} }
} }
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): DocumentViewHolder { override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): DocumentViewHolder {
......
...@@ -3,10 +3,12 @@ package com.base.pdfviewerscannerwhite.ui.document.pdf ...@@ -3,10 +3,12 @@ package com.base.pdfviewerscannerwhite.ui.document.pdf
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Intent import android.content.Intent
import android.view.View import android.view.View
import androidx.activity.addCallback
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_LOCK_PDF 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_MERGE_PDF
import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_SPLIT_PDF import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_SPLIT_PDF
import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_UNLOCK_PDF
import com.base.pdfviewerscannerwhite.bean.DocumentBean import com.base.pdfviewerscannerwhite.bean.DocumentBean
import com.base.pdfviewerscannerwhite.databinding.ActivityPdfSelectBinding import com.base.pdfviewerscannerwhite.databinding.ActivityPdfSelectBinding
import com.base.pdfviewerscannerwhite.helper.BaseActivity import com.base.pdfviewerscannerwhite.helper.BaseActivity
...@@ -46,12 +48,25 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView ...@@ -46,12 +48,25 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView
binding.tvSelectTip.text = "Select a project" binding.tvSelectTip.text = "Select a project"
documentPresenter.initUnLoadData() documentPresenter.initUnLoadData()
} }
DO_UNLOCK_PDF -> {
binding.tvBtnNext.visibility = View.GONE
binding.tvSelectTip.text = "Select a project"
documentPresenter.initLoadData()
}
} }
} }
override fun initListener() { override fun initListener() {
super.initListener() super.initListener()
onBackPressedDispatcher.addCallback {
finishToMain()
}
binding.flFanhui.setOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
binding.tvBtnNext.setOnClickListener { binding.tvBtnNext.setOnClickListener {
val selectList = adapter.items.filter { it.isSelect } val selectList = adapter.items.filter { it.isSelect }
...@@ -78,6 +93,11 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView ...@@ -78,6 +93,11 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView
adapter.remove(it) adapter.remove(it)
}) })
} }
if (doWhat == DO_UNLOCK_PDF) {
showPdfPwdDialog(it, null, false, encryptionAction = {
adapter.remove(it)
})
}
} }
adapter.selectAction = { adapter.selectAction = {
if (it == 0) { if (it == 0) {
...@@ -93,12 +113,16 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView ...@@ -93,12 +113,16 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView
} }
override fun refreshDocumentRv(documentList: List<DocumentBean>, isRefresh: Boolean) { override fun refreshDocumentRv(documentList: List<DocumentBean>, isRefresh: Boolean) {
binding.progressBar.visibility = View.GONE
if (doWhat == DO_MERGE_PDF) { if (doWhat == DO_MERGE_PDF) {
documentList.map { it.uiType = 1 } documentList.map { it.uiType = 1 }
} }
if (doWhat == DO_SPLIT_PDF) { if (doWhat == DO_SPLIT_PDF) {
documentList.map { it.uiType = 2 } documentList.map { it.uiType = 2 }
} }
if (doWhat == DO_LOCK_PDF || doWhat == DO_UNLOCK_PDF) {
documentList.map { it.uiType = 3 }
}
adapter.submitList(documentList) adapter.submitList(documentList)
} }
......
...@@ -52,6 +52,18 @@ class DocumentPresenter( ...@@ -52,6 +52,18 @@ class DocumentPresenter(
} }
} }
fun initLoadData() = lifecycleScope.launch(Dispatchers.IO) {
val documentList = getDocumentBeanList()
documentList.forEach {
it.state = PdfBoxUtils.checkPdfEncryption(it.path)
}
val list = documentList.filter { it.state == 1 }
launch(Dispatchers.Main) {
documentView.refreshDocumentRv(list, true)
}
}
fun saveBookmarkChange(addRemove: Boolean, path: String) { fun saveBookmarkChange(addRemove: Boolean, path: String) {
if (addRemove) { if (addRemove) {
SpStringUtils.addSpString(SpStringUtils.BOOKMARK_KEY, path) SpStringUtils.addSpString(SpStringUtils.BOOKMARK_KEY, path)
......
...@@ -4,6 +4,7 @@ import android.content.Intent ...@@ -4,6 +4,7 @@ import android.content.Intent
import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_LOCK_PDF 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_MERGE_PDF
import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_SPLIT_PDF import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_SPLIT_PDF
import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_UNLOCK_PDF
import com.base.pdfviewerscannerwhite.databinding.FragmentToolBinding import com.base.pdfviewerscannerwhite.databinding.FragmentToolBinding
import com.base.pdfviewerscannerwhite.helper.BaseFragment import com.base.pdfviewerscannerwhite.helper.BaseFragment
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfSelectActivity import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfSelectActivity
...@@ -35,6 +36,11 @@ class ToolFragment : BaseFragment<FragmentToolBinding>() { ...@@ -35,6 +36,11 @@ class ToolFragment : BaseFragment<FragmentToolBinding>() {
putExtra("doWhat", DO_LOCK_PDF) putExtra("doWhat", DO_LOCK_PDF)
}) })
} }
binding.llUnlock.setOnClickListener {
startActivity(Intent(requireContext(), PdfSelectActivity::class.java).apply {
putExtra("doWhat", DO_UNLOCK_PDF)
})
}
} }
} }
\ No newline at end of file
...@@ -113,6 +113,7 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(), SplashView { ...@@ -113,6 +113,7 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(), SplashView {
binding.progressBar.progress = 100 binding.progressBar.progress = 100
binding.root.postDelayed({ binding.root.postDelayed({
startActivity(Intent(this, MainActivity::class.java)) startActivity(Intent(this, MainActivity::class.java))
finish()
}, 200) }, 200)
} }
......
...@@ -249,6 +249,7 @@ object DialogView { ...@@ -249,6 +249,7 @@ object DialogView {
if (item.state == 1) { if (item.state == 1) {
PdfBoxUtils.clearPassword(item.path, pwd) PdfBoxUtils.clearPassword(item.path, pwd)
toast("clear Encryption") toast("clear Encryption")
encryptionAction?.invoke()
} }
} else { } else {
val result = PdfBoxUtils.checkPwd(item.path, pwd) val result = PdfBoxUtils.checkPwd(item.path, pwd)
......
...@@ -63,6 +63,12 @@ ...@@ -63,6 +63,12 @@
android:layout_height="match_parent" android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_document" /> tools:listitem="@layout/item_document" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout> </FrameLayout>
<TextView <TextView
......
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