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
24371d24
authored
Sep 09, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Words are added to the database from NewWordFragment
parent
9e553faa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
3 deletions
app/src/main/java/com/paktalin/vocabularynotebook/ui/NewWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/NewWordFragment.kt
View file @
24371d24
...
...
@@ -9,8 +9,10 @@ import android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.ImageButton
import
android.widget.Toast
import
com.google.firebase.firestore.FirebaseFirestore
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.WordItem
import
kotlinx.android.synthetic.main.fragment_new_word.*
class
NewWordFragment
:
Fragment
()
{
...
...
@@ -83,10 +85,23 @@ class NewWordFragment : Fragment() {
//todo get word data from edit texts and save it
val
word
=
etWord
.
text
.
toString
()
val
translation
=
etTranslation
.
text
.
toString
()
val
vocabularyId
=
(
activity
as
MainActivity
).
vocabularyId
FirebaseFirestore
.
getInstance
()
.
collection
(
"vocabularies"
).
document
(
vocabularyId
)
.
collection
(
"words"
).
add
(
WordItem
.
WordItemPojo
(
word
,
translation
))
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully added a new word"
)
clearFields
()
//todo update recycleView
}
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"addNewWordToDb:failure"
,
it
.
fillInStackTrace
())
Toast
.
makeText
(
activity
,
"Couldn't add the word"
,
Toast
.
LENGTH_SHORT
).
show
()}
}
Log
.
d
(
TAG
,
"vocabularyId: ${(activity as MainActivity).vocabularyId})"
)
FirebaseFirestore
.
getInstance
().
collection
(
"vocabularies"
).
document
()
private
fun
clearFields
()
{
etWord
.
text
.
clear
()
etTranslation
.
text
.
clear
()
}
companion
object
{
private
val
TAG
=
"VN/"
+
NewWordFragment
::
class
.
java
.
simpleName
}
...
...
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