mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -25,6 +25,9 @@ interface ServerDao {
|
||||
@Delete
|
||||
fun delete(vararg server: Server)
|
||||
|
||||
@Query("delete from servers where id = :id")
|
||||
fun delete(id: Long)
|
||||
|
||||
@Query("delete from servers where id < 0")
|
||||
fun deleteDefault()
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import androidx.room.PrimaryKey
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.fromJsonObject
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import org.json.JSONObject
|
||||
|
||||
/**
|
||||
* 服务器
|
||||
@@ -19,7 +20,7 @@ data class Server(
|
||||
var type: TYPE = TYPE.WEBDAV,
|
||||
var config: String? = null,
|
||||
var sortNumber: Int = 0
|
||||
): Parcelable {
|
||||
) : Parcelable {
|
||||
|
||||
enum class TYPE {
|
||||
WEBDAV, ALIYUN, GOOGLEYUN
|
||||
@@ -36,6 +37,12 @@ data class Server(
|
||||
return false
|
||||
}
|
||||
|
||||
fun getConfigJsonObject(): JSONObject? {
|
||||
val json = config
|
||||
json ?: return null
|
||||
return JSONObject(json)
|
||||
}
|
||||
|
||||
fun getWebDavConfig(): WebDavConfig? {
|
||||
return GSON.fromJsonObject<WebDavConfig>(config).getOrNull()
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.app.Application
|
||||
import io.legado.app.base.BaseViewModel
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.constant.BookType
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import io.legado.app.help.AppWebDav
|
||||
import io.legado.app.lib.webdav.Authorization
|
||||
@@ -11,7 +12,6 @@ import io.legado.app.lib.webdav.WebDav
|
||||
import io.legado.app.model.localBook.LocalBook
|
||||
import io.legado.app.model.remote.RemoteBook
|
||||
import io.legado.app.model.remote.RemoteBookWebDav
|
||||
import io.legado.app.utils.ACache
|
||||
import io.legado.app.utils.toastOnUi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
@@ -79,7 +79,7 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
||||
|
||||
fun initData(onSuccess: () -> Unit) {
|
||||
execute {
|
||||
val config = ACache.get().getAsJSONObject("remoteServerConfig")
|
||||
val config = appDb.serverDao.get(10001)?.getConfigJsonObject()
|
||||
if (config != null && config.has("url")) {
|
||||
val url = config.getString("url")
|
||||
if (url.isNotBlank()) {
|
||||
|
||||
@@ -9,11 +9,12 @@ import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import io.legado.app.R
|
||||
import io.legado.app.base.BaseDialogFragment
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.Server
|
||||
import io.legado.app.data.entities.rule.RowUi
|
||||
import io.legado.app.databinding.DialogWebdavServerBinding
|
||||
import io.legado.app.databinding.ItemSourceEditBinding
|
||||
import io.legado.app.lib.theme.primaryColor
|
||||
import io.legado.app.utils.ACache
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.applyTint
|
||||
import io.legado.app.utils.setLayout
|
||||
@@ -48,9 +49,14 @@ class ServerConfigDialog : BaseDialogFragment(R.layout.dialog_webdav_server, tru
|
||||
R.id.menu_save -> {
|
||||
val data = getConfigData()
|
||||
if (data.isEmpty()) {
|
||||
ACache.get().remove("remoteServerConfig")
|
||||
appDb.serverDao.delete(10001)
|
||||
} else {
|
||||
ACache.get().put("remoteServerConfig", GSON.toJson(data))
|
||||
appDb.serverDao.insert(
|
||||
Server(
|
||||
id = 10001,
|
||||
config = GSON.toJson(data)
|
||||
)
|
||||
)
|
||||
}
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
@@ -59,7 +65,7 @@ class ServerConfigDialog : BaseDialogFragment(R.layout.dialog_webdav_server, tru
|
||||
}
|
||||
|
||||
private fun initConfigView() {
|
||||
val data = ACache.get().getAsJSONObject("remoteServerConfig")
|
||||
val data = appDb.serverDao.get(10001)?.getConfigJsonObject()
|
||||
serverUi.forEachIndexed { index, rowUi ->
|
||||
when (rowUi.type) {
|
||||
RowUi.Type.text -> ItemSourceEditBinding.inflate(
|
||||
|
||||
Reference in New Issue
Block a user