Commit 9991f275 authored by wanglei's avatar wanglei

...

parent 915db78d
...@@ -13,6 +13,7 @@ data class DocumentBean( ...@@ -13,6 +13,7 @@ data class DocumentBean(
var state: Int = -1//0正常状态 1 锁定 var state: Int = -1//0正常状态 1 锁定
var password: String = "" var password: String = ""
var lastViewTime: Long = 0 var lastViewTime: Long = 0
var isAd: Boolean = false
companion object { companion object {
const val TYPE_PDF = "type_pdf" const val TYPE_PDF = "type_pdf"
......
...@@ -61,7 +61,7 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView ...@@ -61,7 +61,7 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView
DO_LOCK_PDF -> { DO_LOCK_PDF -> {
binding.tvBtnNext.visibility = View.GONE binding.tvBtnNext.visibility = View.GONE
binding.tvSelectTip.text = getString(R.string.select_a_project) binding.tvSelectTip.text = getString(R.string.select_a_project)
documentPresenter.initUnLoadData() documentPresenter.initUnLockData()
} }
DO_UNLOCK_PDF -> { DO_UNLOCK_PDF -> {
...@@ -96,7 +96,7 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView ...@@ -96,7 +96,7 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView
@SuppressLint("StringFormatMatches") @SuppressLint("StringFormatMatches")
private fun initAdapter() { private fun initAdapter() {
adapter = DocumentAdapter() adapter = DocumentAdapter(this)
adapter.itemClick = { adapter.itemClick = {
if (doWhat == DO_SPLIT_PDF) { if (doWhat == DO_SPLIT_PDF) {
startActivity(Intent(this, PdfSplitActivity::class.java).apply { startActivity(Intent(this, PdfSplitActivity::class.java).apply {
......
package com.base.pdfviewerscannerwhite.ui.main package com.base.pdfviewerscannerwhite.ui.main
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context import android.content.Context
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageView 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.ads.admob.AdmobNativeUtils
import com.base.pdfviewerscannerwhite.bean.DocumentBean import com.base.pdfviewerscannerwhite.bean.DocumentBean
import com.base.pdfviewerscannerwhite.bean.DocumentBean.Companion.TYPE_EXCEL import com.base.pdfviewerscannerwhite.bean.DocumentBean.Companion.TYPE_EXCEL
import com.base.pdfviewerscannerwhite.bean.DocumentBean.Companion.TYPE_PDF import com.base.pdfviewerscannerwhite.bean.DocumentBean.Companion.TYPE_PDF
import com.base.pdfviewerscannerwhite.bean.DocumentBean.Companion.TYPE_PPT import com.base.pdfviewerscannerwhite.bean.DocumentBean.Companion.TYPE_PPT
import com.base.pdfviewerscannerwhite.bean.DocumentBean.Companion.TYPE_WORD import com.base.pdfviewerscannerwhite.bean.DocumentBean.Companion.TYPE_WORD
import com.base.pdfviewerscannerwhite.databinding.ItemAdBinding
import com.base.pdfviewerscannerwhite.databinding.ItemDocumentBinding import com.base.pdfviewerscannerwhite.databinding.ItemDocumentBinding
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfBoxUtils
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatSize import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatSize
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatTime import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatTime
import com.base.pdfviewerscannerwhite.utils.LogEx
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
import java.io.File import java.io.File
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentViewHolder>() { class DocumentAdapter(val activity: Activity) : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentViewHolder>() {
private val TAG = "DocumentAdapter" private val TAG = "DocumentAdapter"
inner class DocumentViewHolder(view: View) : ViewHolder(view) inner class DocumentViewHolder(view: View) : ViewHolder(view)
var itemClick: ((item: DocumentBean) -> Unit)? = null var itemClick: ((item: DocumentBean) -> Unit)? = null
var bookmarkAction: ((addRemove: Boolean, path: String) -> Unit)? = null var bookmarkAction: ((addRemove: Boolean, path: String) -> Unit)? = null
var moreAction: ((item: DocumentBean) -> Unit)? = null var moreAction: ((item: DocumentBean) -> Unit)? = null
var selectAction: ((size: Int) -> Unit)? = null var selectAction: ((size: Int) -> Unit)? = null
var corePoolSize = 4 // 核心线程数
var maximumPoolSize = 10 // 最大线程数
var keepAliveTime: Long = 120 // 非核心线程空闲存活时间
var threadPoolExecutor = ThreadPoolExecutor(
corePoolSize,
maximumPoolSize,
keepAliveTime,
TimeUnit.SECONDS,
LinkedBlockingQueue()
)
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: DocumentViewHolder, position: Int, item: DocumentBean?) { override fun onBindViewHolder(holder: DocumentViewHolder, position: Int, item: DocumentBean?) {
if (item == null) return if (item == null) return
if (item.isAd) {
val binding = ItemAdBinding.bind(holder.itemView)
AdmobNativeUtils.showNativeAd(activity, binding.flAd)
} else {
val binding = ItemDocumentBinding.bind(holder.itemView) val binding = ItemDocumentBinding.bind(holder.itemView)
if (item.type == TYPE_PDF ) { changeIcon(item, binding)
if (item.state==0){
binding.iv.setImageResource(R.mipmap.h_pdfiocn)
}
if (item.state==1){
binding.iv.setImageResource(R.mipmap.suoding)
}
}
if (item.type == TYPE_WORD) {
binding.iv.setImageResource(R.mipmap.h_wordfiocn)
}
if (item.type == TYPE_EXCEL) {
binding.iv.setImageResource(R.mipmap.h_exceliocn)
}
if (item.type == TYPE_PPT) {
binding.iv.setImageResource(R.mipmap.h_pptfiocn)
}
val file = File(item.path) val file = File(item.path)
runCatching { runCatching {
binding.tvName.text = file.name binding.tvName.text = file.name
binding.tvInfo.text = file.lastModified().toFormatTime() + " " + file.length().toFormatSize() binding.tvInfo.text = file.lastModified().toFormatTime() + " " + file.length().toFormatSize()
} }
when (item.uiType) { when (item.uiType) {
0 -> {//首页 0 -> {//首页
binding.flSelect.visibility = View.GONE binding.flSelect.visibility = View.GONE
...@@ -149,9 +121,38 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV ...@@ -149,9 +121,38 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV
} }
} }
}
fun changeIcon(item: DocumentBean, binding: ItemDocumentBinding) {
if (item.type == TYPE_PDF) {
if (item.state == 0) {
binding.iv.setImageResource(R.mipmap.h_pdfiocn)
}
if (item.state == 1) {
binding.iv.setImageResource(R.mipmap.suoding)
}
}
if (item.type == TYPE_WORD) {
binding.iv.setImageResource(R.mipmap.h_wordfiocn)
}
if (item.type == TYPE_EXCEL) {
binding.iv.setImageResource(R.mipmap.h_exceliocn)
}
if (item.type == TYPE_PPT) {
binding.iv.setImageResource(R.mipmap.h_pptfiocn)
}
}
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 { 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
...@@ -93,7 +93,7 @@ class DocumentFragment( ...@@ -93,7 +93,7 @@ class DocumentFragment(
} }
private fun initSearchAdapter() { private fun initSearchAdapter() {
searchAdapter = DocumentAdapter() searchAdapter = DocumentAdapter(requireActivity())
binding.rvSearch.adapter = searchAdapter binding.rvSearch.adapter = searchAdapter
searchAdapter.moreAction = { item -> searchAdapter.moreAction = { item ->
currentPage.documentMoreAction.invoke(item) currentPage.documentMoreAction.invoke(item)
......
...@@ -2,9 +2,10 @@ package com.base.pdfviewerscannerwhite.ui.main ...@@ -2,9 +2,10 @@ package com.base.pdfviewerscannerwhite.ui.main
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Intent import android.content.Intent
import android.util.Log import android.view.View
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.base.pdfviewerscannerwhite.ads.admob.AdmobNativeUtils
import com.base.pdfviewerscannerwhite.bean.ConstObject import com.base.pdfviewerscannerwhite.bean.ConstObject
import com.base.pdfviewerscannerwhite.bean.ConstObject.UI_SORT_FINAL_MODIFIED import com.base.pdfviewerscannerwhite.bean.ConstObject.UI_SORT_FINAL_MODIFIED
import com.base.pdfviewerscannerwhite.bean.ConstObject.UI_SORT_NAME_A_Z import com.base.pdfviewerscannerwhite.bean.ConstObject.UI_SORT_NAME_A_Z
...@@ -33,7 +34,6 @@ class DocumentPageFragment() : BaseFragment<FragmentDocumentPageBinding>(), Docu ...@@ -33,7 +34,6 @@ class DocumentPageFragment() : BaseFragment<FragmentDocumentPageBinding>(), Docu
private val TAG = "DocumentFragment" private val TAG = "DocumentFragment"
var type = TYPE_PDF var type = TYPE_PDF
var dataType: String = "" var dataType: String = ""
private var documentList: ArrayList<DocumentBean> = arrayListOf()
lateinit var adapter: DocumentAdapter lateinit var adapter: DocumentAdapter
lateinit var documentPresenter: DocumentPresenter lateinit var documentPresenter: DocumentPresenter
...@@ -50,8 +50,6 @@ class DocumentPageFragment() : BaseFragment<FragmentDocumentPageBinding>(), Docu ...@@ -50,8 +50,6 @@ class DocumentPageFragment() : BaseFragment<FragmentDocumentPageBinding>(), Docu
documentPresenter = DocumentPresenter(requireContext(), this, type, lifecycleScope) documentPresenter = DocumentPresenter(requireContext(), this, type, lifecycleScope)
initAdapter() initAdapter()
isInitialized = true isInitialized = true
Log.d("glc", "我被调用了setView")
} }
override fun onResume() { override fun onResume() {
...@@ -62,17 +60,32 @@ class DocumentPageFragment() : BaseFragment<FragmentDocumentPageBinding>(), Docu ...@@ -62,17 +60,32 @@ class DocumentPageFragment() : BaseFragment<FragmentDocumentPageBinding>(), Docu
fun refreshData() = lifecycleScope.launch(Dispatchers.IO) { fun refreshData() = lifecycleScope.launch(Dispatchers.IO) {
if (isInitialized && !isHidden) { if (isInitialized && !isHidden) {
val list = val list =
(requireActivity() as MainActivity).mainPresenter.getDataByType(type, dataType) (requireActivity() as MainActivity).mainPresenter.getDataByType(type, dataType).toMutableList()
val dataType = (parentFragment as DocumentFragment).dataType val dataType = (parentFragment as DocumentFragment).dataType
launch(Dispatchers.Main) { launch(Dispatchers.Main) {
if (dataType == ConstObject.RECENT_DATA_TYPE) { if (dataType == ConstObject.RECENT_DATA_TYPE) {
if (list.isNotEmpty()) {
list.add(1, DocumentBean().apply { isAd = true })
}
adapter.submitList(list) adapter.submitList(list)
} else { } else {
val sortList = sortByMode(list) val sortList = sortByMode(list)
adapter.submitList(sortList) val arrayList = arrayListOf<DocumentBean>()
arrayList.addAll(sortList)
if (arrayList.isNotEmpty()) {
arrayList.add(1, DocumentBean().apply { isAd = true })
}
adapter.submitList(arrayList)
} }
binding.llEmpty.isVisible = list.isEmpty() binding.llEmpty.isVisible = list.isEmpty()
if (list.isEmpty()) {
binding.flAd.visibility = View.VISIBLE
AdmobNativeUtils.showNativeAd(requireActivity(), binding.flAd)
} else {
binding.flAd.visibility = View.GONE
}
} }
// Log.d("glc", "加载数据成功:" + type + " list:" + list.size) // Log.d("glc", "加载数据成功:" + type + " list:" + list.size)
} else { } else {
...@@ -107,15 +120,8 @@ class DocumentPageFragment() : BaseFragment<FragmentDocumentPageBinding>(), Docu ...@@ -107,15 +120,8 @@ class DocumentPageFragment() : BaseFragment<FragmentDocumentPageBinding>(), Docu
} }
override fun refreshDocumentRv(documentList: List<DocumentBean>) {
binding.llEmpty.isVisible = documentList.isEmpty()
this.documentList.clear()
this.documentList.addAll(documentList)
adapter.submitList(documentList)
}
private fun initAdapter() { private fun initAdapter() {
adapter = DocumentAdapter() adapter = DocumentAdapter(requireActivity())
adapter.bookmarkAction = { addRemove, path -> adapter.bookmarkAction = { addRemove, path ->
documentPresenter.saveBookmarkChange(addRemove, path) documentPresenter.saveBookmarkChange(addRemove, path)
} }
......
...@@ -75,7 +75,7 @@ class DocumentPresenter( ...@@ -75,7 +75,7 @@ class DocumentPresenter(
} }
fun initUnLoadData() = lifecycleScope.launch(Dispatchers.IO) { fun initUnLockData() = lifecycleScope.launch(Dispatchers.IO) {
val documentList = getDocumentBeanList() val documentList = getDocumentBeanList()
documentList.forEach { documentList.forEach {
it.state = PdfBoxUtils.checkPdfEncryption(it.path) it.state = PdfBoxUtils.checkPdfEncryption(it.path)
......
...@@ -249,7 +249,15 @@ ...@@ -249,7 +249,15 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/ll_bottom" /> app:layout_constraintTop_toBottomOf="@id/ll_bottom">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@mipmap/zhanweitu2"
tools:ignore="ContentDescription" />
</FrameLayout>
<TextView <TextView
android:id="@+id/tv_test" android:id="@+id/tv_test"
......
...@@ -6,6 +6,15 @@ ...@@ -6,6 +6,15 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ui.main.DocumentPageFragment"> tools:context=".ui.main.DocumentPageFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="@+id/fl_ad"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv" android:id="@+id/rv"
...@@ -14,6 +23,9 @@ ...@@ -14,6 +23,9 @@
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_document" /> tools:listitem="@layout/item_document" />
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/ll_empty" android:id="@+id/ll_empty"
android:layout_width="wrap_content" android:layout_width="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fl_ad"
android:layout_width="match_parent"
android:layout_height="match_parent">
</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