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