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