|
|
@ -34,13 +34,12 @@ object BookHelp { |
|
|
|
|
|
|
|
|
|
|
|
fun clearCache() { |
|
|
|
fun clearCache() { |
|
|
|
FileUtils.deleteFile( |
|
|
|
FileUtils.deleteFile( |
|
|
|
FileUtils.getPath(root = downloadDir, subDirs = arrayOf(cacheFolderName)) |
|
|
|
FileUtils.getPath(downloadDir, cacheFolderName) |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun clearCache(book: Book) { |
|
|
|
fun clearCache(book: Book) { |
|
|
|
val filePath = FileUtils.getPath(root = downloadDir, |
|
|
|
val filePath = FileUtils.getPath(downloadDir, cacheFolderName, book.getFolderName()) |
|
|
|
subDirs = arrayOf(cacheFolderName, book.getFolderName())) |
|
|
|
|
|
|
|
FileUtils.deleteFile(filePath) |
|
|
|
FileUtils.deleteFile(filePath) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -67,8 +66,9 @@ object BookHelp { |
|
|
|
//保存文本 |
|
|
|
//保存文本 |
|
|
|
FileUtils.createFileIfNotExist( |
|
|
|
FileUtils.createFileIfNotExist( |
|
|
|
downloadDir, |
|
|
|
downloadDir, |
|
|
|
|
|
|
|
cacheFolderName, |
|
|
|
|
|
|
|
book.getFolderName(), |
|
|
|
formatChapterName(bookChapter), |
|
|
|
formatChapterName(bookChapter), |
|
|
|
subDirs = arrayOf(cacheFolderName, book.getFolderName()) |
|
|
|
|
|
|
|
).writeText(content) |
|
|
|
).writeText(content) |
|
|
|
//保存图片 |
|
|
|
//保存图片 |
|
|
|
content.split("\n").forEach { |
|
|
|
content.split("\n").forEach { |
|
|
@ -78,19 +78,21 @@ object BookHelp { |
|
|
|
src = NetworkUtils.getAbsoluteURL(bookChapter.url, src) |
|
|
|
src = NetworkUtils.getAbsoluteURL(bookChapter.url, src) |
|
|
|
src?.let { |
|
|
|
src?.let { |
|
|
|
saveImage(book, src) |
|
|
|
saveImage(book, src) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
postEvent(EventBus.SAVE_CONTENT, bookChapter) |
|
|
|
postEvent(EventBus.SAVE_CONTENT, bookChapter) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun saveImage(book: Book, src:String) { |
|
|
|
fun saveImage(book: Book, src: String) { |
|
|
|
val analyzeUrl = AnalyzeUrl(src) |
|
|
|
val analyzeUrl = AnalyzeUrl(src) |
|
|
|
analyzeUrl.getImageBytes(book.origin)?.let { |
|
|
|
analyzeUrl.getImageBytes(book.origin)?.let { |
|
|
|
FileUtils.createFileIfNotExist( |
|
|
|
FileUtils.createFileIfNotExist( |
|
|
|
downloadDir, |
|
|
|
downloadDir, |
|
|
|
"${MD5Utils.md5Encode16(src)}${getImageSuffix(src)}", |
|
|
|
cacheFolderName, |
|
|
|
subDirs = arrayOf(cacheFolderName, book.getFolderName(), cacheImageFolderName) |
|
|
|
book.getFolderName(), |
|
|
|
|
|
|
|
cacheImageFolderName, |
|
|
|
|
|
|
|
"${MD5Utils.md5Encode16(src)}${getImageSuffix(src)}" |
|
|
|
).writeBytes(it) |
|
|
|
).writeBytes(it) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -98,8 +100,10 @@ object BookHelp { |
|
|
|
fun getImage(book: Book, src: String): File { |
|
|
|
fun getImage(book: Book, src: String): File { |
|
|
|
return FileUtils.getFile( |
|
|
|
return FileUtils.getFile( |
|
|
|
downloadDir, |
|
|
|
downloadDir, |
|
|
|
"${MD5Utils.md5Encode16(src)}${getImageSuffix(src)}", |
|
|
|
cacheFolderName, |
|
|
|
subDirs = arrayOf(cacheFolderName, book.getFolderName(), cacheImageFolderName) |
|
|
|
book.getFolderName(), |
|
|
|
|
|
|
|
cacheImageFolderName, |
|
|
|
|
|
|
|
"${MD5Utils.md5Encode16(src)}${getImageSuffix(src)}" |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -131,8 +135,9 @@ object BookHelp { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
FileUtils.exists( |
|
|
|
FileUtils.exists( |
|
|
|
downloadDir, |
|
|
|
downloadDir, |
|
|
|
formatChapterName(bookChapter), |
|
|
|
cacheFolderName, |
|
|
|
subDirs = arrayOf(cacheFolderName, book.getFolderName()) |
|
|
|
book.getFolderName(), |
|
|
|
|
|
|
|
formatChapterName(bookChapter) |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -143,8 +148,9 @@ object BookHelp { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val file = FileUtils.getFile( |
|
|
|
val file = FileUtils.getFile( |
|
|
|
downloadDir, |
|
|
|
downloadDir, |
|
|
|
formatChapterName(bookChapter), |
|
|
|
cacheFolderName, |
|
|
|
subDirs = arrayOf(cacheFolderName, book.getFolderName()) |
|
|
|
book.getFolderName(), |
|
|
|
|
|
|
|
formatChapterName(bookChapter) |
|
|
|
) |
|
|
|
) |
|
|
|
if (file.exists()) { |
|
|
|
if (file.exists()) { |
|
|
|
return file.readText() |
|
|
|
return file.readText() |
|
|
@ -159,8 +165,9 @@ object BookHelp { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
FileUtils.createFileIfNotExist( |
|
|
|
FileUtils.createFileIfNotExist( |
|
|
|
downloadDir, |
|
|
|
downloadDir, |
|
|
|
formatChapterName(bookChapter), |
|
|
|
cacheFolderName, |
|
|
|
subDirs = arrayOf(cacheFolderName, book.getFolderName()) |
|
|
|
book.getFolderName(), |
|
|
|
|
|
|
|
formatChapterName(bookChapter) |
|
|
|
).delete() |
|
|
|
).delete() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -183,7 +190,7 @@ object BookHelp { |
|
|
|
fun getDurChapterIndexByChapterTitle( |
|
|
|
fun getDurChapterIndexByChapterTitle( |
|
|
|
title: String?, |
|
|
|
title: String?, |
|
|
|
index: Int, |
|
|
|
index: Int, |
|
|
|
chapters: List<BookChapter> |
|
|
|
chapters: List<BookChapter>, |
|
|
|
): Int { |
|
|
|
): Int { |
|
|
|
if (title.isNullOrEmpty()) { |
|
|
|
if (title.isNullOrEmpty()) { |
|
|
|
return min(index, chapters.lastIndex) |
|
|
|
return min(index, chapters.lastIndex) |
|
|
@ -253,7 +260,7 @@ object BookHelp { |
|
|
|
name: String, |
|
|
|
name: String, |
|
|
|
origin: String?, |
|
|
|
origin: String?, |
|
|
|
content: String, |
|
|
|
content: String, |
|
|
|
enableReplace: Boolean |
|
|
|
enableReplace: Boolean, |
|
|
|
): List<String> { |
|
|
|
): List<String> { |
|
|
|
var c = content |
|
|
|
var c = content |
|
|
|
if (enableReplace) { |
|
|
|
if (enableReplace) { |
|
|
|