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
Hide 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
...
@@ -11,10 +11,12 @@ import android.widget.LinearLayout
import
android.widget.TextView
import
android.widget.TextView
import
com.paktalin.vocabularynotebook.ui.EditWordFragment
import
com.paktalin.vocabularynotebook.ui.EditWordFragment
import
com.paktalin.vocabularynotebook.ui.MainActivity
import
com.paktalin.vocabularynotebook.ui.MainActivity
import
java.util.*
class
VocabularyAdapter
(
private
val
wordItems
:
MutableList
<
WordItem
>,
private
val
activity
:
Activity
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
class
VocabularyAdapter
(
private
val
wordItems
:
MutableList
<
WordItem
>,
private
val
activity
:
Activity
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
private
lateinit
var
recyclerView
:
RecyclerView
private
lateinit
var
recyclerView
:
RecyclerView
private
var
sortByWord
=
true
override
fun
onAttachedToRecyclerView
(
recyclerView
:
RecyclerView
)
{
override
fun
onAttachedToRecyclerView
(
recyclerView
:
RecyclerView
)
{
super
.
onAttachedToRecyclerView
(
recyclerView
)
super
.
onAttachedToRecyclerView
(
recyclerView
)
...
@@ -68,6 +70,26 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
...
@@ -68,6 +70,26 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
this
.
notifyDataSetChanged
()
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"
)
@SuppressLint
(
"ResourceType"
)
private
fun
editWordItem
(
container
:
View
,
wordItem
:
WordItem
)
{
private
fun
editWordItem
(
container
:
View
,
wordItem
:
WordItem
)
{
//set container id
//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;
...
@@ -2,7 +2,7 @@ package com.paktalin.vocabularynotebook.pojo;
public
class
VocabularyPojo
{
public
class
VocabularyPojo
{
String
title
;
private
String
title
;
public
VocabularyPojo
()
{
public
VocabularyPojo
()
{
title
=
"First vocabulary"
;
title
=
"First vocabulary"
;
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
View file @
51f65fec
...
@@ -15,7 +15,9 @@ import android.view.Menu
...
@@ -15,7 +15,9 @@ import android.view.Menu
import
android.view.MenuItem
import
android.view.MenuItem
import
android.view.View
import
android.view.View
import
android.view.inputmethod.InputMethodManager
import
android.view.inputmethod.InputMethodManager
import
com.paktalin.vocabularynotebook.VocabularyAdapter
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
class
MainActivity
:
AppCompatActivity
()
{
class
MainActivity
:
AppCompatActivity
()
{
...
@@ -38,7 +40,7 @@ class MainActivity : AppCompatActivity() {
...
@@ -38,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
)
Log
.
d
(
TAG
,
"sort"
)
(
recyclerView
.
adapter
as
VocabularyAdapter
).
sort
(
)
return
super
.
onOptionsItemSelected
(
item
)
return
super
.
onOptionsItemSelected
(
item
)
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
View file @
51f65fec
...
@@ -43,7 +43,7 @@ class VocabularyFragment : Fragment() {
...
@@ -43,7 +43,7 @@ class VocabularyFragment : Fragment() {
}
}
fun
retrieveWordsData
(
vocabularyId
:
String
)
{
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
)
}
.
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