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
82cb4ebe
authored
Apr 29, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Naming refactoring
parent
2027d343
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
39 deletions
app/src/main/java/com/paktalin/vocabularynotebook/entities/UserPojo.kt
app/src/main/java/com/paktalin/vocabularynotebook/entities/VocabularyPojo.kt
app/src/main/java/com/paktalin/vocabularynotebook/firestore/FirestoreManager.kt
app/src/main/java/com/paktalin/vocabularynotebook/firestore/Model.kt
app/src/main/java/com/paktalin/vocabularynotebook/firestore/UserManager.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/LogInActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/entities/UserPojo.kt
View file @
82cb4ebe
...
...
@@ -3,7 +3,7 @@ package com.paktalin.vocabularynotebook.entities
import
com.google.firebase.firestore.DocumentReference
class
UserPojo
(
var
email
:
String
?)
{
class
UserPojo
(
var
email
:
String
?
,
id
:
String
?
)
{
var
name
:
String
?
=
null
var
vocabularies
:
List
<
DocumentReference
>?
=
null
}
app/src/main/java/com/paktalin/vocabularynotebook/entities/VocabularyPojo.kt
View file @
82cb4ebe
package
com.paktalin.vocabularynotebook.entities
class
VocabularyPojo
(
var
title
:
String
?)
{
class
VocabularyPojo
(
var
title
:
String
?,
val
id
:
String
?)
{
init
{
if
(
title
==
null
)
title
=
"Untitled vocabulary"
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/firestore/FirestoreManager.kt
View file @
82cb4ebe
...
...
@@ -45,7 +45,7 @@ class FirestoreManager {
}
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"Couldn't addAll user to the database"
,
it
.
cause
)
mD
eleteUser
(
firebaseUser
)
d
eleteUser
(
firebaseUser
)
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/firestore/Model.kt
0 → 100644
View file @
82cb4ebe
package
com.paktalin.vocabularynotebook.firestore
import
com.paktalin.vocabularynotebook.entities.UserPojo
import
com.paktalin.vocabularynotebook.entities.VocabularyPojo
import
com.paktalin.vocabularynotebook.entities.WordPojo
class
Model
{
lateinit
var
user
:
UserPojo
lateinit
var
vocabularyPojo
:
VocabularyPojo
lateinit
var
words
:
MutableList
<
WordPojo
>
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/firestore/UserManager.kt
View file @
82cb4ebe
...
...
@@ -12,58 +12,52 @@ import com.paktalin.vocabularynotebook.utils.shortToast
private
const
val
TAG
=
"VN/UserManager"
private
var
mAuth
:
FirebaseAuth
?
=
FirebaseAuth
.
getInstance
()
fun
mD
eleteUser
(
user
:
FirebaseUser
)
{
fun
d
eleteUser
(
user
:
FirebaseUser
)
{
user
.
delete
()
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"UserPojo was successfully deleted"
)
}
.
addOnFailureListener
{
Log
.
i
(
TAG
,
"
mD
eleteUser:failure"
,
it
.
cause
)
}
.
addOnFailureListener
{
Log
.
i
(
TAG
,
"
d
eleteUser:failure"
,
it
.
cause
)
}
}
fun
mL
ogIn
(
onComplete
:
()
->
Unit
,
onSuccess
:
()
->
Unit
,
onFailure
:
()
->
Unit
,
fun
l
ogIn
(
onComplete
:
()
->
Unit
,
onSuccess
:
()
->
Unit
,
onFailure
:
()
->
Unit
,
username
:
String
,
password
:
String
)
{
mAuth
!!
.
signInWithEmailAndPassword
(
e
mail
(
username
),
password
)
.
addOnCompleteListener
{
onComplete
()
}
.
addOnSuccessListener
{
mAuth
?.
signInWithEmailAndPassword
(
constructE
mail
(
username
),
password
)
?
.
addOnCompleteListener
{
onComplete
()
}
?
.
addOnSuccessListener
{
Log
.
d
(
TAG
,
"Successfully signed in"
)
onSuccess
()
}
.
addOnFailureListener
{
?
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"signInWithEmail:failure"
,
it
)
onFailure
()
}
}
internal
fun
isEmail
(
string
:
String
)
=
Patterns
.
EMAIL_ADDRESS
.
matcher
(
string
).
matches
()
fun
mS
ignUp
(
activity
:
LogInActivity
,
username
:
String
,
password
:
String
)
{
mAuth
!!
.
createUserWithEmailAndPassword
(
e
mail
(
username
),
password
)
.
addOnCompleteListener
{
removeProgressBar
(
activity
.
supportFragmentManager
)
}
.
addOnSuccessListener
{
fun
s
ignUp
(
activity
:
LogInActivity
,
username
:
String
,
password
:
String
)
{
mAuth
?.
createUserWithEmailAndPassword
(
constructE
mail
(
username
),
password
)
?
.
addOnCompleteListener
{
removeProgressBar
(
activity
.
supportFragmentManager
)
}
?
.
addOnSuccessListener
{
Log
.
d
(
TAG
,
"Successfully signed up a new user"
)
FirestoreManager
().
addNewUser
(
mAuth
!!
.
currentUser
!!
,
activity
)
mAuth
?.
currentUser
?.
let
{
it1
->
FirestoreManager
().
addNewUser
(
it1
,
activity
)
}
shortToast
(
activity
,
activity
.
resources
.
getString
(
R
.
string
.
toast_successful_sign_up
))
activity
.
login
()
}
.
addOnFailureListener
{
Log
.
d
(
TAG
,
"createUserWithEmail:failure"
,
it
.
fillInStackTrace
())
shortToast
(
activity
,
it
.
message
!!
)
?.
addOnFailureListener
{
msg
->
Log
.
d
(
TAG
,
"createUserWithEmail:failure"
,
msg
.
fillInStackTrace
())
msg
.
message
?.
let
{
it1
->
shortToast
(
activity
,
it1
)
}
}
}
fun
mU
serLoggedIn
():
Boolean
{
return
mAuth
!!
.
currentUser
!=
null
fun
u
serLoggedIn
():
Boolean
{
return
mAuth
?
.
currentUser
!=
null
}
fun
mL
ogOut
()
{
mAuth
!!
.
signOut
()
fun
l
ogOut
()
{
mAuth
?
.
signOut
()
Log
.
i
(
TAG
,
"User logged out"
)
}
private
fun
email
(
username
:
String
):
String
{
return
if
(
isEmail
(
username
))
username
else
{
val
dummyDomain
=
"@wordbook.com"
username
.
toLowerCase
()
+
dummyDomain
}
private
fun
constructEmail
(
username
:
String
):
String
{
return
if
(
isEmail
(
username
))
username
else
username
.
toLowerCase
()
+
"@wordbook.com"
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/LogInActivity.kt
View file @
82cb4ebe
...
...
@@ -3,9 +3,9 @@ package com.paktalin.vocabularynotebook.ui.activities
import
android.os.Bundle
import
androidx.appcompat.app.AppCompatActivity
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestore.
mL
ogIn
import
com.paktalin.vocabularynotebook.firestore.
mS
ignUp
import
com.paktalin.vocabularynotebook.firestore.
mU
serLoggedIn
import
com.paktalin.vocabularynotebook.firestore.
l
ogIn
import
com.paktalin.vocabularynotebook.firestore.
s
ignUp
import
com.paktalin.vocabularynotebook.firestore.
u
serLoggedIn
import
com.paktalin.vocabularynotebook.utils.*
import
kotlinx.android.synthetic.main.activity_log_in.*
...
...
@@ -20,7 +20,7 @@ class LogInActivity : AppCompatActivity() {
override
fun
onStart
()
{
super
.
onStart
()
if
(
mU
serLoggedIn
())
{
if
(
u
serLoggedIn
())
{
startUserActivity
()
}
}
...
...
@@ -29,7 +29,7 @@ class LogInActivity : AppCompatActivity() {
val
(
username
,
password
)
=
getUsernameAndPassword
()
if
(
fieldsNotEmpty
(
username
,
password
,
this
))
{
addProgressBar
()
mL
ogIn
(
l
ogIn
(
{
removeProgressBar
(
supportFragmentManager
)
},
{
startUserActivity
()
},
{
shortToast
(
this
@LogInActivity
,
getString
(
R
.
string
.
toast_auth_failed
))
},
...
...
@@ -41,7 +41,9 @@ class LogInActivity : AppCompatActivity() {
val
(
username
,
password
)
=
getUsernameAndPassword
()
if
(
fieldsNotEmpty
(
username
,
password
,
this
)
&&
validUsername
(
username
,
this
))
{
addProgressBar
()
mSignUp
(
this
,
username
,
password
)
signUp
(
this
,
username
,
password
)
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
View file @
82cb4ebe
...
...
@@ -12,7 +12,6 @@ import androidx.appcompat.widget.SearchView
import
androidx.recyclerview.selection.Selection
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestore.FirestoreManager
import
com.paktalin.vocabularynotebook.firestore.mLogOut
import
com.paktalin.vocabularynotebook.ui.fragments.SubmitAddedFragment
import
com.paktalin.vocabularynotebook.ui.fragments.TagFragment
import
com.paktalin.vocabularynotebook.ui.recycler_view.State
...
...
@@ -63,7 +62,7 @@ class MainActivity : AppCompatActivity() {
}
private
fun
logOut
()
{
mL
ogOut
()
com
.
paktalin
.
vocabularynotebook
.
firestore
.
l
ogOut
()
startActivity
(
this
@MainActivity
,
LogInActivity
::
class
.
java
)
}
...
...
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