Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
likorn
/
vocabulary_notebook
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
30c66e6d
authored
Sep 08, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Shows cancel button when text is entered to empty fields
parent
839416e6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
22 deletions
.idea/assetWizardSettings.xml
app/src/main/java/com/paktalin/vocabularynotebook/ViewHolder.kt
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/res/drawable/ic_cancel_icon.xml
.idea/assetWizardSettings.xml
View file @
30c66e6d
...
...
@@ -14,8 +14,8 @@
<option
name=
"values"
>
<map>
<entry
key=
"assetSourceType"
value=
"FILE"
/>
<entry
key=
"outputName"
value=
"ic_
edit
_icon"
/>
<entry
key=
"sourceFile"
value=
"C:\Users\litak\Desktop\
edit
_icon.svg"
/>
<entry
key=
"outputName"
value=
"ic_
cancel
_icon"
/>
<entry
key=
"sourceFile"
value=
"C:\Users\litak\Desktop\
cancel
_icon.svg"
/>
</map>
</option>
</PersistentState>
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ViewHolder.kt
0 → 100644
View file @
30c66e6d
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
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
30c66e6d
...
...
@@ -2,20 +2,15 @@ package com.paktalin.vocabularynotebook
import
android.app.Activity
import
android.content.Intent
import
android.os.Build
import
android.support.constraint.ConstraintLayout
import
android.support.v7.widget.PopupMenu
import
android.support.v7.widget.RecyclerView
import
android.text.Editable
import
android.text.TextWatcher
import
android.util.Log
import
android.view.LayoutInflater
import
android.view.MotionEvent
import
android.view.View
import
android.view.ViewGroup
import
android.widget.*
import
android.view.*
import
com.paktalin.vocabularynotebook.activities.WordItemInfoActivity
class
VocabularyAdapter
(
private
val
wordItems
:
MutableList
<
WordItem
>,
private
val
context
:
Activity
)
:
RecyclerView
.
Adapter
<
V
ocabularyAdapter
.
V
iewHolder
>()
{
class
VocabularyAdapter
(
private
val
wordItems
:
MutableList
<
WordItem
>,
private
val
context
:
Activity
)
:
RecyclerView
.
Adapter
<
ViewHolder
>()
{
private
lateinit
var
recyclerView
:
RecyclerView
...
...
@@ -49,13 +44,6 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
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
)
{
val
intentWordItemInfo
=
Intent
(
context
,
WordItemInfoActivity
::
class
.
java
)
intentWordItemInfo
.
putExtra
(
"wordItem"
,
wordItem
)
...
...
@@ -85,16 +73,25 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
holder
.
btnPopupMenu
.
visibility
=
View
.
INVISIBLE
Utils
.
setEmptyEditText
(
holder
.
etWord
,
"new word"
)
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
->
if
(
focus
)
showCancelButton
()
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
()
{
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
}
...
...
app/src/main/res/drawable/ic_cancel_icon.xml
0 → 100644
View file @
30c66e6d
<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>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment