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
ae7ee12b
authored
Sep 08, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed test fields from VocabularyFragment
parent
97b5eba8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
58 deletions
app/src/main/java/com/paktalin/vocabularynotebook/activities/VocabularyFragment.kt
app/src/main/res/layout/fragment_vocabulary.xml
app/src/main/java/com/paktalin/vocabularynotebook/activities/VocabularyFragment.kt
View file @
ae7ee12b
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
app/src/main/res/layout/fragment_vocabulary.xml
View file @
ae7ee12b
...
@@ -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"
...
...
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