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
d14cc276
authored
Sep 12, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
All operations on words are moved to Vocabulary class
parent
dacdb0e0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
12 deletions
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/Vocabulary.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
d14cc276
...
...
@@ -17,7 +17,9 @@ import com.paktalin.vocabularynotebook.ui.MainActivity
class
VocabularyAdapter
(
private
val
vocabulary
:
Vocabulary
,
private
val
activity
:
Activity
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
private
lateinit
var
recyclerView
:
RecyclerView
private
var
sortOrder
:
Int
=
0
set
(
value
)
{
field
=
value
;
sort
()
}
override
fun
onAttachedToRecyclerView
(
recyclerView
:
RecyclerView
)
{
super
.
onAttachedToRecyclerView
(
recyclerView
)
...
...
@@ -31,7 +33,7 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val activity
}
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
val
wordItem
=
vocabulary
.
words
[
position
]
val
wordItem
=
vocabulary
.
getAt
(
position
)
holder
.
tvWord
.
text
=
wordItem
.
pojo
.
word
holder
.
tvTranslation
.
text
=
wordItem
.
pojo
.
translation
holder
.
itemView
.
setOnClickListener
{
showPopupMenu
(
holder
.
itemView
,
position
)
}
...
...
@@ -46,7 +48,7 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val activity
inflater
.
inflate
(
R
.
menu
.
word_item_menu
,
popup
.
menu
)
popup
.
setOnMenuItemClickListener
{
if
(
it
.
itemId
==
R
.
id
.
option_delete
)
{
deleteWord
(
position
)
}
if
(
it
.
itemId
==
R
.
id
.
option_edit
)
{
editWord
(
v
,
vocabulary
.
words
[
position
]
)
}
if
(
it
.
itemId
==
R
.
id
.
option_edit
)
{
editWord
(
v
,
vocabulary
.
getAt
(
position
)
)
}
true
}
popup
.
show
()
...
...
@@ -65,17 +67,17 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val activity
this
.
sort
()
}
fun
updateWord
(
updatedWordItem
:
WordItem
)
{
val
updatedItemId
=
vocabulary
.
words
.
indexOf
(
updatedWordItem
)
vocabulary
.
words
[
updatedItemId
]
=
updatedWordItem
fun
updateWord
(
updatedWord
:
WordItem
)
{
vocabulary
.
updateWord
(
updatedWord
)
this
.
sort
()
}
fun
sort
()
{
// update SortOrder
fun
updateSortOrder
()
{
if
(
sortOrder
==
2
)
sortOrder
=
0
else
sortOrder
++
}
private
fun
sort
()
{
vocabulary
.
sort
(
sortOrder
)
this
.
notifyDataSetChanged
()
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/Vocabulary.kt
View file @
d14cc276
...
...
@@ -10,9 +10,7 @@ class Vocabulary(words: MutableList<WordItem>) {
}
var
pojo
:
Pojo
//todo set private
var
words
:
MutableList
<
WordItem
>
private
var
words
:
MutableList
<
WordItem
>
class
Pojo
(
var
title
:
String
?)
{
init
{
...
...
@@ -42,6 +40,15 @@ class Vocabulary(words: MutableList<WordItem>) {
words
.
add
(
0
,
newWord
)
}
fun
updateWord
(
updatedWord
:
WordItem
)
{
val
updatedItemIndex
=
words
.
indexOf
(
updatedWord
)
words
[
updatedItemIndex
]
=
updatedWord
}
fun
getAt
(
position
:
Int
):
WordItem
{
return
words
[
position
]
}
fun
size
():
Int
{
return
words
.
size
}
//region Private methods
...
...
@@ -58,4 +65,4 @@ class Vocabulary(words: MutableList<WordItem>) {
item1
.
pojo
.
translation
.
compareTo
(
item2
.
pojo
.
translation
)
})
}
//endregion
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
View file @
d14cc276
...
...
@@ -40,7 +40,7 @@ class MainActivity : AppCompatActivity() {
override
fun
onOptionsItemSelected
(
item
:
MenuItem
?):
Boolean
{
if
(
item
!!
.
itemId
==
R
.
id
.
sort
)
(
recyclerView
.
adapter
as
VocabularyAdapter
).
sort
()
(
recyclerView
.
adapter
as
VocabularyAdapter
).
updateSortOrder
()
return
super
.
onOptionsItemSelected
(
item
)
}
...
...
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