pull/63/head
kunfei 5 years ago
parent 7628ed1e5e
commit 3b4d0adee9
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt
  2. 18
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  3. 14
      app/src/main/java/io/legado/app/help/storage/Restore.kt

@ -16,6 +16,9 @@ interface BookGroupDao {
@get:Query("SELECT MAX(groupId) FROM book_groups") @get:Query("SELECT MAX(groupId) FROM book_groups")
val maxId: Int val maxId: Int
@Query("SELECT * FROM book_groups ORDER BY `order`")
fun all(): List<BookGroup>
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg bookGroup: BookGroup) fun insert(vararg bookGroup: BookGroup)

@ -27,8 +27,9 @@ object Backup {
legadoPath + File.separator + "Export" legadoPath + File.separator + "Export"
} }
private fun pbackup(path :String = legadoPath){ private fun pBackup(path: String = legadoPath) {
backupBookshelf(path) backupBookshelf(path)
backupBookGroup(path)
backupBookSource(path) backupBookSource(path)
backupRssSource(path) backupRssSource(path)
backupReplaceRule(path) backupReplaceRule(path)
@ -39,7 +40,7 @@ object Backup {
fun backup() { fun backup() {
doAsync { doAsync {
pbackup() pBackup()
uiThread { uiThread {
App.INSTANCE.toast(R.string.backup_success) App.INSTANCE.toast(R.string.backup_success)
} }
@ -48,7 +49,7 @@ object Backup {
fun autoBackup() { fun autoBackup() {
doAsync { doAsync {
pbackup() pBackup()
} }
} }
@ -56,13 +57,22 @@ object Backup {
App.db.bookDao().allBooks.let { App.db.bookDao().allBooks.let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
val json = GSON.toJson(it) val json = GSON.toJson(it)
val file = FileHelp.getFile(path + File.separator + "bookshelf.json") val file = FileHelp.getFile(path + File.separator + "bookshelf.json")
file.writeText(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) { private fun backupBookSource(path: String) {
App.db.bookSourceDao().all.let { App.db.bookSourceDao().all.let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {

@ -9,10 +9,7 @@ import com.jayway.jsonpath.ParseContext
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.data.entities.Book import io.legado.app.data.entities.*
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.help.FileHelp import io.legado.app.help.FileHelp
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.utils.* import io.legado.app.utils.*
@ -47,6 +44,15 @@ object Restore {
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
} }
try {
val file = FileHelp.getFile(path + File.separator + "bookGroup.json")
val json = file.readText()
GSON.fromJsonArray<BookGroup>(json)?.let {
App.db.bookGroupDao().insert(*it.toTypedArray())
}
} catch (e: Exception) {
e.printStackTrace()
}
try { try {
val file = FileHelp.getFile(path + File.separator + "bookSource.json") val file = FileHelp.getFile(path + File.separator + "bookSource.json")
val json = file.readText() val json = file.readText()

Loading…
Cancel
Save