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
af63849b
authored
Sep 12, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sort is made inside Vocabulary class
parent
39d2e21a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
25 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 @
af63849b
...
@@ -72,30 +72,12 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val activity
...
@@ -72,30 +72,12 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val activity
this
.
sort
()
this
.
sort
()
}
}
private
fun
sortByTranslation
()
{
vocabulary
.
words
.
sortWith
(
Comparator
{
item1
,
item2
->
item1
.
pojo
.
translation
.
compareTo
(
item2
.
pojo
.
translation
)
})
}
private
fun
sortByWord
()
{
vocabulary
.
words
.
sortWith
(
Comparator
{
item1
,
item2
->
item1
.
pojo
.
word
.
compareTo
(
item2
.
pojo
.
word
)
})
}
private
fun
sortByTime
()
{
vocabulary
.
words
.
sortWith
(
Comparator
{
item1
,
item2
->
-
item1
.
pojo
.
time
!!
.
compareTo
(
item2
.
pojo
.
time
)
})
}
fun
sort
()
{
fun
sort
()
{
// update SortOrder
if
(
sortOrder
==
2
)
sortOrder
=
0
if
(
sortOrder
==
2
)
sortOrder
=
0
else
sortOrder
++
else
sortOrder
++
when
(
sortOrder
)
{
vocabulary
.
sort
(
sortOrder
)
0
->
sortByTime
()
1
->
sortByWord
()
2
->
sortByTranslation
()
}
this
.
notifyDataSetChanged
()
this
.
notifyDataSetChanged
()
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/Vocabulary.kt
View file @
af63849b
...
@@ -2,6 +2,8 @@ package com.paktalin.vocabularynotebook.firestoreitems
...
@@ -2,6 +2,8 @@ package com.paktalin.vocabularynotebook.firestoreitems
class
Vocabulary
(
var
words
:
MutableList
<
WordItem
>)
{
class
Vocabulary
(
var
words
:
MutableList
<
WordItem
>)
{
companion
object
{
companion
object
{
private
val
TAG
=
"VN/"
+
Vocabulary
::
class
.
java
.
simpleName
private
const
val
SORT_BY_TIME
=
0
private
const
val
SORT_BY_TIME
=
0
private
const
val
SORT_BY_WORD
=
1
private
const
val
SORT_BY_WORD
=
1
private
const
val
SORT_BY_TRANSLATION
=
2
private
const
val
SORT_BY_TRANSLATION
=
2
...
@@ -19,16 +21,25 @@ class Vocabulary(var words: MutableList<WordItem>) {
...
@@ -19,16 +21,25 @@ class Vocabulary(var words: MutableList<WordItem>) {
pojo
=
Pojo
(
null
)
pojo
=
Pojo
(
null
)
}
}
fun
sort
(
index
:
Int
)
{
fun
sort
(
sortOrder
:
Int
)
{
when
(
index
)
{
when
(
sortOrder
)
{
SORT_BY_TIME
->
sortByTime
()
SORT_BY_TIME
->
sortByTime
()
SORT_BY_WORD
->
sortByWord
()
SORT_BY_WORD
->
sortByWord
()
SORT_BY_TRANSLATION
->
sortByTranslation
()
SORT_BY_TRANSLATION
->
sortByTranslation
()
}
}
}
}
private
fun
sortByTime
()
{
}
private
fun
sortByTime
()
{
private
fun
sortByWord
()
{
}
words
.
sortWith
(
Comparator
{
item1
,
item2
->
private
fun
sortByTranslation
()
{
}
-
item1
.
pojo
.
time
!!
.
compareTo
(
item2
.
pojo
.
time
)
})
}
private
fun
sortByWord
()
{
words
.
sortWith
(
Comparator
{
item1
,
item2
->
item1
.
pojo
.
word
.
compareTo
(
item2
.
pojo
.
word
)
})
}
private
fun
sortByTranslation
()
{
words
.
sortWith
(
Comparator
{
item1
,
item2
->
item1
.
pojo
.
translation
.
compareTo
(
item2
.
pojo
.
translation
)
})
}
}
}
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
View file @
af63849b
...
@@ -69,6 +69,7 @@ class MainActivity : AppCompatActivity() {
...
@@ -69,6 +69,7 @@ class MainActivity : AppCompatActivity() {
userDocument
.
get
()
userDocument
.
get
()
.
addOnSuccessListener
{
task
->
.
addOnSuccessListener
{
task
->
hideProgressBar
()
hideProgressBar
()
//todo move Firestore logic and collections names to a separate class
if
(
task
.
get
(
"vocabularies"
)
!=
null
)
{
if
(
task
.
get
(
"vocabularies"
)
!=
null
)
{
val
vocabularies
:
List
<
DocumentReference
>
=
task
.
get
(
"vocabularies"
)
as
List
<
DocumentReference
>
val
vocabularies
:
List
<
DocumentReference
>
=
task
.
get
(
"vocabularies"
)
as
List
<
DocumentReference
>
val
vocabulary
=
db
.
collection
(
"vocabularies"
).
document
(
vocabularies
[
0
].
id
)
val
vocabulary
=
db
.
collection
(
"vocabularies"
).
document
(
vocabularies
[
0
].
id
)
...
...
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