优化
This commit is contained in:
@@ -154,6 +154,7 @@ object AppWebDav {
|
||||
authorization?.let {
|
||||
val webDav = WebDav(rootWebDavUrl + name, it)
|
||||
webDav.downloadTo(zipFilePath, true)
|
||||
FileUtils.delete(Backup.backupPath)
|
||||
ZipUtils.unzipFile(zipFilePath, Backup.backupPath)
|
||||
Restore.restoreDatabase()
|
||||
Restore.restoreConfig()
|
||||
|
||||
@@ -221,9 +221,11 @@ object Restore {
|
||||
|
||||
private inline fun <reified T> fileToListT(path: String, fileName: String): List<T>? {
|
||||
try {
|
||||
val file = FileUtils.createFileIfNotExist(path + File.separator + fileName)
|
||||
FileInputStream(file).use {
|
||||
return GSON.fromJsonArray<T>(it).getOrThrow()
|
||||
val file = File(path + File.separator + fileName)
|
||||
if (file.exists()) {
|
||||
FileInputStream(file).use {
|
||||
return GSON.fromJsonArray<T>(it).getOrThrow()
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
AppLog.put("$fileName\n读取解析出错\n${e.localizedMessage}", e)
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.fragment.app.viewModels
|
||||
import io.legado.app.R
|
||||
import io.legado.app.base.BaseDialogFragment
|
||||
import io.legado.app.data.appDb
|
||||
@@ -30,6 +31,7 @@ class ServerConfigDialog() : BaseDialogFragment(R.layout.dialog_webdav_server, t
|
||||
}
|
||||
|
||||
private val binding by viewBinding(DialogWebdavServerBinding::bind)
|
||||
private val viewModel by viewModels<ServerConfigViewModel>()
|
||||
|
||||
private val serverUi = listOf(
|
||||
RowUi("url"),
|
||||
@@ -47,8 +49,9 @@ class ServerConfigDialog() : BaseDialogFragment(R.layout.dialog_webdav_server, t
|
||||
binding.toolBar.inflateMenu(R.menu.server_config)
|
||||
binding.toolBar.menu.applyTint(requireContext())
|
||||
binding.toolBar.setOnMenuItemClickListener(this)
|
||||
|
||||
upConfigView(null)
|
||||
viewModel.init(arguments?.getLong("id")) {
|
||||
upConfigView(viewModel.server)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMenuItemClick(item: MenuItem): Boolean {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package io.legado.app.ui.book.import.remote
|
||||
|
||||
import android.app.Application
|
||||
import io.legado.app.base.BaseViewModel
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.Server
|
||||
|
||||
class ServerConfigViewModel(application: Application): BaseViewModel(application) {
|
||||
|
||||
var server: Server? = null
|
||||
|
||||
fun init(id: Long?, onSuccess: () -> Unit) {
|
||||
execute {
|
||||
if (server == null && id != null) {
|
||||
server = appDb.serverDao.get(id)
|
||||
}
|
||||
}.onSuccess {
|
||||
onSuccess.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.Server
|
||||
import io.legado.app.databinding.DialogRecyclerViewBinding
|
||||
import io.legado.app.databinding.ItemServerSelectBinding
|
||||
import io.legado.app.lib.dialogs.alert
|
||||
import io.legado.app.lib.theme.backgroundColor
|
||||
import io.legado.app.lib.theme.primaryColor
|
||||
import io.legado.app.ui.widget.recycler.VerticalDivider
|
||||
@@ -92,11 +93,23 @@ class ServersDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
||||
selectServerId = getItemByLayoutPosition(holder.layoutPosition)?.id
|
||||
}
|
||||
}
|
||||
binding.tvEdit.setOnClickListener {
|
||||
binding.ivEdit.setOnClickListener {
|
||||
getItemByLayoutPosition(holder.layoutPosition)?.let { server ->
|
||||
showDialogFragment(ServerConfigDialog(server.id))
|
||||
}
|
||||
}
|
||||
binding.ivDelete.setOnClickListener {
|
||||
alert {
|
||||
setTitle(R.string.draw)
|
||||
setMessage(R.string.sure_del)
|
||||
yesButton {
|
||||
getItemByLayoutPosition(holder.layoutPosition)?.let { server ->
|
||||
viewModel.delete(server)
|
||||
}
|
||||
}
|
||||
noButton()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun convert(
|
||||
|
||||
@@ -2,9 +2,16 @@ package io.legado.app.ui.book.import.remote
|
||||
|
||||
import android.app.Application
|
||||
import io.legado.app.base.BaseViewModel
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.Server
|
||||
|
||||
class ServersViewModel(application: Application): BaseViewModel(application) {
|
||||
|
||||
|
||||
fun delete(server: Server) {
|
||||
execute {
|
||||
appDb.serverDao.delete(server)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user