Commit 581efd02 authored by wanglei's avatar wanglei

...

parent 7c95d62f
......@@ -34,6 +34,15 @@ object ConstObject {
field = value
AppPreferences.getInstance().put("ifAgreePrivacy", value, true)
}
var haveSaveDemo=false
get() {
return AppPreferences.getInstance().getBoolean("haveSaveDemo", field)
}
set(value) {
field = value
AppPreferences.getInstance().put("haveSaveDemo", value, true)
}
//
// var searchEngineSp = GOOGLE
// get() {
......
......@@ -52,16 +52,7 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV
if (item == null) return
val binding = ItemDocumentBinding.bind(holder.itemView)
if (item.type == TYPE_PDF) {
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)
}
}
if (item.type == TYPE_WORD) {
binding.iv.setImageResource(R.mipmap.h_wordfiocn)
......@@ -80,7 +71,7 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV
}
when (item.uiType) {
0 -> {
0 -> {//首页
binding.flSelect.visibility = View.GONE
binding.flMore.visibility = View.VISIBLE
binding.flBookmark.visibility = View.VISIBLE
......@@ -108,7 +99,7 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV
}
}
1 -> {
1 -> {//合并选择
binding.flMore.visibility = View.INVISIBLE
binding.flBookmark.visibility = View.INVISIBLE
binding.flSelect.visibility = View.VISIBLE
......@@ -125,7 +116,7 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV
}
}
2 -> {
2 -> {//拆分选择
binding.flBookmark.visibility = View.GONE
binding.flMore.visibility = View.INVISIBLE
binding.root.setOnClickListener {
......@@ -133,7 +124,7 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV
}
}
3 -> {
3 -> {//解锁模式选择
binding.flBookmark.visibility = View.GONE
binding.flMore.visibility = View.INVISIBLE
binding.root.setOnClickListener {
......@@ -141,7 +132,7 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV
}
}
4 -> {
4 -> {//搜索选择
binding.flBookmark.visibility = View.GONE
binding.flMore.setOnClickListener {
moreAction?.invoke(item)
......
......@@ -15,7 +15,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
import com.base.pdfviewerscannerwhite.ui.view.PdfDialog.showPdfPwdDialog
import com.base.pdfviewerscannerwhite.utils.LogEx
class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView {
......@@ -120,7 +120,7 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView
binding.rv.adapter = adapter
}
override fun refreshDocumentRv(documentList: List<DocumentBean>, isRefresh: Boolean) {
override fun refreshDocumentRv(documentList: List<DocumentBean>) {
binding.progressBar.visibility = View.GONE
if (doWhat == DO_MERGE_PDF) {
LogEx.logDebug(TAG, "refreshDocumentRv 1")
......
......@@ -3,9 +3,8 @@ package com.base.pdfviewerscannerwhite.ui.main
import android.annotation.SuppressLint
import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.content.Intent
import androidx.core.content.ContentProviderCompat.requireContext
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import com.base.pdfviewerscannerwhite.bean.ConstObject
import com.base.pdfviewerscannerwhite.bean.DocumentBean
......@@ -23,19 +22,18 @@ import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfSplitActivity
import com.base.pdfviewerscannerwhite.ui.document.ppt.PptActivity
import com.base.pdfviewerscannerwhite.ui.document.word.WordActivity
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDocumentHomeMoreDialog
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDocumentRenameDialog
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showPdfHomeMoreDialog
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showPdfPwdDialog
import com.base.pdfviewerscannerwhite.ui.view.PdfDialog.showPdfHomeMoreDialog
import com.base.pdfviewerscannerwhite.ui.view.PdfDialog.showPdfPwdDialog
import com.base.pdfviewerscannerwhite.utils.PermissionUtils.checkStorePermission
import java.io.File
import java.util.Locale
class DocumentFragment() : BaseFragment<FragmentDocumentBinding>(), DocumentView {
var type = TYPE_PDF
private var documentList: ArrayList<DocumentBean> = arrayListOf()
private lateinit var adapter: DocumentAdapter
private lateinit var documentPresenter: DocumentPresenter
private var firstDialog: Dialog? = null
lateinit var adapter: DocumentAdapter
lateinit var documentPresenter: DocumentPresenter
constructor(type: String) : this() {
this.type = type
......@@ -53,11 +51,22 @@ class DocumentFragment() : BaseFragment<FragmentDocumentBinding>(), DocumentView
override fun onResume() {
super.onResume()
if (requireContext().checkStorePermission() && adapter.items.isEmpty()) {
initData()
}
fun initData() {
if (requireContext().checkStorePermission()) {
documentPresenter.initData()
}
}
override fun refreshDocumentRv(documentList: List<DocumentBean>) {
binding.llEmpty.isVisible = documentList.isEmpty()
this.documentList.clear()
this.documentList.addAll(documentList)
adapter.submitList(documentList)
}
private fun initAdapter() {
adapter = DocumentAdapter()
adapter.bookmarkAction = { addRemove, path ->
......@@ -73,23 +82,15 @@ class DocumentFragment() : BaseFragment<FragmentDocumentBinding>(), DocumentView
}
var documentMoreAction: (item: DocumentBean) -> Unit = { item ->
val mainActivity = (requireActivity() as MainActivity)
if (item.type == TYPE_PDF) {
requireContext().showPdfHomeMoreDialog(this, item, adapter, dismissAction = { firstDialog = null })
}
if (item.type == TYPE_WORD || item.type == TYPE_EXCEL || item.type == TYPE_PPT) {
firstDialog = requireContext().showDocumentHomeMoreDialog(item, this)
}
requireContext().showPdfHomeMoreDialog(
item, adapter, this, mainActivity
)
}
override fun refreshDocumentRv(documentList: List<DocumentBean>, isRefresh: Boolean) {
if (isRefresh) {
this.documentList.clear()
}
this.documentList.addAll(documentList)
if (adapter.items.isEmpty()) {
adapter.submitList(documentList)
} else {
adapter.addAll(documentList)
if (item.type == TYPE_WORD || item.type == TYPE_EXCEL || item.type == TYPE_PPT) {
requireContext().showDocumentHomeMoreDialog(item, this, mainActivity)
}
}
......@@ -118,6 +119,7 @@ class DocumentFragment() : BaseFragment<FragmentDocumentBinding>(), DocumentView
val recentList = documentList.filter {
(System.currentTimeMillis() - File(it.path).lastModified()) < 300L * 24 * 60 * 60 * 1000
}
binding.llEmpty.isVisible = recentList.isEmpty()
adapter.submitList(recentList)
}
......@@ -132,17 +134,12 @@ class DocumentFragment() : BaseFragment<FragmentDocumentBinding>(), DocumentView
fun setBookmarkList() {
if (isVisible) {
val bookmarkList = documentList.filter { it.isBookmarked }
binding.llEmpty.isVisible = bookmarkList.isEmpty()
adapter.submitList(bookmarkList)
}
}
override fun dialogRename(item: DocumentBean) {
val file = File(item.path)
requireContext().showDocumentRenameDialog(file.name, firstDialog) { newName ->
documentPresenter.renameDocumentBean(file, newName)
}
}
@SuppressLint("NotifyDataSetChanged")
fun changeSelectUi(select: Boolean) {
......@@ -179,11 +176,19 @@ class DocumentFragment() : BaseFragment<FragmentDocumentBinding>(), DocumentView
fun getSearchItems(search: String): List<DocumentBean> {
if (isVisible) {
return adapter.items.filter { File(it.path).name.contains(search) }
return adapter.items.filter { File(it.path).name.lowercase(Locale.ENGLISH).contains(search.lowercase(Locale.ENGLISH)) }
}
return listOf()
}
@SuppressLint("NotifyDataSetChanged")
fun changeHomeUI() {
if (isVisible) {
adapter.items.map { it.uiType == 0 }
adapter.notifyDataSetChanged()
}
}
companion object {
fun Activity.jumpDocument(item: DocumentBean) {
......
......@@ -3,6 +3,7 @@ package com.base.pdfviewerscannerwhite.ui.main
import android.content.Context
import androidx.lifecycle.LifecycleCoroutineScope
import com.base.pdfviewerscannerwhite.bean.ConstObject
import com.base.pdfviewerscannerwhite.bean.ConstObject.haveSaveDemo
import com.base.pdfviewerscannerwhite.bean.DocumentBean
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfBoxUtils
import com.base.pdfviewerscannerwhite.utils.AssetUtils.getDemoDocx
......@@ -10,8 +11,10 @@ import com.base.pdfviewerscannerwhite.utils.AssetUtils.getDemoPdf
import com.base.pdfviewerscannerwhite.utils.AssetUtils.getDemoPptx
import com.base.pdfviewerscannerwhite.utils.AssetUtils.getDemoXlsx
import com.base.pdfviewerscannerwhite.utils.AssetUtils.saveAssetsFile
import com.base.pdfviewerscannerwhite.utils.LogEx
import com.base.pdfviewerscannerwhite.utils.SpStringUtils
import com.base.pdfviewerscannerwhite.utils.getMediaFile
import com.base.pdfviewerscannerwhite.utils.upDateDemoStore
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.io.File
......@@ -22,29 +25,35 @@ class DocumentPresenter(
val type: String,
val lifecycleScope: LifecycleCoroutineScope
) {
private val TAG = "DocumentPresenter"
private fun getDocumentBeanList(): List<DocumentBean> {
LogEx.logDebug(TAG, "getDocumentBeanList")
context.upDateDemoStore()
if (!haveSaveDemo) {
context.saveAssetsFile()
haveSaveDemo = true
}
var selectionArgs = arrayOf(ConstObject.MIME_TYPE_PDF)
val demoDocumentBean = DocumentBean()
val demoFile = File(context.filesDir, "demo")
if (type == DocumentBean.TYPE_PDF) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_PDF)
demoDocumentBean.path = context.getDemoPdf()
demoDocumentBean.path = demoFile.listFiles()?.find { it.name.contains(".pdf") }?.absolutePath ?: ""
}
if (type == DocumentBean.TYPE_WORD) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_DOC, ConstObject.MIME_TYPE_DOCX)
demoDocumentBean.path = context.getDemoDocx()
demoDocumentBean.path = demoFile.listFiles()?.find { it.name.contains(".docx") }?.absolutePath ?: ""
}
if (type == DocumentBean.TYPE_EXCEL) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_XLS, ConstObject.MIME_TYPE_XLSX)
demoDocumentBean.path = context.getDemoXlsx()
demoDocumentBean.path = demoFile.listFiles()?.find { it.name.contains(".xlsx") }?.absolutePath ?: ""
}
if (type == DocumentBean.TYPE_PPT) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_PPT, ConstObject.MIME_TYPE_PPTX)
demoDocumentBean.path = context.getDemoPptx()
demoDocumentBean.path = demoFile.listFiles()?.find { it.name.contains(".pptx") }?.absolutePath ?: ""
}
demoDocumentBean.type = type
......@@ -55,7 +64,9 @@ class DocumentPresenter(
DocumentBean(it.path, uri = it.uri, type = type, isBookmarked = bookmarkList.contains(it.path))
}
val new = documentList.toMutableList()
if (File(demoDocumentBean.path).exists()) {
new.add(0, demoDocumentBean)
}
return new
}
......@@ -63,7 +74,7 @@ class DocumentPresenter(
val documentList = getDocumentBeanList()
launch(Dispatchers.Main) {
documentView.refreshDocumentRv(documentList, true)
documentView.refreshDocumentRv(documentList)
}
}
......@@ -75,7 +86,7 @@ class DocumentPresenter(
}
val list = documentList.filter { it.state == 0 }
launch(Dispatchers.Main) {
documentView.refreshDocumentRv(list, true)
documentView.refreshDocumentRv(list)
}
}
......@@ -86,7 +97,7 @@ class DocumentPresenter(
}
val list = documentList.filter { it.state == 1 }
launch(Dispatchers.Main) {
documentView.refreshDocumentRv(list, true)
documentView.refreshDocumentRv(list)
}
}
......@@ -99,15 +110,23 @@ class DocumentPresenter(
}
}
fun renameDocumentBean(file: File, newName: String) = lifecycleScope.launch(Dispatchers.IO) {
fun renameDocumentBean(
file: File, newName: String,
callBack: ((newPath: String) -> Unit)? = null
) = lifecycleScope.launch(Dispatchers.IO) {
runCatching {
var newPath = ""
try {
val nameFile = File(file.parentFile, newName)
file.renameTo(nameFile)
val result = file.renameTo(nameFile)
if (result) {
newPath = nameFile.absolutePath
}
} catch (e: Exception) {
}
val documentList = getDocumentBeanList()
launch(Dispatchers.Main) {
documentView.refreshDocumentRv(documentList, true)
callBack?.invoke(newPath)
}
}
......
package com.base.pdfviewerscannerwhite.ui.main
import android.app.Dialog
import com.base.pdfviewerscannerwhite.bean.DocumentBean
interface DocumentView {
fun dialogRename(item: DocumentBean) = Unit
fun refreshDocumentRv(documentList: List<DocumentBean>, isRefresh: Boolean) = Unit
fun refreshDocumentRv(documentList: List<DocumentBean>) = Unit
fun splitPdf(path: String) = Unit
......
......@@ -16,6 +16,7 @@ import com.base.pdfviewerscannerwhite.BuildConfig
import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.bean.DocumentBean
import com.base.pdfviewerscannerwhite.databinding.ActivityMainBinding
import com.base.pdfviewerscannerwhite.databinding.ItemDocumentBinding
import com.base.pdfviewerscannerwhite.helper.BaseActivity
import com.base.pdfviewerscannerwhite.ui.adapter.DocumentAdapter
import com.base.pdfviewerscannerwhite.ui.main.DocumentFragment.Companion.jumpDocument
......@@ -31,7 +32,6 @@ import com.base.pdfviewerscannerwhite.utils.LogEx
import com.base.pdfviewerscannerwhite.utils.PermissionUtils.checkStorePermission
import com.base.pdfviewerscannerwhite.utils.ToastUtils.toast
import com.base.pdfviewerscannerwhite.utils.updateMediaStore
import com.cherry.lib.doc.office.fc.ss.usermodel.charts.AxisPosition
@SuppressLint("SetTextI18n")
class MainActivity : BaseActivity<ActivityMainBinding>(), MainView {
......@@ -275,10 +275,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), MainView {
if (currentFragment is DocumentFragment) {
val item = (currentFragment as DocumentFragment).getSearchItems(search)
if (item.isNotEmpty()) {
val arrayList = arrayListOf<DocumentBean>()
arrayList.addAll(item)
arrayList.map { it.uiType = 4 }
searchAdapter.submitList(arrayList)
item.map { it.uiType = 4 }
searchAdapter.submitList(item)
} else {
binding.llEmpty.visibility = View.VISIBLE
}
......@@ -352,6 +350,16 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), MainView {
}
}
@SuppressLint("NotifyDataSetChanged")
override fun refreshSearchRv() {
searchAdapter.notifyDataSetChanged()
}
override fun deleteDocument(item: DocumentBean) {
LogEx.logDebug(TAG, "deleteDocument $item")
searchAdapter.remove(item)
}
override fun onResume() {
super.onResume()
......@@ -516,6 +524,10 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), MainView {
binding.tvTittle.visibility = View.VISIBLE
binding.ivPaixu.visibility = View.VISIBLE
binding.ivXuanze.visibility = View.VISIBLE
if (currentFragment is DocumentFragment) {
(currentFragment as DocumentFragment).changeHomeUI()
}
}
companion object {
......
package com.base.pdfviewerscannerwhite.ui.main
import android.net.Uri
import com.base.pdfviewerscannerwhite.bean.DocumentBean
interface MainView {
fun handleActivityGmsScanResult(imageUri: Uri, pdfUri: Uri)
fun refreshSearchRv()
fun deleteDocument(item: DocumentBean)
}
\ No newline at end of file
......@@ -12,7 +12,7 @@ import com.base.pdfviewerscannerwhite.helper.BaseFragment
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfActivity
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfBoxUtils
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfSelectActivity
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showPdfPwdDialog
import com.base.pdfviewerscannerwhite.ui.view.PdfDialog.showPdfPwdDialog
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
......
......@@ -2,13 +2,10 @@ package com.base.pdfviewerscannerwhite.ui.view
import android.annotation.SuppressLint
import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import androidx.core.content.FileProvider
import androidx.core.widget.addTextChangedListener
import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.bean.DocumentBean
......@@ -22,27 +19,15 @@ import com.base.pdfviewerscannerwhite.databinding.DialogDocumentHomeMoreBinding
import com.base.pdfviewerscannerwhite.databinding.DialogDocumentMoreBinding
import com.base.pdfviewerscannerwhite.databinding.DialogDocumentRenameBinding
import com.base.pdfviewerscannerwhite.databinding.DialogPageNumberBinding
import com.base.pdfviewerscannerwhite.databinding.DialogPdfHomeMoreBinding
import com.base.pdfviewerscannerwhite.databinding.DialogPdfMoreBinding
import com.base.pdfviewerscannerwhite.databinding.DialogPdfPasswordBinding
import com.base.pdfviewerscannerwhite.databinding.DialogStoragePermissionBinding
import com.base.pdfviewerscannerwhite.ui.adapter.DocumentAdapter
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfBoxUtils
import com.base.pdfviewerscannerwhite.ui.main.DocumentView
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfView
import com.base.pdfviewerscannerwhite.ui.main.MainActivity
import com.base.pdfviewerscannerwhite.utils.ActivityLauncher
import com.base.pdfviewerscannerwhite.utils.IntentShareUtils.documentShare
import com.base.pdfviewerscannerwhite.utils.IntentShareUtils.shareExcelIntent
import com.base.pdfviewerscannerwhite.utils.IntentShareUtils.sharePdfIntent
import com.base.pdfviewerscannerwhite.utils.IntentShareUtils.sharePdfPrintIntent
import com.base.pdfviewerscannerwhite.utils.IntentShareUtils.sharePptIntent
import com.base.pdfviewerscannerwhite.utils.IntentShareUtils.shareWordIntent
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatSize
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatTime
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatTime2
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatTime3
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatTime4
import com.base.pdfviewerscannerwhite.utils.LogEx
import com.base.pdfviewerscannerwhite.utils.PermissionUtils.requestStoragePermission
import com.base.pdfviewerscannerwhite.utils.SpStringUtils
import com.base.pdfviewerscannerwhite.utils.SpStringUtils.LAST_VIEW_KEY
......@@ -114,7 +99,11 @@ object DialogView {
}
@SuppressLint("SetTextI18n")
fun Context.showDocumentHomeMoreDialog(item: DocumentBean, documentView: DocumentView): BottomSheetDialog {
fun Context.showDocumentHomeMoreDialog(
item: DocumentBean,
documentView: DocumentView,
mainActivity: MainActivity,
): BottomSheetDialog {
val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
val binding = DialogDocumentHomeMoreBinding.inflate(LayoutInflater.from(this))
dialog.setContentView(binding.root)
......@@ -149,7 +138,7 @@ object DialogView {
}
}
binding.llRename.setOnClickListener {
documentView.dialogRename(item)
}
binding.llDetail.setOnClickListener {
showDocumentDetail(item.path)
......@@ -170,135 +159,6 @@ object DialogView {
}
@SuppressLint("SetTextI18n", "NotifyDataSetChanged")
fun Context.showPdfHomeMoreDialog(
documentView: DocumentView,
item: DocumentBean,
adapter: DocumentAdapter,
dismissAction: () -> Unit
): BottomSheetDialog {
val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
val binding = DialogPdfHomeMoreBinding.inflate(LayoutInflater.from(this))
dialog.setContentView(binding.root)
dialog.setCanceledOnTouchOutside(false)
dialog.show()
val parentView = binding.root.parent as View
val behavior = BottomSheetBehavior.from(parentView)
//展开
behavior.state = BottomSheetBehavior.STATE_EXPANDED
val file = File(item.path)
binding.tvName.text = file.name
binding.tvInfo.text = file.lastModified().toFormatTime() + " " + file.length().toFormatSize()
if (item.isBookmarked) {
binding.ivBookmark.setImageResource(R.mipmap.h_soucang_s)
} else {
binding.ivBookmark.setImageResource(R.mipmap.h_soucang_n)
}
binding.ivBookmark.setOnClickListener {
item.isBookmarked = !item.isBookmarked
adapter.notifyDataSetChanged()
if (item.isBookmarked) {
binding.ivBookmark.setImageResource(R.mipmap.h_soucang_s)
} else {
binding.ivBookmark.setImageResource(R.mipmap.h_soucang_n)
}
}
binding.llRename.setOnClickListener {
documentView.dialogRename(item)
}
binding.llSplit.setOnClickListener {
dialog.dismiss()
documentView.splitPdf(item.path)
}
binding.llMerge.setOnClickListener {
dialog.dismiss()
documentView.mergePdf(item.path)
}
binding.llDelete.setOnClickListener {
dialog.dismiss()
showDeleteDialog {
runCatching {
File(item.path).delete()
}
documentView.deleteDocument(item)
}
}
binding.llDetail.setOnClickListener {
showDocumentDetail(item.path)
}
binding.llShare.setOnClickListener {
val intent = sharePdfIntent(item.uri)
runCatching {
startActivity(intent)
}
}
if (item.state == 1) {
binding.tvLock.text = "Unlock PDF"
}
if (item.state == 0) {
binding.tvLock.text = "Lock PDF"
}
binding.llLock.setOnClickListener {
showPdfPwdDialog(state = item.state, path = item.path, firstDialog = dialog)
}
dialog.setOnDismissListener {
dismissAction.invoke()
}
return dialog
}
fun Activity.showPdfMoreDialog(
pdfView: PdfView,
pageNumber: Int,
pafPath: String,
) {
val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
val binding = DialogPdfMoreBinding.inflate(LayoutInflater.from(this))
dialog.setContentView(binding.root)
dialog.setCanceledOnTouchOutside(false)
dialog.show()
val parentView = binding.root.parent as View
val behavior = BottomSheetBehavior.from(parentView)
//展开
behavior.state = BottomSheetBehavior.STATE_EXPANDED
binding.llJump.setOnClickListener {
showJumpPageNumberDialog(pageNumber) { pageIndex ->
dialog.dismiss()
pdfView.jumpPage(pageIndex)
}
}
binding.llSplit.setOnClickListener {
dialog.dismiss()
pdfView.jumpSplit()
}
binding.llDetail.setOnClickListener {
showDocumentDetail(pafPath)
}
binding.llShare.setOnClickListener {
dialog.dismiss()
val pkg = this.packageName
LogEx.logDebug("showPdfMoreDialog", "pkg=$pkg")
val uri = FileProvider.getUriForFile(
this, this.packageName + ".provider", File(pafPath)
)
startActivity(Intent.createChooser(sharePdfIntent(uri), "Share PDF"))
}
binding.llPrint.setOnClickListener {
val uri = FileProvider.getUriForFile(
this, this.packageName + ".provider", File(pafPath)
)
startActivity(Intent.createChooser(sharePdfPrintIntent(uri), "Print PDF"))
}
}
fun Activity.showDocumentMore(
documentBean: DocumentBean,
pageNumber: Int = 0,
......@@ -352,89 +212,8 @@ object DialogView {
}
@SuppressLint("SetTextI18n")
fun Context.showPdfPwdDialog(
state: Int,
path: String = "",
uri: String? = null,
firstDialog: Dialog? = null,
isCheckPwd: Boolean = false,
verificationAction: ((pwd: String) -> Unit)? = null,
encryptionAction: (() -> Unit)? = null
) {
val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
val binding = DialogPdfPasswordBinding.inflate(LayoutInflater.from(this))
dialog.setContentView(binding.root)
dialog.setCanceledOnTouchOutside(false)
val window = dialog.window
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
dialog.show()
val parentView = binding.root.parent as View
val behavior = BottomSheetBehavior.from(parentView)
//展开
behavior.state = BottomSheetBehavior.STATE_EXPANDED
if (!isCheckPwd) {
if (state == 1) {
binding.tvTittle.text = "Delete Password"
binding.tvTip.text = "Delete password, the file is not password protected"
}
if (state == 0) {
binding.tvTittle.text = "Set Password"
binding.tvTip.text = "Set password protection pdf"
}
} else {
binding.tvTittle.text = "Input Password"
val file = File(path)
binding.tvTip.text = "${file.name} password protected"
binding.tvInputTip.visibility = View.VISIBLE
}
binding.edit.requestFocus()
binding.edit.addTextChangedListener {
binding.tvConfirm.isEnabled = it.toString().isNotEmpty()
binding.tvErrorTip.visibility = View.GONE
}
binding.tvCancel.setOnClickListener {
dialog.dismiss()
}
binding.tvConfirm.setOnClickListener {
val pwd = binding.edit.text.toString()
if (!isCheckPwd) {
dialog.dismiss()
firstDialog?.dismiss()
if (state == 0) {
PdfBoxUtils.setPassword(path, pwd, pwd)
toast("Success Encryption")
encryptionAction?.invoke()
}
if (state == 1) {
PdfBoxUtils.clearPassword(path, pwd)
toast("clear Encryption")
encryptionAction?.invoke()
}
} else {
val result = PdfBoxUtils.checkPwd(path, pwd, uri)
if (!result) {
binding.tvErrorTip.visibility = View.VISIBLE
return@setOnClickListener
}
dialog.dismiss()
firstDialog?.dismiss()
verificationAction?.invoke(pwd)
}
}
}
private fun Context.showJumpPageNumberDialog(pageNumber: Int, okAction: ((pageIndex: Int) -> Unit)?) {
fun Context.showJumpPageNumberDialog(pageNumber: Int, okAction: ((pageIndex: Int) -> Unit)?) {
val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
val binding = DialogPageNumberBinding.inflate(LayoutInflater.from(this))
dialog.setContentView(binding.root)
......@@ -469,7 +248,6 @@ object DialogView {
fun Context.showDocumentRenameDialog(
name: String? = null,
firstDialog: Dialog? = null,
okAction: ((newName: String) -> Unit)? = null,
) {
val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
......@@ -513,7 +291,6 @@ object DialogView {
return@setOnClickListener
}
okAction?.invoke(newName)
firstDialog?.dismiss()
}
}
......
package com.base.pdfviewerscannerwhite.ui.view
import android.annotation.SuppressLint
import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import androidx.core.content.FileProvider
import androidx.core.widget.addTextChangedListener
import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.bean.DocumentBean
import com.base.pdfviewerscannerwhite.databinding.DialogPdfHomeMoreBinding
import com.base.pdfviewerscannerwhite.databinding.DialogPdfMoreBinding
import com.base.pdfviewerscannerwhite.databinding.DialogPdfPasswordBinding
import com.base.pdfviewerscannerwhite.ui.adapter.DocumentAdapter
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfBoxUtils
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfView
import com.base.pdfviewerscannerwhite.ui.main.DocumentFragment
import com.base.pdfviewerscannerwhite.ui.main.MainActivity
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDeleteDialog
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDocumentDetail
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDocumentRenameDialog
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showJumpPageNumberDialog
import com.base.pdfviewerscannerwhite.utils.IntentShareUtils
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatSize
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatTime
import com.base.pdfviewerscannerwhite.utils.LogEx
import com.base.pdfviewerscannerwhite.utils.ToastUtils.toast
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import java.io.File
object PdfDialog {
//pdf首页弹窗
@SuppressLint("SetTextI18n", "NotifyDataSetChanged")
fun Context.showPdfHomeMoreDialog(
item: DocumentBean,
adapter: DocumentAdapter,
documentFragment: DocumentFragment,
mainActivity: MainActivity
): BottomSheetDialog {
val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
val binding = DialogPdfHomeMoreBinding.inflate(LayoutInflater.from(this))
dialog.setContentView(binding.root)
dialog.setCanceledOnTouchOutside(false)
dialog.show()
val parentView = binding.root.parent as View
val behavior = BottomSheetBehavior.from(parentView)
//展开
behavior.state = BottomSheetBehavior.STATE_EXPANDED
val file = File(item.path)
binding.tvName.text = file.name
binding.tvInfo.text = file.lastModified().toFormatTime() + " " + file.length().toFormatSize()
if (item.isBookmarked) {
binding.ivBookmark.setImageResource(R.mipmap.h_soucang_s)
} else {
binding.ivBookmark.setImageResource(R.mipmap.h_soucang_n)
}
binding.ivBookmark.setOnClickListener {
item.isBookmarked = !item.isBookmarked
adapter.notifyDataSetChanged()
if (item.isBookmarked) {
binding.ivBookmark.setImageResource(R.mipmap.h_soucang_s)
} else {
binding.ivBookmark.setImageResource(R.mipmap.h_soucang_n)
}
}
binding.llRename.setOnClickListener {
showDocumentRenameDialog(file.name) { newName ->
dialog.dismiss()
documentFragment.documentPresenter.renameDocumentBean(file, newName) { newPath ->
if (newPath.isNotEmpty()) {
item.path = newPath
documentFragment.adapter.notifyDataSetChanged()
mainActivity.refreshSearchRv()
}
}
}
}
binding.llSplit.setOnClickListener {
dialog.dismiss()
documentFragment.splitPdf(item.path)
}
binding.llMerge.setOnClickListener {
dialog.dismiss()
documentFragment.mergePdf(item.path)
}
binding.llDelete.setOnClickListener {
dialog.dismiss()
showDeleteDialog {
runCatching {
File(item.path).delete()
}
documentFragment.deleteDocument(item)
}
}
binding.llDetail.setOnClickListener {
showDocumentDetail(item.path)
}
binding.llShare.setOnClickListener {
val intent = IntentShareUtils.sharePdfIntent(item.uri)
runCatching {
startActivity(intent)
}
}
if (item.state == 1) {
binding.tvLock.text = "Unlock PDF"
}
if (item.state == 0) {
binding.tvLock.text = "Lock PDF"
}
binding.llLock.setOnClickListener {
showPdfPwdDialog(state = item.state, path = item.path, firstDialog = dialog, encryptionAction = {
dialog.dismiss()
mainActivity?.refreshSearchRv()
})
}
dialog.setOnDismissListener {
}
return dialog
}
fun Activity.showPdfMoreDialog(
pdfView: PdfView,
pageNumber: Int,
pafPath: String,
) {
val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
val binding = DialogPdfMoreBinding.inflate(LayoutInflater.from(this))
dialog.setContentView(binding.root)
dialog.setCanceledOnTouchOutside(false)
dialog.show()
val parentView = binding.root.parent as View
val behavior = BottomSheetBehavior.from(parentView)
//展开
behavior.state = BottomSheetBehavior.STATE_EXPANDED
binding.llJump.setOnClickListener {
showJumpPageNumberDialog(pageNumber) { pageIndex ->
dialog.dismiss()
pdfView.jumpPage(pageIndex)
}
}
binding.llSplit.setOnClickListener {
dialog.dismiss()
pdfView.jumpSplit()
}
binding.llDetail.setOnClickListener {
showDocumentDetail(pafPath)
}
binding.llShare.setOnClickListener {
dialog.dismiss()
val pkg = this.packageName
LogEx.logDebug("showPdfMoreDialog", "pkg=$pkg")
val uri = FileProvider.getUriForFile(
this, this.packageName + ".provider", File(pafPath)
)
startActivity(Intent.createChooser(IntentShareUtils.sharePdfIntent(uri), "Share PDF"))
}
binding.llPrint.setOnClickListener {
val uri = FileProvider.getUriForFile(
this, this.packageName + ".provider", File(pafPath)
)
startActivity(Intent.createChooser(IntentShareUtils.sharePdfPrintIntent(uri), "Print PDF"))
}
}
@SuppressLint("SetTextI18n")
fun Context.showPdfPwdDialog(
state: Int,
path: String = "",
uri: String? = null,
firstDialog: Dialog? = null,
isCheckPwd: Boolean = false,
verificationAction: ((pwd: String) -> Unit)? = null,
encryptionAction: (() -> Unit)? = null,
) {
val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
val binding = DialogPdfPasswordBinding.inflate(LayoutInflater.from(this))
dialog.setContentView(binding.root)
dialog.setCanceledOnTouchOutside(false)
val window = dialog.window
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
dialog.show()
val parentView = binding.root.parent as View
val behavior = BottomSheetBehavior.from(parentView)
//展开
behavior.state = BottomSheetBehavior.STATE_EXPANDED
if (!isCheckPwd) {
if (state == 1) {
binding.tvTittle.text = "Delete Password"
binding.tvTip.text = "Delete password, the file is not password protected"
}
if (state == 0) {
binding.tvTittle.text = "Set Password"
binding.tvTip.text = "Set password protection pdf"
}
} else {
binding.tvTittle.text = "Input Password"
val file = File(path)
binding.tvTip.text = "${file.name} password protected"
binding.tvInputTip.visibility = View.VISIBLE
}
binding.edit.requestFocus()
binding.edit.addTextChangedListener {
binding.tvConfirm.isEnabled = it.toString().isNotEmpty()
binding.tvErrorTip.visibility = View.GONE
}
binding.tvCancel.setOnClickListener {
dialog.dismiss()
}
binding.tvConfirm.setOnClickListener {
val pwd = binding.edit.text.toString()
if (!isCheckPwd) {
dialog.dismiss()
firstDialog?.dismiss()
if (state == 0) {
PdfBoxUtils.setPassword(path, pwd, pwd)
toast("Success Encryption")
encryptionAction?.invoke()
}
if (state == 1) {
PdfBoxUtils.clearPassword(path, pwd)
toast("clear Encryption")
encryptionAction?.invoke()
}
} else {
val result = PdfBoxUtils.checkPwd(path, pwd, uri)
if (!result) {
binding.tvErrorTip.visibility = View.VISIBLE
return@setOnClickListener
}
dialog.dismiss()
firstDialog?.dismiss()
verificationAction?.invoke(pwd)
}
}
}
}
\ No newline at end of file
......@@ -74,6 +74,7 @@ object AssetUtils {
"DEMO.xlsx",
"DEMO.pptx"
).forEach {
val file = File(demoFile, it)
if (file.exists() && file.length() != 0L) {
return
......
......@@ -45,6 +45,13 @@ fun Context.updateMediaStore(
) { path: String?, uri: Uri? -> }
}
fun Context.upDateDemoStore() {
val demoFile = File(filesDir, "demo")
MediaScannerConnection.scanFile(
this, arrayOf(demoFile.absolutePath) , null
) { path: String?, uri: Uri? -> }
}
//图片视频音频不用这个查
fun Context.getMediaFile(selectionArgs: Array<String>? = null): ArrayList<MediaBean> {
......
......@@ -14,5 +14,32 @@
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_document" />
<LinearLayout
android:id="@+id/ll_empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="60dp"
android:orientation="vertical"
android:visibility="gone"
tools:ignore="UseCompoundDrawables,UselessParent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/empty"
tools:ignore="ContentDescription" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:text="Empty"
android:textColor="#B1B4B9"
android:textSize="16sp"
tools:ignore="HardcodedText" />
</LinearLayout>
</FrameLayout>
\ No newline at end of file
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