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
...
@@ -3,7 +3,7 @@ package com.paktalin.vocabularynotebook.entities
import
com.google.firebase.firestore.DocumentReference
import
com.google.firebase.firestore.DocumentReference
class
UserPojo
(
var
email
:
String
?)
{
class
UserPojo
(
var
email
:
String
?
,
id
:
String
?
)
{
var
name
:
String
?
=
null
var
name
:
String
?
=
null
var
vocabularies
:
List
<
DocumentReference
>?
=
null
var
vocabularies
:
List
<
DocumentReference
>?
=
null
}
}
app/src/main/java/com/paktalin/vocabularynotebook/entities/VocabularyPojo.kt
View file @
82cb4ebe
package
com.paktalin.vocabularynotebook.entities
package
com.paktalin.vocabularynotebook.entities
class
VocabularyPojo
(
var
title
:
String
?)
{
class
VocabularyPojo
(
var
title
:
String
?,
val
id
:
String
?)
{
init
{
init
{
if
(
title
==
null
)
title
=
"Untitled vocabulary"
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 {
...
@@ -45,7 +45,7 @@ class FirestoreManager {
}
}
.
addOnFailureListener
{
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"Couldn't addAll user to the database"
,
it
.
cause
)
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
...
@@ -12,58 +12,52 @@ import com.paktalin.vocabularynotebook.utils.shortToast
private
const
val
TAG
=
"VN/UserManager"
private
const
val
TAG
=
"VN/UserManager"
private
var
mAuth
:
FirebaseAuth
?
=
FirebaseAuth
.
getInstance
()
private
var
mAuth
:
FirebaseAuth
?
=
FirebaseAuth
.
getInstance
()
fun
mD
eleteUser
(
user
:
FirebaseUser
)
{
fun
d
eleteUser
(
user
:
FirebaseUser
)
{
user
.
delete
()
user
.
delete
()
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"UserPojo was successfully deleted"
)
}
.
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
)
{
username
:
String
,
password
:
String
)
{
mAuth
!!
.
signInWithEmailAndPassword
(
e
mail
(
username
),
password
)
mAuth
?.
signInWithEmailAndPassword
(
constructE
mail
(
username
),
password
)
.
addOnCompleteListener
{
onComplete
()
}
?
.
addOnCompleteListener
{
onComplete
()
}
.
addOnSuccessListener
{
?
.
addOnSuccessListener
{
Log
.
d
(
TAG
,
"Successfully signed in"
)
Log
.
d
(
TAG
,
"Successfully signed in"
)
onSuccess
()
onSuccess
()
}
}
.
addOnFailureListener
{
?
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"signInWithEmail:failure"
,
it
)
Log
.
w
(
TAG
,
"signInWithEmail:failure"
,
it
)
onFailure
()
onFailure
()
}
}
}
}
internal
fun
isEmail
(
string
:
String
)
=
Patterns
.
EMAIL_ADDRESS
.
matcher
(
string
).
matches
()
internal
fun
isEmail
(
string
:
String
)
=
Patterns
.
EMAIL_ADDRESS
.
matcher
(
string
).
matches
()
fun
mS
ignUp
(
activity
:
LogInActivity
,
username
:
String
,
password
:
String
)
{
fun
s
ignUp
(
activity
:
LogInActivity
,
username
:
String
,
password
:
String
)
{
mAuth
!!
.
createUserWithEmailAndPassword
(
e
mail
(
username
),
password
)
mAuth
?.
createUserWithEmailAndPassword
(
constructE
mail
(
username
),
password
)
.
addOnCompleteListener
{
removeProgressBar
(
activity
.
supportFragmentManager
)
}
?
.
addOnCompleteListener
{
removeProgressBar
(
activity
.
supportFragmentManager
)
}
.
addOnSuccessListener
{
?
.
addOnSuccessListener
{
Log
.
d
(
TAG
,
"Successfully signed up a new user"
)
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
))
shortToast
(
activity
,
activity
.
resources
.
getString
(
R
.
string
.
toast_successful_sign_up
))
activity
.
login
()
activity
.
login
()
}
}
.
addOnFailureListener
{
?.
addOnFailureListener
{
msg
->
Log
.
d
(
TAG
,
"createUserWithEmail:failure"
,
it
.
fillInStackTrace
())
Log
.
d
(
TAG
,
"createUserWithEmail:failure"
,
msg
.
fillInStackTrace
())
shortToast
(
activity
,
it
.
message
!!
)
msg
.
message
?.
let
{
it1
->
shortToast
(
activity
,
it1
)
}
}
}
}
}
fun
mU
serLoggedIn
():
Boolean
{
fun
u
serLoggedIn
():
Boolean
{
return
mAuth
!!
.
currentUser
!=
null
return
mAuth
?
.
currentUser
!=
null
}
}
fun
mL
ogOut
()
{
fun
l
ogOut
()
{
mAuth
!!
.
signOut
()
mAuth
?
.
signOut
()
Log
.
i
(
TAG
,
"User logged out"
)
Log
.
i
(
TAG
,
"User logged out"
)
}
}
private
fun
email
(
username
:
String
):
String
{
private
fun
constructEmail
(
username
:
String
):
String
{
return
if
(
isEmail
(
username
))
return
if
(
isEmail
(
username
))
username
username
else
username
.
toLowerCase
()
+
"@wordbook.com"
else
{
val
dummyDomain
=
"@wordbook.com"
username
.
toLowerCase
()
+
dummyDomain
}
}
}
\ 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
...
@@ -3,9 +3,9 @@ package com.paktalin.vocabularynotebook.ui.activities
import
android.os.Bundle
import
android.os.Bundle
import
androidx.appcompat.app.AppCompatActivity
import
androidx.appcompat.app.AppCompatActivity
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestore.
mL
ogIn
import
com.paktalin.vocabularynotebook.firestore.
l
ogIn
import
com.paktalin.vocabularynotebook.firestore.
mS
ignUp
import
com.paktalin.vocabularynotebook.firestore.
s
ignUp
import
com.paktalin.vocabularynotebook.firestore.
mU
serLoggedIn
import
com.paktalin.vocabularynotebook.firestore.
u
serLoggedIn
import
com.paktalin.vocabularynotebook.utils.*
import
com.paktalin.vocabularynotebook.utils.*
import
kotlinx.android.synthetic.main.activity_log_in.*
import
kotlinx.android.synthetic.main.activity_log_in.*
...
@@ -20,7 +20,7 @@ class LogInActivity : AppCompatActivity() {
...
@@ -20,7 +20,7 @@ class LogInActivity : AppCompatActivity() {
override
fun
onStart
()
{
override
fun
onStart
()
{
super
.
onStart
()
super
.
onStart
()
if
(
mU
serLoggedIn
())
{
if
(
u
serLoggedIn
())
{
startUserActivity
()
startUserActivity
()
}
}
}
}
...
@@ -29,7 +29,7 @@ class LogInActivity : AppCompatActivity() {
...
@@ -29,7 +29,7 @@ class LogInActivity : AppCompatActivity() {
val
(
username
,
password
)
=
getUsernameAndPassword
()
val
(
username
,
password
)
=
getUsernameAndPassword
()
if
(
fieldsNotEmpty
(
username
,
password
,
this
))
{
if
(
fieldsNotEmpty
(
username
,
password
,
this
))
{
addProgressBar
()
addProgressBar
()
mL
ogIn
(
l
ogIn
(
{
removeProgressBar
(
supportFragmentManager
)
},
{
removeProgressBar
(
supportFragmentManager
)
},
{
startUserActivity
()
},
{
startUserActivity
()
},
{
shortToast
(
this
@LogInActivity
,
getString
(
R
.
string
.
toast_auth_failed
))
},
{
shortToast
(
this
@LogInActivity
,
getString
(
R
.
string
.
toast_auth_failed
))
},
...
@@ -41,7 +41,9 @@ class LogInActivity : AppCompatActivity() {
...
@@ -41,7 +41,9 @@ class LogInActivity : AppCompatActivity() {
val
(
username
,
password
)
=
getUsernameAndPassword
()
val
(
username
,
password
)
=
getUsernameAndPassword
()
if
(
fieldsNotEmpty
(
username
,
password
,
this
)
&&
validUsername
(
username
,
this
))
{
if
(
fieldsNotEmpty
(
username
,
password
,
this
)
&&
validUsername
(
username
,
this
))
{
addProgressBar
()
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
...
@@ -12,7 +12,6 @@ import androidx.appcompat.widget.SearchView
import
androidx.recyclerview.selection.Selection
import
androidx.recyclerview.selection.Selection
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestore.FirestoreManager
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.SubmitAddedFragment
import
com.paktalin.vocabularynotebook.ui.fragments.TagFragment
import
com.paktalin.vocabularynotebook.ui.fragments.TagFragment
import
com.paktalin.vocabularynotebook.ui.recycler_view.State
import
com.paktalin.vocabularynotebook.ui.recycler_view.State
...
@@ -63,7 +62,7 @@ class MainActivity : AppCompatActivity() {
...
@@ -63,7 +62,7 @@ class MainActivity : AppCompatActivity() {
}
}
private
fun
logOut
()
{
private
fun
logOut
()
{
mL
ogOut
()
com
.
paktalin
.
vocabularynotebook
.
firestore
.
l
ogOut
()
startActivity
(
this
@MainActivity
,
LogInActivity
::
class
.
java
)
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