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
9843c6ba
authored
Apr 21, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wordItem id is generated by default
parent
af51e854
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
26 deletions
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/WordPojo.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/utils/FirestoreManager.kt
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/ModifiedVocabulary.kt
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/VocabSet.kt
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/WordPojo.kt
View file @
9843c6ba
package
com.paktalin.vocabularynotebook.firestoreitems
import
java.io.Serializable
import
java.util.
Date
import
java.util.
*
class
WordPojo
(
var
word
:
String
,
var
translation
:
String
,
...
...
@@ -11,7 +11,7 @@ class WordPojo(var word: String,
:
Serializable
{
init
{
if
(
time
==
null
)
time
=
Date
(
System
.
currentTimeMillis
()
)
time
=
time
?:
Date
(
System
.
currentTimeMillis
()
)
id
=
id
?:
UUID
.
randomUUID
().
toString
(
)
}
}
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
View file @
9843c6ba
...
...
@@ -15,7 +15,6 @@ import com.paktalin.vocabularynotebook.ui.fragments.EditWordFragment
import
com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker.MySelectionTracker
import
com.paktalin.vocabularynotebook.utils.Log
import
com.paktalin.vocabularynotebook.utils.addFragment
import
com.paktalin.vocabularynotebook.vocabulary.ModifiedVocabulary
import
com.paktalin.vocabularynotebook.vocabulary.Sort
import
com.paktalin.vocabularynotebook.vocabulary.VocabSet
...
...
@@ -128,7 +127,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
notifyDataSetChanged
()
}
fun
getModifiedWords
():
MutableMap
<
WordPojo
,
ModifiedVocabulary
.
Label
>
{
fun
getModifiedWords
():
MutableMap
<
WordPojo
,
Boolean
>
{
return
vocabulary
.
getModified
()
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/utils/FirestoreManager.kt
View file @
9843c6ba
...
...
@@ -9,8 +9,6 @@ import com.paktalin.vocabularynotebook.firestoreitems.UserPojo
import
com.paktalin.vocabularynotebook.firestoreitems.VocabularyPojo
import
com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import
com.paktalin.vocabularynotebook.ui.activities.LogInActivity
import
com.paktalin.vocabularynotebook.vocabulary.ModifiedVocabulary
import
com.paktalin.vocabularynotebook.vocabulary.ModifiedVocabulary.Label
import
java.util.*
class
FirestoreManager
{
...
...
@@ -48,20 +46,17 @@ class FirestoreManager {
}
}
fun
saveWords
(
wordMap
:
MutableMap
<
WordPojo
,
ModifiedVocabulary
.
Label
>)
{
fun
saveWords
(
wordMap
:
MutableMap
<
WordPojo
,
Boolean
>)
{
if
(
wordMap
.
isEmpty
())
return
val
batch
=
db
.
batch
()
wordMap
.
forEach
{
entry
->
run
{
if
(
entry
.
value
==
Label
.
DELETED
)
batch
.
delete
(
wordsCollection
.
document
(
entry
.
key
.
id
!!
))
else
if
(
entry
.
value
==
Label
.
UPDATED
&&
entry
.
key
.
id
!=
null
)
batch
.
set
(
wordsCollection
.
document
(
entry
.
key
.
id
!!
),
entry
.
key
)
else
batch
.
set
(
wordsCollection
.
document
(),
entry
.
key
)
if
(
entry
.
value
)
batch
.
delete
(
wordsCollection
.
document
(
entry
.
key
.
id
!!
))
else
batch
.
set
(
wordsCollection
.
document
(
entry
.
key
.
id
!!
),
entry
.
key
)
}}
wordMap
.
clear
()
batch
.
commit
().
addOnCompleteListener
{
Log
.
d
(
TAG
,
"words are successfully pushed to Firestore"
)
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/ModifiedVocabulary.kt
View file @
9843c6ba
...
...
@@ -4,34 +4,30 @@ import com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import
com.paktalin.vocabularynotebook.utils.FirestoreManager
class
ModifiedVocabulary
:
Vocabulary
{
var
wordMap
=
mutableMapOf
<
WordPojo
,
Label
>()
var
wordMap
=
mutableMapOf
<
WordPojo
,
Boolean
>()
private
val
maxPermitted
=
9
override
fun
addWord
(
newWord
:
WordPojo
)
{
add
(
newWord
,
Label
.
ADDED
)
add
(
newWord
,
false
)
}
override
fun
updateWord
(
updatedWord
:
WordPojo
)
{
add
(
updatedWord
,
Label
.
UPDATED
)
add
(
updatedWord
,
false
)
}
override
fun
deleteWord
(
wordPojo
:
WordPojo
)
{
add
(
wordPojo
,
Label
.
DELETED
)
add
(
wordPojo
,
true
)
}
override
fun
addAll
(
words
:
MutableList
<
WordPojo
>)
{
}
fun
add
(
wordPojo
:
WordPojo
,
label
:
Label
)
{
wordMap
[
wordPojo
]
=
label
private
fun
add
(
wordPojo
:
WordPojo
,
deleted
:
Boolean
)
{
wordMap
[
wordPojo
]
=
deleted
if
(
wordMap
.
size
==
maxPermitted
)
FirestoreManager
().
saveWords
(
wordMap
)
}
fun
get
():
MutableMap
<
WordPojo
,
Label
>
{
fun
get
():
MutableMap
<
WordPojo
,
Boolean
>
{
return
wordMap
}
enum
class
Label
{
ADDED
,
UPDATED
,
DELETED
}
}
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/VocabSet.kt
View file @
9843c6ba
...
...
@@ -67,5 +67,7 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
fun
clearDisplayed
()
{
displayedVocabulary
.
clear
()
}
fun
getModified
():
MutableMap
<
WordPojo
,
ModifiedVocabulary
.
Label
>
{
return
modifiedVocabulary
.
get
()
}
fun
getModified
():
MutableMap
<
WordPojo
,
Boolean
>
{
return
modifiedVocabulary
.
get
()
}
}
\ 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