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