Commit ae7ee12b by Paktalin

Removed test fields from VocabularyFragment

parent 97b5eba8
package com.paktalin.vocabularynotebook.activities package com.paktalin.vocabularynotebook.activities
import android.annotation.SuppressLint
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.LinearLayoutManager
import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
...@@ -17,13 +15,13 @@ import com.paktalin.vocabularynotebook.R ...@@ -17,13 +15,13 @@ import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.VocabularyAdapter import com.paktalin.vocabularynotebook.VocabularyAdapter
import com.paktalin.vocabularynotebook.pojo.WordItemPojo import com.paktalin.vocabularynotebook.pojo.WordItemPojo
import kotlinx.android.synthetic.main.fragment_vocabulary.* import kotlinx.android.synthetic.main.fragment_vocabulary.*
import java.util.*
class VocabularyFragment : Fragment() { class VocabularyFragment : Fragment() {
companion object { companion object {
private val TAG = "VN/" + VocabularyFragment::class.simpleName private val TAG = "VN/" + VocabularyFragment::class.simpleName
private const val VOCABULARIES = "vocabularies" private const val VOCABULARIES = "vocabularies"
private const val WORDS = "words" private const val WORDS = "words"
private const val USERS = "users"
} }
private lateinit var userDocument: DocumentReference private lateinit var userDocument: DocumentReference
...@@ -37,8 +35,7 @@ class VocabularyFragment : Fragment() { ...@@ -37,8 +35,7 @@ class VocabularyFragment : Fragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
fabAddWord.setOnClickListener( { addWord() } ) fabAddWord.setOnClickListener( { addWord() } )
extractUserDocument() retrieveData()
printUserData()
} }
override fun onDestroy() { override fun onDestroy() {
...@@ -46,45 +43,24 @@ class VocabularyFragment : Fragment() { ...@@ -46,45 +43,24 @@ class VocabularyFragment : Fragment() {
FirebaseAuth.getInstance().signOut() FirebaseAuth.getInstance().signOut()
} }
private fun extractUserDocument() { private fun retrieveData() {
val userId = FirebaseAuth.getInstance().currentUser!!.uid val userId = FirebaseAuth.getInstance().currentUser!!.uid
Log.d(TAG, "retrieved userId: $userId") userDocument = db.collection(USERS).document(userId)
userDocument = db.collection("users").document(userId)
}
private fun setVocabularyId(task: DocumentSnapshot) {
//todo if only one vocabulary exists, open it
val vocabularies: List<DocumentReference> = task.get("vocabularies") as List<DocumentReference>
vocabulary = db.collection(VOCABULARIES).document(vocabularies[0].id)
}
@SuppressLint("SetTextI18n")
private fun printUserData() {
userDocument.get().addOnSuccessListener { task -> userDocument.get().addOnSuccessListener { task ->
val email = task.get("email").toString()
tvUserData.text = email
setVocabularyId(task) setVocabularyId(task)
retrieveVocabularyData() retrieveVocabularyData()
} }
} }
private fun retrieveVocabularyData() { private fun setVocabularyId(task: DocumentSnapshot) {
//todo if only one vocabulary exists, open it //todo if only one vocabulary exists, open it
vocabulary.get().addOnSuccessListener { task -> val vocabularies: List<DocumentReference> = task.get("vocabularies") as List<DocumentReference>
val vocabularyTitle = task.get("title").toString() vocabulary = db.collection(VOCABULARIES).document(vocabularies[0].id)
tvUserData.append("\n\nvocabularies:\n$vocabularyTitle")
}
retrieveWordsFromVocabulary()
}
private fun addWord() {
val addWordIntent = Intent(activity, AddWordActivity::class.java)
addWordIntent.putExtra("vocabularyId", vocabulary.id)
startActivity(addWordIntent)
} }
private fun retrieveWordsFromVocabulary() { private fun retrieveVocabularyData() {
//todo if only one vocabulary exists, open it
val mLayoutManager = LinearLayoutManager(activity) val mLayoutManager = LinearLayoutManager(activity)
recyclerView.layoutManager = mLayoutManager recyclerView.layoutManager = mLayoutManager
recyclerView.setHasFixedSize(true) recyclerView.setHasFixedSize(true)
...@@ -102,4 +78,10 @@ class VocabularyFragment : Fragment() { ...@@ -102,4 +78,10 @@ class VocabularyFragment : Fragment() {
recyclerView.adapter = adapter recyclerView.adapter = adapter
} }
} }
private fun addWord() {
val addWordIntent = Intent(activity, AddWordActivity::class.java)
addWordIntent.putExtra("vocabularyId", vocabulary.id)
startActivity(addWordIntent)
}
} }
\ No newline at end of file
...@@ -8,39 +8,18 @@ ...@@ -8,39 +8,18 @@
app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.paktalin.vocabularynotebook.activities.VocabularyFragment"> tools:context="com.paktalin.vocabularynotebook.activities.VocabularyFragment">
<TextView <android.support.v7.widget.RecyclerView
android:id="@+id/tvCongrats" android:id="@+id/recyclerView"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Congratulations! You have successfully logged in!"
app:layout_constraintBottom_toTopOf="@+id/tvUserData"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<TextView
android:id="@+id/tvUserData"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp" android:layout_marginLeft="8dp"
android:layout_marginRight="8dp" android:layout_marginRight="8dp"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvCongrats" /> app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/tvUserData" />
<android.support.design.widget.FloatingActionButton <android.support.design.widget.FloatingActionButton
android:id="@+id/fabAddWord" android:id="@+id/fabAddWord"
......
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