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
f4a8ddf1
authored
Apr 29, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring: sort() function in DisplayedVocabulary
parent
cab16d05
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
21 deletions
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/DisplayedVocabulary.kt
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/VocabSet.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
View file @
f4a8ddf1
...
@@ -131,5 +131,5 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
...
@@ -131,5 +131,5 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
R
.
id
.
main_activity_container
)
R
.
id
.
main_activity_container
)
}
}
val
TAG
=
"VN/"
+
VocabularyAdapter
::
class
.
java
.
simpleName
private
val
TAG
=
"VN/"
+
VocabularyAdapter
::
class
.
java
.
simpleName
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/DisplayedVocabulary.kt
View file @
f4a8ddf1
...
@@ -3,6 +3,7 @@ package com.paktalin.vocabularynotebook.vocabulary
...
@@ -3,6 +3,7 @@ package com.paktalin.vocabularynotebook.vocabulary
import
com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import
com.paktalin.vocabularynotebook.firestoreitems.WordPojo
class
DisplayedVocabulary
(
wordList
:
MutableList
<
WordPojo
>):
BasicVocabulary
(
wordList
)
{
class
DisplayedVocabulary
(
wordList
:
MutableList
<
WordPojo
>):
BasicVocabulary
(
wordList
)
{
var
sort
:
Sort
=
Sort
.
BY_TIME
var
sort
:
Sort
=
Sort
.
BY_TIME
fun
clear
()
{
fun
clear
()
{
...
@@ -29,21 +30,9 @@ class DisplayedVocabulary(wordList: MutableList<WordPojo>): BasicVocabulary(word
...
@@ -29,21 +30,9 @@ class DisplayedVocabulary(wordList: MutableList<WordPojo>): BasicVocabulary(word
fun
sort
(
sort
:
Sort
)
{
fun
sort
(
sort
:
Sort
)
{
this
.
sort
=
sort
this
.
sort
=
sort
when
(
sort
)
{
when
(
sort
)
{
Sort
.
BY_TIME
->
{
Sort
.
BY_TIME
->
wordList
.
sortByDescending
{
w
->
w
.
time
}
wordList
.
sortWith
(
Comparator
{
item1
,
item2
->
Sort
.
BY_WORD
->
wordList
.
sortBy
{
w
->
w
.
word
.
toLowerCase
()
}
-
item1
.
time
!!
.
compareTo
(
item2
.
time
)
Sort
.
BY_TRANSLATION
->
wordList
.
sortBy
{
w
->
w
.
translation
.
toLowerCase
()
}
})
}
Sort
.
BY_WORD
->
{
wordList
.
sortWith
(
Comparator
{
item1
,
item2
->
item1
.
word
.
toLowerCase
().
compareTo
(
item2
.
word
.
toLowerCase
())
})
}
Sort
.
BY_TRANSLATION
->
{
wordList
.
sortWith
(
Comparator
{
item1
,
item2
->
item1
.
translation
.
toLowerCase
().
compareTo
(
item2
.
translation
.
toLowerCase
())
})
}
}
}
}
}
...
@@ -53,7 +42,5 @@ class DisplayedVocabulary(wordList: MutableList<WordPojo>): BasicVocabulary(word
...
@@ -53,7 +42,5 @@ class DisplayedVocabulary(wordList: MutableList<WordPojo>): BasicVocabulary(word
wordPojo
.
translation
.
toLowerCase
().
contains
(
string
)
wordPojo
.
translation
.
toLowerCase
().
contains
(
string
)
}
}
companion
object
{
private
val
TAG
=
"VN/"
+
DisplayedVocabulary
::
class
.
simpleName
private
val
TAG
=
"VN/"
+
DisplayedVocabulary
::
class
.
simpleName
}
}
}
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/VocabSet.kt
View file @
f4a8ddf1
...
@@ -29,8 +29,6 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
...
@@ -29,8 +29,6 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
snapshot
[
"tag"
].
toString
(),
snapshot
[
"tag"
].
toString
(),
snapshot
.
id
)
snapshot
.
id
)
}
}
private
val
TAG
=
"VN/"
+
VocabSet
::
class
.
java
.
simpleName
}
}
init
{
init
{
...
@@ -105,4 +103,6 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
...
@@ -105,4 +103,6 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
private
fun
displayAll
()
{
private
fun
displayAll
()
{
displayedVocabulary
.
addAll
(
wordList
)
displayedVocabulary
.
addAll
(
wordList
)
}
}
private
val
TAG
=
"VN/"
+
VocabSet
::
class
.
java
.
simpleName
}
}
\ 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