修复bug

This commit is contained in:
ocean 2025-12-15 10:11:43 +08:00
parent 82f37cc4c8
commit 5bd33845e1
5 changed files with 18 additions and 9 deletions

View File

@ -42,8 +42,8 @@
# 保留所有 Parcelable # 保留所有 Parcelable
-keep class * implements android.os.Parcelable { *; } -keep class * implements android.os.Parcelable { *; }
-keep @kotlinx.parcelize.Parcelize class *
# 保留所有 Parcelable CREATOR 字段
-keepclassmembers class * implements android.os.Parcelable { -keepclassmembers class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *; public static final android.os.Parcelable$Creator *;
} }

View File

@ -39,6 +39,7 @@ class MergePdfActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
intent.extras?.classLoader = PdfDocumentEntity::class.java.classLoader
binding = ActivityPdfMergeBinding.inflate(layoutInflater) binding = ActivityPdfMergeBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
AnalyticsUtils.logEvent(AnalyticsUtils.Event.MERGE_SHOW) AnalyticsUtils.logEvent(AnalyticsUtils.Event.MERGE_SHOW)
@ -210,6 +211,7 @@ class MergePdfActivity : BaseActivity() {
*/ */
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
private inline fun <reified T : Parcelable> requireParcelableArrayList(key: String): ArrayList<T> { private inline fun <reified T : Parcelable> requireParcelableArrayList(key: String): ArrayList<T> {
intent.extras?.classLoader = T::class.java.classLoader
val result: ArrayList<T>? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { val result: ArrayList<T>? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent.getParcelableArrayListExtra(key, T::class.java) intent.getParcelableArrayListExtra(key, T::class.java)
} else { } else {

View File

@ -42,6 +42,7 @@ class PdfPickerActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
intent.extras?.classLoader = PdfDocumentEntity::class.java.classLoader
binding = ActivityPdfPickerBinding.inflate(layoutInflater) binding = ActivityPdfPickerBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
source = getSerializableOrDefault(EXTRA_SOURCE, PdfPickerSource.NONE) source = getSerializableOrDefault(EXTRA_SOURCE, PdfPickerSource.NONE)
@ -334,6 +335,7 @@ class PdfPickerActivity : BaseActivity() {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
private inline fun <reified T : Parcelable> requireParcelableArrayList(key: String): ArrayList<T> { private inline fun <reified T : Parcelable> requireParcelableArrayList(key: String): ArrayList<T> {
intent.extras?.classLoader = T::class.java.classLoader
val result: ArrayList<T>? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { val result: ArrayList<T>? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent.getParcelableArrayListExtra(key, T::class.java) intent.getParcelableArrayListExtra(key, T::class.java)
} else { } else {

View File

@ -557,12 +557,16 @@ class PdfResultActivity : BaseActivity() {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
private inline fun <reified T : Parcelable> requireParcelableArrayList(key: String): ArrayList<T> { private inline fun <reified T : Parcelable> requireParcelableArrayList(key: String): ArrayList<T> {
val result: ArrayList<T>? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { intent.extras?.classLoader = T::class.java.classLoader
return try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent.getParcelableArrayListExtra(key, T::class.java) intent.getParcelableArrayListExtra(key, T::class.java)
} else { } else {
intent.getParcelableArrayListExtra(key) intent.getParcelableArrayListExtra(key)
} ?: arrayListOf()
} catch (e: Throwable) {
arrayListOf()
} }
return result ?: arrayListOf()
} }
private fun requireStringArrayList(key: String): ArrayList<String> { private fun requireStringArrayList(key: String): ArrayList<String> {

View File

@ -2,6 +2,7 @@ package com.all.pdfreader.pdf.reader.util
import android.util.Log import android.util.Log
import com.github.barteksc.pdfviewer.PDFView import com.github.barteksc.pdfviewer.PDFView
import com.tom_roush.pdfbox.io.MemoryUsageSetting
import com.tom_roush.pdfbox.pdmodel.PDDocument import com.tom_roush.pdfbox.pdmodel.PDDocument
import com.tom_roush.pdfbox.pdmodel.PDPage import com.tom_roush.pdfbox.pdmodel.PDPage
import com.tom_roush.pdfbox.text.PDFTextStripper import com.tom_roush.pdfbox.text.PDFTextStripper
@ -76,9 +77,9 @@ class PDFSearchManager(private val pdfView: PDFView) {
// 如果是新的文件,则关闭旧文档 // 如果是新的文件,则关闭旧文档
cachedDoc?.close() cachedDoc?.close()
cachedDoc = if (!password.isNullOrEmpty()) { cachedDoc = if (!password.isNullOrEmpty()) {
PDDocument.load(file, password) PDDocument.load(file, password, MemoryUsageSetting.setupTempFileOnly())
} else { } else {
PDDocument.load(file) PDDocument.load(file, MemoryUsageSetting.setupTempFileOnly())
} }
cachedPath = file.absolutePath cachedPath = file.absolutePath