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
350ce549
authored
Nov 11, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring
parent
638c1d44
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
26 additions
and
131 deletions
app/src/main/java/com/paktalin/vocabularynotebook/ActivityUtil.kt
app/src/main/java/com/paktalin/vocabularynotebook/UserManager.kt
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.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/ui/fragments/AddWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/EditWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/utils/FirestoreManager.kt
app/src/main/java/com/paktalin/vocabularynotebook/ActivityUtil.kt
deleted
100644 → 0
View file @
638c1d44
package
com.paktalin.vocabularynotebook
import
android.content.Context
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.support.v4.app.FragmentManager
import
android.text.TextUtils
import
android.widget.Toast
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment
import
kotlinx.android.synthetic.main.content_main.*
val
progressFragment
:
Fragment
=
ProgressFragment
()
fun
addFragment
(
fragmentManager
:
FragmentManager
,
fragment
:
Fragment
,
containerId
:
Int
,
arguments
:
Bundle
?)
{
fragment
.
arguments
=
arguments
fragmentManager
.
beginTransaction
().
add
(
containerId
,
fragment
).
commitAllowingStateLoss
()
}
fun
removeFragment
(
fragmentManager
:
FragmentManager
,
fragment
:
Fragment
)
{
fragmentManager
.
beginTransaction
().
remove
(
fragment
).
commitAllowingStateLoss
()
}
fun
addProgressBar
(
fragmentManager
:
FragmentManager
,
containerId
:
Int
)
{
addFragment
(
fragmentManager
,
progressFragment
,
containerId
,
null
)
}
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
)
return
false
}
return
true
}
fun
disableScrolling
(
mainActivity
:
MainActivity
)
{
mainActivity
.
scrollView
!!
.
setScrollingEnabled
(
false
)
}
fun
enableScrolling
(
mainActivity
:
MainActivity
)
{
mainActivity
.
scrollView
!!
.
setScrollingEnabled
(
true
)
}
fun
shortToast
(
context
:
Context
,
text
:
String
)
{
Toast
.
makeText
(
context
,
text
,
Toast
.
LENGTH_SHORT
).
show
()
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/UserManager.kt
deleted
100644 → 0
View file @
638c1d44
package
com.paktalin.vocabularynotebook
import
android.util.Log
import
com.google.firebase.auth.FirebaseAuth
import
com.google.firebase.auth.FirebaseUser
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.ui.activities.LogInActivity
import
com.paktalin.vocabularynotebook.firestoreitems.UserPojo
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import
java.util.*
private
const
val
TAG
=
"VN/UserManager"
private
fun
deleteUser
(
user
:
FirebaseUser
)
{
user
.
delete
()
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"UserPojo was successfully deleted"
)
}
.
addOnFailureListener
{
Log
.
i
(
TAG
,
"deleteUser:failure"
,
it
.
cause
)}
}
fun
addNewUserToDb
(
newUser
:
FirebaseUser
,
logInActivity
:
LogInActivity
)
{
//todo add condition to writing to the db in Firebase Console (request.auth.uid)
val
db
=
ConfiguredFirestore
.
instance
val
user
=
UserPojo
(
newUser
.
email
)
db
.
collection
(
VOCABULARIES
).
add
(
Vocabulary
.
Pojo
(
null
))
.
addOnSuccessListener
{
firstVocabularyRef
->
Log
.
d
(
TAG
,
"VocabularyPojo successfully created: "
+
firstVocabularyRef
.
path
)
user
.
vocabularies
=
Collections
.
singletonList
(
firstVocabularyRef
)
db
.
collection
(
"users"
).
document
(
newUser
.
uid
).
set
(
user
)
.
addOnCompleteListener
{
task
->
if
(
task
.
isSuccessful
)
{
Log
.
i
(
TAG
,
"Successfully added user to the collection"
)
logInActivity
.
startUserActivity
()
}
else
Log
.
w
(
TAG
,
"addUser:failure"
,
task
.
exception
)
}
}
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"Couldn't add user to the database"
,
it
.
cause
)
deleteUser
(
newUser
)
}
}
fun
login
(
onComplete
:
()
->
Unit
,
onSuccess
:
()
->
Unit
,
onFailure
:
()
->
Unit
,
mAuth
:
FirebaseAuth
?,
email
:
String
,
password
:
String
)
{
mAuth
!!
.
signInWithEmailAndPassword
(
email
,
password
)
.
addOnCompleteListener
{
onComplete
()
}
.
addOnSuccessListener
{
Log
.
d
(
TAG
,
"Successfully signed in"
)
onSuccess
()
}
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"signInWithEmail:failure"
,
it
)
onFailure
()
}
}
fun
signUp
(
mAuth
:
FirebaseAuth
?,
activity
:
LogInActivity
,
email
:
String
,
password
:
String
)
{
mAuth
!!
.
createUserWithEmailAndPassword
(
email
,
password
)
.
addOnCompleteListener
{
removeProgressBar
(
activity
.
supportFragmentManager
)
}
.
addOnSuccessListener
{
Log
.
d
(
TAG
,
"Successfully signed up a new user"
)
addNewUserToDb
(
mAuth
.
currentUser
!!
,
activity
)
activity
.
login
()
}
.
addOnFailureListener
{
Log
.
d
(
TAG
,
"createUserWithEmail:failure"
,
it
.
fillInStackTrace
())
shortToast
(
activity
,
it
.
message
!!
)
}
}
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
350ce549
...
...
@@ -12,6 +12,7 @@ import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.ui.fragments.EditWordFragment
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.addFragment
import
kotlinx.android.synthetic.main.word_item.view.*
class
VocabularyAdapter
(
private
val
displayedVocabulary
:
Vocabulary
,
private
val
mainActivity
:
MainActivity
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/LogInActivity.kt
View file @
350ce549
...
...
@@ -8,6 +8,8 @@ import android.util.Log
import
com.google.firebase.auth.FirebaseAuth
import
com.paktalin.vocabularynotebook.*
import
com.paktalin.vocabularynotebook.utils.fieldsNotEmpty
import
com.paktalin.vocabularynotebook.utils.shortToast
import
kotlinx.android.synthetic.main.activity_log_in.*
class
LogInActivity
:
AppCompatActivity
()
{
...
...
@@ -31,13 +33,15 @@ class LogInActivity : AppCompatActivity() {
}
fun
login
()
{
processUser
{
login
(
processUser
{
com
.
paktalin
.
vocabularynotebook
.
utils
.
login
(
{
removeProgressBar
()
},
{
startUserActivity
()
},
{
showToastFailure
()
},
mAuth
,
email
!!
,
password
!!
)
}
}
mAuth
,
email
!!
,
password
!!
)
}
}
private
fun
signUp
()
{
processUser
{
signUp
(
mAuth
,
this
,
email
!!
,
password
!!
)
}
}
private
fun
signUp
()
{
processUser
{
com
.
paktalin
.
vocabularynotebook
.
utils
.
signUp
(
mAuth
,
this
,
email
!!
,
password
!!
)
}
}
private
fun
processUser
(
authAction
:
()
->
Unit
)
{
email
=
etEmail
!!
.
text
.
toString
()
...
...
@@ -55,9 +59,13 @@ class LogInActivity : AppCompatActivity() {
startActivity
(
userActivityIntent
)
}
private
fun
addProgressBar
()
{
addProgressBar
(
supportFragmentManager
,
R
.
id
.
container_login
)
}
private
fun
addProgressBar
()
{
com
.
paktalin
.
vocabularynotebook
.
utils
.
addProgressBar
(
supportFragmentManager
,
R
.
id
.
container_login
)
}
private
fun
removeProgressBar
()
{
removeProgressBar
(
supportFragmentManager
)
}
private
fun
removeProgressBar
()
{
com
.
paktalin
.
vocabularynotebook
.
utils
.
removeProgressBar
(
supportFragmentManager
)
}
private
fun
showToastFailure
()
{
shortToast
(
this
@LogInActivity
,
getString
(
R
.
string
.
toast_auth_failed
))
...
...
@@ -67,7 +75,7 @@ class LogInActivity : AppCompatActivity() {
private
fun
createRandomUser
()
{
etEmail
.
setText
(
"random@gmail.com"
)
etPassword
.
setText
(
"123456"
)
processUser
{
signUp
(
mAuth
,
this
@LogInActivity
,
email
!!
,
password
!!
)
}
processUser
{
com
.
paktalin
.
vocabularynotebook
.
utils
.
signUp
(
mAuth
,
this
@LogInActivity
,
email
!!
,
password
!!
)
}
}
companion
object
{
private
val
TAG
=
"VN/"
+
LogInActivity
::
class
.
simpleName
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
View file @
350ce549
...
...
@@ -20,6 +20,8 @@ import android.support.v7.widget.SearchView
import
com.paktalin.vocabularynotebook.*
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import
com.paktalin.vocabularynotebook.ui.fragments.VocabularyFragment
import
com.paktalin.vocabularynotebook.utils.addFragment
import
com.paktalin.vocabularynotebook.utils.shortToast
class
MainActivity
:
AppCompatActivity
()
{
...
...
@@ -101,11 +103,11 @@ class MainActivity : AppCompatActivity() {
}
fun
addProgressBar
()
{
addProgressBar
(
supportFragmentManager
,
R
.
id
.
container_main
)
com
.
paktalin
.
vocabularynotebook
.
utils
.
addProgressBar
(
supportFragmentManager
,
R
.
id
.
container_main
)
}
fun
removeProgressBar
()
{
removeProgressBar
(
supportFragmentManager
)
com
.
paktalin
.
vocabularynotebook
.
utils
.
removeProgressBar
(
supportFragmentManager
)
}
fun
showToastNoWords
()
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/AddWordFragment.kt
View file @
350ce549
...
...
@@ -7,7 +7,7 @@ import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.shortToast
import
com.paktalin.vocabularynotebook.
utils.
shortToast
import
kotlinx.android.synthetic.main.fragment_editable_word.*
class
AddWordFragment
:
WordFragment
()
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/EditWordFragment.kt
View file @
350ce549
...
...
@@ -13,6 +13,10 @@ import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.disableScrolling
import
com.paktalin.vocabularynotebook.utils.enableScrolling
import
com.paktalin.vocabularynotebook.utils.removeFragment
import
com.paktalin.vocabularynotebook.utils.shortToast
import
kotlinx.android.synthetic.main.fragment_editable_word.*
import
kotlinx.android.synthetic.main.content_main.*
import
kotlinx.android.synthetic.main.word_item.view.*
...
...
app/src/main/java/com/paktalin/vocabularynotebook/utils/FirestoreManager.kt
0 → 100644
View file @
350ce549
package
com.paktalin.vocabularynotebook.utils
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