🚀 Improve Chapter naming
* Improved chapter naming by taking the first line of the chapter when no TOC(Table of Contents) found
This commit is contained in:
parent
5cda9bbbe6
commit
13278298db
2 changed files with 12 additions and 2 deletions
|
|
@ -13,6 +13,7 @@ import ua.acclorite.book_story.domain.model.Chapter
|
|||
import ua.acclorite.book_story.domain.model.ChapterWithText
|
||||
import ua.acclorite.book_story.domain.util.Resource
|
||||
import ua.acclorite.book_story.domain.util.UIText
|
||||
import ua.acclorite.book_story.presentation.core.util.clearMarkdown
|
||||
import java.io.File
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipFile
|
||||
|
|
@ -107,7 +108,12 @@ class EpubTextParser @Inject constructor(
|
|||
it.readText()
|
||||
}
|
||||
|
||||
val chapter = documentParser.run { Jsoup.parse(content).parseDocument() }
|
||||
val chapter =
|
||||
documentParser.run { Jsoup.parse(content).parseDocument() }.toMutableList()
|
||||
val chapterTitle = chapter.firstOrNull()?.clearMarkdown()
|
||||
?: "Chapter $chapterIndex" // In case could not get first line(shouldn't happen)
|
||||
chapter.removeFirstOrNull()
|
||||
|
||||
if (chapter.isEmpty()) {
|
||||
Log.w(EPUB_TAG, "Chapter ${entry.name} is empty.")
|
||||
return@forEach
|
||||
|
|
@ -117,7 +123,7 @@ class EpubTextParser @Inject constructor(
|
|||
ChapterWithText(
|
||||
chapter = Chapter(
|
||||
index = chapters.size,
|
||||
title = "Chapter $chapterIndex", // Generic name, but at least something
|
||||
title = chapterTitle,
|
||||
startIndex = chapterTextIndex + 1,
|
||||
endIndex = chapterTextIndex + chapter.size
|
||||
),
|
||||
|
|
|
|||
|
|
@ -61,4 +61,8 @@ fun Modifier.noRippleClickable(
|
|||
onDoubleClick = onDoubleClick,
|
||||
onClick = onClick
|
||||
)
|
||||
}
|
||||
|
||||
fun String.clearMarkdown(): String {
|
||||
return replace(Regex("_|\\*\\*"), "").trim()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue