|
|
|
@ -7,6 +7,7 @@ import io.legado.app.constant.BookType |
|
|
|
|
import io.legado.app.constant.Bus |
|
|
|
|
import io.legado.app.help.storage.Restore |
|
|
|
|
import io.legado.app.model.WebBook |
|
|
|
|
import io.legado.app.utils.LogUtils |
|
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
|
import kotlinx.coroutines.delay |
|
|
|
@ -25,9 +26,11 @@ class MainViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
execute { |
|
|
|
|
App.db.bookDao().allBooks.forEach { book -> |
|
|
|
|
if (book.origin != BookType.local) { |
|
|
|
|
if (!updateList.contains(book.bookUrl)) { |
|
|
|
|
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> |
|
|
|
|
synchronized(this) { |
|
|
|
|
updateList.add(book.bookUrl) |
|
|
|
|
LogUtils.d("updateAdd", book.name) |
|
|
|
|
postEvent(Bus.UP_BOOK, book.bookUrl) |
|
|
|
|
} |
|
|
|
|
WebBook(bookSource).getChapterList(book) |
|
|
|
@ -41,11 +44,13 @@ class MainViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
.onFinally { |
|
|
|
|
synchronized(this) { |
|
|
|
|
updateList.remove(book.bookUrl) |
|
|
|
|
LogUtils.d("updateRemove", book.name) |
|
|
|
|
postEvent(Bus.UP_BOOK, book.bookUrl) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
delay(50) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|