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
f1da1510
authored
Apr 20, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed unused functions
parent
533a542b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
2 additions
and
36 deletions
app/src/main/java/com/paktalin/vocabularynotebook/utils/FirestoreManager.kt
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/Vocabulary.kt
app/src/test/java/com/paktalin/vocabularynotebook/VocabularyTest.kt
app/src/main/java/com/paktalin/vocabularynotebook/utils/FirestoreManager.kt
View file @
f1da1510
...
...
@@ -46,25 +46,11 @@ class FirestoreManager {
}
}
fun
saveNewWord
(
onSuccess
:
(
documentId
:
String
)
->
Unit
,
onFailure
:
()
->
Unit
,
wordPojo
:
WordItem
.
Pojo
)
{
vocabularyDocument
()
.
collection
(
WORDS
).
add
(
wordPojo
)
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully added a new word"
)
onSuccess
(
it
.
id
)
}
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"addNewWordToDb:failure"
,
it
.
fillInStackTrace
())
onFailure
()
}
}
fun
saveWords
(
wordList
:
MutableSet
<
WordItem
>)
{
if
(
wordList
.
isEmpty
())
return
val
batch
=
db
.
batch
()
wordList
.
forEach
{
w
->
kotlin
.
run
{
Log
.
d
(
TAG
,
"${w.pojo.word} ${w.pojo.translation} ${w.id} ${w.modifiedLabel}"
)
if
(
w
.
modifiedLabel
==
ModifiedLabel
.
DELETED
)
batch
.
delete
(
vocabularyDocument
().
collection
(
WORDS
).
document
(
w
.
id
!!
))
else
if
(
w
.
modifiedLabel
==
ModifiedLabel
.
UPDATED
&&
w
.
id
!=
null
)
...
...
@@ -72,27 +58,7 @@ class FirestoreManager {
else
batch
.
set
(
vocabularyDocument
().
collection
(
WORDS
).
document
(),
w
.
pojo
)
}}
batch
.
commit
().
addOnCompleteListener
{
Log
.
d
(
TAG
,
"words successfully updated"
)
}
}
fun
updateWord
(
onSuccess
:
()
->
Unit
,
onFailure
:
()
->
Unit
,
wordItem
:
WordItem
,
wordPojo
:
WordItem
.
Pojo
)
{
vocabularyDocument
()
.
collection
(
WORDS
).
document
(
wordItem
.
id
!!
).
set
(
wordPojo
)
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully updated the word"
)
onSuccess
()
}
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"updateExistingWord:failure"
,
it
.
fillInStackTrace
())
onFailure
()
}
}
fun
deleteWord
(
id
:
String
)
{
vocabularyDocument
()
.
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
())
}
batch
.
commit
().
addOnCompleteListener
{
Log
.
d
(
TAG
,
"words are successfully pushed to Firestore"
)
}
}
fun
extractVocabulary
(
onComplete
:
(
querySnapshot
:
QuerySnapshot
?)
->
Unit
)
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/Vocabulary.kt
View file @
f1da1510
...
...
@@ -22,7 +22,6 @@ class Vocabulary() {
fun
createFromSnapshot
(
querySnapshot
:
QuerySnapshot
):
Vocabulary
{
val
wordsFromDocs
=
mutableListOf
<
WordItem
>()
querySnapshot
.
forEach
{
snapshot
->
Log
.
d
(
TAG
,
"extracting ${snapshot["
word
"]} ${snapshot["
translation
"]} ${snapshot.id}"
)
wordsFromDocs
.
add
(
WordItem
(
snapshot
[
"word"
].
toString
(),
snapshot
[
"translation"
].
toString
(),
...
...
app/src/test/java/com/paktalin/vocabularynotebook/VocabularyTest.kt
View file @
f1da1510
package
com.paktalin.vocabularynotebook
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.vocabulary.Vocabulary
import
org.junit.Assert.*
import
org.junit.Test
...
...
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