Commit 30c66e6d by Paktalin

Shows cancel button when text is entered to empty fields

parent 839416e6
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
<option name="values"> <option name="values">
<map> <map>
<entry key="assetSourceType" value="FILE" /> <entry key="assetSourceType" value="FILE" />
<entry key="outputName" value="ic_edit_icon" /> <entry key="outputName" value="ic_cancel_icon" />
<entry key="sourceFile" value="C:\Users\litak\Desktop\edit_icon.svg" /> <entry key="sourceFile" value="C:\Users\litak\Desktop\cancel_icon.svg" />
</map> </map>
</option> </option>
</PersistentState> </PersistentState>
......
package com.paktalin.vocabularynotebook
import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.EditText
import android.widget.ImageButton
import android.widget.LinearLayout
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val etWord: EditText = itemView.findViewById(R.id.etWord)
val etTranslation: EditText = itemView.findViewById(R.id.etTranslation)
val btnPopupMenu: ImageButton = itemView.findViewById(R.id.btnContextMenu)
val layout: LinearLayout = itemView.findViewById(R.id.tableLayout)
}
\ No newline at end of file
...@@ -2,20 +2,15 @@ package com.paktalin.vocabularynotebook ...@@ -2,20 +2,15 @@ package com.paktalin.vocabularynotebook
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Build
import android.support.constraint.ConstraintLayout
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.Editable
import android.text.TextWatcher
import android.util.Log import android.util.Log
import android.view.LayoutInflater import android.view.*
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.*
import com.paktalin.vocabularynotebook.activities.WordItemInfoActivity import com.paktalin.vocabularynotebook.activities.WordItemInfoActivity
class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private val context: Activity) : RecyclerView.Adapter<VocabularyAdapter.ViewHolder>() { class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private val context: Activity) : RecyclerView.Adapter<ViewHolder>() {
private lateinit var recyclerView: RecyclerView private lateinit var recyclerView: RecyclerView
...@@ -49,13 +44,6 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va ...@@ -49,13 +44,6 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
return wordItems.size return wordItems.size
} }
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val etWord: EditText = itemView.findViewById(R.id.etWord)
val etTranslation: EditText = itemView.findViewById(R.id.etTranslation)
val btnPopupMenu: ImageButton = itemView.findViewById(R.id.btnContextMenu)
val layout: LinearLayout = itemView.findViewById(R.id.tableLayout)
}
private fun openWordItemInfo(wordItem: WordItem) { private fun openWordItemInfo(wordItem: WordItem) {
val intentWordItemInfo = Intent(context, WordItemInfoActivity::class.java) val intentWordItemInfo = Intent(context, WordItemInfoActivity::class.java)
intentWordItemInfo.putExtra("wordItem", wordItem) intentWordItemInfo.putExtra("wordItem", wordItem)
...@@ -85,16 +73,25 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va ...@@ -85,16 +73,25 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
holder.btnPopupMenu.visibility = View.INVISIBLE holder.btnPopupMenu.visibility = View.INVISIBLE
Utils.setEmptyEditText(holder.etWord, "new word") Utils.setEmptyEditText(holder.etWord, "new word")
Utils.setEmptyEditText(holder.etTranslation, "translation") Utils.setEmptyEditText(holder.etTranslation, "translation")
holder.etWord.setOnFocusChangeListener({ _, focus ->
if (focus) showCancelButton() 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.setOnFocusChangeListener({ _, focus -> holder.etTranslation.addTextChangedListener(object : TextWatcher {
if (focus) showCancelButton() 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() { private fun showCancelButton(holder: ViewHolder) {
Log.d(TAG, "empty word is focused") 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 }
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2zM17,15.59L15.59,17 12,13.41 8.41,17 7,15.59 10.59,12 7,8.41 8.41,7 12,10.59 15.59,7 17,8.41 13.41,12 17,15.59z"/>
</vector>
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