Commit e1c664a9 authored by wanglei's avatar wanglei

...

parent 026eed03
package com.base.pdfreaderallpdfreader.ui.document
import android.annotation.SuppressLint
import android.app.Activity
import android.os.Bundle
import androidx.fragment.app.Fragment
......@@ -27,15 +28,19 @@ import com.base.pdfreaderallpdfreader.ui.main.getPptDocument
import com.base.pdfreaderallpdfreader.ui.main.getWordDocument
import com.base.pdfreaderallpdfreader.ui.pdf.PdfActivity
import com.base.pdfreaderallpdfreader.ui.ppt.PptActivity
import com.base.pdfreaderallpdfreader.ui.view.DialogCallBack
import com.base.pdfreaderallpdfreader.ui.view.DocumentDialog.showDocumentHomeMoreDialog
import com.base.pdfreaderallpdfreader.ui.view.PdfDialog.showPdfHomeMoreDialog
import com.base.pdfreaderallpdfreader.ui.word.WordActivity
import com.base.pdfreaderallpdfreader.utils.PdfBoxUtils.checkPdfEncryption
import com.base.pdfreaderallpdfreader.utils.SpStringUtils
import com.base.pdfreaderallpdfreader.utils.SpStringUtils.BOOKMARK_KEY
import com.base.pdfreaderallpdfreader.utils.updateMediaStore
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.io.File
class DocumentFragment() : Fragment() {
class DocumentFragment() : Fragment(), DialogCallBack {
private var type = TYPE_PDF
......@@ -56,7 +61,7 @@ class DocumentFragment() : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
adapter = DocumentAdapter()
adapter = DocumentAdapter(requireActivity())
adapter?.itemClickAction = { item: DocumentBean ->
if (item.type == TYPE_PDF) {
PdfActivity.jumpPdfActivity(requireActivity(), item)
......@@ -66,7 +71,7 @@ class DocumentFragment() : Fragment() {
}
adapter?.moreAction = { item: DocumentBean ->
if (item.type == TYPE_PDF) {
requireActivity().showPdfHomeMoreDialog(item, this)
} else {
requireContext().showDocumentHomeMoreDialog(item, this)
}
......@@ -169,14 +174,15 @@ class DocumentFragment() : Fragment() {
return list
}
fun deleteDocument(item: DocumentBean) {
override fun deleteDocument(item: DocumentBean) {
val flag = File(item.path).delete()
if (flag) {
adapter?.remove(item)
}
}
fun renameDocumentBean(file: File, newName: String) {
override fun renameDocumentBean(file: File, newName: String) {
try {
val newFile = File(file.parentFile, newName)
val result = file.renameTo(newFile)
......@@ -188,6 +194,25 @@ class DocumentFragment() : Fragment() {
}
}
@SuppressLint("NotifyDataSetChanged")
override fun changeBookmark(path: String, isBookmarked: Boolean) {
if (isBookmarked) {
SpStringUtils.addSpString(BOOKMARK_KEY, path)
} else {
SpStringUtils.deleteSpString(BOOKMARK_KEY, path)
}
adapter?.items?.find { it.path == path }?.isBookmarked = isBookmarked
adapter?.notifyDataSetChanged()
}
@SuppressLint("NotifyDataSetChanged")
override fun changePdfLock(item: DocumentBean) {
val pdf = adapter?.items?.find { it.path == item.path }
pdf?.state = requireContext().checkPdfEncryption(item.path)
adapter?.notifyDataSetChanged()
}
companion object {
var pdfNeedRefresh: Boolean = true
......
package com.base.pdfreaderallpdfreader.ui.main
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.pdfreaderallpdfreader.R
import com.base.pdfreaderallpdfreader.ads.admob.AdmobNativeUtils
import com.base.pdfreaderallpdfreader.bean.DocumentBean
import com.base.pdfreaderallpdfreader.bean.DocumentBean.Companion.TYPE_EXCEL
import com.base.pdfreaderallpdfreader.bean.DocumentBean.Companion.TYPE_PDF
import com.base.pdfreaderallpdfreader.bean.DocumentBean.Companion.TYPE_PPT
import com.base.pdfreaderallpdfreader.bean.DocumentBean.Companion.TYPE_WORD
import com.base.pdfreaderallpdfreader.databinding.ItemAdBinding
import com.base.pdfreaderallpdfreader.databinding.ItemDocumentBinding
import com.base.pdfreaderallpdfreader.utils.KotlinExt.toFormatSize
import com.base.pdfreaderallpdfreader.utils.KotlinExt.toFormatTime5
......@@ -19,7 +22,9 @@ import com.base.pdfreaderallpdfreader.utils.XmlEx.inflate
import com.chad.library.adapter4.BaseQuickAdapter
import java.io.File
class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentViewHolder>() {
class DocumentAdapter(
val activity: Activity
) : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentViewHolder>() {
private val TAG = "DocumentAdapter"
......@@ -31,43 +36,58 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: DocumentViewHolder, position: Int, item: DocumentBean?) {
item ?: return
val binding = ItemDocumentBinding.bind(holder.itemView)
if (item.isAd) {
val binding = ItemAdBinding.bind(holder.itemView)
AdmobNativeUtils.showNativeAd(activity, binding.flAd, R.layout.layout_admob_document)
} else {
val binding = ItemDocumentBinding.bind(holder.itemView)
when (item.type) {
TYPE_PDF -> {
LogEx.logDebug(TAG, "pdf state = ${item.state}")
if (item.state == 0) {
binding.ivIcon.setImageResource(R.mipmap.r_pdf)
} else {
binding.ivIcon.setImageResource(R.mipmap.rv_pdf_lock)
when (item.type) {
TYPE_PDF -> {
LogEx.logDebug(TAG, "pdf state = ${item.state}")
if (item.state == 0) {
binding.ivIcon.setImageResource(R.mipmap.r_pdf)
} else {
binding.ivIcon.setImageResource(R.mipmap.rv_pdf_lock)
}
}
}
TYPE_WORD -> {
binding.ivIcon.setImageResource(R.mipmap.rv_word)
}
TYPE_WORD -> {
binding.ivIcon.setImageResource(R.mipmap.rv_word)
}
TYPE_EXCEL -> {
binding.ivIcon.setImageResource(R.mipmap.rv_excel)
TYPE_EXCEL -> {
binding.ivIcon.setImageResource(R.mipmap.rv_excel)
}
TYPE_PPT -> {
binding.ivIcon.setImageResource(R.mipmap.r_ppt)
}
}
val file = File(item.path)
binding.tvName.text = file.name
binding.tvInfo.text = file.lastModified().toFormatTime5() + " " + file.length().toFormatSize()
TYPE_PPT -> {
binding.ivIcon.setImageResource(R.mipmap.r_ppt)
binding.flMore.setOnClickListener {
moreAction?.invoke(item)
}
binding.root.setOnClickListener {
itemClickAction?.invoke(item)
}
}
val file = File(item.path)
binding.tvName.text = file.name
binding.tvInfo.text = file.lastModified().toFormatTime5() + " " + file.length().toFormatSize()
binding.flMore.setOnClickListener {
moreAction?.invoke(item)
}
binding.root.setOnClickListener {
itemClickAction?.invoke(item)
}
}
override fun getItemViewType(position: Int, list: List<DocumentBean>): Int {
val item = list[position]
return if (item.isAd) 1 else 0
}
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): DocumentViewHolder {
return DocumentViewHolder(R.layout.item_document.inflate(parent))
return if (viewType == 0) {
DocumentViewHolder(R.layout.item_document.inflate(parent))
} else {
DocumentViewHolder(R.layout.item_ad.inflate(parent))
}
}
}
\ No newline at end of file
......@@ -36,7 +36,7 @@ class BookmarkFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
adapter = DocumentAdapter()
adapter = DocumentAdapter(requireActivity())
binding.rv.adapter = adapter
}
......
......@@ -45,7 +45,7 @@ class RecentFragment() : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
adapter = DocumentAdapter()
adapter = DocumentAdapter(requireActivity())
binding.rv.adapter = adapter
}
......
......@@ -15,15 +15,15 @@ import com.base.pdfreaderallpdfreader.databinding.ItemTabDocumentBinding
import com.base.pdfreaderallpdfreader.ui.document.DocumentFragment.Companion.jumpOtherDocument
import com.base.pdfreaderallpdfreader.ui.main.DocumentAdapter
import com.base.pdfreaderallpdfreader.ui.pdf.PdfActivity
import com.base.pdfreaderallpdfreader.ui.view.DialogCallBack
import com.base.pdfreaderallpdfreader.ui.view.DocumentDialog.showDocumentHomeMoreDialog
import com.base.pdfreaderallpdfreader.ui.view.DocumentHomeMoreCallBack
import com.base.pdfreaderallpdfreader.utils.BarUtils
import com.base.pdfreaderallpdfreader.utils.LogEx
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.io.File
class SearchActivity : BaseActivity<ActivitySearchBinding>(), DocumentHomeMoreCallBack {
class SearchActivity : BaseActivity<ActivitySearchBinding>(), DialogCallBack {
private val TAG = "SearchActivity"
private lateinit var searchViewModel: SearchViewModel
......@@ -39,10 +39,10 @@ class SearchActivity : BaseActivity<ActivitySearchBinding>(), DocumentHomeMoreCa
binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
searchViewModel = ViewModelProvider(this)[SearchViewModel::class.java]
adapter = DocumentAdapter()
adapter = DocumentAdapter(this)
binding.rv.adapter = adapter
adapter?.moreAction = { item: DocumentBean ->
showDocumentHomeMoreDialog(item, null, this)
showDocumentHomeMoreDialog(item, this)
}
adapter?.itemClickAction = { item: DocumentBean ->
if (item.type == TYPE_PDF) {
......
......@@ -3,9 +3,8 @@ package com.base.pdfreaderallpdfreader.ui.splash
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.splashscreen.SplashScreen
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.splashscreen.SplashScreenViewProvider
import com.base.pdfreaderallpdfreader.utils.LogEx
import java.util.concurrent.atomic.AtomicBoolean
/**
......@@ -14,6 +13,8 @@ import java.util.concurrent.atomic.AtomicBoolean
*/
class SystemStartActivity : AppCompatActivity() {
private val TAG = "SystemStartActivity"
// 数据
private var mKeepOnAtomicBool = AtomicBoolean(true)
......@@ -28,16 +29,21 @@ class SystemStartActivity : AppCompatActivity() {
splashScreen.setKeepOnScreenCondition {
mKeepOnAtomicBool.get()
}
LogEx.logDebug(TAG, "setKeepOnScreenCondition...")
startActivity(Intent(this@SystemStartActivity, MyStartActivity::class.java))
this@SystemStartActivity.finish()
overridePendingTransition(0, 0)
mKeepOnAtomicBool.compareAndSet(true, false)
// Splash展示完毕的监听方法
splashScreen.setOnExitAnimationListener(object : SplashScreen.OnExitAnimationListener {
override fun onSplashScreenExit(splashScreenViewProvider: SplashScreenViewProvider) {
startActivity(Intent(this@SystemStartActivity, MyStartActivity::class.java))
this@SystemStartActivity.finish()
overridePendingTransition(0, 0)
mKeepOnAtomicBool.compareAndSet(true, false)
}
})
// Splash动画展示完毕的监听方法,无动画不用
// splashScreen.setOnExitAnimationListener(object : SplashScreen.OnExitAnimationListener {
// override fun onSplashScreenExit(splashScreenViewProvider: SplashScreenViewProvider) {
// LogEx.logDebug(TAG, "onSplashScreenExit")
// startActivity(Intent(this@SystemStartActivity, MyStartActivity::class.java))
// this@SystemStartActivity.finish()
// overridePendingTransition(0, 0)
// mKeepOnAtomicBool.compareAndSet(true, false)
// }
// })
}
}
\ No newline at end of file
package com.base.pdfreaderallpdfreader.ui.view
import com.base.pdfreaderallpdfreader.bean.DocumentBean
import java.io.File
interface DialogCallBack {
fun changeBookmark(path: String, isBookmarked: Boolean) = Unit
fun deleteDocument(item: DocumentBean) = Unit
fun changePdfLock(item: DocumentBean) = Unit
fun renameDocumentBean(file: File, newName: String) = Unit
}
\ No newline at end of file
......@@ -16,7 +16,6 @@ import com.base.pdfreaderallpdfreader.databinding.DialogDocumentDetailBinding
import com.base.pdfreaderallpdfreader.databinding.DialogDocumentHomeMoreBinding
import com.base.pdfreaderallpdfreader.databinding.DialogDocumentMoreBinding
import com.base.pdfreaderallpdfreader.databinding.DialogPageNumberBinding
import com.base.pdfreaderallpdfreader.ui.document.DocumentFragment
import com.base.pdfreaderallpdfreader.ui.view.DialogView.showDeleteDialog
import com.base.pdfreaderallpdfreader.ui.view.NameDialog.showDocumentRenameDialog
import com.base.pdfreaderallpdfreader.utils.IntentShareUtils.documentShare
......@@ -32,25 +31,12 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
import java.io.File
interface DocumentHomeMoreCallBack {
fun renameDocumentBean(file: File, newName: String) {
}
fun deleteDocument(item: DocumentBean) {
}
}
object DocumentDialog {
@SuppressLint("SetTextI18n", "NotifyDataSetChanged")
fun Context.showDocumentHomeMoreDialog(
item: DocumentBean,
documentFragment: DocumentFragment? = null,
documentHomeMoreCallBack: DocumentHomeMoreCallBack? = null
dialogCallBack: DialogCallBack
): BottomSheetDialog {
val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
val binding = DialogDocumentHomeMoreBinding.inflate(LayoutInflater.from(this))
......@@ -88,8 +74,7 @@ object DocumentDialog {
binding.llRename.setOnClickListener {
showDocumentRenameDialog(file.name, okAction = { newName ->
dialog.dismiss()
documentFragment?.renameDocumentBean(file, newName)
documentHomeMoreCallBack?.renameDocumentBean(file, newName)
dialogCallBack.renameDocumentBean(file, newName)
})
}
binding.llDetail.setOnClickListener {
......@@ -101,8 +86,7 @@ object DocumentDialog {
binding.llDelete.setOnClickListener {
dialog.dismiss()
showDeleteDialog {
documentFragment?.deleteDocument(item)
documentHomeMoreCallBack?.deleteDocument(item)
dialogCallBack.deleteDocument(item)
}
}
return dialog
......
This diff is collapsed.
......@@ -98,6 +98,7 @@
<string name="send">Send</string>
<string name="pdf_reader">PDF Reader</string>
<string name="lock_pdf">Lock Pdf</string>
<string name="unlock_pdf">Unlock Pdf</string>
<string name="no_bookmark_file">No Bookmark File</string>
</resources>
\ 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