mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,8 @@
|
||||
android:layout_gravity="center_vertical"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="8dp">
|
||||
android:paddingHorizontal="8dp"
|
||||
tools:ignore="VisualLintBounds">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -15,77 +15,46 @@
|
||||
app:fitStatusBar="false"
|
||||
app:title="@string/rss_source_edit" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
<HorizontalScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="12dp"
|
||||
android:paddingRight="12dp"
|
||||
android:orientation="horizontal"
|
||||
android:layout_gravity="center_vertical">
|
||||
android:scrollbars="none">
|
||||
|
||||
<TextView
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="source:"
|
||||
tools:ignore="HardcodedText,RtlHardcoded" />
|
||||
android:layout_gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="8dp"
|
||||
tools:ignore="VisualLintBounds">
|
||||
|
||||
<io.legado.app.lib.theme.view.ThemeCheckBox
|
||||
android:id="@+id/cb_is_enable"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:text="@string/is_enable"
|
||||
tools:ignore="TouchTargetSizeCheck" />
|
||||
<io.legado.app.lib.theme.view.ThemeCheckBox
|
||||
android:id="@+id/cb_is_enable"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:text="@string/is_enable"
|
||||
tools:ignore="TouchTargetSizeCheck" />
|
||||
|
||||
<io.legado.app.lib.theme.view.ThemeCheckBox
|
||||
android:id="@+id/cb_single_url"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="false"
|
||||
android:text="@string/single_url"
|
||||
tools:ignore="TouchTargetSizeCheck" />
|
||||
<io.legado.app.lib.theme.view.ThemeCheckBox
|
||||
android:id="@+id/cb_single_url"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="false"
|
||||
android:text="@string/single_url"
|
||||
tools:ignore="TouchTargetSizeCheck" />
|
||||
|
||||
<io.legado.app.lib.theme.view.ThemeCheckBox
|
||||
android:id="@+id/cb_is_enable_cookie"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:text="@string/auto_save_cookie"
|
||||
tools:ignore="TouchTargetSizeCheck" />
|
||||
<io.legado.app.lib.theme.view.ThemeCheckBox
|
||||
android:id="@+id/cb_is_enable_cookie"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:text="@string/auto_save_cookie"
|
||||
tools:ignore="TouchTargetSizeCheck" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
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>
|
||||
</HorizontalScrollView>
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tab_layout"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
@@ -9,6 +10,7 @@
|
||||
<io.legado.app.lib.theme.view.ThemeCheckBox
|
||||
android:id="@+id/check_box"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
tools:ignore="TouchTargetSizeCheck" />
|
||||
|
||||
</FrameLayout>
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -9,6 +10,7 @@
|
||||
android:id="@+id/editText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textMultiLine" />
|
||||
android:inputType="textMultiLine"
|
||||
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
|
||||
|
||||
</io.legado.app.ui.widget.text.TextInputLayout>
|
||||
20
app/src/main/res/layout/item_source_edit_check_box.xml
Normal file
20
app/src/main/res/layout/item_source_edit_check_box.xml
Normal file
@@ -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