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
4dd660d5
authored
Sep 07, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New words are added to the database
parent
6277fd14
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
102 additions
and
23 deletions
app/src/main/java/com/paktalin/vocabularynotebook/Utils.kt
app/src/main/java/com/paktalin/vocabularynotebook/WordPojo.java
app/src/main/java/com/paktalin/vocabularynotebook/activities/AddWordActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/activities/LogInActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/activities/VocabularyFragment.kt
app/src/main/res/layout/activity_add_word.xml
app/src/main/java/com/paktalin/vocabularynotebook/Utils.kt
0 → 100644
View file @
4dd660d5
package
com.paktalin.vocabularynotebook
import
android.content.Context
import
android.text.TextUtils
import
android.widget.Toast
class
Utils
{
companion
object
{
fun
fieldsNotEmpty
(
text1
:
String
,
text2
:
String
,
toastMessage
:
String
,
context
:
Context
):
Boolean
{
if
(
TextUtils
.
isEmpty
(
text1
)
||
TextUtils
.
isEmpty
(
text2
))
{
Toast
.
makeText
(
context
,
toastMessage
,
Toast
.
LENGTH_SHORT
).
show
()
return
false
}
return
true
}
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/WordPojo.java
0 → 100644
View file @
4dd660d5
package
com
.
paktalin
.
vocabularynotebook
;
public
class
WordPojo
{
private
String
word
,
translation
;
public
WordPojo
(
String
word
,
String
translation
)
{
this
.
word
=
word
;
this
.
translation
=
translation
;
}
public
String
getWord
()
{
return
word
;
}
public
void
setWord
(
String
word
)
{
this
.
word
=
word
;
}
public
String
getTranslation
()
{
return
translation
;
}
public
void
setTranslation
(
String
translation
)
{
this
.
translation
=
translation
;
}
}
app/src/main/java/com/paktalin/vocabularynotebook/activities/AddWordActivity.kt
View file @
4dd660d5
...
...
@@ -2,13 +2,50 @@ package com.paktalin.vocabularynotebook.activities
import
android.os.Bundle
import
android.support.v7.app.AppCompatActivity
import
android.util.Log
import
android.widget.Toast
import
com.google.firebase.firestore.FirebaseFirestore
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.Utils
import
com.paktalin.vocabularynotebook.WordPojo
import
kotlinx.android.synthetic.main.activity_add_word.*
class
AddWordActivity
:
AppCompatActivity
()
{
companion
object
{
private
val
TAG
=
"VN/"
+
AddWordActivity
::
class
.
simpleName
private
const
val
VOCABULARIES
=
"vocabularies"
private
const
val
WORDS
=
"words"
}
private
lateinit
var
vocabularyId
:
String
private
val
db
=
FirebaseFirestore
.
getInstance
()
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_add_word
)
vocabularyId
=
intent
.
getStringExtra
(
"vocabularyId"
)
btnSubmitNewWord
.
setOnClickListener
(
{
addWordToDb
()
})
}
private
fun
addWordToDb
()
{
val
word
=
etWord
.
text
.
toString
()
val
translation
=
etTranslation
.
text
.
toString
()
if
(
Utils
.
fieldsNotEmpty
(
word
,
translation
,
"Please, enter word and translation"
,
this
))
{
db
.
collection
(
VOCABULARIES
).
document
(
vocabularyId
)
.
collection
(
WORDS
).
add
(
WordPojo
(
word
,
translation
)).
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully added a new word $word"
)
clearFields
()
}
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"addNewWordToDb:failure"
,
it
.
fillInStackTrace
())
Toast
.
makeText
(
this
,
"Couldn't add the word"
,
Toast
.
LENGTH_SHORT
).
show
()
}
}
}
private
fun
clearFields
()
{
etWord
.
text
.
clear
()
etTranslation
.
text
.
clear
()
}
}
app/src/main/java/com/paktalin/vocabularynotebook/activities/LogInActivity.kt
View file @
4dd660d5
...
...
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import
android.content.Intent
import
android.support.v7.app.AppCompatActivity
import
android.os.Bundle
import
android.text.TextUtils
import
android.util.Log
import
android.widget.Toast
...
...
@@ -12,9 +11,9 @@ import com.google.firebase.auth.FirebaseAuth
import
kotlinx.android.synthetic.main.activity_log_in.*
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.UserManager
import
com.paktalin.vocabularynotebook.Utils
class
LogInActivity
:
AppCompatActivity
()
{
private
var
mAuth
:
FirebaseAuth
?
=
null
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
...
...
@@ -39,7 +38,7 @@ class LogInActivity : AppCompatActivity() {
val
email
=
etEmail
!!
.
text
.
toString
()
val
password
=
etPassword
!!
.
text
.
toString
()
if
(
fieldsNotEmpty
(
email
,
password
))
{
if
(
Utils
.
fieldsNotEmpty
(
email
,
password
,
"Please, enter email and password"
,
this
))
{
mAuth
!!
.
signInWithEmailAndPassword
(
email
,
password
)
.
addOnCompleteListener
{
task
->
if
(
task
.
isSuccessful
)
{
...
...
@@ -59,7 +58,7 @@ class LogInActivity : AppCompatActivity() {
val
email
=
etEmail
!!
.
text
.
toString
()
val
password
=
etPassword
!!
.
text
.
toString
()
if
(
fieldsNotEmpty
(
email
,
password
))
{
if
(
Utils
.
fieldsNotEmpty
(
email
,
password
,
"Please, enter email and password"
,
this
))
{
//todo check if the password is good
// todo verify email
mAuth
!!
.
createUserWithEmailAndPassword
(
email
,
password
)
...
...
@@ -80,14 +79,6 @@ class LogInActivity : AppCompatActivity() {
startActivity
(
userActivityIntent
)
}
private
fun
fieldsNotEmpty
(
email
:
String
,
password
:
String
):
Boolean
{
if
(
TextUtils
.
isEmpty
(
email
)
||
TextUtils
.
isEmpty
(
password
))
{
Toast
.
makeText
(
this
@LogInActivity
,
"Please, enter email and password"
,
Toast
.
LENGTH_SHORT
).
show
()
return
false
}
return
true
}
@SuppressLint
(
"SetTextI18n"
)
private
fun
createRandomUser
()
{
etEmail
.
setText
(
"random@gmail.com"
)
...
...
app/src/main/java/com/paktalin/vocabularynotebook/activities/VocabularyFragment.kt
View file @
4dd660d5
...
...
@@ -19,6 +19,7 @@ class VocabularyFragment : Fragment() {
private
lateinit
var
userDocument
:
DocumentReference
private
val
db
=
FirebaseFirestore
.
getInstance
()
private
lateinit
var
vocabularyId
:
String
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
return
inflater
.
inflate
(
R
.
layout
.
fragment_vocabulary
,
container
,
false
)
...
...
@@ -42,21 +43,26 @@ class VocabularyFragment : Fragment() {
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
>
vocabularyId
=
vocabularies
[
0
].
id
}
@SuppressLint
(
"SetTextI18n"
)
private
fun
printUserData
()
{
userDocument
.
get
().
addOnSuccessListener
{
task
->
val
email
=
task
.
get
(
"email"
).
toString
()
tvUserData
.
text
=
email
retrieveVocabulary
(
task
)
setVocabularyId
(
task
)
retrieveVocabularyData
()
}
}
private
fun
retrieveVocabulary
(
task
:
DocumentSnapshot
)
{
private
fun
retrieveVocabulary
Data
(
)
{
//todo if only one vocabulary exists, open it
val
vocabularies
:
List
<
DocumentReference
>
=
task
.
get
(
"vocabularies"
)
as
List
<
DocumentReference
>
val
firstVocab
=
vocabularies
[
0
].
id
db
.
collection
(
"vocabularies"
).
document
(
firstVocab
).
get
().
addOnSuccessListener
{
task
->
db
.
collection
(
"vocabularies"
).
document
(
vocabularyId
).
get
().
addOnSuccessListener
{
task
->
val
vocabTitle
=
task
.
get
(
"title"
).
toString
()
tvUserData
.
append
(
"\n\nvocabularies:\n$vocabTitle"
)
...
...
@@ -65,10 +71,9 @@ class VocabularyFragment : Fragment() {
private
fun
addWord
()
{
val
addWordIntent
=
Intent
(
activity
,
AddWordActivity
::
class
.
java
)
addWordIntent
.
putExtra
(
"vocabularyId"
,
vocabularyId
)
startActivity
(
addWordIntent
)
}
companion
object
{
private
val
TAG
=
"VN/"
+
VocabularyFragment
::
class
.
simpleName
}
}
companion
object
{
private
val
TAG
=
"VN/"
+
VocabularyFragment
::
class
.
simpleName
}
}
\ No newline at end of file
app/src/main/res/layout/activity_add_word.xml
View file @
4dd660d5
...
...
@@ -23,13 +23,13 @@
android:layout_marginTop=
"8dp"
android:ems=
"10"
android:hint=
"Translation"
app:layout_constraintBottom_toTopOf=
"@+id/btnSubmit"
app:layout_constraintBottom_toTopOf=
"@+id/btnSubmit
NewWord
"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/etWord"
/>
<Button
android:id=
"@+id/btnSubmit"
android:id=
"@+id/btnSubmit
NewWord
"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"16dp"
...
...
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