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
6a28bf07
authored
Sep 12, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Words can be sorted by time
parent
38b6f6d7
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
36 additions
and
47 deletions
app/src/main/java/com/paktalin/vocabularynotebook/UserManager.kt
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/WordItem.kt
app/src/main/java/com/paktalin/vocabularynotebook/pojo/UserPojo.java → app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/UserPojo.java
app/src/main/java/com/paktalin/vocabularynotebook/pojo/Vocabulary.kt → app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/Vocabulary.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/AddWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/EditWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/WordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/UserManager.kt
View file @
6a28bf07
...
...
@@ -4,8 +4,8 @@ import android.util.Log
import
com.google.firebase.auth.FirebaseUser
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.ui.LogInActivity
import
com.paktalin.vocabularynotebook.
pojo
.UserPojo
import
com.paktalin.vocabularynotebook.
pojo
.Vocabulary
import
com.paktalin.vocabularynotebook.
firestoreitems
.UserPojo
import
com.paktalin.vocabularynotebook.
firestoreitems
.Vocabulary
import
java.util.*
class
UserManager
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
6a28bf07
...
...
@@ -6,9 +6,11 @@ import android.os.Build
import
android.os.Bundle
import
android.support.v7.widget.PopupMenu
import
android.support.v7.widget.RecyclerView
import
android.util.Log
import
android.view.*
import
android.widget.LinearLayout
import
android.widget.TextView
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.ui.EditWordFragment
import
com.paktalin.vocabularynotebook.ui.MainActivity
import
java.util.*
...
...
@@ -16,7 +18,7 @@ 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
sort
ByWord
=
true
private
var
sort
Order
:
Int
=
0
override
fun
onAttachedToRecyclerView
(
recyclerView
:
RecyclerView
)
{
super
.
onAttachedToRecyclerView
(
recyclerView
)
...
...
@@ -31,8 +33,8 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
val
wordItem
=
wordItems
[
position
]
holder
.
tvWord
.
text
=
wordItem
.
pojo
!!
.
word
holder
.
tvTranslation
.
text
=
wordItem
.
pojo
!!
.
translation
holder
.
tvWord
.
text
=
wordItem
.
pojo
.
word
holder
.
tvTranslation
.
text
=
wordItem
.
pojo
.
translation
holder
.
itemView
.
setOnClickListener
{
showPopupMenu
(
holder
.
itemView
,
position
)
}
//todo set click listener to menu
}
...
...
@@ -72,20 +74,30 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
private
fun
sortByTranslation
()
{
wordItems
.
sortWith
(
Comparator
{
item1
,
item2
->
item1
.
pojo
!!
.
translation
!!
.
compareTo
(
item2
.
pojo
!!
.
translation
!!
)
})
item1
.
pojo
.
translation
.
compareTo
(
item2
.
pojo
.
translation
)
})
}
private
fun
sortByWord
()
{
wordItems
.
sortWith
(
Comparator
{
item1
,
item2
->
item1
.
pojo
!!
.
word
!!
.
compareTo
(
item2
.
pojo
!!
.
word
!!
)
item1
.
pojo
.
word
.
compareTo
(
item2
.
pojo
.
word
)
})
}
private
fun
sortByTime
()
{
wordItems
.
sortWith
(
Comparator
{
item1
,
item2
->
-
item1
.
pojo
.
time
!!
.
compareTo
(
item2
.
pojo
.
time
)
})
wordItems
.
forEach
{
item
->
Log
.
d
(
TAG
,
item
.
pojo
.
print
())}
}
fun
sort
()
{
sortByWord
=
!
sortByWord
if
(
sortByWord
)
sortByWord
()
else
sortByTranslation
()
if
(
sortOrder
==
2
)
sortOrder
=
0
else
sortOrder
++
when
(
sortOrder
)
{
0
->
sortByTime
()
1
->
sortByWord
()
2
->
sortByTranslation
()
}
this
.
notifyDataSetChanged
()
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/WordItem.kt
deleted
100644 → 0
View file @
38b6f6d7
package
com.paktalin.vocabularynotebook
import
android.util.Log
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
java.io.Serializable
class
WordItem
(
word
:
String
,
translation
:
String
,
var
id
:
String
,
private
val
vocabularyId
:
String
)
:
Serializable
{
var
pojo
:
Pojo
?
=
null
class
Pojo
(
var
word
:
String
?,
var
translation
:
String
?)
:
Serializable
init
{
this
.
pojo
=
Pojo
(
word
,
translation
)
}
constructor
(
pojo
:
Pojo
,
id
:
String
,
vocabularyId
:
String
)
:
this
(
pojo
.
word
!!
,
pojo
.
translation
!!
,
id
,
vocabularyId
)
fun
delete
()
{
ConfiguredFirestore
.
instance
.
collection
(
"vocabularies"
).
document
(
vocabularyId
)
.
collection
(
"words"
).
document
(
id
!!
).
delete
()
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully deleted word with id $id"
)
}
.
addOnFailureListener
{
e
->
Log
.
w
(
TAG
,
"deleteWordWithId $id:failure"
,
e
.
fillInStackTrace
())
}
}
companion
object
{
private
val
TAG
=
"VN/"
+
WordItem
::
class
.
java
.
simpleName
}
}
app/src/main/java/com/paktalin/vocabularynotebook/
pojo
/UserPojo.java
→
app/src/main/java/com/paktalin/vocabularynotebook/
firestoreitems
/UserPojo.java
View file @
6a28bf07
package
com
.
paktalin
.
vocabularynotebook
.
pojo
;
package
com
.
paktalin
.
vocabularynotebook
.
firestoreitems
;
import
com.google.firebase.firestore.DocumentReference
;
...
...
app/src/main/java/com/paktalin/vocabularynotebook/
pojo
/Vocabulary.kt
→
app/src/main/java/com/paktalin/vocabularynotebook/
firestoreitems
/Vocabulary.kt
View file @
6a28bf07
package
com.paktalin.vocabularynotebook.
pojo
package
com.paktalin.vocabularynotebook.
firestoreitems
class
Vocabulary
{
var
pojo
:
Pojo
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/AddWordFragment.kt
View file @
6a28bf07
...
...
@@ -8,7 +8,7 @@ import android.view.ViewGroup
import
android.widget.Toast
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.WordItem
import
com.paktalin.vocabularynotebook.
firestoreitems.
WordItem
class
AddWordFragment
:
WordFragment
()
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/EditWordFragment.kt
View file @
6a28bf07
...
...
@@ -11,7 +11,7 @@ import android.widget.ImageView
import
android.widget.TextView
import
android.widget.Toast
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.WordItem
import
com.paktalin.vocabularynotebook.
firestoreitems.
WordItem
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
kotlinx.android.synthetic.main.fragment_new_word.*
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
View file @
6a28bf07
...
...
@@ -8,8 +8,10 @@ import android.view.View
import
android.view.ViewGroup
import
com.google.firebase.auth.FirebaseAuth
import
com.google.firebase.firestore.DocumentSnapshot
import
com.google.firebase.firestore.Query
import
com.paktalin.vocabularynotebook.*
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
class
VocabularyFragment
:
Fragment
()
{
...
...
@@ -43,7 +45,9 @@ class VocabularyFragment : Fragment() {
}
fun
retrieveWordsData
(
vocabularyId
:
String
)
{
db
.
collection
(
VOCABULARIES
).
document
(
vocabularyId
).
collection
(
WORDS
).
orderBy
(
"word"
).
get
()
db
.
collection
(
VOCABULARIES
).
document
(
vocabularyId
).
collection
(
WORDS
)
.
orderBy
(
"time"
,
Query
.
Direction
.
DESCENDING
)
.
get
()
.
addOnSuccessListener
{
if
(
it
.
documents
.
size
!=
0
)
setVocabularyAdapter
(
it
.
documents
,
vocabularyId
)
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/WordFragment.kt
View file @
6a28bf07
...
...
@@ -8,7 +8,7 @@ import android.view.View
import
android.widget.FrameLayout
import
android.widget.ImageButton
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.WordItem
import
com.paktalin.vocabularynotebook.
firestoreitems.
WordItem
import
kotlinx.android.synthetic.main.fragment_new_word.*
abstract
class
WordFragment
:
Fragment
()
{
...
...
@@ -70,7 +70,7 @@ abstract class WordFragment : Fragment() {
val
word
=
word
.
text
.
toString
()
val
translation
=
translation
.
text
.
toString
()
val
vocabularyId
=
(
activity
as
MainActivity
).
vocabularyId
val
wordPojo
=
WordItem
.
Pojo
(
word
,
translation
)
val
wordPojo
=
WordItem
.
Pojo
(
word
,
translation
,
null
)
saveToFirestore
(
wordPojo
,
vocabularyId
)
}
...
...
@@ -80,6 +80,6 @@ abstract class WordFragment : Fragment() {
translation
.
text
.
clear
()
}
protected
abstract
fun
saveToFirestore
(
wordPojo
:
WordItem
.
Pojo
,
vocabularyId
:
String
)
protected
abstract
fun
saveToFirestore
(
wordPojo
:
WordItem
.
Pojo
,
vocabularyId
:
String
)
protected
abstract
fun
updateRecycleView
(
wordItem
:
WordItem
)
}
\ 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