优化 #5379
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package io.legado.app.help.storage
|
||||
|
||||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteConstraintException
|
||||
import android.net.Uri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import io.legado.app.BuildConfig
|
||||
@@ -105,14 +106,23 @@ object Restore {
|
||||
.forEach { book ->
|
||||
book.coverUrl = LocalBook.getCoverPath(book)
|
||||
}
|
||||
val books = if (BackupConfig.ignoreLocalBook) {
|
||||
it.filter { book ->
|
||||
!book.isLocal
|
||||
val newBooks = arrayListOf<Book>()
|
||||
val ignoreLocalBook = BackupConfig.ignoreLocalBook
|
||||
it.forEach { book ->
|
||||
if (ignoreLocalBook && book.isLocal) {
|
||||
return@forEach
|
||||
}
|
||||
if (appDb.bookDao.has(book.bookUrl)) {
|
||||
try {
|
||||
appDb.bookDao.update(book)
|
||||
} catch (_: SQLiteConstraintException) {
|
||||
appDb.bookDao.insert(book)
|
||||
}
|
||||
} else {
|
||||
newBooks.add(book)
|
||||
}
|
||||
} else {
|
||||
it
|
||||
}
|
||||
appDb.bookDao.insert(*books.toTypedArray())
|
||||
appDb.bookDao.insert(*newBooks.toTypedArray())
|
||||
}
|
||||
fileToListT<Bookmark>(path, "bookmark.json")?.let {
|
||||
appDb.bookmarkDao.insert(*it.toTypedArray())
|
||||
|
||||
Reference in New Issue
Block a user