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
c370f256
authored
Apr 29, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring
parent
eb0e29a6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
11 deletions
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/MyUserManager.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/utils/ActivityUtil.kt
app/src/main/java/com/paktalin/vocabularynotebook/firestore/FirestoreManager.kt
View file @
c370f256
package
com.paktalin.vocabularynotebook.firestore
import
android.content.Context
import
com.google.firebase.auth.FirebaseAuth
import
com.google.firebase.auth.FirebaseUser
import
com.google.firebase.firestore.*
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
...
...
@@ -22,8 +21,7 @@ class FirestoreManager {
fun
extractVocabularyId
(
onSuccess
:
()
->
Unit
,
showToastNoWords
:
()
->
Unit
,
removeProgressBar
:
()
->
Unit
,
mainActivity
:
Context
)
{
val
userId
=
FirebaseAuth
.
getInstance
()
!!
.
currentUser
!!
.
uid
userDocument
(
userId
)
?.
get
()
userDocument
(
Model
.
userId
)
?.
get
()
?.
addOnSuccessListener
{
snapshot
->
removeProgressBar
()
if
(
snapshot
.
get
(
VOCABULARIES
)
!=
null
)
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/firestore/Model.kt
View file @
c370f256
...
...
@@ -9,5 +9,9 @@ class Model {
lateinit
var
vocabularyPojo
:
VocabularyPojo
lateinit
var
words
:
MutableList
<
WordPojo
>
companion
object
{
var
userId
:
String
?
=
null
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/firestore/MyUserManager.kt
View file @
c370f256
...
...
@@ -24,10 +24,11 @@ class MyUserManager {
Log
.
d
(
TAG
,
"Successfully signed in"
)
onSuccess
()
}
?.
addOnFailureListener
{
Log
.
w
(
TAG
,
"signInWithEmail:failure"
,
it
)
?.
addOnFailureListener
{
e
->
Log
.
w
(
TAG
,
"signInWithEmail:failure"
,
e
)
onFailure
()
}
Model
.
userId
=
this
.
user
?.
uid
}
fun
signUp
(
username
:
String
,
password
:
String
,
...
...
@@ -46,6 +47,7 @@ class MyUserManager {
Log
.
d
(
TAG
,
"createUserWithEmail:failure"
,
e
.
fillInStackTrace
())
onFailure
()
}
Model
.
userId
=
this
.
user
?.
uid
}
fun
deleteUser
(
user
:
FirebaseUser
?)
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/LogInActivity.kt
View file @
c370f256
...
...
@@ -36,7 +36,10 @@ class LogInActivity : AppCompatActivity() {
addProgressBar
(
supportFragmentManager
,
R
.
id
.
container_login
)
MyUserManager
.
signUp
(
u
,
p
,
onComplete
=
{
removeProgressBar
(
supportFragmentManager
)
},
onSuccess
=
{
shortToast
(
this
,
resources
.
getString
(
R
.
string
.
toast_successful_sign_up
));
login
()
},
onSuccess
=
{
shortToast
(
this
,
resources
.
getString
(
R
.
string
.
toast_successful_sign_up
))
startActivity
(
this
,
MainActivity
::
class
.
java
)
},
onFailure
=
{
shortToast
(
this
,
resources
.
getString
(
R
.
string
.
toast_sign_up_failed
))
},
logInActivity
=
this
)
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
View file @
c370f256
...
...
@@ -86,7 +86,8 @@ class MainActivity : AppCompatActivity() {
private
fun
setUpVocabularyAdapter
()
{
addProgressBar
(
supportFragmentManager
,
R
.
id
.
container_main
)
FirestoreManager
().
extractVocabularyId
({
FirestoreManager
().
extractVocabularyId
(
onSuccess
=
{
FirestoreManager
().
extractVocabulary
{
querySnapshot
->
run
{
if
(
querySnapshot
!=
null
&&
!
querySnapshot
.
isEmpty
)
{
...
...
@@ -97,10 +98,12 @@ class MainActivity : AppCompatActivity() {
}
}
},
{
shortToast
(
this
,
getString
(
R
.
string
.
toast_empty_vocabulary
))
},
{
removeProgressBar
(
supportFragmentManager
)
},
this
)
showToastNoWords
=
{
shortToast
(
this
,
getString
(
R
.
string
.
toast_empty_vocabulary
))
},
removeProgressBar
=
{
removeProgressBar
(
supportFragmentManager
)
},
mainActivity
=
this
)
}
private
fun
setUpAddWordTouchListeners
()
{
word
.
setOnTouchListener
{
_
,
_
->
addSubmitFragment
(
supportFragmentManager
,
SubmitAddedFragment
(),
R
.
id
.
main_activity_container
)
...
...
app/src/main/java/com/paktalin/vocabularynotebook/utils/ActivityUtil.kt
View file @
c370f256
...
...
@@ -3,6 +3,7 @@ package com.paktalin.vocabularynotebook.utils
import
android.content.Context
import
android.content.Intent
import
android.os.Bundle
import
android.util.Patterns
import
android.view.View
import
android.view.inputmethod.InputMethodManager
import
android.widget.Toast
...
...
@@ -10,7 +11,6 @@ import androidx.appcompat.app.AppCompatActivity
import
androidx.fragment.app.Fragment
import
androidx.fragment.app.FragmentManager
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestore.isEmail
import
com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment
import
com.paktalin.vocabularynotebook.ui.fragments.SubmitFragment
import
org.apache.commons.lang3.StringUtils
...
...
@@ -49,7 +49,7 @@ fun fieldsNotEmpty(username: String, password: String, context: Context): Boolea
}
fun
validUsername
(
username
:
String
,
context
:
Context
):
Boolean
{
return
if
(
isEmail
(
username
)
||
return
if
(
Patterns
.
EMAIL_ADDRESS
.
matcher
(
username
).
matches
(
)
||
StringUtils
.
containsOnly
(
username
.
toLowerCase
(),
"abcdefghijklmnopqrstuvwxyz0123456789-_."
))
true
else
{
...
...
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