优化
This commit is contained in:
@@ -13,6 +13,7 @@ object PreferKey {
|
||||
const val coverShowAuthor = "coverShowAuthor"
|
||||
const val coverShowNameN = "coverShowNameN"
|
||||
const val coverShowAuthorN = "coverShowAuthorN"
|
||||
const val remoteServerId = "remoteServerId"
|
||||
const val hideStatusBar = "hideStatusBar"
|
||||
const val clickActionTL = "clickActionTopLeft"
|
||||
const val clickActionTC = "clickActionTopCenter"
|
||||
|
||||
@@ -174,6 +174,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
appCtx.putPrefInt(PreferKey.threadCount, value)
|
||||
}
|
||||
|
||||
var remoteServerId: Long
|
||||
get() = appCtx.getPrefLong(PreferKey.remoteServerId)
|
||||
set(value) {
|
||||
appCtx.putPrefLong(PreferKey.remoteServerId, value)
|
||||
}
|
||||
|
||||
// 添加本地选择的目录
|
||||
var importBookPath: String?
|
||||
get() = appCtx.getPrefString("importBookPath")
|
||||
|
||||
@@ -7,6 +7,7 @@ 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.help.config.AppConfig
|
||||
import io.legado.app.lib.webdav.Authorization
|
||||
import io.legado.app.model.analyzeRule.CustomUrl
|
||||
import io.legado.app.model.localBook.LocalBook
|
||||
@@ -79,12 +80,13 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
||||
|
||||
fun initData(onSuccess: () -> Unit) {
|
||||
execute {
|
||||
val config = appDb.serverDao.get(10001)?.getConfigJsonObject()
|
||||
if (config != null && config.has("url")) {
|
||||
val url = config.getString("url")
|
||||
val server = appDb.serverDao.get(AppConfig.remoteServerId)
|
||||
val serverConfig = server?.getConfigJsonObject()
|
||||
if (serverConfig != null && serverConfig.has("url")) {
|
||||
val url = serverConfig.getString("url")
|
||||
if (url.isNotBlank()) {
|
||||
val user = config.getString("user")
|
||||
val password = config.getString("password")
|
||||
val user = serverConfig.getString("user")
|
||||
val password = serverConfig.getString("password")
|
||||
val authorization = Authorization(user, password)
|
||||
remoteBookWebDav = RemoteBookWebDav(url, authorization, 10001)
|
||||
return@execute
|
||||
|
||||
@@ -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.help.config.AppConfig
|
||||
import io.legado.app.lib.dialogs.alert
|
||||
import io.legado.app.lib.theme.backgroundColor
|
||||
import io.legado.app.lib.theme.primaryColor
|
||||
@@ -25,6 +26,7 @@ import io.legado.app.utils.applyTint
|
||||
import io.legado.app.utils.setLayout
|
||||
import io.legado.app.utils.showDialogFragment
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import io.legado.app.utils.visible
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class ServersDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
||||
@@ -56,6 +58,21 @@ class ServersDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
||||
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||
binding.recyclerView.addItemDecoration(VerticalDivider(requireContext()))
|
||||
binding.recyclerView.adapter = adapter
|
||||
binding.tvFooterLeft.text = getString(R.string.text_default)
|
||||
binding.tvFooterLeft.visible()
|
||||
binding.tvFooterLeft.setOnClickListener {
|
||||
AppConfig.remoteServerId = 0
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
binding.tvCancel.visible()
|
||||
binding.tvCancel.setOnClickListener {
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
binding.tvOk.visible()
|
||||
binding.tvOk.setOnClickListener {
|
||||
AppConfig.remoteServerId = adapter.selectServerId
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
}
|
||||
|
||||
private fun initData() {
|
||||
@@ -81,7 +98,7 @@ class ServersDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
||||
inner class ServersAdapter(context: Context) :
|
||||
RecyclerAdapter<Server, ItemServerSelectBinding>(context) {
|
||||
|
||||
private var selectServerId: Long? = null
|
||||
var selectServerId: Long = AppConfig.remoteServerId
|
||||
|
||||
override fun getViewBinding(parent: ViewGroup): ItemServerSelectBinding {
|
||||
return ItemServerSelectBinding.inflate(inflater, parent, false)
|
||||
@@ -90,7 +107,8 @@ class ServersDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
||||
override fun registerListener(holder: ItemViewHolder, binding: ItemServerSelectBinding) {
|
||||
binding.rbServer.setOnCheckedChangeListener { buttonView, isChecked ->
|
||||
if (buttonView.isPressed && isChecked) {
|
||||
selectServerId = getItemByLayoutPosition(holder.layoutPosition)?.id
|
||||
selectServerId = getItemByLayoutPosition(holder.layoutPosition)!!.id
|
||||
adapter.updateItems(0, itemCount - 1, "upSelect")
|
||||
}
|
||||
}
|
||||
binding.ivEdit.setOnClickListener {
|
||||
|
||||
Reference in New Issue
Block a user