Commit cf0341cf by Paktalin

Fixed columns

parent fa2d779e
package com.paktalin.vocabularynotebook
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.FirebaseFirestoreSettings
object ConfiguredFirestore {
val instance: FirebaseFirestore
get() {
val firestore = FirebaseFirestore.getInstance()
val settings = FirebaseFirestoreSettings.Builder()
.setTimestampsInSnapshotsEnabled(true)
.build()
firestore.firestoreSettings = settings
return firestore
}
}
......@@ -2,7 +2,6 @@ package com.paktalin.vocabularynotebook
import android.util.Log
import com.google.firebase.auth.FirebaseUser
import com.google.firebase.firestore.FirebaseFirestore
import com.paktalin.vocabularynotebook.ui.LogInActivity
import com.paktalin.vocabularynotebook.pojo.UserPojo
import com.paktalin.vocabularynotebook.pojo.VocabularyPojo
......@@ -20,7 +19,7 @@ class UserManager {
fun addNewUserToDb(newUser: FirebaseUser, logInActivity: LogInActivity) {
//todo add condition to writing to the db in Firebase Console (request.auth.uid)
val db = FirebaseFirestore.getInstance()
val db = ConfiguredFirestore.instance
val user = UserPojo(newUser.email)
db.collection("vocabularies").add(VocabularyPojo())
......
......@@ -2,11 +2,6 @@ package com.paktalin.vocabularynotebook
import android.util.Log
import com.google.android.gms.tasks.OnFailureListener
import com.google.android.gms.tasks.OnSuccessListener
import com.google.firebase.firestore.DocumentReference
import com.google.firebase.firestore.FirebaseFirestore
import java.io.Serializable
class WordItem(word: String, translation: String, var id: String, private val vocabularyId: String) : Serializable {
......@@ -22,7 +17,7 @@ class WordItem(word: String, translation: String, var id: String, private val vo
: this(pojo.word!!, pojo.translation!!, id, vocabularyId)
fun delete() {
FirebaseFirestore.getInstance().collection("vocabularies").document(vocabularyId)
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()) }
......
......@@ -6,7 +6,6 @@ import android.support.v7.app.AppCompatActivity
import android.util.Log
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.DocumentReference
import com.google.firebase.firestore.FirebaseFirestore
import com.paktalin.vocabularynotebook.R
import kotlinx.android.synthetic.main.activity_main.*
......@@ -14,6 +13,7 @@ import android.view.WindowManager
import android.app.Activity
import android.view.View
import android.view.inputmethod.InputMethodManager
import com.paktalin.vocabularynotebook.ConfiguredFirestore
class MainActivity : AppCompatActivity() {
......@@ -45,7 +45,7 @@ class MainActivity : AppCompatActivity() {
private fun extractVocabularyData() {
val userId = FirebaseAuth.getInstance().currentUser!!.uid
val db = FirebaseFirestore.getInstance()
val db = ConfiguredFirestore.instance
val userDocument = db.collection("users").document(userId)
......
......@@ -11,7 +11,7 @@ import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageButton
import android.widget.Toast
import com.google.firebase.firestore.FirebaseFirestore
import com.paktalin.vocabularynotebook.ConfiguredFirestore
import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.WordItem
import kotlinx.android.synthetic.main.fragment_new_word.*
......@@ -79,7 +79,7 @@ class NewWordFragment : Fragment() {
val translation = etTranslation.text.toString()
val vocabularyId = (activity as MainActivity).vocabularyId
val newWordItemPojo = WordItem.WordItemPojo(word, translation)
FirebaseFirestore.getInstance()
ConfiguredFirestore.instance
.collection("vocabularies").document(vocabularyId)
.collection("words").add(newWordItemPojo)
.addOnSuccessListener {
......
......@@ -8,7 +8,6 @@ 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.FirebaseFirestore
import com.paktalin.vocabularynotebook.*
import kotlinx.android.synthetic.main.fragment_vocabulary.*
......@@ -19,7 +18,7 @@ class VocabularyFragment : Fragment() {
private const val WORDS = "words"
}
private val db = FirebaseFirestore.getInstance()
private val db = ConfiguredFirestore.instance
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_vocabulary, container, false)
......
......@@ -8,7 +8,7 @@
<EditText
android:id="@+id/etWord"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:background="@android:color/transparent"
......@@ -20,7 +20,7 @@
<EditText
android:id="@+id/etTranslation"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:background="@android:color/transparent"
......@@ -32,7 +32,7 @@
<ImageButton
android:id="@+id/btnClear"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="invisible"
......
......@@ -11,7 +11,7 @@
<TextView
android:id="@+id/etWord"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:textSize="22sp"
......@@ -20,7 +20,7 @@
<TextView
android:id="@+id/etTranslation"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:textSize="22sp"
......@@ -29,7 +29,7 @@
<ImageButton
android:id="@+id/btnClear"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/transparent"
......
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