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
e92751b8
authored
Sep 07, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Linked vocabularies collection to users
parent
c34cf757
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
5 deletions
app/src/main/java/com/paktalin/vocabularynotebook/User.java
app/src/main/java/com/paktalin/vocabularynotebook/Vocabulary.java
app/src/main/java/com/paktalin/vocabularynotebook/activities/LogInActivity.kt
app/src/main/res/layout/activity_log_in.xml
app/src/main/java/com/paktalin/vocabularynotebook/User.java
View file @
e92751b8
package
com
.
paktalin
.
vocabularynotebook
;
import
com.google.firebase.firestore.DocumentReference
;
import
java.util.List
;
public
class
User
{
private
final
static
String
TAG
=
"VN/"
+
User
.
class
.
getSimpleName
();
private
String
email
,
name
;
private
List
<
DocumentReference
>
vocabularies
;
public
User
(
String
email
)
{
this
.
email
=
email
;
...
...
@@ -22,4 +29,12 @@ public class User {
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
List
<
DocumentReference
>
getVocabularies
()
{
return
vocabularies
;
}
public
void
setVocabularies
(
List
<
DocumentReference
>
vocabularies
)
{
this
.
vocabularies
=
vocabularies
;
}
}
app/src/main/java/com/paktalin/vocabularynotebook/Vocabulary.java
0 → 100644
View file @
e92751b8
package
com
.
paktalin
.
vocabularynotebook
;
public
class
Vocabulary
{
String
title
;
public
Vocabulary
()
{
title
=
"First vocabulary"
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
}
app/src/main/java/com/paktalin/vocabularynotebook/activities/LogInActivity.kt
View file @
e92751b8
package
com.paktalin.vocabularynotebook.activities
import
android.annotation.SuppressLint
import
android.content.Intent
import
android.support.v7.app.AppCompatActivity
import
android.os.Bundle
...
...
@@ -14,6 +15,8 @@ import kotlinx.android.synthetic.main.activity_log_in.*
import
com.google.firebase.firestore.FirebaseFirestore
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.User
import
com.paktalin.vocabularynotebook.Vocabulary
import
java.util.*
class
LogInActivity
:
AppCompatActivity
()
{
...
...
@@ -26,6 +29,7 @@ class LogInActivity : AppCompatActivity() {
mAuth
=
FirebaseAuth
.
getInstance
()
btnLogIn
!!
.
setOnClickListener
({
signIn
()
})
btnSignUp
!!
.
setOnClickListener
({
signUp
()
})
btnRandomUser
!!
.
setOnClickListener
({
createRandomUser
()
})
}
override
fun
onStart
()
{
...
...
@@ -93,12 +97,28 @@ class LogInActivity : AppCompatActivity() {
private
fun
addNewUserToDb
(
newUser
:
FirebaseUser
)
{
//todo add condition to writing to the db in Firebase Console (request.auth.uid)
//todo delete account if couldn't add user to the db
val
db
=
FirebaseFirestore
.
getInstance
()
db
.
collection
(
"users"
).
document
(
newUser
.
uid
).
set
(
User
(
newUser
.
email
))
.
addOnCompleteListener
({
task
->
if
(
task
.
isSuccessful
)
Log
.
i
(
TAG
,
"Successfully added user to the collection"
)
else
Log
.
w
(
TAG
,
"addUser:failure"
,
task
.
exception
)
})
val
user
=
User
(
newUser
.
email
)
db
.
collection
(
"vocabularies"
).
add
(
Vocabulary
())
.
addOnSuccessListener
{
firstVocabularyRef
->
Log
.
d
(
TAG
,
"Vocabulary successfully created: "
+
firstVocabularyRef
.
path
)
user
.
vocabularies
=
Collections
.
singletonList
(
firstVocabularyRef
)
db
.
collection
(
"users"
).
document
(
newUser
.
uid
).
set
(
user
)
.
addOnCompleteListener
({
task
->
if
(
task
.
isSuccessful
)
Log
.
i
(
TAG
,
"Successfully added user to the collection"
)
else
Log
.
w
(
TAG
,
"addUser:failure"
,
task
.
exception
)
})
}
}
@SuppressLint
(
"SetTextI18n"
)
private
fun
createRandomUser
()
{
etEmail
.
setText
(
"random@gmail.com"
)
etPassword
.
setText
(
"123456"
)
signUp
()
}
companion
object
{
...
...
app/src/main/res/layout/activity_log_in.xml
View file @
e92751b8
...
...
@@ -74,4 +74,18 @@
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toEndOf=
"@+id/btnLogIn"
app:layout_constraintTop_toTopOf=
"@+id/btnLogIn"
/>
<Button
android:id=
"@+id/btnRandomUser"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"8dp"
android:layout_marginLeft=
"8dp"
android:layout_marginRight=
"8dp"
android:layout_marginStart=
"8dp"
android:layout_marginTop=
"8dp"
android:text=
"Create random user"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
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