Commit 6124010d by Paktalin

Moved ViewHolder methods to ViewHolder class

parent 30c66e6d
package com.paktalin.vocabularynotebook package com.paktalin.vocabularynotebook
import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.view.View import android.view.View
import android.widget.EditText import android.widget.EditText
import android.widget.ImageButton import android.widget.ImageButton
...@@ -11,4 +14,34 @@ class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { ...@@ -11,4 +14,34 @@ class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val etTranslation: EditText = itemView.findViewById(R.id.etTranslation) val etTranslation: EditText = itemView.findViewById(R.id.etTranslation)
val btnPopupMenu: ImageButton = itemView.findViewById(R.id.btnContextMenu) val btnPopupMenu: ImageButton = itemView.findViewById(R.id.btnContextMenu)
val layout: LinearLayout = itemView.findViewById(R.id.tableLayout) val layout: LinearLayout = itemView.findViewById(R.id.tableLayout)
fun showEmptyItem() {
btnPopupMenu.isClickable = false
btnPopupMenu.visibility = View.INVISIBLE
Utils.setEmptyEditText(etWord, "new word")
Utils.setEmptyEditText(etTranslation, "translation")
etWord.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { }
override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { }
override fun afterTextChanged(editable: Editable) {
if (!etWord.text.isEmpty()) showCancelButton() }
})
this.etTranslation.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { }
override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { }
override fun afterTextChanged(editable: Editable) {
if (!etTranslation.text.isEmpty()) showCancelButton() }
})
}
private fun showCancelButton() {
Log.d(TAG, "empty word is focused")
btnPopupMenu.setImageResource(R.drawable.ic_cancel_icon)
btnPopupMenu.visibility = View.VISIBLE
//todo add button click listener
}
companion object { private val TAG = "VN/" + ViewHolder::class.java.simpleName }
} }
\ No newline at end of file
...@@ -4,9 +4,6 @@ import android.app.Activity ...@@ -4,9 +4,6 @@ import android.app.Activity
import android.content.Intent import android.content.Intent
import android.support.v7.widget.PopupMenu import android.support.v7.widget.PopupMenu
import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.view.* import android.view.*
import com.paktalin.vocabularynotebook.activities.WordItemInfoActivity import com.paktalin.vocabularynotebook.activities.WordItemInfoActivity
...@@ -26,7 +23,7 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va ...@@ -26,7 +23,7 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
} }
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
if (position == 0) showEmptyItem(holder) if (position == 0) holder.showEmptyItem()
else { else {
val wordItem = wordItems[position] val wordItem = wordItems[position]
holder.etWord.setText(wordItem.pojo!!.word) holder.etWord.setText(wordItem.pojo!!.word)
...@@ -68,32 +65,6 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va ...@@ -68,32 +65,6 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
this.notifyItemRangeChanged(position, wordItems.size) this.notifyItemRangeChanged(position, wordItems.size)
} }
private fun showEmptyItem(holder: ViewHolder) {
holder.btnPopupMenu.isClickable = false
holder.btnPopupMenu.visibility = View.INVISIBLE
Utils.setEmptyEditText(holder.etWord, "new word")
Utils.setEmptyEditText(holder.etTranslation, "translation")
holder.etWord.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { }
override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { }
override fun afterTextChanged(editable: Editable) {
if (!holder.etWord.text.isEmpty()) showCancelButton(holder) }
})
holder.etTranslation.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { }
override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { }
override fun afterTextChanged(editable: Editable) {
if (!holder.etTranslation.text.isEmpty()) showCancelButton(holder) }
})
}
private fun showCancelButton(holder: ViewHolder) {
Log.d(TAG, "empty word is focused")
holder.btnPopupMenu.setImageResource(R.drawable.ic_cancel_icon)
holder.btnPopupMenu.visibility = View.VISIBLE
}
companion object { private val TAG = "VN/" + VocabularyAdapter::class.java.simpleName } companion object { private val TAG = "VN/" + VocabularyAdapter::class.java.simpleName }
init { wordItems.add(0, WordItem.createEmpty()) } init { wordItems.add(0, WordItem.createEmpty()) }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment