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
...
@@ -17,7 +17,9 @@ import com.paktalin.vocabularynotebook.ui.MainActivity
class
VocabularyAdapter
(
private
val
vocabulary
:
Vocabulary
,
private
val
activity
:
Activity
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
class
VocabularyAdapter
(
private
val
vocabulary
:
Vocabulary
,
private
val
activity
:
Activity
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
private
lateinit
var
recyclerView
:
RecyclerView
private
lateinit
var
recyclerView
:
RecyclerView
private
var
sortOrder
:
Int
=
0
private
var
sortOrder
:
Int
=
0
set
(
value
)
{
field
=
value
;
sort
()
}
override
fun
onAttachedToRecyclerView
(
recyclerView
:
RecyclerView
)
{
override
fun
onAttachedToRecyclerView
(
recyclerView
:
RecyclerView
)
{
super
.
onAttachedToRecyclerView
(
recyclerView
)
super
.
onAttachedToRecyclerView
(
recyclerView
)
...
@@ -31,7 +33,7 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val activity
...
@@ -31,7 +33,7 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val activity
}
}
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
val
wordItem
=
vocabulary
.
words
[
position
]
val
wordItem
=
vocabulary
.
getAt
(
position
)
holder
.
tvWord
.
text
=
wordItem
.
pojo
.
word
holder
.
tvWord
.
text
=
wordItem
.
pojo
.
word
holder
.
tvTranslation
.
text
=
wordItem
.
pojo
.
translation
holder
.
tvTranslation
.
text
=
wordItem
.
pojo
.
translation
holder
.
itemView
.
setOnClickListener
{
showPopupMenu
(
holder
.
itemView
,
position
)
}
holder
.
itemView
.
setOnClickListener
{
showPopupMenu
(
holder
.
itemView
,
position
)
}
...
@@ -46,7 +48,7 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val activity
...
@@ -46,7 +48,7 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val activity
inflater
.
inflate
(
R
.
menu
.
word_item_menu
,
popup
.
menu
)
inflater
.
inflate
(
R
.
menu
.
word_item_menu
,
popup
.
menu
)
popup
.
setOnMenuItemClickListener
{
popup
.
setOnMenuItemClickListener
{
if
(
it
.
itemId
==
R
.
id
.
option_delete
)
{
deleteWord
(
position
)
}
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
true
}
}
popup
.
show
()
popup
.
show
()
...
@@ -65,17 +67,17 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val activity
...
@@ -65,17 +67,17 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val activity
this
.
sort
()
this
.
sort
()
}
}
fun
updateWord
(
updatedWordItem
:
WordItem
)
{
fun
updateWord
(
updatedWord
:
WordItem
)
{
val
updatedItemId
=
vocabulary
.
words
.
indexOf
(
updatedWordItem
)
vocabulary
.
updateWord
(
updatedWord
)
vocabulary
.
words
[
updatedItemId
]
=
updatedWordItem
this
.
sort
()
this
.
sort
()
}
}
fun
sort
()
{
fun
updateSortOrder
()
{
// update SortOrder
if
(
sortOrder
==
2
)
sortOrder
=
0
if
(
sortOrder
==
2
)
sortOrder
=
0
else
sortOrder
++
else
sortOrder
++
}
private
fun
sort
()
{
vocabulary
.
sort
(
sortOrder
)
vocabulary
.
sort
(
sortOrder
)
this
.
notifyDataSetChanged
()
this
.
notifyDataSetChanged
()
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/Vocabulary.kt
View file @
d14cc276
...
@@ -10,9 +10,7 @@ class Vocabulary(words: MutableList<WordItem>) {
...
@@ -10,9 +10,7 @@ class Vocabulary(words: MutableList<WordItem>) {
}
}
var
pojo
:
Pojo
var
pojo
:
Pojo
private
var
words
:
MutableList
<
WordItem
>
//todo set private
var
words
:
MutableList
<
WordItem
>
class
Pojo
(
var
title
:
String
?)
{
class
Pojo
(
var
title
:
String
?)
{
init
{
init
{
...
@@ -42,6 +40,15 @@ class Vocabulary(words: MutableList<WordItem>) {
...
@@ -42,6 +40,15 @@ class Vocabulary(words: MutableList<WordItem>) {
words
.
add
(
0
,
newWord
)
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
}
fun
size
():
Int
{
return
words
.
size
}
//region Private methods
//region Private methods
...
@@ -58,4 +65,4 @@ class Vocabulary(words: MutableList<WordItem>) {
...
@@ -58,4 +65,4 @@ class Vocabulary(words: MutableList<WordItem>) {
item1
.
pojo
.
translation
.
compareTo
(
item2
.
pojo
.
translation
)
})
item1
.
pojo
.
translation
.
compareTo
(
item2
.
pojo
.
translation
)
})
}
}
//endregion
//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() {
...
@@ -40,7 +40,7 @@ class MainActivity : AppCompatActivity() {
override
fun
onOptionsItemSelected
(
item
:
MenuItem
?):
Boolean
{
override
fun
onOptionsItemSelected
(
item
:
MenuItem
?):
Boolean
{
if
(
item
!!
.
itemId
==
R
.
id
.
sort
)
if
(
item
!!
.
itemId
==
R
.
id
.
sort
)
(
recyclerView
.
adapter
as
VocabularyAdapter
).
sort
()
(
recyclerView
.
adapter
as
VocabularyAdapter
).
updateSortOrder
()
return
super
.
onOptionsItemSelected
(
item
)
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