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

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

Loading…
Cancel
Save