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
6124010d
authored
Sep 08, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved ViewHolder methods to ViewHolder class
parent
30c66e6d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
30 deletions
app/src/main/java/com/paktalin/vocabularynotebook/ViewHolder.kt
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/ViewHolder.kt
View file @
6124010d
package
com.paktalin.vocabularynotebook
import
android.support.v7.widget.RecyclerView
import
android.text.Editable
import
android.text.TextWatcher
import
android.util.Log
import
android.view.View
import
android.widget.EditText
import
android.widget.ImageButton
...
...
@@ -11,4 +14,34 @@ class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val
etTranslation
:
EditText
=
itemView
.
findViewById
(
R
.
id
.
etTranslation
)
val
btnPopupMenu
:
ImageButton
=
itemView
.
findViewById
(
R
.
id
.
btnContextMenu
)
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
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
6124010d
...
...
@@ -4,9 +4,6 @@ import android.app.Activity
import
android.content.Intent
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.*
import
com.paktalin.vocabularynotebook.activities.WordItemInfoActivity
...
...
@@ -26,7 +23,7 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
}
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
if
(
position
==
0
)
showEmptyItem
(
holder
)
if
(
position
==
0
)
holder
.
showEmptyItem
(
)
else
{
val
wordItem
=
wordItems
[
position
]
holder
.
etWord
.
setText
(
wordItem
.
pojo
!!
.
word
)
...
...
@@ -68,32 +65,6 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
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
}
init
{
wordItems
.
add
(
0
,
WordItem
.
createEmpty
())
}
...
...
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