优化
This commit is contained in:
@@ -195,8 +195,6 @@ class RssSourceEditActivity :
|
|||||||
binding.cbIsEnable.isChecked = rs.enabled
|
binding.cbIsEnable.isChecked = rs.enabled
|
||||||
binding.cbSingleUrl.isChecked = rs.singleUrl
|
binding.cbSingleUrl.isChecked = rs.singleUrl
|
||||||
binding.cbIsEnableCookie.isChecked = rs.enabledCookieJar == true
|
binding.cbIsEnableCookie.isChecked = rs.enabledCookieJar == true
|
||||||
binding.cbEnableJs.isChecked = rs.enableJs
|
|
||||||
binding.cbEnableBaseUrl.isChecked = rs.loadWithBaseUrl
|
|
||||||
}
|
}
|
||||||
sourceEntities.clear()
|
sourceEntities.clear()
|
||||||
sourceEntities.apply {
|
sourceEntities.apply {
|
||||||
@@ -226,6 +224,22 @@ class RssSourceEditActivity :
|
|||||||
}
|
}
|
||||||
webViewEntities.clear()
|
webViewEntities.clear()
|
||||||
webViewEntities.apply {
|
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("ruleContent", rs?.ruleContent, R.string.r_content))
|
||||||
add(EditEntity("style", rs?.style, R.string.r_style))
|
add(EditEntity("style", rs?.style, R.string.r_style))
|
||||||
add(EditEntity("injectJs", rs?.injectJs, R.string.r_inject_js))
|
add(EditEntity("injectJs", rs?.injectJs, R.string.r_inject_js))
|
||||||
@@ -241,8 +255,6 @@ class RssSourceEditActivity :
|
|||||||
source.enabled = binding.cbIsEnable.isChecked
|
source.enabled = binding.cbIsEnable.isChecked
|
||||||
source.singleUrl = binding.cbSingleUrl.isChecked
|
source.singleUrl = binding.cbSingleUrl.isChecked
|
||||||
source.enabledCookieJar = binding.cbIsEnableCookie.isChecked
|
source.enabledCookieJar = binding.cbIsEnableCookie.isChecked
|
||||||
source.enableJs = binding.cbEnableJs.isChecked
|
|
||||||
source.loadWithBaseUrl = binding.cbEnableBaseUrl.isChecked
|
|
||||||
sourceEntities.forEach {
|
sourceEntities.forEach {
|
||||||
when (it.key) {
|
when (it.key) {
|
||||||
"sourceName" -> source.sourceName = it.value ?: ""
|
"sourceName" -> source.sourceName = it.value ?: ""
|
||||||
@@ -279,6 +291,8 @@ class RssSourceEditActivity :
|
|||||||
}
|
}
|
||||||
webViewEntities.forEach {
|
webViewEntities.forEach {
|
||||||
when (it.key) {
|
when (it.key) {
|
||||||
|
"enableJs" -> source.enableJs = it.value.isTrue()
|
||||||
|
"loadWithBaseUrl" -> source.loadWithBaseUrl = it.value.isTrue()
|
||||||
"ruleContent" -> source.ruleContent =
|
"ruleContent" -> source.ruleContent =
|
||||||
viewModel.ruleComplete(it.value, source.ruleArticles)
|
viewModel.ruleComplete(it.value, source.ruleArticles)
|
||||||
"style" -> source.style = it.value
|
"style" -> source.style = it.value
|
||||||
|
|||||||
@@ -9,13 +9,15 @@ import android.view.ViewGroup
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.databinding.ItemSourceEditBinding
|
import io.legado.app.databinding.ItemSourceEditBinding
|
||||||
|
import io.legado.app.databinding.ItemSourceEditCheckBoxBinding
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
import io.legado.app.ui.widget.code.addJsPattern
|
import io.legado.app.ui.widget.code.addJsPattern
|
||||||
import io.legado.app.ui.widget.code.addJsonPattern
|
import io.legado.app.ui.widget.code.addJsonPattern
|
||||||
import io.legado.app.ui.widget.code.addLegadoPattern
|
import io.legado.app.ui.widget.code.addLegadoPattern
|
||||||
import io.legado.app.ui.widget.text.EditEntity
|
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
|
val editEntityMaxLine = AppConfig.sourceEditMaxLine
|
||||||
|
|
||||||
@@ -26,24 +28,41 @@ class RssSourceEditAdapter : RecyclerView.Adapter<RssSourceEditAdapter.MyViewHol
|
|||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
|
override fun getItemViewType(position: Int): Int {
|
||||||
val binding = ItemSourceEditBinding
|
val item = editEntities[position]
|
||||||
.inflate(LayoutInflater.from(parent.context), parent, false)
|
return item.viewType
|
||||||
binding.editText.addLegadoPattern()
|
|
||||||
binding.editText.addJsonPattern()
|
|
||||||
binding.editText.addJsPattern()
|
|
||||||
return MyViewHolder(binding)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||||
holder.bind(editEntities[position])
|
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 {
|
override fun getItemCount(): Int {
|
||||||
return editEntities.size
|
return editEntities.size
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class MyViewHolder(val binding: ItemSourceEditBinding) :
|
inner class EditTextViewHolder(val binding: ItemSourceEditBinding) :
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
|
|
||||||
fun bind(editEntity: EditEntity) = binding.run {
|
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(
|
data class EditEntity(
|
||||||
var key: String,
|
var key: String,
|
||||||
var value: String?,
|
var value: String?,
|
||||||
var hint: String
|
var hint: String,
|
||||||
|
val viewType: Int = 0
|
||||||
) {
|
) {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
key: String,
|
key: String,
|
||||||
value: String?,
|
value: String?,
|
||||||
hint: Int
|
hint: Int,
|
||||||
) : this(key, value, appCtx.getString(hint))
|
viewType: Int = 0
|
||||||
|
) : this(
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
appCtx.getString(hint),
|
||||||
|
viewType
|
||||||
|
)
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
object ViewType {
|
||||||
|
|
||||||
|
const val checkBox = 1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,8 @@
|
|||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:paddingHorizontal="8dp">
|
android:paddingHorizontal="8dp"
|
||||||
|
tools:ignore="VisualLintBounds">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
@@ -15,77 +15,46 @@
|
|||||||
app:fitStatusBar="false"
|
app:fitStatusBar="false"
|
||||||
app:title="@string/rss_source_edit" />
|
app:title="@string/rss_source_edit" />
|
||||||
|
|
||||||
<LinearLayout
|
<HorizontalScrollView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingLeft="12dp"
|
android:scrollbars="none">
|
||||||
android:paddingRight="12dp"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_gravity="center_vertical">
|
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="source:"
|
android:layout_gravity="center_vertical"
|
||||||
tools:ignore="HardcodedText,RtlHardcoded" />
|
android:orientation="horizontal"
|
||||||
|
android:paddingHorizontal="8dp"
|
||||||
|
tools:ignore="VisualLintBounds">
|
||||||
|
|
||||||
<io.legado.app.lib.theme.view.ThemeCheckBox
|
<io.legado.app.lib.theme.view.ThemeCheckBox
|
||||||
android:id="@+id/cb_is_enable"
|
android:id="@+id/cb_is_enable"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:checked="true"
|
android:checked="true"
|
||||||
android:text="@string/is_enable"
|
android:text="@string/is_enable"
|
||||||
tools:ignore="TouchTargetSizeCheck" />
|
tools:ignore="TouchTargetSizeCheck" />
|
||||||
|
|
||||||
<io.legado.app.lib.theme.view.ThemeCheckBox
|
<io.legado.app.lib.theme.view.ThemeCheckBox
|
||||||
android:id="@+id/cb_single_url"
|
android:id="@+id/cb_single_url"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:checked="false"
|
android:checked="false"
|
||||||
android:text="@string/single_url"
|
android:text="@string/single_url"
|
||||||
tools:ignore="TouchTargetSizeCheck" />
|
tools:ignore="TouchTargetSizeCheck" />
|
||||||
|
|
||||||
<io.legado.app.lib.theme.view.ThemeCheckBox
|
<io.legado.app.lib.theme.view.ThemeCheckBox
|
||||||
android:id="@+id/cb_is_enable_cookie"
|
android:id="@+id/cb_is_enable_cookie"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:checked="true"
|
android:checked="true"
|
||||||
android:text="@string/auto_save_cookie"
|
android:text="@string/auto_save_cookie"
|
||||||
tools:ignore="TouchTargetSizeCheck" />
|
tools:ignore="TouchTargetSizeCheck" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
</HorizontalScrollView>
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingLeft="12dp"
|
|
||||||
android:paddingRight="12dp"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_gravity="center_vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="WebView:"
|
|
||||||
tools:ignore="HardcodedText,RtlHardcoded" />
|
|
||||||
|
|
||||||
<io.legado.app.lib.theme.view.ThemeCheckBox
|
|
||||||
android:id="@+id/cb_enable_js"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:checked="false"
|
|
||||||
android:text="@string/enable_js"
|
|
||||||
tools:ignore="TouchTargetSizeCheck" />
|
|
||||||
|
|
||||||
<io.legado.app.lib.theme.view.ThemeCheckBox
|
|
||||||
android:id="@+id/cb_enable_base_url"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:checked="false"
|
|
||||||
android:text="@string/load_with_base_url"
|
|
||||||
tools:ignore="TouchTargetSizeCheck" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<com.google.android.material.tabs.TabLayout
|
<com.google.android.material.tabs.TabLayout
|
||||||
android:id="@+id/tab_layout"
|
android:id="@+id/tab_layout"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
@@ -9,6 +10,7 @@
|
|||||||
<io.legado.app.lib.theme.view.ThemeCheckBox
|
<io.legado.app.lib.theme.view.ThemeCheckBox
|
||||||
android:id="@+id/check_box"
|
android:id="@+id/check_box"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content"
|
||||||
|
tools:ignore="TouchTargetSizeCheck" />
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<io.legado.app.ui.widget.text.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<io.legado.app.ui.widget.text.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/textInputLayout"
|
android:id="@+id/textInputLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -9,6 +10,7 @@
|
|||||||
android:id="@+id/editText"
|
android:id="@+id/editText"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:inputType="textMultiLine" />
|
android:inputType="textMultiLine"
|
||||||
|
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
|
||||||
|
|
||||||
</io.legado.app.ui.widget.text.TextInputLayout>
|
</io.legado.app.ui.widget.text.TextInputLayout>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/root_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="3dp">
|
||||||
|
|
||||||
|
<io.legado.app.lib.theme.view.ThemeCheckBox
|
||||||
|
android:id="@+id/check_box"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingVertical="3dp"/>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="@color/secondaryText"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user