pull/67/head
kunfei 5 years ago
parent 75d69cb249
commit be233f5615
  1. 40
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  2. 3
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@ -7,6 +7,7 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.help.FileHelp
import io.legado.app.help.ReadBookConfig
import io.legado.app.utils.DocumentUtils
import io.legado.app.utils.FileUtils
import io.legado.app.utils.GSON
import org.jetbrains.anko.defaultSharedPreferences
@ -33,23 +34,38 @@ object Backup {
fun backup(context: Context, uri: Uri) {
DocumentFile.fromTreeUri(context, uri)?.listFiles()?.forEach { doc ->
when (doc.name) {
"bookshelf.json" -> {
"bookshelf.json" -> App.db.bookDao().allBooks.let {
if (it.isNotEmpty()) {
val json = GSON.toJson(it)
DocumentUtils.writeText(context, json, doc.uri)
}
"bookGroup.json" -> {
}
"bookSource.json" -> {
"bookGroup.json" -> App.db.bookGroupDao().all().let {
if (it.isNotEmpty()) {
val json = GSON.toJson(it)
DocumentUtils.writeText(context, json, doc.uri)
}
"rssSource.json" -> {
}
"replaceRule.json" -> {
"bookSource.json" -> App.db.bookSourceDao().all.let {
if (it.isNotEmpty()) {
val json = GSON.toJson(it)
DocumentUtils.writeText(context, json, doc.uri)
}
ReadBookConfig.readConfigFileName -> {
}
"rssSource.json" -> App.db.rssSourceDao().all.let {
if (it.isNotEmpty()) {
val json = GSON.toJson(it)
DocumentUtils.writeText(context, json, doc.uri)
}
}
"replaceRule.json" -> App.db.replaceRuleDao().all.let {
if (it.isNotEmpty()) {
val json = GSON.toJson(it)
DocumentUtils.writeText(context, json, doc.uri)
}
}
ReadBookConfig.readConfigFileName -> GSON.toJson(ReadBookConfig.configList)?.let {
DocumentUtils.writeText(context, it, doc.uri)
}
"config.xml" -> {

@ -211,6 +211,7 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
putPrefString(PreferKey.backupPath, uri.toString())
Backup.backup(this, uri)
}
}
@ -220,7 +221,7 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
putPrefString(PreferKey.backupPath, uri.toString())
}
}
}

Loading…
Cancel
Save