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
fccb0efd
authored
Sep 12, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added progressBar to AddWordFragment and EditWordFragment
parent
bb6016cf
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
9 deletions
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/MainActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/WordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/AddWordFragment.kt
View file @
fccb0efd
...
...
@@ -13,25 +13,28 @@ import com.paktalin.vocabularynotebook.WordItem
class
AddWordFragment
:
WordFragment
()
{
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
mainActivity
=
activity
as
MainActivity
return
inflater
.
inflate
(
R
.
layout
.
fragment_new_word
,
container
,
false
)
}
override
fun
saveToFirestore
(
wordPojo
:
WordItem
.
Pojo
,
vocabularyId
:
String
)
{
mainActivity
.
showProgressBar
()
ConfiguredFirestore
.
instance
.
collection
(
vocabularies
).
document
(
vocabularyId
)
.
collection
(
words
).
add
(
wordPojo
)
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully added a new word"
)
clearFields
()
mainActivity
.
hideProgressBar
()
val
wordItem
=
WordItem
(
wordPojo
,
it
.
id
,
vocabularyId
)
updateRecycleView
(
wordItem
)
}
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"addNewWordToDb:failure"
,
it
.
fillInStackTrace
())
Toast
.
makeText
(
a
ctivity
,
"Couldn't add the word"
,
Toast
.
LENGTH_SHORT
).
show
()}
Toast
.
makeText
(
mainA
ctivity
,
"Couldn't add the word"
,
Toast
.
LENGTH_SHORT
).
show
()}
}
override
fun
updateRecycleView
(
wordItem
:
WordItem
)
{
val
vocabularyFragment
=
activity
!!
val
vocabularyFragment
=
mainActivity
.
supportFragmentManager
.
findFragmentById
(
R
.
id
.
fragment_vocabulary
)
as
VocabularyFragment
vocabularyFragment
.
addWordItem
(
wordItem
)
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/EditWordFragment.kt
View file @
fccb0efd
...
...
@@ -6,7 +6,6 @@ import android.util.Log
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.view.WindowManager
import
android.view.inputmethod.InputMethodManager
import
android.widget.ImageView
import
android.widget.TextView
...
...
@@ -20,6 +19,7 @@ class EditWordFragment : WordFragment() {
private
lateinit
var
wordItem
:
WordItem
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
mainActivity
=
activity
as
MainActivity
hidePreviousViews
(
container
)
wordItem
=
arguments
!!
[
"wordItem"
]
as
WordItem
return
inflater
.
inflate
(
R
.
layout
.
fragment_new_word
,
container
,
false
)
...
...
@@ -37,9 +37,8 @@ class EditWordFragment : WordFragment() {
}
private
fun
setFocusOnWord
()
{
activity
!!
.
window
.
setSoftInputMode
(
WindowManager
.
LayoutParams
.
SOFT_INPUT_STATE_VISIBLE
)
word
.
requestFocus
()
val
imm
=
activity
!!
.
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
)
as
InputMethodManager
?
val
imm
=
mainActivity
.
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
)
as
InputMethodManager
?
imm
!!
.
toggleSoftInput
(
InputMethodManager
.
SHOW_FORCED
,
InputMethodManager
.
HIDE_IMPLICIT_ONLY
)
}
...
...
@@ -52,20 +51,22 @@ class EditWordFragment : WordFragment() {
}
override
fun
saveToFirestore
(
wordPojo
:
WordItem
.
Pojo
,
vocabularyId
:
String
)
{
mainActivity
.
showProgressBar
()
ConfiguredFirestore
.
instance
.
collection
(
vocabularies
).
document
(
vocabularyId
)
.
collection
(
words
).
document
(
wordItem
.
id
).
set
(
wordPojo
)
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully updated the word"
)
hideSubmitButton
()
mainActivity
.
hideProgressBar
()
wordItem
.
pojo
=
wordPojo
updateRecycleView
(
wordItem
)
}
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"updateExistingWord:failure"
,
it
.
fillInStackTrace
())
Toast
.
makeText
(
a
ctivity
,
"Couldn't update the word"
,
Toast
.
LENGTH_SHORT
).
show
()}
}
Toast
.
makeText
(
mainA
ctivity
,
"Couldn't update the word"
,
Toast
.
LENGTH_SHORT
).
show
()}
}
override
fun
updateRecycleView
(
wordItem
:
WordItem
)
{
val
vocabularyFragment
=
activity
!!
val
vocabularyFragment
=
mainActivity
.
supportFragmentManager
.
findFragmentById
(
R
.
id
.
fragment_vocabulary
)
as
VocabularyFragment
vocabularyFragment
.
updateWordItem
(
wordItem
)
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
View file @
fccb0efd
...
...
@@ -51,10 +51,10 @@ class MainActivity : AppCompatActivity() {
val
db
=
ConfiguredFirestore
.
instance
val
userDocument
=
db
.
collection
(
"users"
).
document
(
userId
)
progress
.
visibility
=
View
.
VISIBLE
showProgressBar
()
userDocument
.
get
()
.
addOnSuccessListener
{
task
->
progress
.
visibility
=
View
.
GONE
hideProgressBar
()
if
(
task
.
get
(
"vocabularies"
)
!=
null
)
{
val
vocabularies
:
List
<
DocumentReference
>
=
task
.
get
(
"vocabularies"
)
as
List
<
DocumentReference
>
//todo represent specific vocabulary instead of the first one
...
...
@@ -78,6 +78,14 @@ class MainActivity : AppCompatActivity() {
imm
.
hideSoftInputFromWindow
(
view
.
windowToken
,
0
)
}
fun
showProgressBar
()
{
progress
.
visibility
=
View
.
VISIBLE
}
fun
hideProgressBar
()
{
progress
.
visibility
=
View
.
GONE
}
override
fun
onPause
()
{
super
.
onPause
()
hideKeyboard
()
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/WordFragment.kt
View file @
fccb0efd
...
...
@@ -14,6 +14,7 @@ import kotlinx.android.synthetic.main.fragment_new_word.*
abstract
class
WordFragment
:
Fragment
()
{
protected
val
vocabularies
=
"vocabularies"
protected
val
words
=
"words"
protected
lateinit
var
mainActivity
:
MainActivity
private
var
wordEmpty
:
Boolean
=
true
set
(
value
)
{
field
=
value
;
updateButtons
()
}
...
...
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