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
38b6f6d7
authored
Sep 12, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor refactoring
parent
54c05326
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 additions
and
4 deletions
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
38b6f6d7
...
@@ -62,34 +62,31 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
...
@@ -62,34 +62,31 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
fun
addWordItem
(
newWordItem
:
WordItem
)
{
fun
addWordItem
(
newWordItem
:
WordItem
)
{
wordItems
.
add
(
0
,
newWordItem
)
wordItems
.
add
(
0
,
newWordItem
)
this
.
sort
()
this
.
sort
()
this
.
notifyItemInserted
(
0
)
}
}
fun
updateWordItem
(
updatedWordItem
:
WordItem
)
{
fun
updateWordItem
(
updatedWordItem
:
WordItem
)
{
val
updatedItemId
=
wordItems
.
indexOf
(
updatedWordItem
)
val
updatedItemId
=
wordItems
.
indexOf
(
updatedWordItem
)
wordItems
[
updatedItemId
]
=
updatedWordItem
wordItems
[
updatedItemId
]
=
updatedWordItem
this
.
sort
()
this
.
sort
()
this
.
notifyDataSetChanged
()
}
}
private
fun
sortByTranslation
()
{
private
fun
sortByTranslation
()
{
wordItems
.
sortWith
(
Comparator
{
item1
,
item2
->
wordItems
.
sortWith
(
Comparator
{
item1
,
item2
->
item1
.
pojo
!!
.
translation
!!
.
compareTo
(
item2
.
pojo
!!
.
translation
!!
)
item1
.
pojo
!!
.
translation
!!
.
compareTo
(
item2
.
pojo
!!
.
translation
!!
)
})
})
this
.
notifyDataSetChanged
()
}
}
private
fun
sortByWord
()
{
private
fun
sortByWord
()
{
wordItems
.
sortWith
(
Comparator
{
item1
,
item2
->
wordItems
.
sortWith
(
Comparator
{
item1
,
item2
->
item1
.
pojo
!!
.
word
!!
.
compareTo
(
item2
.
pojo
!!
.
word
!!
)
item1
.
pojo
!!
.
word
!!
.
compareTo
(
item2
.
pojo
!!
.
word
!!
)
})
})
this
.
notifyDataSetChanged
()
}
}
fun
sort
()
{
fun
sort
()
{
sortByWord
=
!
sortByWord
sortByWord
=
!
sortByWord
if
(
sortByWord
)
sortByWord
()
if
(
sortByWord
)
sortByWord
()
else
sortByTranslation
()
else
sortByTranslation
()
this
.
notifyDataSetChanged
()
}
}
@SuppressLint
(
"ResourceType"
)
@SuppressLint
(
"ResourceType"
)
...
...
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