|
|
@ -137,14 +137,20 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
private fun download(book: Book, chapter: BookChapter) { |
|
|
|
private fun download(book: Book, chapter: BookChapter) { |
|
|
|
webBook?.getContent(book, chapter, scope = this) |
|
|
|
webBook?.getContent(book, chapter, scope = this) |
|
|
|
?.onSuccess(IO) { content -> |
|
|
|
?.onSuccess(IO) { content -> |
|
|
|
content?.let { |
|
|
|
if (content.isNullOrEmpty()) { |
|
|
|
BookHelp.saveContent(book, chapter, it) |
|
|
|
callBack?.contentLoadFinish(chapter, context.getString(R.string.content_empty)) |
|
|
|
callBack?.contentLoadFinish(chapter, it) |
|
|
|
synchronized(loadingLock) { |
|
|
|
|
|
|
|
loadingChapters.remove(chapter.index) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
BookHelp.saveContent(book, chapter, content) |
|
|
|
|
|
|
|
callBack?.contentLoadFinish(chapter, content) |
|
|
|
synchronized(loadingLock) { |
|
|
|
synchronized(loadingLock) { |
|
|
|
loadingChapters.remove(chapter.index) |
|
|
|
loadingChapters.remove(chapter.index) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}?.onError { |
|
|
|
}?.onError { |
|
|
|
|
|
|
|
callBack?.contentLoadFinish(chapter, it.localizedMessage) |
|
|
|
synchronized(loadingLock) { |
|
|
|
synchronized(loadingLock) { |
|
|
|
loadingChapters.remove(chapter.index) |
|
|
|
loadingChapters.remove(chapter.index) |
|
|
|
} |
|
|
|
} |
|
|
|