Commit acc3f3c1 authored by wanglei's avatar wanglei

...

parent 4e4c14f5
package com.base.pdfviewerscannerwhite
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.base.pdfviewerscannerwhite", appContext.packageName)
}
}
\ No newline at end of file
...@@ -18,11 +18,13 @@ ...@@ -18,11 +18,13 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.PDFViewerScannerWhite" android:theme="@style/Theme.PDFViewerScannerWhite"
tools:targetApi="34"> tools:targetApi="34">
<activity
android:name=".ui.document.pdf.PdfSplitActivity"
android:exported="false" />
<meta-data <meta-data
android:name="com.google.android.gms.version" android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" /> android:value="@integer/google_play_services_version" />
<meta-data <meta-data
android:name="com.google.mlkit.vision.DEPENDENCIES" android:name="com.google.mlkit.vision.DEPENDENCIES"
android:value="document_ui" /> android:value="document_ui" />
...@@ -61,7 +63,6 @@ ...@@ -61,7 +63,6 @@
android:name="android.support.FILE_PROVIDER_PATHS" android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" /> android:resource="@xml/file_paths" />
</provider> </provider>
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -21,6 +21,7 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV ...@@ -21,6 +21,7 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV
var itemClick: ((path: String) -> Unit)? = null var itemClick: ((path: String) -> Unit)? = null
var bookmarkAction: ((addRemove: Boolean, path: String) -> Unit)? = null var bookmarkAction: ((addRemove: Boolean, path: String) -> Unit)? = null
var moreAction: ((item: DocumentBean) -> Unit)? = null
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: DocumentViewHolder, position: Int, item: DocumentBean?) { override fun onBindViewHolder(holder: DocumentViewHolder, position: Int, item: DocumentBean?) {
...@@ -47,6 +48,9 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV ...@@ -47,6 +48,9 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV
item.isBookmarked = !item.isBookmarked item.isBookmarked = !item.isBookmarked
notifyItemChanged(position, "aaaa") notifyItemChanged(position, "aaaa")
} }
binding.flMore.setOnClickListener {
moreAction?.invoke(item)
}
binding.root.setOnClickListener { binding.root.setOnClickListener {
itemClick?.invoke(item.path) itemClick?.invoke(item.path)
} }
......
package com.base.pdfviewerscannerwhite.ui.document package com.base.pdfviewerscannerwhite.ui.document
import android.app.Dialog
import android.content.Intent import android.content.Intent
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.base.pdfviewerscannerwhite.bean.ConstObject
import com.base.pdfviewerscannerwhite.bean.DocumentBean import com.base.pdfviewerscannerwhite.bean.DocumentBean
import com.base.pdfviewerscannerwhite.bean.DocumentBean.Companion.TYPE_PDF import com.base.pdfviewerscannerwhite.bean.DocumentBean.Companion.TYPE_PDF
import com.base.pdfviewerscannerwhite.databinding.FragmentDocumentBinding import com.base.pdfviewerscannerwhite.databinding.FragmentDocumentBinding
import com.base.pdfviewerscannerwhite.helper.BaseFragment import com.base.pdfviewerscannerwhite.helper.BaseFragment
import com.base.pdfviewerscannerwhite.ui.adapter.DocumentAdapter import com.base.pdfviewerscannerwhite.ui.adapter.DocumentAdapter
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfActivity import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfActivity
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfSplitActivity
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDocumentRenameDialog
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showPdfDetailDialog
import com.base.pdfviewerscannerwhite.utils.PermissionUtils.checkStorePermission import com.base.pdfviewerscannerwhite.utils.PermissionUtils.checkStorePermission
import com.base.pdfviewerscannerwhite.utils.SpStringUtils
import com.base.pdfviewerscannerwhite.utils.SpStringUtils.BOOKMARK_KEY
import com.base.pdfviewerscannerwhite.utils.getMediaFile
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.io.File import java.io.File
class DocumentFragment() : BaseFragment<FragmentDocumentBinding>(), DocumentView {
class DocumentFragment() : BaseFragment<FragmentDocumentBinding>() {
private var type = TYPE_PDF private var type = TYPE_PDF
private var documentList: List<DocumentBean>? = null private var documentList: List<DocumentBean>? = null
private lateinit var adapter: DocumentAdapter private lateinit var adapter: DocumentAdapter
private lateinit var documentPresenter: DocumentPresenter
private var firstDialog: Dialog? = null
constructor(type: String) : this() { constructor(type: String) : this() {
this.type = type this.type = type
...@@ -33,52 +32,45 @@ class DocumentFragment() : BaseFragment<FragmentDocumentBinding>() { ...@@ -33,52 +32,45 @@ class DocumentFragment() : BaseFragment<FragmentDocumentBinding>() {
} }
override fun setView() { override fun setView() {
documentPresenter = DocumentPresenter(this, type, lifecycleScope)
initAdapter() initAdapter()
if (documentList != null) { if (documentList != null) {
adapter.submitList(documentList) adapter.submitList(documentList)
} else { } else {
if (requireContext().checkStorePermission()) { if (requireContext().checkStorePermission()) {
initData() documentPresenter.initData(requireContext())
} }
} }
} }
private fun initAdapter() { private fun initAdapter() {
adapter = DocumentAdapter() adapter = DocumentAdapter()
adapter.bookmarkAction = { addRemove, path -> adapter.bookmarkAction = { addRemove, path ->
if (addRemove) { documentPresenter.saveBookmarkChange(addRemove, path)
SpStringUtils.addSpString(BOOKMARK_KEY, path)
} else {
SpStringUtils.deleteSpString(BOOKMARK_KEY, path)
}
} }
adapter.itemClick = { path -> adapter.itemClick = { path ->
startActivity(Intent(requireContext(), PdfActivity::class.java).apply { startActivity(Intent(requireContext(), PdfActivity::class.java).apply {
putExtra("path", path) putExtra("path", path)
}) })
} }
binding.rv.adapter = adapter adapter.moreAction = { item ->
if (item.type == TYPE_PDF) {
requireContext().showPdfDetailDialog(this, item, adapter, dismissAction = { firstDialog = null })
} }
private fun initData() = lifecycleScope.launch(Dispatchers.IO) {
val selectionArgs = arrayOf(ConstObject.MIME_TYPE_PDF)
if (type == TYPE_PDF) {
} }
val bookmarkList = SpStringUtils.getSpStringList(BOOKMARK_KEY) binding.rv.adapter = adapter
val list = requireContext().getMediaFile(selectionArgs = selectionArgs)
val documentList = list.map {
DocumentBean(it.path, type, bookmarkList.contains(it.path))
} }
this@DocumentFragment.documentList = documentList
launch(Dispatchers.Main) { override fun refreshDocumentRv(documentList: List<DocumentBean>) {
this@DocumentFragment.documentList = documentList
adapter.submitList(documentList) adapter.submitList(documentList)
} }
override fun splitPdf(path: String) {
startActivity(Intent(requireContext(), PdfSplitActivity::class.java).apply {
putExtra("path", path)
})
} }
fun setRecentList() { fun setRecentList() {
...@@ -97,5 +89,12 @@ class DocumentFragment() : BaseFragment<FragmentDocumentBinding>() { ...@@ -97,5 +89,12 @@ class DocumentFragment() : BaseFragment<FragmentDocumentBinding>() {
adapter.submitList(bookmarkList) adapter.submitList(bookmarkList)
} }
override fun dialogRename(item: DocumentBean) {
val file = File(item.path)
requireContext().showDocumentRenameDialog(file.name, firstDialog) { newName ->
documentPresenter.renameDocumentBean(requireContext(), file, newName)
}
}
} }
\ No newline at end of file
package com.base.pdfviewerscannerwhite.ui.document
import android.content.Context
import androidx.lifecycle.LifecycleCoroutineScope
import com.base.pdfviewerscannerwhite.bean.ConstObject
import com.base.pdfviewerscannerwhite.bean.DocumentBean
import com.base.pdfviewerscannerwhite.utils.SpStringUtils
import com.base.pdfviewerscannerwhite.utils.getMediaFile
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.io.File
class DocumentPresenter(
val documentView: DocumentView,
val type: String,
val lifecycleScope: LifecycleCoroutineScope
) {
fun getDocumentBeanList(context: Context): List<DocumentBean> {
var selectionArgs = arrayOf(ConstObject.MIME_TYPE_PDF)
if (type == DocumentBean.TYPE_PDF) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_PDF)
}
val bookmarkList = SpStringUtils.getSpStringList(SpStringUtils.BOOKMARK_KEY)
val list = context.getMediaFile(selectionArgs = selectionArgs)
val documentList = list.map {
DocumentBean(it.path, type, bookmarkList.contains(it.path))
}
return documentList
}
fun initData(context: Context) = lifecycleScope.launch(Dispatchers.IO) {
val documentList = getDocumentBeanList(context)
launch(Dispatchers.Main) {
documentView.refreshDocumentRv(documentList)
}
}
fun saveBookmarkChange(addRemove: Boolean, path: String) {
if (addRemove) {
SpStringUtils.addSpString(SpStringUtils.BOOKMARK_KEY, path)
} else {
SpStringUtils.deleteSpString(SpStringUtils.BOOKMARK_KEY, path)
}
}
fun renameDocumentBean(context: Context, file: File, newName: String) = lifecycleScope.launch(Dispatchers.IO) {
runCatching {
val nameFile = File(file.parentFile, newName)
file.renameTo(nameFile)
}
val documentList = getDocumentBeanList(context)
launch(Dispatchers.Main) {
documentView.refreshDocumentRv(documentList)
}
}
}
\ No newline at end of file
package com.base.pdfviewerscannerwhite.ui.document
import com.base.pdfviewerscannerwhite.bean.DocumentBean
interface DocumentView {
fun dialogRename(item: DocumentBean)
fun refreshDocumentRv(documentList: List<DocumentBean>)
fun splitPdf(path: String)
}
\ No newline at end of file
...@@ -5,10 +5,12 @@ import android.content.Context ...@@ -5,10 +5,12 @@ import android.content.Context
import android.os.Handler import android.os.Handler
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView.ViewHolder import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.pdfviewerscannerwhite.R import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.bean.PdfPageBean import com.base.pdfviewerscannerwhite.bean.PdfPageBean
import com.base.pdfviewerscannerwhite.databinding.ItemPdfPagerBinding import com.base.pdfviewerscannerwhite.databinding.ItemPdfPagerBinding
import com.base.pdfviewerscannerwhite.databinding.ItemPdfPagerSplitBinding
import com.base.pdfviewerscannerwhite.utils.PdfUtils import com.base.pdfviewerscannerwhite.utils.PdfUtils
import com.base.pdfviewerscannerwhite.utils.XmlEx.inflate import com.base.pdfviewerscannerwhite.utils.XmlEx.inflate
import com.chad.library.adapter4.BaseQuickAdapter import com.chad.library.adapter4.BaseQuickAdapter
...@@ -17,7 +19,10 @@ import java.util.concurrent.ThreadPoolExecutor ...@@ -17,7 +19,10 @@ import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
class PdfPagerAdapter(val pdfPath: String) : BaseQuickAdapter<PdfPageBean, PdfPagerAdapter.PdfPagerViewHolder>() { class PdfPagerAdapter(val pdfPath: String, val itemLayout: Int = R.layout.item_pdf_pager) :
BaseQuickAdapter<PdfPageBean, PdfPagerAdapter.PdfPagerViewHolder>() {
var selectAction: ((enable: Boolean, allSelect: Boolean) -> Unit)? = null
inner class PdfPagerViewHolder(view: View) : ViewHolder(view) inner class PdfPagerViewHolder(view: View) : ViewHolder(view)
...@@ -35,26 +40,55 @@ class PdfPagerAdapter(val pdfPath: String) : BaseQuickAdapter<PdfPageBean, PdfPa ...@@ -35,26 +40,55 @@ class PdfPagerAdapter(val pdfPath: String) : BaseQuickAdapter<PdfPageBean, PdfPa
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: PdfPagerViewHolder, position: Int, item: PdfPageBean?) { override fun onBindViewHolder(holder: PdfPagerViewHolder, position: Int, item: PdfPageBean?) {
if (item == null) return if (item == null) return
when (itemLayout) {
R.layout.item_pdf_pager -> {
val binding = ItemPdfPagerBinding.bind(holder.itemView) val binding = ItemPdfPagerBinding.bind(holder.itemView)
val context = holder.itemView.context val context = holder.itemView.context
binding.tvPagerIndex.isSelected = item.isSelect binding.tvPagerIndex.isSelected = item.isSelect
binding.tvPagerIndex.text = (item.pageIndex + 1).toString() binding.tvPagerIndex.text = (item.pageIndex + 1).toString()
binding.flBorder.isSelected = item.isSelect binding.flBorder.isSelected = item.isSelect
item.pageDrawable?.let {
binding.ivPager.setImageDrawable(it) if (item.pageDrawable != null) {
binding.ivPager.setImageDrawable(item.pageDrawable)
} else {
loadPagerDrawable(context, item, binding.root, binding.ivPager)
} }
loadPagerDrawable(context, binding, item)
} }
private fun loadPagerDrawable(context: Context, binding: ItemPdfPagerBinding, item: PdfPageBean) { R.layout.item_pdf_pager_split -> {
val binding = ItemPdfPagerSplitBinding.bind(holder.itemView)
binding.ivSelector.isSelected = item.isSelect
if (item.pageDrawable != null) {
binding.ivPager.setImageDrawable(item.pageDrawable)
} else {
loadPagerDrawable(context, item, binding.root, binding.ivPager, 1.5f)
}
binding.ivSelector.setOnClickListener {
item.isSelect = !item.isSelect
notifyItemChanged(position, "aaa")
selectAction?.invoke(items.any { it.isSelect }, items.all { it.isSelect })
}
}
}
}
private fun loadPagerDrawable(
context: Context,
item: PdfPageBean,
itemView: View,
iv: ImageView,
scale: Float = 1f
) {
threadPoolExecutor.execute { threadPoolExecutor.execute {
runCatching { runCatching {
val drawable = PdfUtils.getPdfDrawablePage(context, pdfPath, item.pageIndex) val drawable = PdfUtils.getPdfDrawablePage(context, pdfPath, item.pageIndex, scale)
item.pageDrawable = drawable item.pageDrawable = drawable
// 任务代码 // 任务代码
binding.root.post { itemView.post {
item.pageDrawable?.let { item.pageDrawable?.let {
binding.ivPager.setImageDrawable(it) iv.setImageDrawable(it)
} }
} }
} }
...@@ -63,6 +97,12 @@ class PdfPagerAdapter(val pdfPath: String) : BaseQuickAdapter<PdfPageBean, PdfPa ...@@ -63,6 +97,12 @@ class PdfPagerAdapter(val pdfPath: String) : BaseQuickAdapter<PdfPageBean, PdfPa
} }
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): PdfPagerViewHolder { override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): PdfPagerViewHolder {
return PdfPagerViewHolder(R.layout.item_pdf_pager.inflate(parent)) return PdfPagerViewHolder(itemLayout.inflate(parent))
}
@SuppressLint("NotifyDataSetChanged")
fun toggleSelect(select: Boolean) {
items.forEach { it.isSelect = select }
notifyDataSetChanged()
} }
} }
\ No newline at end of file
package com.base.pdfviewerscannerwhite.ui.document.pdf package com.base.pdfviewerscannerwhite.ui.document.pdf
import android.content.Context import android.content.Context
import android.os.Environment
import android.os.Handler import android.os.Handler
import com.base.pdfviewerscannerwhite.bean.PdfPageBean import com.base.pdfviewerscannerwhite.bean.PdfPageBean
import com.base.pdfviewerscannerwhite.utils.PdfUtils import com.base.pdfviewerscannerwhite.utils.PdfUtils
import com.base.pdfviewerscannerwhite.utils.ToastUtils.toast import com.tom_roush.pdfbox.pdmodel.PDDocument
import java.io.File import java.io.File
...@@ -13,16 +12,6 @@ class PdfPresenter(val context: Context, val pdfView: PdfView) { ...@@ -13,16 +12,6 @@ class PdfPresenter(val context: Context, val pdfView: PdfView) {
var handler: Handler? = null var handler: Handler? = null
fun splitPdf(pdfPath: String) = Thread {
val drawableList = PdfUtils.getPdfDrawables(context, pdfPath)
handler?.post {
context.toast("size=${drawableList.size}")
}
}.start()
fun iniPdfPage(filePath: String) { fun iniPdfPage(filePath: String) {
val list = arrayListOf<PdfPageBean>() val list = arrayListOf<PdfPageBean>()
val number = PdfUtils.getNumberOfPages(filePath) val number = PdfUtils.getNumberOfPages(filePath)
...@@ -31,4 +20,29 @@ class PdfPresenter(val context: Context, val pdfView: PdfView) { ...@@ -31,4 +20,29 @@ class PdfPresenter(val context: Context, val pdfView: PdfView) {
} }
pdfView.initPdfPageRv(list) pdfView.initPdfPageRv(list)
} }
fun splitPdf(file: File, newName: String, splitIndex: List<Int>) {
try {
// 加载现有 PDF 文档
val sourceDocument = PDDocument.load(file)
// 创建新的 PDF 文档
val newDocument = PDDocument()
// 遍历指定的页面范围
splitIndex.forEach { index ->
val page = sourceDocument.getPage(index)
newDocument.addPage(page)
}
val newFile = File(file.parentFile, newName)
// 保存新的 PDF 文档
newDocument.save(newFile)
newDocument.close()
sourceDocument.close()
}catch (e:Exception){
println("Error occurred while splitting PDF.")
}
}
} }
\ No newline at end of file
package com.base.pdfviewerscannerwhite.ui.document.pdf
import androidx.activity.addCallback
import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.bean.PdfPageBean
import com.base.pdfviewerscannerwhite.databinding.ActivityPdfSplitBinding
import com.base.pdfviewerscannerwhite.helper.BaseActivity
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDocumentRenameDialog
import java.io.File
class PdfSplitActivity : BaseActivity<ActivityPdfSplitBinding>(), PdfView {
private lateinit var pdfPresenter: PdfPresenter
private lateinit var pdfPagerAdapter: PdfPagerAdapter
private var path: String = ""
override val binding: ActivityPdfSplitBinding by lazy {
ActivityPdfSplitBinding.inflate(layoutInflater)
}
override fun initView() {
pdfPresenter = PdfPresenter(this, this)
path = intent.extras?.getString("path", "") ?: ""
initAdapter()
pdfPresenter.iniPdfPage(path)
}
override fun initListener() {
super.initListener()
onBackPressedDispatcher.addCallback {
finishToMain()
}
binding.flFanhui.setOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
binding.ivSelector.setOnClickListener {
binding.ivSelector.isSelected = !binding.ivSelector.isSelected
pdfPagerAdapter.toggleSelect(binding.ivSelector.isSelected)
}
binding.tvBtnSplit.setOnClickListener {
val splitIndex = pdfPagerAdapter.items.filter { it.isSelect }.map { it.pageIndex }
val file = File(path)
showDocumentRenameDialog { newName ->
pdfPresenter.splitPdf(file, newName, splitIndex)
}
}
}
private fun initAdapter() {
pdfPagerAdapter = PdfPagerAdapter(path, R.layout.item_pdf_pager_split)
pdfPagerAdapter.selectAction = { enable, allSelect ->
binding.tvBtnSplit.isEnabled = enable
binding.ivSelector.isSelected = allSelect
}
binding.rv.adapter = pdfPagerAdapter
}
override fun initPdfPageRv(items: List<PdfPageBean>) {
pdfPagerAdapter.submitList(items)
}
}
\ No newline at end of file
package com.base.pdfviewerscannerwhite.ui.view
import android.annotation.SuppressLint
import android.app.Dialog
import android.content.Context
import android.view.LayoutInflater
import android.view.WindowManager
import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.bean.DocumentBean
import com.base.pdfviewerscannerwhite.databinding.DialogDocumentRenameBinding
import com.base.pdfviewerscannerwhite.databinding.DialogPdfDetailBinding
import com.base.pdfviewerscannerwhite.ui.adapter.DocumentAdapter
import com.base.pdfviewerscannerwhite.ui.document.DocumentPresenter
import com.base.pdfviewerscannerwhite.ui.document.DocumentView
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfPresenter
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.ToastUtils.toast
import com.google.android.material.bottomsheet.BottomSheetDialog
import java.io.File
object DialogView {
@SuppressLint("SetTextI18n", "NotifyDataSetChanged")
fun Context.showPdfDetailDialog(
documentView: DocumentView,
item: DocumentBean,
adapter: DocumentAdapter,
dismissAction: () -> Unit
): BottomSheetDialog {
val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
val binding = DialogPdfDetailBinding.inflate(LayoutInflater.from(this))
dialog.setContentView(binding.root)
dialog.setCanceledOnTouchOutside(false)
dialog.show()
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)
}
dialog.setOnDismissListener {
dismissAction.invoke()
}
return dialog
}
fun Context.showDocumentRenameDialog(
name: String? = null,
firstDialog: Dialog? = null,
okAction: ((newName: String) -> Unit)? = null,
) {
val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
val binding = DialogDocumentRenameBinding.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 tempName = "Split_" + System.currentTimeMillis().toFormatTime2()
binding.edit.setText(name ?: tempName)
binding.edit.requestFocus()
binding.tvCancel.setOnClickListener {
dialog.dismiss()
}
binding.tvOk.setOnClickListener {
dialog.dismiss()
val newName = binding.edit.text.toString()
if (newName.isEmpty()) {
toast("name can't be empty!")
return@setOnClickListener
}
okAction?.invoke(newName)
firstDialog?.dismiss()
}
}
}
\ No newline at end of file
...@@ -27,6 +27,11 @@ object KotlinExt { ...@@ -27,6 +27,11 @@ object KotlinExt {
return SimpleDateFormat("MMM dd,yyyy", Locale.ENGLISH).format(this) return SimpleDateFormat("MMM dd,yyyy", Locale.ENGLISH).format(this)
} }
fun Long.toFormatTime2(): String {
return SimpleDateFormat("yyyyMMdd_HHmmss,", Locale.ENGLISH).format(this)
}
fun Array<String>.array2String(): String { fun Array<String>.array2String(): String {
val stringBuilder = StringBuilder() val stringBuilder = StringBuilder()
forEach { forEach {
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#7FDCEE" />
<corners android:radius="10dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00B8DE"/>
<corners android:radius="10dp"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F1F1F1" />
<corners android:topLeftRadius="25dp" android:topRightRadius="25dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F1F2F6"/>
<corners android:radius="10dp"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F3F3F3" />
<corners
android:topLeftRadius="25dp"
android:topRightRadius="25dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/xuan" android:state_selected="true" />
<item android:drawable="@mipmap/weixuan" android:state_selected="false" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/bg_00b8de_10" android:state_enabled="false" />
<item android:drawable="@drawable/bg_7fdcee_10" android:state_enabled="true" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="0.5dp"
android:color="#BABABA" />
<corners android:radius="10dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ui.document.pdf.PdfSplitActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="60dp">
<FrameLayout
android:id="@+id/fl_fanhui"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/fanhui_b"
tools:ignore="ContentDescription" />
</FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="13dp"
android:text="Split PDF"
android:textColor="@color/black"
android:textSize="19sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/fl_fanhui"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />
<ImageView
android:id="@+id/iv_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="34dp"
android:src="@drawable/bg_selector_select"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="3"
tools:listitem="@layout/item_pdf_pager_split" />
<TextView
android:id="@+id/tv_btn_split"
android:layout_width="338dp"
android:layout_height="48dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="35dp"
android:background="@drawable/bg_selector_split"
android:enabled="false"
android:gravity="center"
android:text="Split"
android:textColor="@color/white"
android:textSize="18sp"
tools:ignore="HardcodedText" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_f3f3f3_tlr25"
android:orientation="vertical">
<FrameLayout
android:id="@+id/fl"
android:layout_width="match_parent"
android:layout_height="65dp"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="16dp"
android:includeFontPadding="false"
android:text="Rename"
android:textColor="#333333"
android:textSize="17sp"
android:textStyle="bold"
tools:ignore="HardcodedText" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/fl">
<EditText
android:id="@+id/edit"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="32dp"
android:background="@drawable/bg_stoke_bababa_10"
android:ellipsize="end"
android:gravity="center_vertical"
android:paddingHorizontal="20dp"
android:singleLine="true"
android:text="DEMO.pdf"
android:textColor="#333333"
android:textSize="18sp"
tools:ignore="Autofill,HardcodedText,LabelFor,TextFields" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="26dp"
android:layout_marginBottom="20dp">
<TextView
android:id="@+id/tv_cancel"
android:layout_width="163dp"
android:layout_height="48dp"
android:background="@drawable/bg_f1f2f6_10"
android:gravity="center"
android:text="Cancel"
android:textColor="#505050"
android:textSize="18sp"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/tv_ok"
android:layout_width="163dp"
android:layout_height="48dp"
android:layout_marginStart="14dp"
android:background="@drawable/bg_00b8de_10"
android:gravity="center"
android:text="Ok"
android:textColor="@color/white"
android:textSize="18sp"
tools:ignore="HardcodedText" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fl_border"
android:layout_width="103dp"
android:layout_height="145dp"
android:layout_marginHorizontal="12.5dp"
android:layout_marginVertical="7dp"
android:background="@drawable/bg_selector_pager_border">
<ImageView
android:id="@+id/iv_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:importantForAccessibility="no"
android:scaleType="fitXY" />
<ImageView
android:id="@+id/iv_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|top"
android:layout_margin="8dp"
android:src="@drawable/bg_selector_select"
tools:ignore="ContentDescription" />
</FrameLayout>
\ No newline at end of file
...@@ -12,4 +12,12 @@ ...@@ -12,4 +12,12 @@
<item name="android:windowFullscreen">false</item> <item name="android:windowFullscreen">false</item>
</style> </style>
<style name="BottomSheetDialog" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/bottomSheetStyleWrapper</item>
</style>
<style name="bottomSheetStyleWrapper" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@android:color/transparent</item>
</style>
</resources> </resources>
\ No newline at end of file
package com.base.pdfviewerscannerwhite
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
\ 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