Commit f1da1510 by Paktalin

Removed unused functions

parent 533a542b
...@@ -46,25 +46,11 @@ class FirestoreManager { ...@@ -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>) { fun saveWords(wordList: MutableSet<WordItem>) {
if (wordList.isEmpty()) if (wordList.isEmpty())
return return
val batch = db.batch() val batch = db.batch()
wordList.forEach { w -> kotlin.run { wordList.forEach { w -> kotlin.run {
Log.d(TAG, "${w.pojo.word} ${w.pojo.translation} ${w.id} ${w.modifiedLabel}")
if (w.modifiedLabel == ModifiedLabel.DELETED) if (w.modifiedLabel == ModifiedLabel.DELETED)
batch.delete(vocabularyDocument().collection(WORDS).document(w.id!!)) batch.delete(vocabularyDocument().collection(WORDS).document(w.id!!))
else if (w.modifiedLabel == ModifiedLabel.UPDATED && w.id != null) else if (w.modifiedLabel == ModifiedLabel.UPDATED && w.id != null)
...@@ -72,27 +58,7 @@ class FirestoreManager { ...@@ -72,27 +58,7 @@ class FirestoreManager {
else else
batch.set(vocabularyDocument().collection(WORDS).document(), w.pojo) batch.set(vocabularyDocument().collection(WORDS).document(), w.pojo)
}} }}
batch.commit().addOnCompleteListener { Log.d(TAG, "words successfully updated") } batch.commit().addOnCompleteListener { Log.d(TAG, "words are successfully pushed to Firestore") }
}
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()) }
} }
fun extractVocabulary(onComplete: (querySnapshot: QuerySnapshot?) -> Unit) { fun extractVocabulary(onComplete: (querySnapshot: QuerySnapshot?) -> Unit) {
......
...@@ -22,7 +22,6 @@ class Vocabulary() { ...@@ -22,7 +22,6 @@ class Vocabulary() {
fun createFromSnapshot(querySnapshot: QuerySnapshot): Vocabulary { fun createFromSnapshot(querySnapshot: QuerySnapshot): Vocabulary {
val wordsFromDocs = mutableListOf<WordItem>() val wordsFromDocs = mutableListOf<WordItem>()
querySnapshot.forEach { snapshot -> querySnapshot.forEach { snapshot ->
Log.d(TAG, "extracting ${snapshot["word"]} ${snapshot["translation"]} ${snapshot.id}")
wordsFromDocs.add(WordItem( wordsFromDocs.add(WordItem(
snapshot["word"].toString(), snapshot["word"].toString(),
snapshot["translation"].toString(), snapshot["translation"].toString(),
......
package com.paktalin.vocabularynotebook package com.paktalin.vocabularynotebook
import com.paktalin.vocabularynotebook.firestoreitems.WordItem import com.paktalin.vocabularynotebook.firestoreitems.WordItem
import com.paktalin.vocabularynotebook.vocabulary.Vocabulary
import org.junit.Assert.* import org.junit.Assert.*
import org.junit.Test import org.junit.Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment