🚀 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.model.ChapterWithText
|
||||||
import ua.acclorite.book_story.domain.util.Resource
|
import ua.acclorite.book_story.domain.util.Resource
|
||||||
import ua.acclorite.book_story.domain.util.UIText
|
import ua.acclorite.book_story.domain.util.UIText
|
||||||
|
import ua.acclorite.book_story.presentation.core.util.clearMarkdown
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
|
|
@ -107,7 +108,12 @@ class EpubTextParser @Inject constructor(
|
||||||
it.readText()
|
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()) {
|
if (chapter.isEmpty()) {
|
||||||
Log.w(EPUB_TAG, "Chapter ${entry.name} is empty.")
|
Log.w(EPUB_TAG, "Chapter ${entry.name} is empty.")
|
||||||
return@forEach
|
return@forEach
|
||||||
|
|
@ -117,7 +123,7 @@ class EpubTextParser @Inject constructor(
|
||||||
ChapterWithText(
|
ChapterWithText(
|
||||||
chapter = Chapter(
|
chapter = Chapter(
|
||||||
index = chapters.size,
|
index = chapters.size,
|
||||||
title = "Chapter $chapterIndex", // Generic name, but at least something
|
title = chapterTitle,
|
||||||
startIndex = chapterTextIndex + 1,
|
startIndex = chapterTextIndex + 1,
|
||||||
endIndex = chapterTextIndex + chapter.size
|
endIndex = chapterTextIndex + chapter.size
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -61,4 +61,8 @@ fun Modifier.noRippleClickable(
|
||||||
onDoubleClick = onDoubleClick,
|
onDoubleClick = onDoubleClick,
|
||||||
onClick = onClick
|
onClick = onClick
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun String.clearMarkdown(): String {
|
||||||
|
return replace(Regex("_|\\*\\*"), "").trim()
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue