Commit 6638b4f8 authored by wanglei's avatar wanglei

...

parent 84c1ced5
...@@ -16,6 +16,7 @@ import com.base.pdfreader2.databinding.ItemAdBinding ...@@ -16,6 +16,7 @@ import com.base.pdfreader2.databinding.ItemAdBinding
import com.base.pdfreader2.databinding.ItemDocumentBinding import com.base.pdfreader2.databinding.ItemDocumentBinding
import com.base.pdfreader2.utils.KotlinExt.toFormatSize import com.base.pdfreader2.utils.KotlinExt.toFormatSize
import com.base.pdfreader2.utils.KotlinExt.toFormatTime import com.base.pdfreader2.utils.KotlinExt.toFormatTime
import com.base.pdfreader2.utils.LogEx
import com.base.pdfreader2.utils.XmlEx.inflate import com.base.pdfreader2.utils.XmlEx.inflate
import com.chad.library.adapter4.BaseQuickAdapter import com.chad.library.adapter4.BaseQuickAdapter
import java.io.File import java.io.File
...@@ -46,6 +47,7 @@ class DocumentAdapter() : BaseQuickAdapter<DocumentBean, DocumentAdapter.Documen ...@@ -46,6 +47,7 @@ class DocumentAdapter() : BaseQuickAdapter<DocumentBean, DocumentAdapter.Documen
binding.tvTime.text = file.lastModified().toFormatTime() binding.tvTime.text = file.lastModified().toFormatTime()
binding.tvSize.text = file.length().toFormatSize() binding.tvSize.text = file.length().toFormatSize()
} }
LogEx.logDebug(TAG, "uiType=${item.uiType}")
when (item.uiType) { when (item.uiType) {
0 -> {//首页 0 -> {//首页
binding.flSelect.visibility = View.GONE binding.flSelect.visibility = View.GONE
......
...@@ -73,7 +73,7 @@ class DocumentPresenter( ...@@ -73,7 +73,7 @@ class DocumentPresenter(
*/ */
fun getRecentDocument(type: String): List<DocumentBean> { fun getRecentDocument(type: String): List<DocumentBean> {
val recentList = SpStringUtils.getSpStringList(LAST_VIEW_KEY) val recentList = SpStringUtils.getSpStringList(LAST_VIEW_KEY)
val list = getAllDocument(type,false) val list = getAllDocument(type, false)
list.forEach { recentFilter(recentList, it) } list.forEach { recentFilter(recentList, it) }
return list.filter { it.lastViewTime != 0L }.sortedByDescending { it.lastViewTime } return list.filter { it.lastViewTime != 0L }.sortedByDescending { it.lastViewTime }
} }
...@@ -98,43 +98,53 @@ class DocumentPresenter( ...@@ -98,43 +98,53 @@ class DocumentPresenter(
return list.filter { it.isBookmarked } return list.filter { it.isBookmarked }
} }
fun getAllPdfDataRefresh(lifecycleCoroutineScope: LifecycleCoroutineScope, adapter: DocumentAdapter, progressBar: ProgressBar) { fun getAllPdfDataRefresh(
lifecycleCoroutineScope: LifecycleCoroutineScope,
uiType: Int,
uiAction: (list: List<DocumentBean>) -> Unit
) {
lifecycleCoroutineScope.launch(Dispatchers.IO) { lifecycleCoroutineScope.launch(Dispatchers.IO) {
val list = getPdfData() val list = getPdfData()
list.map { it.uiType == 1 } list.map { it.uiType = uiType }
launch(Dispatchers.Main) { launch(Dispatchers.Main) {
adapter.submitList(list) uiAction.invoke(list)
progressBar.visibility = View.GONE
} }
} }
} }
fun getUnLockData(lifecycleCoroutineScope: LifecycleCoroutineScope, adapter: DocumentAdapter, progressBar: ProgressBar) { fun getUnLockData(
lifecycleCoroutineScope: LifecycleCoroutineScope,
uiType: Int,
uiAction: (list: List<DocumentBean>) -> Unit
) {
lifecycleCoroutineScope.launch(Dispatchers.IO) { lifecycleCoroutineScope.launch(Dispatchers.IO) {
val documentList = getPdfData() val documentList = getPdfData()
documentList.forEach { documentList.forEach {
it.state = context.checkPdfEncryption(it.path) it.state = context.checkPdfEncryption(it.path)
it.uiType = 3 it.uiType = uiType
} }
val list = documentList.filter { it.state == 0 } val list = documentList.filter { it.state == 0 }
launch(Dispatchers.Main) { launch(Dispatchers.Main) {
adapter.submitList(list) uiAction.invoke(list)
progressBar.visibility = View.GONE
} }
} }
} }
fun getLockData(lifecycleCoroutineScope: LifecycleCoroutineScope, adapter: DocumentAdapter, progressBar: ProgressBar) { fun getLockData(
lifecycleCoroutineScope: LifecycleCoroutineScope,
uiType: Int,
uiAction: (list: List<DocumentBean>) -> Unit
) {
lifecycleCoroutineScope.launch(Dispatchers.IO) { lifecycleCoroutineScope.launch(Dispatchers.IO) {
val documentList = getPdfData() val documentList = getPdfData()
documentList.forEach { documentList.forEach {
it.state = context.checkPdfEncryption(it.path) it.state = context.checkPdfEncryption(it.path)
it.uiType = 3 it.uiType = uiType
} }
val list = documentList.filter { it.state == 1 } val list = documentList.filter { it.state == 1 }
launch(Dispatchers.Main) { launch(Dispatchers.Main) {
adapter.submitList(list) uiAction.invoke(list)
progressBar.visibility = View.GONE
} }
} }
} }
......
...@@ -93,7 +93,7 @@ class PdfActivity : BaseActivity<ActivityPdfBinding>(), PdfView { ...@@ -93,7 +93,7 @@ class PdfActivity : BaseActivity<ActivityPdfBinding>(), PdfView {
while (isActive) { while (isActive) {
binding.progressBar.progress += 2 binding.progressBar.progress += 2
delay(150) delay(150)
if (binding.progressBar.progress >= Random.nextInt(30, 40)) { if (binding.progressBar.progress >= Random.nextInt(25, 40)) {
binding.flLoading.visibility = View.GONE binding.flLoading.visibility = View.GONE
cancel() cancel()
} }
......
...@@ -57,6 +57,10 @@ class PdfLoadingActivity : BaseActivity<ActivityPdfLoadingBinding>() { ...@@ -57,6 +57,10 @@ class PdfLoadingActivity : BaseActivity<ActivityPdfLoadingBinding>() {
} }
override fun initView() { override fun initView() {
if (checkNeedRecreate(MyApplication.pdfLoadingLanguage)) {
return
}
pdfPresenter = PdfPresenter(this) pdfPresenter = PdfPresenter(this)
initSpPa() initSpPa()
pdfPresenter.password = pwd pdfPresenter.password = pwd
......
...@@ -61,6 +61,7 @@ class PdfMergeActivity : BaseActivity<ActivityPdfMergeBinding>() { ...@@ -61,6 +61,7 @@ class PdfMergeActivity : BaseActivity<ActivityPdfMergeBinding>() {
putExtra("doWhat", DO_MERGE_PDF) putExtra("doWhat", DO_MERGE_PDF)
putExtra("newPath", pdfPresenter.createNewPdfPath(name)) putExtra("newPath", pdfPresenter.createNewPdfPath(name))
}) })
finish()
}) })
} }
......
...@@ -4,6 +4,7 @@ import android.annotation.SuppressLint ...@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.content.Intent import android.content.Intent
import android.view.View import android.view.View
import androidx.activity.addCallback import androidx.activity.addCallback
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.base.pdfreader2.R import com.base.pdfreader2.R
import com.base.pdfreader2.ads.AdmobHelper import com.base.pdfreader2.ads.AdmobHelper
...@@ -12,6 +13,7 @@ import com.base.pdfreader2.bean.ConstObject.DO_LOCK_PDF ...@@ -12,6 +13,7 @@ import com.base.pdfreader2.bean.ConstObject.DO_LOCK_PDF
import com.base.pdfreader2.bean.ConstObject.DO_MERGE_PDF import com.base.pdfreader2.bean.ConstObject.DO_MERGE_PDF
import com.base.pdfreader2.bean.ConstObject.DO_SPLIT_PDF import com.base.pdfreader2.bean.ConstObject.DO_SPLIT_PDF
import com.base.pdfreader2.bean.ConstObject.DO_UNLOCK_PDF import com.base.pdfreader2.bean.ConstObject.DO_UNLOCK_PDF
import com.base.pdfreader2.bean.DocumentBean
import com.base.pdfreader2.databinding.ActivityPdfSelectBinding import com.base.pdfreader2.databinding.ActivityPdfSelectBinding
import com.base.pdfreader2.helper.BaseActivity import com.base.pdfreader2.helper.BaseActivity
import com.base.pdfreader2.helper.MyApplication import com.base.pdfreader2.helper.MyApplication
...@@ -40,8 +42,16 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>() { ...@@ -40,8 +42,16 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>() {
} }
} }
override fun initView() { override fun initView() {
if (checkNeedRecreate(MyApplication.pdfSelectLanguage)) {
return
}
doWhat = intent.extras?.getString("doWhat", "") ?: "" doWhat = intent.extras?.getString("doWhat", "") ?: ""
LogEx.logDebug(TAG, "doWhat=$doWhat")
documentPresenter = DocumentPresenter(this) documentPresenter = DocumentPresenter(this)
initAdapter() initAdapter()
...@@ -50,32 +60,52 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>() { ...@@ -50,32 +60,52 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>() {
DO_SPLIT_PDF -> { DO_SPLIT_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.getAllPdfDataRefresh(lifecycleScope, adapter,binding.progressBar) documentPresenter.getAllPdfDataRefresh(lifecycleScope, 2) {
refreshUI(it)
}
} }
DO_MERGE_PDF -> { DO_MERGE_PDF -> {
binding.tvSelectTip.text = getString(R.string.select_a_project) binding.tvSelectTip.text = getString(R.string.select_a_project)
documentPresenter.getAllPdfDataRefresh(lifecycleScope, adapter, binding.progressBar) documentPresenter.getAllPdfDataRefresh(lifecycleScope, 1) {
refreshUI(it)
}
} }
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.getUnLockData(lifecycleScope, adapter,binding.progressBar) documentPresenter.getUnLockData(lifecycleScope, 3) {
refreshUI(it)
}
} }
DO_UNLOCK_PDF -> { DO_UNLOCK_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.getLockData(lifecycleScope, adapter,binding.progressBar) documentPresenter.getLockData(lifecycleScope, 3) {
refreshUI(it)
}
} }
} }
} }
private fun refreshUI(list: List<DocumentBean>) {
adapter.submitList(list)
binding.llEmpty.isVisible = list.isEmpty()
binding.progressBar.visibility = View.GONE
}
override fun initListener() { override fun initListener() {
super.initListener() super.initListener()
if (checkNeedRecreate(MyApplication.pdfSelectLanguage)) {
return
}
onBackPressedDispatcher.addCallback { onBackPressedDispatcher.addCallback {
finishToMain() finishToMain()
} }
...@@ -121,9 +151,11 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>() { ...@@ -121,9 +151,11 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>() {
if (AdmobHelper.canCommonShowAd()) { if (AdmobHelper.canCommonShowAd()) {
AdmobInterstitialUtils.showInterstitialAd(this) { flag -> AdmobInterstitialUtils.showInterstitialAd(this) { flag ->
adapter.remove(it) adapter.remove(it)
binding.llEmpty.isVisible = adapter.items.isEmpty()
} }
} else { } else {
adapter.remove(it) adapter.remove(it)
binding.llEmpty.isVisible = adapter.items.isEmpty()
} }
}) })
} }
...@@ -132,9 +164,11 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>() { ...@@ -132,9 +164,11 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>() {
if (AdmobHelper.canCommonShowAd()) { if (AdmobHelper.canCommonShowAd()) {
AdmobInterstitialUtils.showInterstitialAd(this) { flag -> AdmobInterstitialUtils.showInterstitialAd(this) { flag ->
adapter.remove(it) adapter.remove(it)
binding.llEmpty.isVisible = adapter.items.isEmpty()
} }
} else { } else {
adapter.remove(it) adapter.remove(it)
binding.llEmpty.isVisible = adapter.items.isEmpty()
} }
}) })
} }
...@@ -154,5 +188,4 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>() { ...@@ -154,5 +188,4 @@ class PdfSelectActivity : BaseActivity<ActivityPdfSelectBinding>() {
} }
} }
\ No newline at end of file
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
android:id="@+id/cl_top" android:id="@+id/cl_top"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/white"> android:background="#DE202A">
<FrameLayout <FrameLayout
android:id="@+id/fl_fanhui" android:id="@+id/fl_fanhui"
......
...@@ -96,7 +96,8 @@ ...@@ -96,7 +96,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:src="@mipmap/h_sousuo" android:backgroundTint="@color/black"
android:src="@mipmap/sousuo_b"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/iv_more" app:layout_constraintEnd_toStartOf="@id/iv_more"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
......
...@@ -68,6 +68,35 @@ ...@@ -68,6 +68,35 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" /> android:layout_gravity="center" />
<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> </FrameLayout>
<TextView <TextView
......
...@@ -153,6 +153,7 @@ ...@@ -153,6 +153,7 @@
</LinearLayout> </LinearLayout>
<View <View
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="1px" android:layout_height="1px"
......
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