mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
远程书籍单独配置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()
|
||||
}
|
||||
|
||||
51
app/src/main/res/layout/dialog_webdav_server.xml
Normal file
51
app/src/main/res/layout/dialog_webdav_server.xml
Normal file
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="16dp">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/vw_bg"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:background="@drawable/shape_card_view"
|
||||
android:orientation="vertical"
|
||||
tools:ignore="UselessParent">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/tool_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/background_menu"
|
||||
android:elevation="5dp"
|
||||
android:theme="?attr/actionBarStyle"
|
||||
app:title="@string/server_config"
|
||||
app:displayHomeAsUp="false"
|
||||
app:fitStatusBar="false"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay"
|
||||
app:titleTextAppearance="@style/ToolbarTitle" />
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:overScrollMode="ifContentScrolls">
|
||||
|
||||
<com.google.android.flexbox.FlexboxLayout
|
||||
android:id="@+id/flexbox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:clipToPadding="false"
|
||||
android:padding="3dp"
|
||||
app:dividerDrawable="@drawable/shape_space_divider"
|
||||
app:flexDirection="row"
|
||||
app:flexWrap="wrap"
|
||||
app:showDivider="middle" />
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
11
app/src/main/res/menu/server_config.xml
Normal file
11
app/src/main/res/menu/server_config.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_save"
|
||||
android:icon="@drawable/ic_save"
|
||||
android:title="@string/action_save"
|
||||
app:showAsAction="always" />
|
||||
|
||||
</menu>
|
||||
Reference in New Issue
Block a user