diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index 303be7d5c..cbd0f61ce 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -45,7 +45,7 @@ interface BookDao { val hasUpdateBooks: List @get:Query("SELECT * FROM books") - val allBooks: List + val all: List @get:Query("SELECT * FROM books where type = 0 ORDER BY durChapterTime DESC limit 1") val lastReadBook: Book? diff --git a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt index b06e7ac9e..af15188bb 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt @@ -19,8 +19,8 @@ interface BookGroupDao { @get:Query("SELECT MAX(`order`) FROM book_groups") val maxOrder: Int - @Query("SELECT * FROM book_groups ORDER BY `order`") - fun all(): List + @get:Query("SELECT * FROM book_groups ORDER BY `order`") + val all: List @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg bookGroup: BookGroup) diff --git a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt index ea5bb1ad8..fbf3c3611 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt @@ -32,4 +32,6 @@ interface RssArticleDao { @Insert(onConflict = OnConflictStrategy.IGNORE) fun insertRecord(vararg rssReadRecord: RssReadRecord) + + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/dao/RssStarDao.kt b/app/src/main/java/io/legado/app/data/dao/RssStarDao.kt index 87e527f75..faaf85b9f 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssStarDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssStarDao.kt @@ -7,6 +7,9 @@ import io.legado.app.data.entities.RssStar @Dao interface RssStarDao { + @get:Query("select * from rssStars order by starTime desc") + val all: List + @Query("select * from rssStars where origin = :origin and link = :link") fun get(origin: String, link: String): RssStar? diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index fd28eea7f..d8fc7e4a3 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -36,6 +36,7 @@ object Backup { "bookGroup.json", "bookSource.json", "rssSource.json", + "rssStar.json", "replaceRule.json", ReadBookConfig.readConfigFileName, "config.xml" @@ -44,41 +45,13 @@ object Backup { suspend fun backup(context: Context, uri: Uri?) { withContext(IO) { - App.db.bookDao().allBooks.let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - FileUtils.createFileIfNotExist(backupPath + File.separator + "bookshelf.json") - .writeText(json) - } - } - App.db.bookGroupDao().all().let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - FileUtils.createFileIfNotExist(backupPath + File.separator + "bookGroup.json") - .writeText(json) - } - } - App.db.bookSourceDao().all.let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - FileUtils.createFileIfNotExist(backupPath + File.separator + "bookSource.json") - .writeText(json) - } - } - App.db.rssSourceDao().all.let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - FileUtils.createFileIfNotExist(backupPath + File.separator + "rssSource.json") - .writeText(json) - } - } - App.db.replaceRuleDao().all.let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - FileUtils.createFileIfNotExist(backupPath + File.separator + "replaceRule.json") - .writeText(json) - } - } + writeListToJson(App.db.bookDao().all, "bookshelf.json", backupPath) + writeListToJson(App.db.bookGroupDao().all, "bookGroup.json", backupPath) + writeListToJson(App.db.bookSourceDao().all, "bookSource.json", backupPath) + writeListToJson(App.db.rssSourceDao().all, "rssSource.json", backupPath) + writeListToJson(App.db.rssStarDao().all, "rssStar.json", backupPath) + writeListToJson(App.db.replaceRuleDao().all, "replaceRule.json", backupPath) + GSON.toJson(ReadBookConfig.configList)?.let { FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.readConfigFileName) .writeText(it) @@ -106,6 +79,13 @@ object Backup { } } + private fun writeListToJson(list: List, fileName: String, path: String) { + if (list.isNotEmpty()) { + val json = GSON.toJson(list) + FileUtils.createFileIfNotExist(path + File.separator + fileName).writeText(json) + } + } + private fun copyBackup(context: Context, uri: Uri) { DocumentFile.fromTreeUri(context, uri)?.let { treeDoc -> for (fileName in backupFileNames) { diff --git a/app/src/main/java/io/legado/app/web/controller/BookshelfController.kt b/app/src/main/java/io/legado/app/web/controller/BookshelfController.kt index 87bcb3e1c..961407998 100644 --- a/app/src/main/java/io/legado/app/web/controller/BookshelfController.kt +++ b/app/src/main/java/io/legado/app/web/controller/BookshelfController.kt @@ -13,7 +13,7 @@ class BookshelfController { val bookshelf: ReturnData get() { - val books = App.db.bookDao().allBooks + val books = App.db.bookDao().all val returnData = ReturnData() return if (books.isEmpty()) { returnData.setErrorMsg("还没有添加小说")