pull/36/head
kunfei 5 years ago
parent 91e3ae3c5d
commit 5c3d50657a
  1. 3
      app/src/main/java/io/legado/app/data/entities/EditEntity.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt
  3. 5
      app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditAdapter.kt
  4. 1
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  5. 85
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditAdapter.kt
  6. 4
      app/src/main/res/layout/activity_rss_source_edit.xml

@ -0,0 +1,3 @@
package io.legado.app.data.entities
data class EditEntity(var key: String, var value: String?, var hint: Int)

@ -19,6 +19,7 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.EditEntity
import io.legado.app.data.entities.rule.* import io.legado.app.data.entities.rule.*
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.ui.book.source.debug.SourceDebugActivity import io.legado.app.ui.book.source.debug.SourceDebugActivity
@ -618,5 +619,4 @@ class SourceEditActivity :
} }
} }
class EditEntity(var key: String, var value: String?, var hint: Int)
} }

@ -7,11 +7,12 @@ import android.view.View
import android.view.ViewGroup 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.data.entities.EditEntity
import kotlinx.android.synthetic.main.item_source_edit.view.* import kotlinx.android.synthetic.main.item_source_edit.view.*
class SourceEditAdapter : RecyclerView.Adapter<SourceEditAdapter.MyViewHolder>() { class SourceEditAdapter : RecyclerView.Adapter<SourceEditAdapter.MyViewHolder>() {
var editEntities: ArrayList<SourceEditActivity.EditEntity> = ArrayList() var editEntities: ArrayList<EditEntity> = ArrayList()
set(value) { set(value) {
field = value field = value
notifyDataSetChanged() notifyDataSetChanged()
@ -34,7 +35,7 @@ class SourceEditAdapter : RecyclerView.Adapter<SourceEditAdapter.MyViewHolder>()
} }
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(editEntity: SourceEditActivity.EditEntity) = with(itemView) { fun bind(editEntity: EditEntity) = with(itemView) {
if (editText.getTag(R.id.tag1) == null) { if (editText.getTag(R.id.tag1) == null) {
val listener = object : View.OnAttachStateChangeListener { val listener = object : View.OnAttachStateChangeListener {
override fun onViewAttachedToWindow(v: View) { override fun onViewAttachedToWindow(v: View) {

@ -0,0 +1,85 @@
package io.legado.app.ui.rss.source.edit
import android.text.Editable
import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.data.entities.EditEntity
import kotlinx.android.synthetic.main.item_source_edit.view.*
class RssSourceEditAdapter : RecyclerView.Adapter<RssSourceEditAdapter.MyViewHolder>() {
var editEntities: ArrayList<EditEntity> = ArrayList()
set(value) {
field = value
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
return MyViewHolder(
LayoutInflater.from(
parent.context
).inflate(R.layout.item_source_edit, parent, false)
)
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
holder.bind(editEntities[position])
}
override fun getItemCount(): Int {
return editEntities.size
}
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(editEntity: EditEntity) = with(itemView) {
if (editText.getTag(R.id.tag1) == null) {
val listener = object : View.OnAttachStateChangeListener {
override fun onViewAttachedToWindow(v: View) {
editText.isCursorVisible = false
editText.isCursorVisible = true
editText.isFocusable = true
editText.isFocusableInTouchMode = true
}
override fun onViewDetachedFromWindow(v: View) {
}
}
editText.addOnAttachStateChangeListener(listener)
editText.setTag(R.id.tag1, listener)
}
editText.getTag(R.id.tag2)?.let {
if (it is TextWatcher) {
editText.removeTextChangedListener(it)
}
}
editText.setText(editEntity.value)
textInputLayout.hint = context.getString(editEntity.hint)
val textWatcher = object : TextWatcher {
override fun beforeTextChanged(
s: CharSequence,
start: Int,
count: Int,
after: Int
) {
}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
}
override fun afterTextChanged(s: Editable?) {
editEntity.value = (s?.toString())
}
}
editText.addTextChangedListener(textWatcher)
editText.setTag(R.id.tag2, textWatcher)
}
}
}

@ -13,5 +13,9 @@
app:displayHomeAsUp="true" app:displayHomeAsUp="true"
app:title="@string/rss_source_edit" /> app:title="@string/rss_source_edit" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout> </LinearLayout>
Loading…
Cancel
Save