|
|
@ -3,7 +3,6 @@ package io.legado.app.ui.main |
|
|
|
import android.app.Application |
|
|
|
import android.app.Application |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.constant.BookType |
|
|
|
|
|
|
|
import io.legado.app.constant.Bus |
|
|
|
import io.legado.app.constant.Bus |
|
|
|
import io.legado.app.model.WebBook |
|
|
|
import io.legado.app.model.WebBook |
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
import io.legado.app.utils.postEvent |
|
|
@ -16,34 +15,32 @@ class MainViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
fun upChapterList() { |
|
|
|
fun upChapterList() { |
|
|
|
execute { |
|
|
|
execute { |
|
|
|
App.db.bookDao().hasUpdateBooks.forEach { book -> |
|
|
|
App.db.bookDao().hasUpdateBooks.forEach { book -> |
|
|
|
if (book.origin != BookType.local) { |
|
|
|
if (!updateList.contains(book.bookUrl)) { |
|
|
|
if (!updateList.contains(book.bookUrl)) { |
|
|
|
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> |
|
|
|
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> |
|
|
|
synchronized(this) { |
|
|
|
synchronized(this) { |
|
|
|
updateList.add(book.bookUrl) |
|
|
|
updateList.add(book.bookUrl) |
|
|
|
postEvent(Bus.UP_BOOK, book.bookUrl) |
|
|
|
postEvent(Bus.UP_BOOK, book.bookUrl) |
|
|
|
} |
|
|
|
} |
|
|
|
WebBook(bookSource).getChapterList(book) |
|
|
|
WebBook(bookSource).getChapterList(book) |
|
|
|
.timeout(300000) |
|
|
|
.timeout(300000) |
|
|
|
.onSuccess(IO) { |
|
|
|
.onSuccess(IO) { |
|
|
|
synchronized(this) { |
|
|
|
synchronized(this) { |
|
|
|
updateList.remove(book.bookUrl) |
|
|
|
updateList.remove(book.bookUrl) |
|
|
|
postEvent(Bus.UP_BOOK, book.bookUrl) |
|
|
|
postEvent(Bus.UP_BOOK, book.bookUrl) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
it?.let { |
|
|
|
|
|
|
|
App.db.bookDao().update(book) |
|
|
|
|
|
|
|
App.db.bookChapterDao().delByBook(book.bookUrl) |
|
|
|
|
|
|
|
App.db.bookChapterDao().insert(*it.toTypedArray()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
.onError { |
|
|
|
it?.let { |
|
|
|
synchronized(this) { |
|
|
|
App.db.bookDao().update(book) |
|
|
|
updateList.remove(book.bookUrl) |
|
|
|
App.db.bookChapterDao().delByBook(book.bookUrl) |
|
|
|
postEvent(Bus.UP_BOOK, book.bookUrl) |
|
|
|
App.db.bookChapterDao().insert(*it.toTypedArray()) |
|
|
|
} |
|
|
|
|
|
|
|
it.printStackTrace() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
.onError { |
|
|
|
|
|
|
|
synchronized(this) { |
|
|
|
|
|
|
|
updateList.remove(book.bookUrl) |
|
|
|
|
|
|
|
postEvent(Bus.UP_BOOK, book.bookUrl) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
it.printStackTrace() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
delay(50) |
|
|
|
delay(50) |
|
|
|