|
|
|
@ -77,31 +77,6 @@ object BookHelp { |
|
|
|
|
postEvent(EventBus.SAVE_CONTENT, bookChapter) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Suppress("unused") |
|
|
|
|
fun saveFont(book: Book, bookChapter: BookChapter, font: ByteArray) { |
|
|
|
|
FileUtils.createFileIfNotExist( |
|
|
|
|
downloadDir, |
|
|
|
|
cacheFolderName, |
|
|
|
|
book.getFolderName(), |
|
|
|
|
"font", |
|
|
|
|
bookChapter.getFontName() |
|
|
|
|
).writeBytes(font) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun getFontPath(book: Book, bookChapter: BookChapter): String? { |
|
|
|
|
val fontFile = FileUtils.getFile( |
|
|
|
|
downloadDir, |
|
|
|
|
cacheFolderName, |
|
|
|
|
book.getFolderName(), |
|
|
|
|
"font", |
|
|
|
|
bookChapter.getFontName() |
|
|
|
|
) |
|
|
|
|
if (fontFile.exists()) { |
|
|
|
|
return fontFile.absolutePath |
|
|
|
|
} |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
suspend fun saveImage(book: Book, src: String) { |
|
|
|
|
while (downloadImages.contains(src)) { |
|
|
|
|
delay(100) |
|
|
|
@ -174,6 +149,24 @@ object BookHelp { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun hasImageContent(book: Book, bookChapter: BookChapter): Boolean { |
|
|
|
|
if (!hasContent(book, bookChapter)) { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
getContent(book, bookChapter)?.let { |
|
|
|
|
val matcher = AppPattern.imgPattern.matcher(it) |
|
|
|
|
while (matcher.find()) { |
|
|
|
|
matcher.group(1)?.let { src -> |
|
|
|
|
val image = getImage(book, src) |
|
|
|
|
if (!image.exists()) { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun getContent(book: Book, bookChapter: BookChapter): String? { |
|
|
|
|
if (book.isLocalTxt()) { |
|
|
|
|
return LocalBook.getContext(book, bookChapter) |
|
|
|
|