Commit 9991f275 authored by wanglei's avatar wanglei

...

parent 915db78d
......@@ -13,6 +13,7 @@ data class DocumentBean(
var state: Int = -1//0正常状态 1 锁定
var password: String = ""
var lastViewTime: Long = 0
var isAd: Boolean = false
companion object {
const val TYPE_PDF = "type_pdf"
......
......@@ -61,7 +61,7 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView
DO_LOCK_PDF -> {
binding.tvBtnNext.visibility = View.GONE
binding.tvSelectTip.text = getString(R.string.select_a_project)
documentPresenter.initUnLoadData()
documentPresenter.initUnLockData()
}
DO_UNLOCK_PDF -> {
......@@ -96,7 +96,7 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>(), DocumentView
@SuppressLint("StringFormatMatches")
private fun initAdapter() {
adapter = DocumentAdapter()
adapter = DocumentAdapter(this)
adapter.itemClick = {
if (doWhat == DO_SPLIT_PDF) {
startActivity(Intent(this, PdfSplitActivity::class.java).apply {
......
......@@ -93,7 +93,7 @@ class DocumentFragment(
}
private fun initSearchAdapter() {
searchAdapter = DocumentAdapter()
searchAdapter = DocumentAdapter(requireActivity())
binding.rvSearch.adapter = searchAdapter
searchAdapter.moreAction = { item ->
currentPage.documentMoreAction.invoke(item)
......
......@@ -2,9 +2,10 @@ package com.base.pdfviewerscannerwhite.ui.main
import android.annotation.SuppressLint
import android.content.Intent
import android.util.Log
import android.view.View
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import com.base.pdfviewerscannerwhite.ads.admob.AdmobNativeUtils
import com.base.pdfviewerscannerwhite.bean.ConstObject
import com.base.pdfviewerscannerwhite.bean.ConstObject.UI_SORT_FINAL_MODIFIED
import com.base.pdfviewerscannerwhite.bean.ConstObject.UI_SORT_NAME_A_Z
......@@ -33,7 +34,6 @@ class DocumentPageFragment() : BaseFragment<FragmentDocumentPageBinding>(), Docu
private val TAG = "DocumentFragment"
var type = TYPE_PDF
var dataType: String = ""
private var documentList: ArrayList<DocumentBean> = arrayListOf()
lateinit var adapter: DocumentAdapter
lateinit var documentPresenter: DocumentPresenter
......@@ -50,8 +50,6 @@ class DocumentPageFragment() : BaseFragment<FragmentDocumentPageBinding>(), Docu
documentPresenter = DocumentPresenter(requireContext(), this, type, lifecycleScope)
initAdapter()
isInitialized = true
Log.d("glc", "我被调用了setView")
}
override fun onResume() {
......@@ -62,17 +60,32 @@ class DocumentPageFragment() : BaseFragment<FragmentDocumentPageBinding>(), Docu
fun refreshData() = lifecycleScope.launch(Dispatchers.IO) {
if (isInitialized && !isHidden) {
val list =
(requireActivity() as MainActivity).mainPresenter.getDataByType(type, dataType)
(requireActivity() as MainActivity).mainPresenter.getDataByType(type, dataType).toMutableList()
val dataType = (parentFragment as DocumentFragment).dataType
launch(Dispatchers.Main) {
if (dataType == ConstObject.RECENT_DATA_TYPE) {
if (list.isNotEmpty()) {
list.add(1, DocumentBean().apply { isAd = true })
}
adapter.submitList(list)
} else {
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()
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)
} else {
......@@ -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() {
adapter = DocumentAdapter()
adapter = DocumentAdapter(requireActivity())
adapter.bookmarkAction = { addRemove, path ->
documentPresenter.saveBookmarkChange(addRemove, path)
}
......
......@@ -75,7 +75,7 @@ class DocumentPresenter(
}
fun initUnLoadData() = lifecycleScope.launch(Dispatchers.IO) {
fun initUnLockData() = lifecycleScope.launch(Dispatchers.IO) {
val documentList = getDocumentBeanList()
documentList.forEach {
it.state = PdfBoxUtils.checkPdfEncryption(it.path)
......
......@@ -249,7 +249,15 @@
android:layout_width="match_parent"
android:layout_height="0dp"
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
android:id="@+id/tv_test"
......
......@@ -6,13 +6,25 @@
android:layout_height="match_parent"
tools:context=".ui.main.DocumentPageFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_document" />
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
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_document" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_empty"
......
<?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