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
d0c5f749
authored
Nov 17, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changing registration procedure in progress
parent
b8cead78
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
34 additions
and
16 deletions
.idea/caches/build_file_checksums.ser
.idea/misc.xml
app/build.gradle
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/LogInActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/utils/ActivityUtil.kt
app/src/main/java/com/paktalin/vocabularynotebook/utils/UserManager.kt
app/src/main/res/values/strings.xml
.idea/caches/build_file_checksums.ser
View file @
d0c5f749
No preview for this file type
.idea/misc.xml
View file @
d0c5f749
...
...
@@ -25,7 +25,7 @@
</value>
</option>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
8
"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
7
"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<output
url=
"file://$PROJECT_DIR$/build/classes"
/>
</component>
<component
name=
"ProjectType"
>
...
...
app/build.gradle
View file @
d0c5f749
...
...
@@ -32,6 +32,7 @@ dependencies {
implementation
"org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation
'com.android.support:multidex:1.0.3'
implementation
'org.apache.commons:commons-lang3:3.6'
implementation
'com.google.firebase:firebase-core:16.0.3'
implementation
'com.google.firebase:firebase-database:16.0.1'
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/LogInActivity.kt
View file @
d0c5f749
...
...
@@ -24,21 +24,23 @@ class LogInActivity : AppCompatActivity() {
}
fun
login
()
{
processUser
{
processUser
(
resources
.
getString
(
R
.
string
.
toast_incorrect_username_password
))
{
mLogIn
(
{
removeProgressBar
()
},
{
startUserActivity
()
},
{
showToastFailure
()
},
email
!!
,
password
!!
)
}
}
}
}
private
fun
signUp
()
{
processUser
{
mSignUp
(
this
,
email
!!
,
password
!!
)
}
}
private
fun
signUp
()
{
processUser
(
resources
.
getString
(
R
.
string
.
toast_username_characters
))
{
mSignUp
(
this
,
email
!!
,
password
!!
)
}
}
private
fun
processUser
(
authAction
:
()
->
Unit
)
{
private
fun
processUser
(
invalidUsername
:
String
,
authAction
:
()
->
Unit
)
{
email
=
etEmail
!!
.
text
.
toString
()
password
=
etPassword
!!
.
text
.
toString
()
if
(
fieldsNotEmpty
(
email
!!
,
password
!!
,
"Please, enter email and password"
,
this
))
{
if
(
validInput
(
email
!!
,
password
!!
,
this
,
invalidUsername
))
{
addProgressBar
()
authAction
()
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/utils/ActivityUtil.kt
View file @
d0c5f749
...
...
@@ -6,13 +6,11 @@ import android.os.Bundle
import
android.support.v4.app.Fragment
import
android.support.v4.app.FragmentManager
import
android.text.TextUtils
import
android.view.Menu
import
android.view.View
import
android.widget.Toast
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment
import
kotlinx.android.synthetic.main.content_main.*
import
kotlinx.android.synthetic.main.fragment_editable_word.view.*
import
org.apache.commons.lang3.StringUtils.containsOnly
val
progressFragment
:
Fragment
=
ProgressFragment
()
...
...
@@ -33,14 +31,22 @@ fun removeProgressBar(fragmentManager: FragmentManager) {
removeFragment
(
fragmentManager
,
progressFragment
)
}
fun
fieldsNotEmpty
(
text1
:
String
,
text2
:
String
,
toastMessage
:
String
,
context
:
Context
):
Boolean
{
if
(
TextUtils
.
isEmpty
(
text1
)
||
TextUtils
.
isEmpty
(
text2
))
{
shortToast
(
context
,
toastMessage
)
fun
validInput
(
username
:
String
,
password
:
String
,
context
:
Context
,
invalidUsername
:
String
):
Boolean
{
if
(
TextUtils
.
isEmpty
(
username
)
||
TextUtils
.
isEmpty
(
password
))
{
shortToast
(
context
,
context
.
resources
.
getString
(
R
.
string
.
toast_enter_username_password
))
return
false
}
else
if
(!
appropriateCharacters
(
username
))
{
shortToast
(
context
,
invalidUsername
)
return
false
}
return
true
}
private
fun
appropriateCharacters
(
username
:
String
):
Boolean
{
return
containsOnly
(
username
.
toLowerCase
(),
"abcdefghijklmnopqrstuvwxyz0123456789-_."
)
}
fun
shortToast
(
context
:
Context
,
text
:
String
)
{
Toast
.
makeText
(
context
,
text
,
Toast
.
LENGTH_SHORT
).
show
()
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/utils/UserManager.kt
View file @
d0c5f749
...
...
@@ -15,8 +15,8 @@ fun mDeleteUser(user: FirebaseUser) {
}
fun
mLogIn
(
onComplete
:
()
->
Unit
,
onSuccess
:
()
->
Unit
,
onFailure
:
()
->
Unit
,
email
:
String
,
password
:
String
)
{
mAuth
!!
.
signInWithEmailAndPassword
(
email
,
password
)
username
:
String
,
password
:
String
)
{
mAuth
!!
.
signInWithEmailAndPassword
(
email
(
username
)
,
password
)
.
addOnCompleteListener
{
onComplete
()
}
.
addOnSuccessListener
{
Log
.
d
(
TAG
,
"Successfully signed in"
)
...
...
@@ -28,8 +28,8 @@ fun mLogIn(onComplete: () -> Unit, onSuccess: () -> Unit, onFailure: () -> Unit,
}
}
fun
mSignUp
(
activity
:
LogInActivity
,
email
:
String
,
password
:
String
)
{
mAuth
!!
.
createUserWithEmailAndPassword
(
email
,
password
)
fun
mSignUp
(
activity
:
LogInActivity
,
username
:
String
,
password
:
String
)
{
mAuth
!!
.
createUserWithEmailAndPassword
(
email
(
username
)
,
password
)
.
addOnCompleteListener
{
removeProgressBar
(
activity
.
supportFragmentManager
)
}
.
addOnSuccessListener
{
Log
.
d
(
TAG
,
"Successfully signed up a new user"
)
...
...
@@ -50,3 +50,8 @@ fun mLogOut() {
mAuth
!!
.
signOut
()
Log
.
i
(
TAG
,
"User logged out"
)
}
private
fun
email
(
username
:
String
):
String
{
val
dummyDomain
=
"@wordbook.com"
return
username
.
toLowerCase
()
+
dummyDomain
}
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
d0c5f749
...
...
@@ -23,4 +23,7 @@
<string
name=
"toast_new_word_fail"
>
Couldn\'t add the word
</string>
<string
name=
"toast_update_word_failed"
>
Couldn\'t update the word
</string>
<string
name=
"toast_successful_sign_up"
>
Congratulations! You can now access your vocabulary from any device
</string>
<string
name=
"toast_enter_username_password"
>
Please, enter username and password
</string>
<string
name=
"toast_username_characters"
>
Please, create a username using letters a–z, numbers 0–9 and characters -_.
</string>
<string
name=
"toast_incorrect_username_password"
>
Username or password is incorrect
</string>
</resources>
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