|
@@ -15,7 +15,6 @@ import io.legado.app.constant.AppLog
|
|
|
import io.legado.app.constant.AppPattern
|
|
import io.legado.app.constant.AppPattern
|
|
|
import io.legado.app.constant.BookType
|
|
import io.legado.app.constant.BookType
|
|
|
import io.legado.app.constant.EventBus
|
|
import io.legado.app.constant.EventBus
|
|
|
-import io.legado.app.data.appDb
|
|
|
|
|
import io.legado.app.data.entities.Book
|
|
import io.legado.app.data.entities.Book
|
|
|
import io.legado.app.data.entities.BookChapter
|
|
import io.legado.app.data.entities.BookChapter
|
|
|
import io.legado.app.data.entities.BookSource
|
|
import io.legado.app.data.entities.BookSource
|
|
@@ -23,8 +22,12 @@ import io.legado.app.data.entities.SearchBook
|
|
|
import io.legado.app.data.entities.readRecord.ReadRecordTimelineDay
|
|
import io.legado.app.data.entities.readRecord.ReadRecordTimelineDay
|
|
|
import io.legado.app.domain.gateway.BookKnowledgeGateway
|
|
import io.legado.app.domain.gateway.BookKnowledgeGateway
|
|
|
import io.legado.app.data.repository.BookGroupRepository
|
|
import io.legado.app.data.repository.BookGroupRepository
|
|
|
|
|
+import io.legado.app.data.repository.BookRepository
|
|
|
|
|
+import io.legado.app.data.repository.BookSourceRepository
|
|
|
|
|
+import io.legado.app.data.repository.HighlightTagRuleRepository
|
|
|
import io.legado.app.data.repository.ReadRecordRepository
|
|
import io.legado.app.data.repository.ReadRecordRepository
|
|
|
import io.legado.app.data.repository.RemoteBookRepository
|
|
import io.legado.app.data.repository.RemoteBookRepository
|
|
|
|
|
+import io.legado.app.data.repository.SearchRepository
|
|
|
import io.legado.app.domain.usecase.ChangeBookSourceUseCase
|
|
import io.legado.app.domain.usecase.ChangeBookSourceUseCase
|
|
|
import io.legado.app.domain.gateway.ThemeSettingsGateway
|
|
import io.legado.app.domain.gateway.ThemeSettingsGateway
|
|
|
import io.legado.app.domain.gateway.CoverSettingsGateway
|
|
import io.legado.app.domain.gateway.CoverSettingsGateway
|
|
@@ -102,6 +105,10 @@ class BookInfoViewModel(
|
|
|
private val changeBookSourceUseCase: ChangeBookSourceUseCase,
|
|
private val changeBookSourceUseCase: ChangeBookSourceUseCase,
|
|
|
private val clearBookCacheUseCase: ClearBookCacheUseCase,
|
|
private val clearBookCacheUseCase: ClearBookCacheUseCase,
|
|
|
private val bookGroupRepository: BookGroupRepository,
|
|
private val bookGroupRepository: BookGroupRepository,
|
|
|
|
|
+ private val bookRepository: BookRepository,
|
|
|
|
|
+ private val bookSourceRepository: BookSourceRepository,
|
|
|
|
|
+ private val searchRepository: SearchRepository,
|
|
|
|
|
+ private val highlightTagRuleRepository: HighlightTagRuleRepository,
|
|
|
private val imageLoader: ImageLoader,
|
|
private val imageLoader: ImageLoader,
|
|
|
private val bookKnowledgeGateway: BookKnowledgeGateway,
|
|
private val bookKnowledgeGateway: BookKnowledgeGateway,
|
|
|
private val themeSettingsGateway: ThemeSettingsGateway,
|
|
private val themeSettingsGateway: ThemeSettingsGateway,
|
|
@@ -230,12 +237,12 @@ class BookInfoViewModel(
|
|
|
characterLoadJob?.cancel()
|
|
characterLoadJob?.cancel()
|
|
|
syncUiState()
|
|
syncUiState()
|
|
|
execute {
|
|
execute {
|
|
|
- val dbBook = appDb.bookDao.getBook(bookUrl)
|
|
|
|
|
|
|
+ val dbBook = bookRepository.getBook(bookUrl)
|
|
|
if (dbBook != null) {
|
|
if (dbBook != null) {
|
|
|
inBookshelf = !dbBook.isNotShelf
|
|
inBookshelf = !dbBook.isNotShelf
|
|
|
dbBook
|
|
dbBook
|
|
|
} else {
|
|
} else {
|
|
|
- val searchBook = appDb.searchBookDao.getSearchBook(bookUrl)?.toBook()
|
|
|
|
|
|
|
+ val searchBook = searchRepository.getSearchBook(bookUrl)?.toBook()
|
|
|
if (searchBook != null) {
|
|
if (searchBook != null) {
|
|
|
inBookshelf = false
|
|
inBookshelf = false
|
|
|
searchBook
|
|
searchBook
|
|
@@ -251,7 +258,7 @@ class BookInfoViewModel(
|
|
|
val source = if (book.isLocal) {
|
|
val source = if (book.isLocal) {
|
|
|
null
|
|
null
|
|
|
} else {
|
|
} else {
|
|
|
- appDb.bookSourceDao.getBookSource(book.origin)
|
|
|
|
|
|
|
+ bookSourceRepository.getBookSource(book.origin)
|
|
|
}
|
|
}
|
|
|
upBook(book, source)
|
|
upBook(book, source)
|
|
|
}.onError {
|
|
}.onError {
|
|
@@ -382,7 +389,7 @@ class BookInfoViewModel(
|
|
|
|
|
|
|
|
fun onSourceEdited() {
|
|
fun onSourceEdited() {
|
|
|
currentBook?.let { book ->
|
|
currentBook?.let { book ->
|
|
|
- bookSource = appDb.bookSourceDao.getBookSource(book.origin)
|
|
|
|
|
|
|
+ bookSource = bookSourceRepository.getBookSourceSync(book.origin)
|
|
|
syncUiState()
|
|
syncUiState()
|
|
|
refreshBook(book)
|
|
refreshBook(book)
|
|
|
}
|
|
}
|
|
@@ -391,11 +398,11 @@ class BookInfoViewModel(
|
|
|
fun onInfoEdited() {
|
|
fun onInfoEdited() {
|
|
|
currentBook?.bookUrl?.let { bookUrl ->
|
|
currentBook?.bookUrl?.let { bookUrl ->
|
|
|
execute {
|
|
execute {
|
|
|
- val book = appDb.bookDao.getBook(bookUrl) ?: return@execute null
|
|
|
|
|
|
|
+ val book = bookRepository.getBook(bookUrl) ?: return@execute null
|
|
|
val source = if (book.isLocal) {
|
|
val source = if (book.isLocal) {
|
|
|
null
|
|
null
|
|
|
} else {
|
|
} else {
|
|
|
- appDb.bookSourceDao.getBookSource(book.origin)
|
|
|
|
|
|
|
+ bookSourceRepository.getBookSource(book.origin)
|
|
|
}
|
|
}
|
|
|
book to source
|
|
book to source
|
|
|
}.onSuccess {
|
|
}.onSuccess {
|
|
@@ -416,7 +423,7 @@ class BookInfoViewModel(
|
|
|
execute {
|
|
execute {
|
|
|
book.durChapterIndex = result.first
|
|
book.durChapterIndex = result.first
|
|
|
book.durChapterPos = result.second
|
|
book.durChapterPos = result.second
|
|
|
- appDb.bookDao.update(book)
|
|
|
|
|
|
|
+ bookRepository.update(book)
|
|
|
book
|
|
book
|
|
|
}.onSuccess {
|
|
}.onSuccess {
|
|
|
currentBook = it
|
|
currentBook = it
|
|
@@ -441,7 +448,7 @@ class BookInfoViewModel(
|
|
|
fun refreshShelfState() {
|
|
fun refreshShelfState() {
|
|
|
val bookUrl = currentBook?.bookUrl ?: return
|
|
val bookUrl = currentBook?.bookUrl ?: return
|
|
|
execute {
|
|
execute {
|
|
|
- appDb.bookDao.getBook(bookUrl)
|
|
|
|
|
|
|
+ bookRepository.getBook(bookUrl)
|
|
|
}.onSuccess { dbBook ->
|
|
}.onSuccess { dbBook ->
|
|
|
val nextInBookshelf = dbBook != null && !dbBook.isNotShelf
|
|
val nextInBookshelf = dbBook != null && !dbBook.isNotShelf
|
|
|
if (nextInBookshelf) {
|
|
if (nextInBookshelf) {
|
|
@@ -540,10 +547,10 @@ class BookInfoViewModel(
|
|
|
fun topBook() {
|
|
fun topBook() {
|
|
|
currentBook?.let { book ->
|
|
currentBook?.let { book ->
|
|
|
execute {
|
|
execute {
|
|
|
- val minOrder = appDb.bookDao.minOrder
|
|
|
|
|
|
|
+ val minOrder = bookRepository.getMinOrder()
|
|
|
book.order = minOrder - 1
|
|
book.order = minOrder - 1
|
|
|
book.durChapterTime = System.currentTimeMillis()
|
|
book.durChapterTime = System.currentTimeMillis()
|
|
|
- appDb.bookDao.update(book)
|
|
|
|
|
|
|
+ bookRepository.update(book)
|
|
|
book
|
|
book
|
|
|
}.onSuccess {
|
|
}.onSuccess {
|
|
|
currentBook = it
|
|
currentBook = it
|
|
@@ -558,8 +565,8 @@ class BookInfoViewModel(
|
|
|
execute {
|
|
execute {
|
|
|
setBusy(true)
|
|
setBusy(true)
|
|
|
val newBook = remoteBookRepository.syncBookFromRemote(book)
|
|
val newBook = remoteBookRepository.syncBookFromRemote(book)
|
|
|
- appDb.bookDao.delete(book)
|
|
|
|
|
- appDb.bookDao.insert(newBook)
|
|
|
|
|
|
|
+ bookRepository.delete(book)
|
|
|
|
|
+ bookRepository.insert(newBook)
|
|
|
newBook
|
|
newBook
|
|
|
}.onSuccess { newBook ->
|
|
}.onSuccess { newBook ->
|
|
|
currentBook = newBook
|
|
currentBook = newBook
|
|
@@ -660,9 +667,9 @@ class BookInfoViewModel(
|
|
|
book ?: return
|
|
book ?: return
|
|
|
execute {
|
|
execute {
|
|
|
if (book.order == 0) {
|
|
if (book.order == 0) {
|
|
|
- book.order = appDb.bookDao.minOrder - 1
|
|
|
|
|
|
|
+ book.order = bookRepository.getMinOrder() - 1
|
|
|
}
|
|
}
|
|
|
- appDb.bookDao.getBook(book.name, book.author)?.let {
|
|
|
|
|
|
|
+ bookRepository.getBook(book.name, book.author)?.let {
|
|
|
book.durChapterIndex = it.durChapterIndex
|
|
book.durChapterIndex = it.durChapterIndex
|
|
|
book.durChapterPos = it.durChapterPos
|
|
book.durChapterPos = it.durChapterPos
|
|
|
book.durChapterTitle = it.durChapterTitle
|
|
book.durChapterTitle = it.durChapterTitle
|
|
@@ -685,7 +692,7 @@ class BookInfoViewModel(
|
|
|
|
|
|
|
|
fun saveChapterList(success: (() -> Unit)? = null) {
|
|
fun saveChapterList(success: (() -> Unit)? = null) {
|
|
|
execute {
|
|
execute {
|
|
|
- appDb.bookChapterDao.insert(*currentChapterList.toTypedArray())
|
|
|
|
|
|
|
+ bookRepository.insertChapters(*currentChapterList.toTypedArray())
|
|
|
}.onSuccess {
|
|
}.onSuccess {
|
|
|
success?.invoke()
|
|
success?.invoke()
|
|
|
}
|
|
}
|
|
@@ -696,9 +703,9 @@ class BookInfoViewModel(
|
|
|
execute {
|
|
execute {
|
|
|
book.removeType(BookType.notShelf)
|
|
book.removeType(BookType.notShelf)
|
|
|
if (book.order == 0) {
|
|
if (book.order == 0) {
|
|
|
- book.order = appDb.bookDao.minOrder - 1
|
|
|
|
|
|
|
+ book.order = bookRepository.getMinOrder() - 1
|
|
|
}
|
|
}
|
|
|
- appDb.bookDao.getBook(book.name, book.author)?.let {
|
|
|
|
|
|
|
+ bookRepository.getBook(book.name, book.author)?.let {
|
|
|
book.durChapterIndex = it.durChapterIndex
|
|
book.durChapterIndex = it.durChapterIndex
|
|
|
book.durChapterPos = it.durChapterPos
|
|
book.durChapterPos = it.durChapterPos
|
|
|
book.durChapterTitle = it.durChapterTitle
|
|
book.durChapterTitle = it.durChapterTitle
|
|
@@ -710,7 +717,7 @@ class BookInfoViewModel(
|
|
|
}
|
|
}
|
|
|
book.save()
|
|
book.save()
|
|
|
SourceCallBack.callBackBook(SourceCallBack.ADD_BOOK_SHELF, bookSource, book)
|
|
SourceCallBack.callBackBook(SourceCallBack.ADD_BOOK_SHELF, bookSource, book)
|
|
|
- appDb.bookChapterDao.insert(*currentChapterList.toTypedArray())
|
|
|
|
|
|
|
+ bookRepository.insertChapters(*currentChapterList.toTypedArray())
|
|
|
book
|
|
book
|
|
|
}.onSuccess {
|
|
}.onSuccess {
|
|
|
currentBook = it
|
|
currentBook = it
|
|
@@ -724,10 +731,10 @@ class BookInfoViewModel(
|
|
|
execute {
|
|
execute {
|
|
|
book.removeType(BookType.notShelf)
|
|
book.removeType(BookType.notShelf)
|
|
|
if (book.order == 0) {
|
|
if (book.order == 0) {
|
|
|
- book.order = appDb.bookDao.minOrder - 1
|
|
|
|
|
|
|
+ book.order = bookRepository.getMinOrder() - 1
|
|
|
}
|
|
}
|
|
|
- appDb.bookDao.insert(book)
|
|
|
|
|
- appDb.bookChapterDao.insert(*toc.toTypedArray())
|
|
|
|
|
|
|
+ bookRepository.insert(book)
|
|
|
|
|
+ bookRepository.insertChapters(*toc.toTypedArray())
|
|
|
book
|
|
book
|
|
|
}.onSuccess {
|
|
}.onSuccess {
|
|
|
if (currentBook?.bookUrl == it.bookUrl) {
|
|
if (currentBook?.bookUrl == it.bookUrl) {
|
|
@@ -806,7 +813,7 @@ class BookInfoViewModel(
|
|
|
}
|
|
}
|
|
|
WebBook.getBookInfo(scope, source, book, canReName = canReName)
|
|
WebBook.getBookInfo(scope, source, book, canReName = canReName)
|
|
|
.onSuccess(IO) { loadedBook ->
|
|
.onSuccess(IO) { loadedBook ->
|
|
|
- val dbBook = appDb.bookDao.getBook(loadedBook.name, loadedBook.author)
|
|
|
|
|
|
|
+ val dbBook = bookRepository.getBook(loadedBook.name, loadedBook.author)
|
|
|
if (!inBookshelf && dbBook != null && !dbBook.isNotShelf && dbBook.origin == loadedBook.origin) {
|
|
if (!inBookshelf && dbBook != null && !dbBook.isNotShelf && dbBook.origin == loadedBook.origin) {
|
|
|
dbBook.updateTo(loadedBook)
|
|
dbBook.updateTo(loadedBook)
|
|
|
inBookshelf = true
|
|
inBookshelf = true
|
|
@@ -888,7 +895,7 @@ class BookInfoViewModel(
|
|
|
loadBookInfo(book, runPreUpdateJs = inBookshelf, showLoading = false)
|
|
loadBookInfo(book, runPreUpdateJs = inBookshelf, showLoading = false)
|
|
|
} else {
|
|
} else {
|
|
|
execute {
|
|
execute {
|
|
|
- appDb.bookChapterDao.getChapterList(book.bookUrl)
|
|
|
|
|
|
|
+ bookRepository.getChapters(book.bookUrl)
|
|
|
}.onSuccess { chapters ->
|
|
}.onSuccess { chapters ->
|
|
|
if (chapters.isNotEmpty()) {
|
|
if (chapters.isNotEmpty()) {
|
|
|
currentChapterList = chapters
|
|
currentChapterList = chapters
|
|
@@ -926,14 +933,14 @@ class BookInfoViewModel(
|
|
|
private fun refreshMeta(book: Book) {
|
|
private fun refreshMeta(book: Book) {
|
|
|
execute {
|
|
execute {
|
|
|
book.upKind()
|
|
book.upKind()
|
|
|
- val userGroupIds = appDb.bookGroupDao.idsSum
|
|
|
|
|
|
|
+ val userGroupIds = bookGroupRepository.getIdsSum()
|
|
|
val groupAnd = userGroupIds and book.group
|
|
val groupAnd = userGroupIds and book.group
|
|
|
val hasCustomGroup = book.group > 0L && groupAnd != 0L
|
|
val hasCustomGroup = book.group > 0L && groupAnd != 0L
|
|
|
- val groupNames = appDb.bookGroupDao.getGroupNames(book.group).joinToString(",")
|
|
|
|
|
|
|
+ val groupNames = bookGroupRepository.getGroupNames(book.group).joinToString(",")
|
|
|
val normalizedGroupNames = groupNames.ifBlank { null }
|
|
val normalizedGroupNames = groupNames.ifBlank { null }
|
|
|
- appDb.bookDao.update(book)
|
|
|
|
|
|
|
+ bookRepository.update(book)
|
|
|
val finalKinds = book.getDisplayTagList()
|
|
val finalKinds = book.getDisplayTagList()
|
|
|
- val enabledRules = appDb.highlightTagRuleDao.getEnabled()
|
|
|
|
|
|
|
+ val enabledRules = highlightTagRuleRepository.getEnabled()
|
|
|
val (highlighted, regular) = parseHighlightedTags(finalKinds, enabledRules)
|
|
val (highlighted, regular) = parseHighlightedTags(finalKinds, enabledRules)
|
|
|
HighlightMeta(highlighted, regular, normalizedGroupNames, hasCustomGroup)
|
|
HighlightMeta(highlighted, regular, normalizedGroupNames, hasCustomGroup)
|
|
|
}.onSuccess {
|
|
}.onSuccess {
|
|
@@ -963,9 +970,9 @@ class BookInfoViewModel(
|
|
|
if (book.isLocal) {
|
|
if (book.isLocal) {
|
|
|
execute(scope) {
|
|
execute(scope) {
|
|
|
LocalBook.getChapterList(book).also {
|
|
LocalBook.getChapterList(book).also {
|
|
|
- appDb.bookDao.update(book)
|
|
|
|
|
- appDb.bookChapterDao.delByBook(book.bookUrl)
|
|
|
|
|
- appDb.bookChapterDao.insert(*it.toTypedArray())
|
|
|
|
|
|
|
+ bookRepository.update(book)
|
|
|
|
|
+ bookRepository.deleteChaptersByBook(book.bookUrl)
|
|
|
|
|
+ bookRepository.insertChapters(*it.toTypedArray())
|
|
|
ReadBook.onChapterListUpdated(book)
|
|
ReadBook.onChapterListUpdated(book)
|
|
|
}
|
|
}
|
|
|
}.onSuccess {
|
|
}.onSuccess {
|
|
@@ -988,12 +995,12 @@ class BookInfoViewModel(
|
|
|
WebBook.getChapterList(scope, source, book, runPreUpdateJs)
|
|
WebBook.getChapterList(scope, source, book, runPreUpdateJs)
|
|
|
.onSuccess(IO) { chapters ->
|
|
.onSuccess(IO) { chapters ->
|
|
|
if (inBookshelf) {
|
|
if (inBookshelf) {
|
|
|
- appDb.bookDao.replace(oldBook, book)
|
|
|
|
|
|
|
+ bookRepository.replace(oldBook, book)
|
|
|
if (oldBook.bookUrl != book.bookUrl) {
|
|
if (oldBook.bookUrl != book.bookUrl) {
|
|
|
BookHelp.updateCacheFolder(oldBook, book)
|
|
BookHelp.updateCacheFolder(oldBook, book)
|
|
|
}
|
|
}
|
|
|
- appDb.bookChapterDao.delByBook(oldBook.bookUrl)
|
|
|
|
|
- appDb.bookChapterDao.insert(*chapters.toTypedArray())
|
|
|
|
|
|
|
+ bookRepository.deleteChaptersByBook(oldBook.bookUrl)
|
|
|
|
|
+ bookRepository.insertChapters(*chapters.toTypedArray())
|
|
|
ReadBook.onChapterListUpdated(book)
|
|
ReadBook.onChapterListUpdated(book)
|
|
|
}
|
|
}
|
|
|
currentBook = book
|
|
currentBook = book
|
|
@@ -1269,7 +1276,7 @@ class BookInfoViewModel(
|
|
|
private fun onOriginClick() {
|
|
private fun onOriginClick() {
|
|
|
val book = currentBook ?: return
|
|
val book = currentBook ?: return
|
|
|
if (book.isLocal) return
|
|
if (book.isLocal) return
|
|
|
- if (!appDb.bookSourceDao.has(book.origin)) {
|
|
|
|
|
|
|
+ if (!bookSourceRepository.has(book.origin)) {
|
|
|
showMessage(R.string.error_no_source)
|
|
showMessage(R.string.error_no_source)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|