远程书籍单独配置webDav,多个webDav看情况再添加
This commit is contained in:
@@ -6,6 +6,16 @@ import kotlinx.parcelize.Parcelize
|
||||
@Parcelize
|
||||
data class RowUi(
|
||||
var name: String,
|
||||
var type: String?,
|
||||
var action: String?
|
||||
) : Parcelable
|
||||
var type: String = "text",
|
||||
var action: String? = null
|
||||
) : Parcelable {
|
||||
|
||||
object Type {
|
||||
|
||||
const val text = "text"
|
||||
const val password = "password"
|
||||
const val button = "button"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -93,7 +93,7 @@ class RemoteBookActivity : BaseImportBookActivity<ActivityImportBookBinding, Rem
|
||||
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.menu_refresh -> upPath()
|
||||
R.id.menu_server_config -> {}
|
||||
R.id.menu_server_config -> showDialogFragment(ServerConfigDialog())
|
||||
R.id.menu_log -> showDialogFragment<AppLogDialog>()
|
||||
R.id.menu_help -> showHelp("webDavBookHelp")
|
||||
R.id.menu_sort_name -> {
|
||||
|
||||
@@ -1,4 +1,97 @@
|
||||
package io.legado.app.ui.book.import.remote
|
||||
|
||||
class ServerConfigDialog {
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
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.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
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
|
||||
class ServerConfigDialog : BaseDialogFragment(R.layout.dialog_webdav_server, true),
|
||||
Toolbar.OnMenuItemClickListener {
|
||||
|
||||
private val binding by viewBinding(DialogWebdavServerBinding::bind)
|
||||
|
||||
private val serverUi = listOf(
|
||||
RowUi("url"),
|
||||
RowUi("user"),
|
||||
RowUi("password", RowUi.Type.password)
|
||||
)
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
|
||||
}
|
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||
binding.toolBar.setBackgroundColor(primaryColor)
|
||||
binding.toolBar.inflateMenu(R.menu.server_config)
|
||||
binding.toolBar.menu.applyTint(requireContext())
|
||||
binding.toolBar.setOnMenuItemClickListener(this)
|
||||
initConfigView()
|
||||
}
|
||||
|
||||
override fun onMenuItemClick(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.menu_save -> {
|
||||
val data = getConfigData()
|
||||
ACache.get().put("remoteServerConfig", GSON.toJson(data))
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun initConfigView() {
|
||||
val data = ACache.get().getAsJSONObject("remoteServerConfig")
|
||||
serverUi.forEachIndexed { index, rowUi ->
|
||||
when (rowUi.type) {
|
||||
RowUi.Type.text -> ItemSourceEditBinding.inflate(
|
||||
layoutInflater,
|
||||
binding.root,
|
||||
false
|
||||
).let {
|
||||
binding.flexbox.addView(it.root)
|
||||
it.root.id = index + 1000
|
||||
it.textInputLayout.hint = rowUi.name
|
||||
it.editText.setText(data?.getString(rowUi.name))
|
||||
}
|
||||
RowUi.Type.password -> ItemSourceEditBinding.inflate(
|
||||
layoutInflater,
|
||||
binding.root,
|
||||
false
|
||||
).let {
|
||||
binding.flexbox.addView(it.root)
|
||||
it.root.id = index + 1000
|
||||
it.textInputLayout.hint = rowUi.name
|
||||
it.editText.inputType =
|
||||
InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT
|
||||
it.editText.setText(data?.getString(rowUi.name))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getConfigData(): Map<String, String> {
|
||||
val data = hashMapOf<String, String>()
|
||||
serverUi.forEachIndexed { index, rowUi ->
|
||||
val rowView = binding.root.findViewById<View>(index + 1000)
|
||||
ItemSourceEditBinding.bind(rowView).editText.text?.let {
|
||||
data[rowUi.name] = it.toString()
|
||||
}
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
}
|
||||
@@ -45,24 +45,35 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) {
|
||||
val loginUi = source.loginUi()
|
||||
loginUi?.forEachIndexed { index, rowUi ->
|
||||
when (rowUi.type) {
|
||||
"text" -> ItemSourceEditBinding.inflate(layoutInflater, binding.root, false).let {
|
||||
RowUi.Type.text -> ItemSourceEditBinding.inflate(
|
||||
layoutInflater,
|
||||
binding.root,
|
||||
false
|
||||
).let {
|
||||
binding.flexbox.addView(it.root)
|
||||
it.root.id = index
|
||||
it.root.id = index + 1000
|
||||
it.textInputLayout.hint = rowUi.name
|
||||
it.editText.setText(loginInfo?.get(rowUi.name))
|
||||
}
|
||||
"password" -> ItemSourceEditBinding.inflate(layoutInflater, binding.root, false)
|
||||
.let {
|
||||
binding.flexbox.addView(it.root)
|
||||
it.root.id = index
|
||||
it.textInputLayout.hint = rowUi.name
|
||||
it.editText.inputType =
|
||||
InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT
|
||||
it.editText.setText(loginInfo?.get(rowUi.name))
|
||||
}
|
||||
"button" -> ItemFilletTextBinding.inflate(layoutInflater, binding.root, false).let {
|
||||
RowUi.Type.password -> ItemSourceEditBinding.inflate(
|
||||
layoutInflater,
|
||||
binding.root,
|
||||
false
|
||||
).let {
|
||||
binding.flexbox.addView(it.root)
|
||||
it.root.id = index
|
||||
it.root.id = index + 1000
|
||||
it.textInputLayout.hint = rowUi.name
|
||||
it.editText.inputType =
|
||||
InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT
|
||||
it.editText.setText(loginInfo?.get(rowUi.name))
|
||||
}
|
||||
RowUi.Type.button -> ItemFilletTextBinding.inflate(
|
||||
layoutInflater,
|
||||
binding.root,
|
||||
false
|
||||
).let {
|
||||
binding.flexbox.addView(it.root)
|
||||
it.root.id = index + 1000
|
||||
it.textView.text = rowUi.name
|
||||
it.textView.setPadding(16.dpToPx())
|
||||
it.root.onClick {
|
||||
@@ -77,8 +88,11 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) {
|
||||
put("result", getLoginData(loginUi))
|
||||
}
|
||||
}
|
||||
}.onFailure {
|
||||
AppLog.put("LoginUI Button ${rowUi.name} JavaScript error", it)
|
||||
}.onFailure { e ->
|
||||
AppLog.put(
|
||||
"LoginUI Button ${rowUi.name} JavaScript error",
|
||||
e
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,7 +126,7 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) {
|
||||
loginUi?.forEachIndexed { index, rowUi ->
|
||||
when (rowUi.type) {
|
||||
"text", "password" -> {
|
||||
val rowView = binding.root.findViewById<View>(index)
|
||||
val rowView = binding.root.findViewById<View>(index + 1000)
|
||||
ItemSourceEditBinding.bind(rowView).editText.text?.let {
|
||||
loginData[rowUi.name] = it.toString()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user