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
839416e6
authored
Sep 08, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
An empty field added to the recycler view
parent
4decc79b
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
103 additions
and
40 deletions
app/src/main/java/com/paktalin/vocabularynotebook/Utils.kt
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/WordItem.kt
app/src/main/java/com/paktalin/vocabularynotebook/activities/WordItemInfoActivity.kt
app/src/main/res/layout/activity_word_info.xml
app/src/main/res/layout/word_item.xml
app/src/main/java/com/paktalin/vocabularynotebook/Utils.kt
View file @
839416e6
package
com.paktalin.vocabularynotebook
package
com.paktalin.vocabularynotebook
import
android.content.Context
import
android.content.Context
import
android.os.Build
import
android.text.TextUtils
import
android.text.TextUtils
import
android.widget.EditText
import
android.widget.Toast
import
android.widget.Toast
class
Utils
{
class
Utils
{
...
@@ -13,5 +15,14 @@ class Utils {
...
@@ -13,5 +15,14 @@ class Utils {
}
}
return
true
return
true
}
}
fun
setEmptyEditText
(
et
:
EditText
,
hint
:
String
)
{
et
.
isClickable
=
true
et
.
isFocusable
=
true
et
.
isFocusableInTouchMode
=
true
et
.
isCursorVisible
=
true
et
.
hint
=
hint
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
JELLY_BEAN
)
et
.
background
=
null
}
}
}
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
839416e6
...
@@ -2,17 +2,20 @@ package com.paktalin.vocabularynotebook
...
@@ -2,17 +2,20 @@ 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.util.Log
import
android.view.LayoutInflater
import
android.view.LayoutInflater
import
android.view.MotionEvent
import
android.view.View
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
import
android.widget.ImageButton
import
android.widget.*
import
android.widget.TextView
import
com.paktalin.vocabularynotebook.activities.WordItemInfoActivity
import
com.paktalin.vocabularynotebook.activities.WordItemInfoActivity
class
VocabularyAdapter
(
private
val
wordItems
:
MutableList
<
WordItem
>,
class
VocabularyAdapter
(
private
val
wordItems
:
MutableList
<
WordItem
>,
private
val
context
:
Activity
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
private
val
context
:
Activity
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
private
lateinit
var
recyclerView
:
RecyclerView
private
lateinit
var
recyclerView
:
RecyclerView
...
@@ -28,22 +31,29 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>,
...
@@ -28,22 +31,29 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>,
}
}
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
if
(
position
==
0
)
showEmptyItem
(
holder
)
else
{
val
wordItem
=
wordItems
[
position
]
val
wordItem
=
wordItems
[
position
]
holder
.
tvWord
.
text
=
wordItem
.
pojo
!!
.
word
holder
.
etWord
.
setText
(
wordItem
.
pojo
!!
.
word
)
holder
.
tvTranslation
.
text
=
wordItem
.
pojo
!!
.
translation
holder
.
etTranslation
.
setText
(
wordItem
.
pojo
!!
.
translation
)
holder
.
itemView
.
setOnClickListener
{
openWordItemInfo
(
wordItem
)
}
holder
.
layout
.
setOnClickListener
{
openWordItemInfo
(
wordItem
)
}
holder
.
etWord
.
setOnClickListener
{
openWordItemInfo
(
wordItem
)
}
holder
.
etTranslation
.
setOnClickListener
{
openWordItemInfo
(
wordItem
)
}
holder
.
btnPopupMenu
.
setOnClickListener
{
showPopupMenu
(
holder
.
btnPopupMenu
,
position
)
}
holder
.
btnPopupMenu
.
setOnClickListener
{
showPopupMenu
(
holder
.
btnPopupMenu
,
position
)
}
//todo set click listener to menu
//todo set click listener to menu
}
}
}
override
fun
getItemCount
():
Int
{
override
fun
getItemCount
():
Int
{
return
wordItems
.
size
return
wordItems
.
size
}
}
inner
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
inner
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
val
tvWord
:
TextView
=
itemView
.
findViewById
(
R
.
id
.
tv
Word
)
val
etWord
:
EditText
=
itemView
.
findViewById
(
R
.
id
.
et
Word
)
val
tvTranslation
:
TextView
=
itemView
.
findViewById
(
R
.
id
.
tv
Translation
)
val
etTranslation
:
EditText
=
itemView
.
findViewById
(
R
.
id
.
et
Translation
)
val
btnPopupMenu
:
ImageButton
=
itemView
.
findViewById
(
R
.
id
.
btnContextMenu
)
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
)
{
...
@@ -70,5 +80,24 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>,
...
@@ -70,5 +80,24 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>,
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
.
setOnFocusChangeListener
({
_
,
focus
->
if
(
focus
)
showCancelButton
()
})
holder
.
etTranslation
.
setOnFocusChangeListener
({
_
,
focus
->
if
(
focus
)
showCancelButton
()
})
}
private
fun
showCancelButton
()
{
Log
.
d
(
TAG
,
"empty word is focused"
)
}
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
())
}
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/WordItem.kt
View file @
839416e6
...
@@ -9,29 +9,29 @@ import com.google.firebase.firestore.FirebaseFirestore
...
@@ -9,29 +9,29 @@ import com.google.firebase.firestore.FirebaseFirestore
import
java.io.Serializable
import
java.io.Serializable
class
WordItem
(
class
WordItem
(
word
:
String
?,
translation
:
String
?,
var
id
:
String
?,
private
val
vocabularyId
:
String
?)
:
Serializable
{
word
:
String
,
translation
:
String
,
var
id
:
String
?,
private
val
vocabularyId
:
String
)
:
Serializable
{
var
pojo
:
WordItemPojo
?
=
null
var
pojo
:
WordItemPojo
?
=
null
class
WordItemPojo
(
var
word
:
String
?,
class
WordItemPojo
(
var
word
:
String
?,
var
translation
:
String
?)
:
Serializable
var
translation
:
String
?)
:
Serializable
init
{
init
{
this
.
pojo
=
WordItemPojo
(
word
,
translation
)
this
.
pojo
=
WordItemPojo
(
word
,
translation
)
}
}
fun
delete
()
{
fun
delete
()
{
if
(
vocabularyId
!=
null
)
{
FirebaseFirestore
.
getInstance
().
collection
(
"vocabularies"
).
document
(
vocabularyId
)
FirebaseFirestore
.
getInstance
().
collection
(
"vocabularies"
).
document
(
vocabularyId
)
.
collection
(
"words"
).
document
(
id
!!
).
delete
()
.
collection
(
"words"
).
document
(
id
!!
).
delete
()
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully deleted word with id $id"
)
}
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully deleted word with id $id"
)
}
.
addOnFailureListener
{
e
->
Log
.
w
(
TAG
,
"deleteWordWithId $id:failure"
,
e
.
fillInStackTrace
())
}
.
addOnFailureListener
{
e
->
Log
.
w
(
TAG
,
"deleteWordWithId $id:failure"
,
e
.
fillInStackTrace
())
}
}
}
}
companion
object
{
companion
object
{
private
val
TAG
=
"VN/"
+
WordItem
::
class
.
java
.
simpleName
private
val
TAG
=
"VN/"
+
WordItem
::
class
.
java
.
simpleName
fun
createEmpty
()
:
WordItem
{
return
WordItem
(
null
,
null
,
null
,
null
)
}
}
}
}
}
app/src/main/java/com/paktalin/vocabularynotebook/activities/WordItemInfoActivity.kt
View file @
839416e6
...
@@ -40,8 +40,8 @@ class WordItemInfoActivity: AppCompatActivity() {
...
@@ -40,8 +40,8 @@ class WordItemInfoActivity: AppCompatActivity() {
}
}
private
fun
setData
()
{
private
fun
setData
()
{
tv
Word
.
text
=
wordItem
.
pojo
!!
.
word
et
Word
.
text
=
wordItem
.
pojo
!!
.
word
tv
Translation
.
text
=
wordItem
.
pojo
!!
.
translation
et
Translation
.
text
=
wordItem
.
pojo
!!
.
translation
}
}
private
fun
cancel
()
{
private
fun
cancel
()
{
...
...
app/src/main/res/layout/activity_word_info.xml
View file @
839416e6
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
<include
layout=
"@layout/img_background"
/>
<include
layout=
"@layout/img_background"
/>
<TextView
<TextView
android:id=
"@+id/
tv
Word"
android:id=
"@+id/
et
Word"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"8dp"
android:layout_marginLeft=
"8dp"
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
app:layout_constraintTop_toTopOf=
"parent"
/>
app:layout_constraintTop_toTopOf=
"parent"
/>
<TextView
<TextView
android:id=
"@+id/
tv
Translation"
android:id=
"@+id/
et
Translation"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"8dp"
android:layout_marginLeft=
"8dp"
...
@@ -27,6 +27,6 @@
...
@@ -27,6 +27,6 @@
android:layout_marginTop=
"8dp"
android:layout_marginTop=
"8dp"
android:text=
"Translation"
android:text=
"Translation"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/
tv
Word"
/>
app:layout_constraintTop_toBottomOf=
"@+id/
et
Word"
/>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
app/src/main/res/layout/word_item.xml
View file @
839416e6
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/tableLayout"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:stretchColumns=
"0, 1, 2"
>
android:orientation=
"horizontal"
android:clickable=
"true"
<TableRow
android:padding=
"8dp"
>
android:focusable=
"true"
android:focusableInTouchMode=
"true"
android:padding=
"8dp"
>
<TextView
<EditText
android:id=
"@+id/tv
Word"
android:id=
"@+id/et
Word"
android:layout_width=
"92dp
"
android:layout_width=
"wrap_content
"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"word"
android:layout_weight=
"8"
android:textSize=
"22sp"
/>
android:background=
"@android:color/transparent"
android:cursorVisible=
"false"
android:clickable=
"false"
android:focusable=
"false"
android:focusableInTouchMode=
"false"
android:textSize=
"22sp"
tools:ignore=
"LabelFor"
android:inputType=
"text"
/>
<TextView
<EditText
android:id=
"@+id/tv
Translation"
android:id=
"@+id/et
Translation"
android:layout_width=
"145dp
"
android:layout_width=
"wrap_content
"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"translation"
android:layout_weight=
"8"
android:textSize=
"22sp"
/>
android:background=
"@android:color/transparent"
android:cursorVisible=
"false"
android:clickable=
"false"
android:focusable=
"false"
android:focusableInTouchMode=
"false"
android:textSize=
"22sp"
tools:ignore=
"LabelFor"
android:inputType=
"text"
/>
<ImageButton
<ImageButton
android:id=
"@+id/btnContextMenu"
android:id=
"@+id/btnContextMenu"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:background=
"@android:color/transparent"
android:background=
"@android:color/transparent"
app:srcCompat=
"@drawable/ic_delete_icon"
/>
app:srcCompat=
"@drawable/ic_delete_icon"
tools:ignore=
"ContentDescription"
/>
</TableRow>
</LinearLayout>
</TableLayout>
\ No newline at end of file
\ No newline at end of file
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