|
|
|
@ -1,10 +1,13 @@ |
|
|
|
|
package io.legado.app.ui.sourceedit |
|
|
|
|
|
|
|
|
|
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 kotlinx.android.synthetic.main.item_source_edit.view.* |
|
|
|
|
|
|
|
|
|
class SourceEditAdapter : RecyclerView.Adapter<SourceEditAdapter.MyViewHolder>() { |
|
|
|
|
|
|
|
|
@ -15,7 +18,7 @@ class SourceEditAdapter : RecyclerView.Adapter<SourceEditAdapter.MyViewHolder>() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { |
|
|
|
|
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. |
|
|
|
|
holder.bind(sourceEditEntities[position]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun getItemCount(): Int { |
|
|
|
@ -23,12 +26,51 @@ class SourceEditAdapter : RecyclerView.Adapter<SourceEditAdapter.MyViewHolder>() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { |
|
|
|
|
fun bind(sourceEditEntity: SourceEditEntity) = 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(sourceEditEntity.value) |
|
|
|
|
sourceEditEntity.hint?.let { textInputLayout.hint = context.getString(it) } |
|
|
|
|
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?) { |
|
|
|
|
sourceEditEntity.value=(s?.toString()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
editText.addTextChangedListener(textWatcher) |
|
|
|
|
editText.setTag(R.id.tag2, textWatcher) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class SourceEditEntity { |
|
|
|
|
var key:String?=null |
|
|
|
|
var value:String?=null |
|
|
|
|
var hint:String?=null |
|
|
|
|
var hint:Int?=null |
|
|
|
|
} |
|
|
|
|
} |