Explorar el Código

本地书籍统计每章字数 (#4417)

* 共存版命名优化

* 本地书籍添加章节字数统计

* 本地书籍添加本书总字数统计
niuhb hace 1 año
padre
commit
5d409a8d06

+ 7 - 5
app/build.gradle

@@ -78,6 +78,11 @@ android {
                 signingConfig signingConfigs.myConfig
                 signingConfig signingConfigs.myConfig
             }
             }
             applicationIdSuffix '.release'
             applicationIdSuffix '.release'
+            if (getApplicationIdSuffix() == '.releaseA') {
+                manifestPlaceholders.put("app_name", "@string/app_name_a")
+            }else {
+                manifestPlaceholders.put("app_name", "@string/app_name")
+            }
 
 
             minifyEnabled true
             minifyEnabled true
             shrinkResources true
             shrinkResources true
@@ -87,6 +92,8 @@ android {
             if (project.hasProperty("RELEASE_STORE_FILE")) {
             if (project.hasProperty("RELEASE_STORE_FILE")) {
                 signingConfig signingConfigs.myConfig
                 signingConfig signingConfigs.myConfig
             }
             }
+            manifestPlaceholders.put("app_name", "@string/app_name")
+
             applicationIdSuffix '.debug'
             applicationIdSuffix '.debug'
             versionNameSuffix 'debug'
             versionNameSuffix 'debug'
             minifyEnabled false
             minifyEnabled false
@@ -99,11 +106,6 @@ android {
         app {
         app {
             dimension "mode"
             dimension "mode"
             manifestPlaceholders.put("APP_CHANNEL_VALUE", "app")
             manifestPlaceholders.put("APP_CHANNEL_VALUE", "app")
-            if ('.release' == '.releaseA') {
-                manifestPlaceholders.put("app_name", "@string/app_name_a")
-            }else {
-                manifestPlaceholders.put("app_name", "@string/app_name")
-            }
         }
         }
     }
     }
 
 

+ 6 - 1
app/src/main/java/io/legado/app/model/localBook/LocalBook.kt

@@ -109,9 +109,14 @@ object LocalBook {
             throw TocEmptyException(appCtx.getString(R.string.chapter_list_empty))
             throw TocEmptyException(appCtx.getString(R.string.chapter_list_empty))
         }
         }
         val list = ArrayList(LinkedHashSet(chapters))
         val list = ArrayList(LinkedHashSet(chapters))
-        list.forEachIndexed { index, bookChapter -> bookChapter.index = index }
+        var wordCount = 0
+        list.forEachIndexed { index, bookChapter ->
+            bookChapter.index = index
+            wordCount += bookChapter.tag?.toInt() ?: 0
+        }
         book.latestChapterTitle = list.last().title
         book.latestChapterTitle = list.last().title
         book.totalChapterNum = list.size
         book.totalChapterNum = list.size
+        book.wordCount = wordCount.toString() + "字"
         book.save()
         book.save()
         return list
         return list
     }
     }

+ 8 - 2
app/src/main/java/io/legado/app/model/localBook/TextFile.kt

@@ -222,6 +222,7 @@ class TextFile(private var book: Book) {
                                 qyChapter.title = "前言"
                                 qyChapter.title = "前言"
                                 qyChapter.start = curOffset
                                 qyChapter.start = curOffset
                                 qyChapter.end = curOffset + chapterLength
                                 qyChapter.end = curOffset + chapterLength
+                                qyChapter.tag = chapterContent.length.toString()
                                 toc.add(qyChapter)
                                 toc.add(qyChapter)
                                 book.intro = if (chapterContent.length <= 500) {
                                 book.intro = if (chapterContent.length <= 500) {
                                     chapterContent
                                     chapterContent
@@ -241,6 +242,7 @@ class TextFile(private var book: Book) {
                                 chapterContent.substringAfter(lastChapter.title).isBlank()
                                 chapterContent.substringAfter(lastChapter.title).isBlank()
                             //将当前段落添加上一章去
                             //将当前段落添加上一章去
                             lastChapter.end = lastChapter.end!! + chapterLength
                             lastChapter.end = lastChapter.end!! + chapterLength
+                            lastChapter.tag = ((lastChapter.tag?.toInt() ?: 0) + chapterContent.length).toString()
                             //创建当前章节
                             //创建当前章节
                             val curChapter = BookChapter()
                             val curChapter = BookChapter()
                             curChapter.title = matcher.group()
                             curChapter.title = matcher.group()
@@ -255,6 +257,7 @@ class TextFile(private var book: Book) {
                                 chapterContent.substringAfter(lastChapter.title).isBlank()
                                 chapterContent.substringAfter(lastChapter.title).isBlank()
                             lastChapter.end =
                             lastChapter.end =
                                 lastChapter.start!! + chapterLength
                                 lastChapter.start!! + chapterLength
+                            lastChapter.tag = chapterContent.length.toString()
                             //创建当前章节
                             //创建当前章节
                             val curChapter = BookChapter()
                             val curChapter = BookChapter()
                             curChapter.title = matcher.group()
                             curChapter.title = matcher.group()
@@ -265,6 +268,7 @@ class TextFile(private var book: Book) {
                             curChapter.title = matcher.group()
                             curChapter.title = matcher.group()
                             curChapter.start = curOffset
                             curChapter.start = curOffset
                             curChapter.end = curOffset
                             curChapter.end = curOffset
+                            curChapter.tag = chapterContent.length.toString()
                             toc.add(curChapter)
                             toc.add(curChapter)
                         }
                         }
                     }
                     }
@@ -274,8 +278,10 @@ class TextFile(private var book: Book) {
                 //block的偏移点
                 //block的偏移点
                 curOffset += length.toLong()
                 curOffset += length.toLong()
                 //设置上一章的结尾
                 //设置上一章的结尾
-                toc.lastOrNull()?.end = curOffset
-
+                toc.lastOrNull()?.let {
+                    it.end = curOffset
+                    it.tag = blockContent.substring(seekPos).length.toString()
+                }
             }
             }
             toc.lastOrNull()?.let { chapter ->
             toc.lastOrNull()?.let { chapter ->
                 //章节字数太多进行拆分
                 //章节字数太多进行拆分