Horis il y a 1 an
Parent
commit
4b57f89a87

+ 3 - 0
app/proguard-rules.pro

@@ -100,6 +100,9 @@ cn.hutool.core.util.**{*;}
     *** mNavButtonView;
 }
 
+# FileDocExtensions.kt TreeDocumentFileConstructor
+-keep class androidx.documentfile.provider.TreeDocumentFile
+
 # JsoupXpath
 -keep,allowobfuscation class * implements org.seimicrawler.xpath.core.AxisSelector{*;}
 -keep,allowobfuscation class * implements org.seimicrawler.xpath.core.NodeTest{*;}

+ 1 - 15
app/src/main/java/io/legado/app/data/entities/Book.kt

@@ -17,15 +17,12 @@ import io.legado.app.help.book.ContentProcessor
 import io.legado.app.help.book.getFolderNameNoCache
 import io.legado.app.help.book.isEpub
 import io.legado.app.help.book.isImage
-import io.legado.app.help.book.isLocal
 import io.legado.app.help.book.simulatedTotalChapterNum
 import io.legado.app.help.config.AppConfig
 import io.legado.app.help.config.ReadBookConfig
 import io.legado.app.model.ReadBook
-import io.legado.app.utils.ConvertUtils
-import io.legado.app.utils.fromJsonObject
-import io.legado.app.utils.FileUtils
 import io.legado.app.utils.GSON
+import io.legado.app.utils.fromJsonObject
 import kotlinx.parcelize.IgnoredOnParcel
 import kotlinx.parcelize.Parcelize
 import java.nio.charset.Charset
@@ -169,17 +166,6 @@ data class Book(
 
     fun getDisplayIntro() = if (customIntro.isNullOrEmpty()) intro else customIntro
 
-    override fun getKindList(): List<String> {
-        val kindList = super.getKindList().toMutableList()
-        if (isLocal) {
-            // local book add filesize tag
-            val size = FileUtils.getLength(bookUrl)
-            if (size > 0) {
-                kindList.add(ConvertUtils.formatFileSize(size))
-            }
-        }
-        return kindList
-    }
     //自定义简介有自动更新的需求时,可通过更新intro再调用upCustomIntro()完成
     @Suppress("unused")
     fun upCustomIntro() {

+ 3 - 1
app/src/main/java/io/legado/app/help/JsExtensions.kt

@@ -862,6 +862,7 @@ interface JsExtensions : JsEncodeUtils {
     ): String {
         if (errorQueryTTF == null || correctQueryTTF == null) return text
         val contentArray = text.toStringArray() //这里不能用toCharArray,因为有些文字占多个字节
+        val intArray = IntArray(1)
         contentArray.forEachIndexed { index, s ->
             val oldCode = s.codePointAt(0)
             // 忽略正常的空白字符
@@ -878,7 +879,8 @@ interface JsExtensions : JsEncodeUtils {
             // 使用轮廓数据反查Unicode
             val code = correctQueryTTF.getUnicodeByGlyf(glyf)
             if (code != 0) {
-                contentArray[index] = code.toChar().toString()
+                intArray[0] = code
+                contentArray[index] = String(intArray, 0, 1)
             }
         }
         return contentArray.joinToString("")

+ 24 - 7
app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt

@@ -60,6 +60,8 @@ import io.legado.app.ui.widget.dialog.PhotoDialog
 import io.legado.app.ui.widget.dialog.VariableDialog
 import io.legado.app.ui.widget.dialog.WaitDialog
 import io.legado.app.utils.ColorUtils
+import io.legado.app.utils.ConvertUtils
+import io.legado.app.utils.FileDoc
 import io.legado.app.utils.GSON
 import io.legado.app.utils.StartActivityContract
 import io.legado.app.utils.applyNavigationBarPadding
@@ -339,16 +341,31 @@ class BookInfoActivity :
         tvIntro.text = book.getDisplayIntro()
         llToc?.visible(!book.isWebFile)
         upTvBookshelf()
-        val kinds = book.getKindList()
-        if (kinds.isEmpty()) {
-            lbKind.gone()
-        } else {
-            lbKind.visible()
-            lbKind.setLabels(kinds)
-        }
+        upKinds(book)
         upGroup(book.group)
     }
 
+    private fun upKinds(book: Book) = binding.run {
+        lifecycleScope.launch {
+            var kinds = book.getKindList()
+            if (book.isLocal) {
+                withContext(IO) {
+                    val size = FileDoc.fromFile(book.bookUrl).size
+                    if (size > 0) {
+                        kinds = kinds.toMutableList()
+                        kinds.add(ConvertUtils.formatFileSize(size))
+                    }
+                }
+            }
+            if (kinds.isEmpty()) {
+                lbKind.gone()
+            } else {
+                lbKind.visible()
+                lbKind.setLabels(kinds)
+            }
+        }
+    }
+
     private fun showCover(book: Book) {
         binding.ivCover.load(book.getDisplayCover(), book.name, book.author, false, book.origin) {
             if (!AppConfig.isEInkMode) {

+ 16 - 8
app/src/main/java/io/legado/app/utils/FileDocExtensions.kt

@@ -45,14 +45,7 @@ data class FileDoc(
     fun asDocumentFile(): DocumentFile? {
         if (isContentScheme) {
             return if (isDir) {
-                Class.forName("androidx.documentfile.provider.TreeDocumentFile")
-                    .getDeclaredConstructor(
-                        DocumentFile::class.java,
-                        Context::class.java,
-                        Uri::class.java
-                    ).apply {
-                        isAccessible = true
-                    }.newInstance(null, appCtx, uri) as DocumentFile
+                TreeDocumentFileConstructor.newInstance(null, appCtx, uri) as DocumentFile
             } else {
                 DocumentFile.fromSingleUri(appCtx, uri)
             }
@@ -69,10 +62,25 @@ data class FileDoc(
 
     companion object {
 
+        private val TreeDocumentFileConstructor by lazy {
+            Class.forName("androidx.documentfile.provider.TreeDocumentFile")
+                .getDeclaredConstructor(
+                    DocumentFile::class.java,
+                    Context::class.java,
+                    Uri::class.java
+                ).apply {
+                    isAccessible = true
+                }
+        }
+
         fun fromDir(path: String): FileDoc {
             return fromUri(path.toUri(), true)
         }
 
+        fun fromFile(path: String): FileDoc {
+            return fromUri(path.toUri(), false)
+        }
+
         fun fromUri(uri: Uri, isDir: Boolean): FileDoc {
             if (uri.isContentScheme()) {
                 val doc = if (isDir) {