From 3b4d0adee962866a9fee5a82a15ef93cc0999fda Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 28 Dec 2019 16:43:57 +0800 Subject: [PATCH] up --- .../io/legado/app/data/dao/BookGroupDao.kt | 3 +++ .../java/io/legado/app/help/storage/Backup.kt | 18 ++++++++++++++---- .../java/io/legado/app/help/storage/Restore.kt | 14 ++++++++++---- 3 files changed, 27 insertions(+), 8 deletions(-) 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 0078eb26b..c48bd6e6b 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 @@ -16,6 +16,9 @@ interface BookGroupDao { @get:Query("SELECT MAX(groupId) FROM book_groups") val maxId: Int + @Query("SELECT * FROM book_groups ORDER BY `order`") + fun all(): List + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg bookGroup: BookGroup) 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 7062d1951..529deb629 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 @@ -27,8 +27,9 @@ object Backup { legadoPath + File.separator + "Export" } - private fun pbackup(path :String = legadoPath){ + private fun pBackup(path: String = legadoPath) { backupBookshelf(path) + backupBookGroup(path) backupBookSource(path) backupRssSource(path) backupReplaceRule(path) @@ -39,7 +40,7 @@ object Backup { fun backup() { doAsync { - pbackup() + pBackup() uiThread { App.INSTANCE.toast(R.string.backup_success) } @@ -48,7 +49,7 @@ object Backup { fun autoBackup() { doAsync { - pbackup() + pBackup() } } @@ -56,13 +57,22 @@ object Backup { App.db.bookDao().allBooks.let { if (it.isNotEmpty()) { val json = GSON.toJson(it) - val file = FileHelp.getFile(path + File.separator + "bookshelf.json") file.writeText(json) } } } + private fun backupBookGroup(path: String) { + App.db.bookGroupDao().all().let { + if (it.isNotEmpty()) { + val json = GSON.toJson(it) + val file = FileHelp.getFile(path + File.separator + "bookGroup.json") + file.writeText(json) + } + } + } + private fun backupBookSource(path: String) { App.db.bookSourceDao().all.let { if (it.isNotEmpty()) { diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 53b040f28..b2e34783e 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -9,10 +9,7 @@ import com.jayway.jsonpath.ParseContext import io.legado.app.App import io.legado.app.R import io.legado.app.constant.AppConst -import io.legado.app.data.entities.Book -import io.legado.app.data.entities.BookSource -import io.legado.app.data.entities.ReplaceRule -import io.legado.app.data.entities.RssSource +import io.legado.app.data.entities.* import io.legado.app.help.FileHelp import io.legado.app.help.ReadBookConfig import io.legado.app.utils.* @@ -47,6 +44,15 @@ object Restore { } catch (e: Exception) { e.printStackTrace() } + try { + val file = FileHelp.getFile(path + File.separator + "bookGroup.json") + val json = file.readText() + GSON.fromJsonArray(json)?.let { + App.db.bookGroupDao().insert(*it.toTypedArray()) + } + } catch (e: Exception) { + e.printStackTrace() + } try { val file = FileHelp.getFile(path + File.separator + "bookSource.json") val json = file.readText()