mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
cd1fe2bdd3
commit
52980246e6
@ -104,8 +104,8 @@ interface BookDao {
|
||||
@Query("select 1 from books where originName = :fileName")
|
||||
fun hasFile(fileName: String): Boolean?
|
||||
|
||||
@Upsert
|
||||
fun upsert(vararg book: Book)
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insert(vararg book: Book)
|
||||
|
||||
@Update
|
||||
fun update(vararg book: Book)
|
||||
|
@ -1,9 +1,6 @@
|
||||
package io.legado.app.data.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Query
|
||||
import androidx.room.Upsert
|
||||
import androidx.room.*
|
||||
import io.legado.app.data.entities.DictRule
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@ -23,8 +20,8 @@ interface DictRuleDao {
|
||||
@Query("select * from dictRules where name = :name")
|
||||
fun getByName(name: String): DictRule?
|
||||
|
||||
@Upsert
|
||||
fun upsert(vararg dictRule: DictRule)
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insert(vararg dictRule: DictRule)
|
||||
|
||||
@Delete
|
||||
fun delete(vararg dictRule: DictRule)
|
||||
|
@ -298,7 +298,7 @@ data class Book(
|
||||
if (appDb.bookDao.has(bookUrl) == true) {
|
||||
appDb.bookDao.update(this)
|
||||
} else {
|
||||
appDb.bookDao.upsert(this)
|
||||
appDb.bookDao.insert(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ object DefaultData {
|
||||
}
|
||||
|
||||
fun importDefaultDictRules() {
|
||||
appDb.dictRuleDao.upsert(*dictRules.toTypedArray())
|
||||
appDb.dictRuleDao.insert(*dictRules.toTypedArray())
|
||||
}
|
||||
|
||||
}
|
@ -87,7 +87,7 @@ object ImportOldData {
|
||||
|
||||
private fun importOldBookshelf(json: String): Int {
|
||||
val books = fromOldBooks(json)
|
||||
appDb.bookDao.upsert(*books.toTypedArray())
|
||||
appDb.bookDao.insert(*books.toTypedArray())
|
||||
return books.size
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ object Restore {
|
||||
.forEach { book ->
|
||||
book.coverUrl = LocalBook.getCoverPath(book)
|
||||
}
|
||||
appDb.bookDao.upsert(*it.toTypedArray())
|
||||
appDb.bookDao.insert(*it.toTypedArray())
|
||||
}
|
||||
fileToListT<Bookmark>(path, "bookmark.json")?.let {
|
||||
appDb.bookmarkDao.insert(*it.toTypedArray())
|
||||
|
@ -184,7 +184,7 @@ object LocalBook {
|
||||
if (book.isEpub) EpubFile.upBookInfo(book)
|
||||
if (book.isUmd) UmdFile.upBookInfo(book)
|
||||
if (book.isPdf) PdfFile.upBookInfo(book)
|
||||
appDb.bookDao.upsert(book)
|
||||
appDb.bookDao.insert(book)
|
||||
} else {
|
||||
//已有书籍说明是更新,删除原有目录
|
||||
appDb.bookChapterDao.delByBook(bookUrl)
|
||||
|
@ -51,7 +51,7 @@ class ImportDictRuleViewModel(app: Application) : BaseViewModel(app) {
|
||||
selectSource.add(allSources[index])
|
||||
}
|
||||
}
|
||||
appDb.dictRuleDao.upsert(*selectSource.toTypedArray())
|
||||
appDb.dictRuleDao.insert(*selectSource.toTypedArray())
|
||||
}.onFinally {
|
||||
finally.invoke()
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ class AudioPlayActivity :
|
||||
launch {
|
||||
withContext(IO) {
|
||||
AudioPlay.book?.migrateTo(book, toc)
|
||||
appDb.bookDao.upsert(book)
|
||||
appDb.bookDao.insert(book)
|
||||
}
|
||||
startActivity<ReadBookActivity> {
|
||||
putExtra("bookUrl", book.bookUrl)
|
||||
|
@ -79,7 +79,7 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
|
||||
fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>) {
|
||||
execute {
|
||||
AudioPlay.book?.migrateTo(book, toc)
|
||||
appDb.bookDao.upsert(book)
|
||||
appDb.bookDao.insert(book)
|
||||
AudioPlay.book = book
|
||||
AudioPlay.bookSource = source
|
||||
appDb.bookChapterDao.insert(*toc.toTypedArray())
|
||||
|
@ -196,7 +196,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
||||
if (oldBook.bookUrl == book.bookUrl) {
|
||||
appDb.bookDao.update(book)
|
||||
} else {
|
||||
appDb.bookDao.upsert(book)
|
||||
appDb.bookDao.insert(book)
|
||||
BookHelp.updateCacheFolder(oldBook, book)
|
||||
}
|
||||
appDb.bookChapterDao.delByBook(oldBook.bookUrl)
|
||||
@ -237,7 +237,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
||||
bookData.value?.migrateTo(book, toc)
|
||||
if (inBookshelf) {
|
||||
book.removeType(BookType.updateError)
|
||||
appDb.bookDao.upsert(book)
|
||||
appDb.bookDao.insert(book)
|
||||
appDb.bookChapterDao.insert(*toc.toTypedArray())
|
||||
}
|
||||
bookData.postValue(book)
|
||||
|
@ -59,7 +59,7 @@ class BookshelfManageViewModel(application: Application) : BaseViewModel(applica
|
||||
}.getOrNull()?.let { toc ->
|
||||
book.migrateTo(newBook, toc)
|
||||
book.removeType(BookType.updateError)
|
||||
appDb.bookDao.upsert(newBook)
|
||||
appDb.bookDao.insert(newBook)
|
||||
appDb.bookChapterDao.insert(*toc.toTypedArray())
|
||||
}
|
||||
}
|
||||
|
@ -833,7 +833,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
ReadAloud.stop(this)
|
||||
launch {
|
||||
ReadBook.book?.migrateTo(book, toc)
|
||||
appDb.bookDao.upsert(book)
|
||||
appDb.bookDao.insert(book)
|
||||
}
|
||||
startActivity<AudioPlayActivity> {
|
||||
putExtra("bookUrl", book.bookUrl)
|
||||
|
@ -165,7 +165,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
||||
if (oldBook.bookUrl == book.bookUrl) {
|
||||
appDb.bookDao.update(book)
|
||||
} else {
|
||||
appDb.bookDao.upsert(book)
|
||||
appDb.bookDao.insert(book)
|
||||
BookHelp.updateCacheFolder(oldBook, book)
|
||||
}
|
||||
appDb.bookChapterDao.delByBook(oldBook.bookUrl)
|
||||
@ -216,7 +216,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
||||
ReadBook.upMsg(context.getString(R.string.loading))
|
||||
ReadBook.book?.migrateTo(book, toc)
|
||||
book.removeType(BookType.updateError)
|
||||
appDb.bookDao.upsert(book)
|
||||
appDb.bookDao.insert(book)
|
||||
appDb.bookChapterDao.insert(*toc.toTypedArray())
|
||||
ReadBook.resetData(book)
|
||||
ReadBook.upMsg(null)
|
||||
|
@ -91,7 +91,7 @@ class DictRuleEditDialog() : BaseDialogFragment(R.layout.dialog_dict_rule_edit,
|
||||
dictRule?.let {
|
||||
appDb.dictRuleDao.delete(it)
|
||||
}
|
||||
appDb.dictRuleDao.upsert(newDictRule)
|
||||
appDb.dictRuleDao.insert(newDictRule)
|
||||
dictRule = newDictRule
|
||||
}.onFinally {
|
||||
onFinally.invoke()
|
||||
|
@ -11,7 +11,7 @@ class DictRuleViewModel(application: Application) : BaseViewModel(application) {
|
||||
|
||||
fun upsert(vararg dictRule: DictRule) {
|
||||
execute {
|
||||
appDb.dictRuleDao.upsert(*dictRule)
|
||||
appDb.dictRuleDao.insert(*dictRule)
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ class DictRuleViewModel(application: Application) : BaseViewModel(application) {
|
||||
for ((index, rule) in rules.withIndex()) {
|
||||
rule.sortNumber = index + 1
|
||||
}
|
||||
appDb.dictRuleDao.upsert(*rules.toTypedArray())
|
||||
appDb.dictRuleDao.insert(*rules.toTypedArray())
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ class DictRuleViewModel(application: Application) : BaseViewModel(application) {
|
||||
dictRule.forEach {
|
||||
it.enabled = true
|
||||
}
|
||||
appDb.dictRuleDao.upsert(*dictRule)
|
||||
appDb.dictRuleDao.insert(*dictRule)
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ class DictRuleViewModel(application: Application) : BaseViewModel(application) {
|
||||
dictRule.forEach {
|
||||
it.enabled = false
|
||||
}
|
||||
appDb.dictRuleDao.upsert(*dictRule)
|
||||
appDb.dictRuleDao.insert(*dictRule)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
|
||||
appDb.bookDao.update(book)
|
||||
} else {
|
||||
upTocAdd(book.bookUrl)
|
||||
appDb.bookDao.upsert(book)
|
||||
appDb.bookDao.insert(book)
|
||||
BookHelp.updateCacheFolder(oldBook, book)
|
||||
}
|
||||
appDb.bookChapterDao.delByBook(bookUrl)
|
||||
|
Loading…
Reference in New Issue
Block a user