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
54f4a681
authored
Nov 09, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduced ProgressFragment and ActivityUtil
parent
0bd690e9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
79 additions
and
33 deletions
app/src/main/java/com/paktalin/vocabularynotebook/Utils.kt → app/src/main/java/com/paktalin/vocabularynotebook/ActivityUtil.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/AddWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/EditWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/LogInActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/ProgressFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/WordFragment.kt
app/src/main/res/layout/activity_main.xml
app/src/main/res/layout/fragment_progress.xml
app/src/main/java/com/paktalin/vocabularynotebook/
Utils
.kt
→
app/src/main/java/com/paktalin/vocabularynotebook/
ActivityUtil
.kt
View file @
54f4a681
package
com.paktalin.vocabularynotebook
package
com.paktalin.vocabularynotebook
import
android.content.Context
import
android.content.Context
import
android.support.v4.app.Fragment
import
android.support.v4.app.FragmentManager
import
android.text.TextUtils
import
android.text.TextUtils
import
android.widget.Toast
import
android.widget.Toast
import
com.paktalin.vocabularynotebook.ui.ProgressFragment
class
Utils
{
val
progressFragment
:
Fragment
=
ProgressFragment
()
companion
object
{
fun
fieldsNotEmpty
(
text1
:
String
,
text2
:
String
,
toastMessage
:
String
,
context
:
Context
):
Boolean
{
fun
addFragment
(
fragmentManager
:
FragmentManager
,
fragment
:
Fragment
,
containerId
:
Int
)
{
if
(
TextUtils
.
isEmpty
(
text1
)
||
TextUtils
.
isEmpty
(
text2
))
{
fragmentManager
.
beginTransaction
().
add
(
containerId
,
fragment
).
commitAllowingStateLoss
()
Utils
.
shortToast
(
context
,
toastMessage
)
}
return
false
}
return
true
}
fun
shortToast
(
context
:
Context
,
text
:
String
)
{
fun
removeFragment
(
fragmentManager
:
FragmentManager
,
fragment
:
Fragment
)
{
Toast
.
makeText
(
context
,
text
,
Toast
.
LENGTH_SHORT
).
show
()
fragmentManager
.
beginTransaction
().
remove
(
fragment
).
commitAllowingStateLoss
()
}
}
fun
addProgressBar
(
fragmentManager
:
FragmentManager
,
containerId
:
Int
)
{
addFragment
(
fragmentManager
,
progressFragment
,
containerId
)
}
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
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/ui/AddWordFragment.kt
View file @
54f4a681
...
@@ -3,11 +3,11 @@ package com.paktalin.vocabularynotebook.ui
...
@@ -3,11 +3,11 @@ package com.paktalin.vocabularynotebook.ui
import
android.util.Log
import
android.util.Log
import
android.view.View
import
android.view.View
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.Utils
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.shortToast
import
kotlinx.android.synthetic.main.fragment_new_word.*
import
kotlinx.android.synthetic.main.fragment_new_word.*
class
AddWordFragment
:
WordFragment
()
{
class
AddWordFragment
:
WordFragment
()
{
...
@@ -20,12 +20,12 @@ class AddWordFragment : WordFragment() {
...
@@ -20,12 +20,12 @@ class AddWordFragment : WordFragment() {
.
addOnSuccessListener
{
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully added a new word"
)
Log
.
i
(
TAG
,
"Successfully added a new word"
)
clearFields
()
clearFields
()
mainActivity
.
hid
eProgressBar
()
mainActivity
.
remov
eProgressBar
()
val
wordItem
=
WordItem
(
wordPojo
,
it
.
id
,
vocabularyId
)
val
wordItem
=
WordItem
(
wordPojo
,
it
.
id
,
vocabularyId
)
updateRecycleView
(
wordItem
)
}
updateRecycleView
(
wordItem
)
}
.
addOnFailureListener
{
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"addNewWordToDb:failure"
,
it
.
fillInStackTrace
())
Log
.
w
(
TAG
,
"addNewWordToDb:failure"
,
it
.
fillInStackTrace
())
Utils
.
shortToast
(
mainActivity
,
getString
(
R
.
string
.
toast_new_word_fail
))
shortToast
(
mainActivity
,
getString
(
R
.
string
.
toast_new_word_fail
))
}
}
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/EditWordFragment.kt
View file @
54f4a681
...
@@ -7,13 +7,12 @@ import android.view.LayoutInflater
...
@@ -7,13 +7,12 @@ import android.view.LayoutInflater
import
android.view.View
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
import
android.view.inputmethod.InputMethodManager
import
android.view.inputmethod.InputMethodManager
import
android.widget.Toast
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.Utils
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
import
com.paktalin.vocabularynotebook.shortToast
import
kotlinx.android.synthetic.main.fragment_new_word.*
import
kotlinx.android.synthetic.main.fragment_new_word.*
import
kotlinx.android.synthetic.main.notebook_sheet.*
import
kotlinx.android.synthetic.main.notebook_sheet.*
import
kotlinx.android.synthetic.main.word_item.view.*
import
kotlinx.android.synthetic.main.word_item.view.*
...
@@ -61,14 +60,14 @@ class EditWordFragment : WordFragment() {
...
@@ -61,14 +60,14 @@ class EditWordFragment : WordFragment() {
.
addOnSuccessListener
{
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully updated the word"
)
Log
.
i
(
TAG
,
"Successfully updated the word"
)
hideSubmitButton
()
hideSubmitButton
()
mainActivity
.
hid
eProgressBar
()
mainActivity
.
remov
eProgressBar
()
wordItem
.
pojo
=
wordPojo
wordItem
.
pojo
=
wordPojo
updateRecycleView
(
wordItem
)
updateRecycleView
(
wordItem
)
stop
()
stop
()
}
}
.
addOnFailureListener
{
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"updateExistingWord:failure"
,
it
.
fillInStackTrace
())
Log
.
w
(
TAG
,
"updateExistingWord:failure"
,
it
.
fillInStackTrace
())
Utils
.
shortToast
(
mainActivity
,
getString
(
R
.
string
.
toast_update_word_failed
))
shortToast
(
mainActivity
,
getString
(
R
.
string
.
toast_update_word_failed
))
stop
()
stop
()
}
}
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/LogInActivity.kt
View file @
54f4a681
...
@@ -11,7 +11,8 @@ import com.google.firebase.auth.FirebaseAuth
...
@@ -11,7 +11,8 @@ import com.google.firebase.auth.FirebaseAuth
import
kotlinx.android.synthetic.main.activity_log_in.*
import
kotlinx.android.synthetic.main.activity_log_in.*
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.UserManager
import
com.paktalin.vocabularynotebook.UserManager
import
com.paktalin.vocabularynotebook.Utils
import
com.paktalin.vocabularynotebook.fieldsNotEmpty
import
com.paktalin.vocabularynotebook.shortToast
class
LogInActivity
:
AppCompatActivity
()
{
class
LogInActivity
:
AppCompatActivity
()
{
private
var
mAuth
:
FirebaseAuth
?
=
null
private
var
mAuth
:
FirebaseAuth
?
=
null
...
@@ -35,7 +36,7 @@ class LogInActivity : AppCompatActivity() {
...
@@ -35,7 +36,7 @@ class LogInActivity : AppCompatActivity() {
val
email
=
etEmail
!!
.
text
.
toString
()
val
email
=
etEmail
!!
.
text
.
toString
()
val
password
=
etPassword
!!
.
text
.
toString
()
val
password
=
etPassword
!!
.
text
.
toString
()
if
(
Utils
.
fieldsNotEmpty
(
email
,
password
,
"Please, enter email and password"
,
this
))
{
if
(
fieldsNotEmpty
(
email
,
password
,
"Please, enter email and password"
,
this
))
{
showProgressBar
()
showProgressBar
()
mAuth
!!
.
signInWithEmailAndPassword
(
email
,
password
)
mAuth
!!
.
signInWithEmailAndPassword
(
email
,
password
)
.
addOnCompleteListener
{
hideProgressBar
()
}
.
addOnCompleteListener
{
hideProgressBar
()
}
...
@@ -45,7 +46,7 @@ class LogInActivity : AppCompatActivity() {
...
@@ -45,7 +46,7 @@ class LogInActivity : AppCompatActivity() {
}
}
.
addOnFailureListener
{
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"signInWithEmail:failure"
,
it
)
Log
.
w
(
TAG
,
"signInWithEmail:failure"
,
it
)
Utils
.
shortToast
(
this
@LogInActivity
,
getString
(
R
.
string
.
toast_auth_failed
))
shortToast
(
this
@LogInActivity
,
getString
(
R
.
string
.
toast_auth_failed
))
}
}
}
}
}
}
...
@@ -54,7 +55,7 @@ class LogInActivity : AppCompatActivity() {
...
@@ -54,7 +55,7 @@ class LogInActivity : AppCompatActivity() {
val
email
=
etEmail
!!
.
text
.
toString
()
val
email
=
etEmail
!!
.
text
.
toString
()
val
password
=
etPassword
!!
.
text
.
toString
()
val
password
=
etPassword
!!
.
text
.
toString
()
if
(
Utils
.
fieldsNotEmpty
(
email
,
password
,
"Please, enter email and password"
,
this
))
{
if
(
fieldsNotEmpty
(
email
,
password
,
"Please, enter email and password"
,
this
))
{
//todo check if the password is good
//todo check if the password is good
// todo verify email
// todo verify email
showProgressBar
()
showProgressBar
()
...
@@ -66,7 +67,7 @@ class LogInActivity : AppCompatActivity() {
...
@@ -66,7 +67,7 @@ class LogInActivity : AppCompatActivity() {
}
}
.
addOnFailureListener
{
.
addOnFailureListener
{
Log
.
d
(
TAG
,
"createUserWithEmail:failure"
,
it
.
fillInStackTrace
())
Log
.
d
(
TAG
,
"createUserWithEmail:failure"
,
it
.
fillInStackTrace
())
Utils
.
shortToast
(
this
@LogInActivity
,
it
.
message
!!
)
shortToast
(
this
@LogInActivity
,
it
.
message
!!
)
}
}
}
}
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
View file @
54f4a681
...
@@ -7,7 +7,6 @@ import android.util.Log
...
@@ -7,7 +7,6 @@ import android.util.Log
import
com.google.firebase.auth.FirebaseAuth
import
com.google.firebase.auth.FirebaseAuth
import
com.google.firebase.firestore.DocumentReference
import
com.google.firebase.firestore.DocumentReference
import
com.paktalin.vocabularynotebook.R
import
kotlinx.android.synthetic.main.activity_main.*
import
kotlinx.android.synthetic.main.activity_main.*
import
android.view.WindowManager
import
android.view.WindowManager
import
android.app.Activity
import
android.app.Activity
...
@@ -16,11 +15,10 @@ import android.view.Menu
...
@@ -16,11 +15,10 @@ import android.view.Menu
import
android.view.MenuItem
import
android.view.MenuItem
import
android.view.View
import
android.view.View
import
android.view.inputmethod.InputMethodManager
import
android.view.inputmethod.InputMethodManager
import
com.paktalin.vocabularynotebook.VocabularyAdapter
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
import
android.support.v7.widget.SearchView
import
android.support.v7.widget.SearchView
import
com.paktalin.vocabularynotebook.
Utils
import
com.paktalin.vocabularynotebook.
*
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
...
@@ -71,10 +69,10 @@ class MainActivity : AppCompatActivity() {
...
@@ -71,10 +69,10 @@ class MainActivity : AppCompatActivity() {
val
db
=
ConfiguredFirestore
.
instance
val
db
=
ConfiguredFirestore
.
instance
val
userDocument
=
db
.
collection
(
"users"
).
document
(
userId
)
val
userDocument
=
db
.
collection
(
"users"
).
document
(
userId
)
show
ProgressBar
()
add
ProgressBar
()
userDocument
.
get
()
userDocument
.
get
()
.
addOnSuccessListener
{
task
->
.
addOnSuccessListener
{
task
->
hid
eProgressBar
()
remov
eProgressBar
()
//todo move Firestore logic and collections names to a separate class
//todo move Firestore logic and collections names to a separate class
if
(
task
.
get
(
VOCABULARIES
)
!=
null
)
{
if
(
task
.
get
(
VOCABULARIES
)
!=
null
)
{
val
vocabularies
:
List
<
DocumentReference
>
=
task
.
get
(
VOCABULARIES
)
as
List
<
DocumentReference
>
val
vocabularies
:
List
<
DocumentReference
>
=
task
.
get
(
VOCABULARIES
)
as
List
<
DocumentReference
>
...
@@ -105,12 +103,16 @@ class MainActivity : AppCompatActivity() {
...
@@ -105,12 +103,16 @@ class MainActivity : AppCompatActivity() {
imm
.
hideSoftInputFromWindow
(
view
.
windowToken
,
0
)
imm
.
hideSoftInputFromWindow
(
view
.
windowToken
,
0
)
}
}
fun
showProgressBar
()
{
progress
.
visibility
=
View
.
VISIBLE
}
fun
addProgressBar
()
{
addProgressBar
(
supportFragmentManager
,
R
.
id
.
frameLayout
)
}
fun
hideProgressBar
()
{
progress
.
visibility
=
View
.
GONE
}
fun
removeProgressBar
()
{
removeProgressBar
(
supportFragmentManager
)
}
fun
showToastNoWords
()
{
fun
showToastNoWords
()
{
Utils
.
shortToast
(
this
,
getString
(
R
.
string
.
toast_no_words
))
shortToast
(
this
,
getString
(
R
.
string
.
toast_no_words
))
}
}
fun
removeFragment
(
fragment
:
Fragment
)
{
fun
removeFragment
(
fragment
:
Fragment
)
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/ProgressFragment.kt
0 → 100644
View file @
54f4a681
package
com.paktalin.vocabularynotebook.ui
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
com.paktalin.vocabularynotebook.R
class
ProgressFragment
:
Fragment
()
{
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
return
inflater
.
inflate
(
R
.
layout
.
fragment_progress
,
container
,
false
)
}
}
app/src/main/java/com/paktalin/vocabularynotebook/ui/WordFragment.kt
View file @
54f4a681
...
@@ -63,7 +63,7 @@ abstract class WordFragment : Fragment() {
...
@@ -63,7 +63,7 @@ abstract class WordFragment : Fragment() {
val
word
=
word
.
text
.
toString
()
val
word
=
word
.
text
.
toString
()
val
translation
=
translation
.
text
.
toString
()
val
translation
=
translation
.
text
.
toString
()
val
vocabularyId
=
mainActivity
.
vocabularyId
val
vocabularyId
=
mainActivity
.
vocabularyId
mainActivity
.
show
ProgressBar
()
mainActivity
.
add
ProgressBar
()
saveToFirestore
(
word
,
translation
,
vocabularyId
)
saveToFirestore
(
word
,
translation
,
vocabularyId
)
return
return
}
}
...
...
app/src/main/res/layout/activity_main.xml
View file @
54f4a681
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
android:background=
"#66330E"
>
android:background=
"#66330E"
>
<FrameLayout
<FrameLayout
android:id=
"@+id/frameLayout"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
android:layout_height=
"match_parent"
>
...
...
app/src/main/res/layout/fragment_progress.xml
0 → 100644
View file @
54f4a681
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<ProgressBar
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
/>
</FrameLayout>
\ No newline at end of file
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