优化
This commit is contained in:
@@ -195,8 +195,6 @@ class RssSourceEditActivity :
|
||||
binding.cbIsEnable.isChecked = rs.enabled
|
||||
binding.cbSingleUrl.isChecked = rs.singleUrl
|
||||
binding.cbIsEnableCookie.isChecked = rs.enabledCookieJar == true
|
||||
binding.cbEnableJs.isChecked = rs.enableJs
|
||||
binding.cbEnableBaseUrl.isChecked = rs.loadWithBaseUrl
|
||||
}
|
||||
sourceEntities.clear()
|
||||
sourceEntities.apply {
|
||||
@@ -226,6 +224,22 @@ class RssSourceEditActivity :
|
||||
}
|
||||
webViewEntities.clear()
|
||||
webViewEntities.apply {
|
||||
add(
|
||||
EditEntity(
|
||||
"enableJs",
|
||||
rs?.enableJs.toString(),
|
||||
R.string.enable_js,
|
||||
EditEntity.ViewType.checkBox
|
||||
)
|
||||
)
|
||||
add(
|
||||
EditEntity(
|
||||
"loadWithBaseUrl",
|
||||
rs?.loadWithBaseUrl.toString(),
|
||||
R.string.load_with_base_url,
|
||||
EditEntity.ViewType.checkBox
|
||||
)
|
||||
)
|
||||
add(EditEntity("ruleContent", rs?.ruleContent, R.string.r_content))
|
||||
add(EditEntity("style", rs?.style, R.string.r_style))
|
||||
add(EditEntity("injectJs", rs?.injectJs, R.string.r_inject_js))
|
||||
@@ -241,8 +255,6 @@ class RssSourceEditActivity :
|
||||
source.enabled = binding.cbIsEnable.isChecked
|
||||
source.singleUrl = binding.cbSingleUrl.isChecked
|
||||
source.enabledCookieJar = binding.cbIsEnableCookie.isChecked
|
||||
source.enableJs = binding.cbEnableJs.isChecked
|
||||
source.loadWithBaseUrl = binding.cbEnableBaseUrl.isChecked
|
||||
sourceEntities.forEach {
|
||||
when (it.key) {
|
||||
"sourceName" -> source.sourceName = it.value ?: ""
|
||||
@@ -279,6 +291,8 @@ class RssSourceEditActivity :
|
||||
}
|
||||
webViewEntities.forEach {
|
||||
when (it.key) {
|
||||
"enableJs" -> source.enableJs = it.value.isTrue()
|
||||
"loadWithBaseUrl" -> source.loadWithBaseUrl = it.value.isTrue()
|
||||
"ruleContent" -> source.ruleContent =
|
||||
viewModel.ruleComplete(it.value, source.ruleArticles)
|
||||
"style" -> source.style = it.value
|
||||
|
||||
@@ -9,13 +9,15 @@ import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.legado.app.R
|
||||
import io.legado.app.databinding.ItemSourceEditBinding
|
||||
import io.legado.app.databinding.ItemSourceEditCheckBoxBinding
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.ui.widget.code.addJsPattern
|
||||
import io.legado.app.ui.widget.code.addJsonPattern
|
||||
import io.legado.app.ui.widget.code.addLegadoPattern
|
||||
import io.legado.app.ui.widget.text.EditEntity
|
||||
import io.legado.app.utils.isTrue
|
||||
|
||||
class RssSourceEditAdapter : RecyclerView.Adapter<RssSourceEditAdapter.MyViewHolder>() {
|
||||
class RssSourceEditAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
|
||||
val editEntityMaxLine = AppConfig.sourceEditMaxLine
|
||||
|
||||
@@ -26,24 +28,41 @@ class RssSourceEditAdapter : RecyclerView.Adapter<RssSourceEditAdapter.MyViewHol
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
|
||||
val binding = ItemSourceEditBinding
|
||||
.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
binding.editText.addLegadoPattern()
|
||||
binding.editText.addJsonPattern()
|
||||
binding.editText.addJsPattern()
|
||||
return MyViewHolder(binding)
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
val item = editEntities[position]
|
||||
return item.viewType
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
|
||||
holder.bind(editEntities[position])
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
return when (viewType) {
|
||||
EditEntity.ViewType.checkBox -> {
|
||||
val binding = ItemSourceEditCheckBoxBinding
|
||||
.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
CheckBoxViewHolder(binding)
|
||||
}
|
||||
else -> {
|
||||
val binding = ItemSourceEditBinding
|
||||
.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
binding.editText.addLegadoPattern()
|
||||
binding.editText.addJsonPattern()
|
||||
binding.editText.addJsPattern()
|
||||
EditTextViewHolder(binding)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
when (holder) {
|
||||
is CheckBoxViewHolder -> holder.bind(editEntities[position])
|
||||
is EditTextViewHolder -> holder.bind(editEntities[position])
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return editEntities.size
|
||||
}
|
||||
|
||||
inner class MyViewHolder(val binding: ItemSourceEditBinding) :
|
||||
inner class EditTextViewHolder(val binding: ItemSourceEditBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(editEntity: EditEntity) = binding.run {
|
||||
@@ -94,4 +113,20 @@ class RssSourceEditAdapter : RecyclerView.Adapter<RssSourceEditAdapter.MyViewHol
|
||||
}
|
||||
}
|
||||
|
||||
inner class CheckBoxViewHolder(val binding: ItemSourceEditCheckBoxBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(editEntity: EditEntity) = binding.run {
|
||||
checkBox.setOnCheckedChangeListener(null)
|
||||
checkBox.text = editEntity.hint
|
||||
checkBox.isChecked = editEntity.value.isTrue()
|
||||
checkBox.setOnCheckedChangeListener { _, isChecked ->
|
||||
editEntity.value = isChecked.toString()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,13 +5,27 @@ import splitties.init.appCtx
|
||||
data class EditEntity(
|
||||
var key: String,
|
||||
var value: String?,
|
||||
var hint: String
|
||||
var hint: String,
|
||||
val viewType: Int = 0
|
||||
) {
|
||||
|
||||
constructor(
|
||||
key: String,
|
||||
value: String?,
|
||||
hint: Int
|
||||
) : this(key, value, appCtx.getString(hint))
|
||||
hint: Int,
|
||||
viewType: Int = 0
|
||||
) : this(
|
||||
key,
|
||||
value,
|
||||
appCtx.getString(hint),
|
||||
viewType
|
||||
)
|
||||
|
||||
@Suppress("unused")
|
||||
object ViewType {
|
||||
|
||||
const val checkBox = 1
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user