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
51f65fec
authored
Sep 12, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Options sortByWord and sortByTranslation are available
parent
a0a60ff8
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
3 deletions
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/pojo/VocabularyPojo.java
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
51f65fec
...
...
@@ -11,10 +11,12 @@ import android.widget.LinearLayout
import
android.widget.TextView
import
com.paktalin.vocabularynotebook.ui.EditWordFragment
import
com.paktalin.vocabularynotebook.ui.MainActivity
import
java.util.*
class
VocabularyAdapter
(
private
val
wordItems
:
MutableList
<
WordItem
>,
private
val
activity
:
Activity
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
private
lateinit
var
recyclerView
:
RecyclerView
private
var
sortByWord
=
true
override
fun
onAttachedToRecyclerView
(
recyclerView
:
RecyclerView
)
{
super
.
onAttachedToRecyclerView
(
recyclerView
)
...
...
@@ -68,6 +70,26 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
this
.
notifyDataSetChanged
()
}
private
fun
sortByTranslation
()
{
wordItems
.
sortWith
(
Comparator
{
item1
,
item2
->
item1
.
pojo
!!
.
translation
!!
.
compareTo
(
item2
.
pojo
!!
.
translation
!!
)
})
this
.
notifyDataSetChanged
()
}
private
fun
sortByWord
()
{
wordItems
.
sortWith
(
Comparator
{
item1
,
item2
->
item1
.
pojo
!!
.
word
!!
.
compareTo
(
item2
.
pojo
!!
.
word
!!
)
})
this
.
notifyDataSetChanged
()
}
fun
sort
()
{
sortByWord
=
!
sortByWord
if
(
sortByWord
)
sortByWord
()
else
sortByTranslation
()
}
@SuppressLint
(
"ResourceType"
)
private
fun
editWordItem
(
container
:
View
,
wordItem
:
WordItem
)
{
//set container id
...
...
app/src/main/java/com/paktalin/vocabularynotebook/pojo/VocabularyPojo.java
View file @
51f65fec
...
...
@@ -2,7 +2,7 @@ package com.paktalin.vocabularynotebook.pojo;
public
class
VocabularyPojo
{
String
title
;
private
String
title
;
public
VocabularyPojo
()
{
title
=
"First vocabulary"
;
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
View file @
51f65fec
...
...
@@ -15,7 +15,9 @@ import android.view.Menu
import
android.view.MenuItem
import
android.view.View
import
android.view.inputmethod.InputMethodManager
import
com.paktalin.vocabularynotebook.VocabularyAdapter
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
class
MainActivity
:
AppCompatActivity
()
{
...
...
@@ -38,7 +40,7 @@ class MainActivity : AppCompatActivity() {
override
fun
onOptionsItemSelected
(
item
:
MenuItem
?):
Boolean
{
if
(
item
!!
.
itemId
==
R
.
id
.
sort
)
Log
.
d
(
TAG
,
"sort"
)
(
recyclerView
.
adapter
as
VocabularyAdapter
).
sort
(
)
return
super
.
onOptionsItemSelected
(
item
)
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
View file @
51f65fec
...
...
@@ -43,7 +43,7 @@ class VocabularyFragment : Fragment() {
}
fun
retrieveWordsData
(
vocabularyId
:
String
)
{
db
.
collection
(
VOCABULARIES
).
document
(
vocabularyId
).
collection
(
WORDS
).
get
()
db
.
collection
(
VOCABULARIES
).
document
(
vocabularyId
).
collection
(
WORDS
).
orderBy
(
"word"
).
get
()
.
addOnSuccessListener
{
setVocabularyAdapter
(
it
.
documents
,
vocabularyId
)
}
}
...
...
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