优化
This commit is contained in:
@@ -154,6 +154,7 @@ object AppWebDav {
|
|||||||
authorization?.let {
|
authorization?.let {
|
||||||
val webDav = WebDav(rootWebDavUrl + name, it)
|
val webDav = WebDav(rootWebDavUrl + name, it)
|
||||||
webDav.downloadTo(zipFilePath, true)
|
webDav.downloadTo(zipFilePath, true)
|
||||||
|
FileUtils.delete(Backup.backupPath)
|
||||||
ZipUtils.unzipFile(zipFilePath, Backup.backupPath)
|
ZipUtils.unzipFile(zipFilePath, Backup.backupPath)
|
||||||
Restore.restoreDatabase()
|
Restore.restoreDatabase()
|
||||||
Restore.restoreConfig()
|
Restore.restoreConfig()
|
||||||
|
|||||||
@@ -221,9 +221,11 @@ object Restore {
|
|||||||
|
|
||||||
private inline fun <reified T> fileToListT(path: String, fileName: String): List<T>? {
|
private inline fun <reified T> fileToListT(path: String, fileName: String): List<T>? {
|
||||||
try {
|
try {
|
||||||
val file = FileUtils.createFileIfNotExist(path + File.separator + fileName)
|
val file = File(path + File.separator + fileName)
|
||||||
FileInputStream(file).use {
|
if (file.exists()) {
|
||||||
return GSON.fromJsonArray<T>(it).getOrThrow()
|
FileInputStream(file).use {
|
||||||
|
return GSON.fromJsonArray<T>(it).getOrThrow()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
AppLog.put("$fileName\n读取解析出错\n${e.localizedMessage}", e)
|
AppLog.put("$fileName\n读取解析出错\n${e.localizedMessage}", e)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.view.MenuItem
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
|
import androidx.fragment.app.viewModels
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.BaseDialogFragment
|
import io.legado.app.base.BaseDialogFragment
|
||||||
import io.legado.app.data.appDb
|
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 binding by viewBinding(DialogWebdavServerBinding::bind)
|
||||||
|
private val viewModel by viewModels<ServerConfigViewModel>()
|
||||||
|
|
||||||
private val serverUi = listOf(
|
private val serverUi = listOf(
|
||||||
RowUi("url"),
|
RowUi("url"),
|
||||||
@@ -47,8 +49,9 @@ class ServerConfigDialog() : BaseDialogFragment(R.layout.dialog_webdav_server, t
|
|||||||
binding.toolBar.inflateMenu(R.menu.server_config)
|
binding.toolBar.inflateMenu(R.menu.server_config)
|
||||||
binding.toolBar.menu.applyTint(requireContext())
|
binding.toolBar.menu.applyTint(requireContext())
|
||||||
binding.toolBar.setOnMenuItemClickListener(this)
|
binding.toolBar.setOnMenuItemClickListener(this)
|
||||||
|
viewModel.init(arguments?.getLong("id")) {
|
||||||
upConfigView(null)
|
upConfigView(viewModel.server)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMenuItemClick(item: MenuItem): Boolean {
|
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.data.entities.Server
|
||||||
import io.legado.app.databinding.DialogRecyclerViewBinding
|
import io.legado.app.databinding.DialogRecyclerViewBinding
|
||||||
import io.legado.app.databinding.ItemServerSelectBinding
|
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.backgroundColor
|
||||||
import io.legado.app.lib.theme.primaryColor
|
import io.legado.app.lib.theme.primaryColor
|
||||||
import io.legado.app.ui.widget.recycler.VerticalDivider
|
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
|
selectServerId = getItemByLayoutPosition(holder.layoutPosition)?.id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.tvEdit.setOnClickListener {
|
binding.ivEdit.setOnClickListener {
|
||||||
getItemByLayoutPosition(holder.layoutPosition)?.let { server ->
|
getItemByLayoutPosition(holder.layoutPosition)?.let { server ->
|
||||||
showDialogFragment(ServerConfigDialog(server.id))
|
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(
|
override fun convert(
|
||||||
|
|||||||
@@ -2,9 +2,16 @@ package io.legado.app.ui.book.import.remote
|
|||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import io.legado.app.base.BaseViewModel
|
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) {
|
class ServersViewModel(application: Application): BaseViewModel(application) {
|
||||||
|
|
||||||
|
|
||||||
|
fun delete(server: Server) {
|
||||||
|
execute {
|
||||||
|
appDb.serverDao.delete(server)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:background="@color/background"
|
android:background="@color/background"
|
||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
@@ -16,12 +17,27 @@
|
|||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:textColor="@color/primaryText" />
|
android:textColor="@color/primaryText" />
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tv_edit"
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
android:layout_width="wrap_content"
|
android:id="@+id/iv_edit"
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="36dp"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:layout_height="36dp"
|
||||||
android:padding="8dp"
|
android:layout_gravity="center"
|
||||||
android:text="@string/edit" />
|
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/edit"
|
||||||
|
android:padding="6dp"
|
||||||
|
android:src="@drawable/ic_edit"
|
||||||
|
android:tint="@color/primaryText" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:id="@+id/iv_delete"
|
||||||
|
android:layout_width="36dp"
|
||||||
|
android:layout_height="36dp"
|
||||||
|
android:padding="6dp"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:src="@drawable/ic_outline_delete"
|
||||||
|
android:tint="@color/primaryText"
|
||||||
|
android:contentDescription="@string/delete"
|
||||||
|
tools:ignore="RtlHardcoded" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user