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
632ea2a0
authored
Apr 19, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed saving to Firestore right after editing/adding
parent
9f8de0f3
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
16 additions
and
46 deletions
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/WordItem.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/ui/fragments/WordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/utils/FirestoreManager.kt
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
632ea2a0
...
...
@@ -56,7 +56,7 @@ class VocabularyAdapter(private val fullVocabulary: Vocabulary, private val main
}
private
fun
deleteWord
(
position
:
Int
)
{
//TODO delete
entry point
//TODO delete
from fullVocabulary
displayedVocabulary
.
deleteWord
(
position
)
// update recyclerView
recyclerView
.
removeViewAt
(
position
)
...
...
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/WordItem.kt
View file @
632ea2a0
...
...
@@ -4,7 +4,7 @@ import com.paktalin.vocabularynotebook.utils.FirestoreManager
import
java.io.Serializable
import
java.util.Date
class
WordItem
(
word
:
String
,
translation
:
String
,
time
:
Date
?,
var
id
:
String
,
private
val
vocabularyId
:
String
)
:
Serializable
{
class
WordItem
(
word
:
String
,
translation
:
String
,
time
:
Date
?,
var
id
:
String
?,
private
val
vocabularyId
:
String
?
)
:
Serializable
{
var
pojo
:
Pojo
=
Pojo
(
word
,
translation
,
time
)
class
Pojo
(
var
word
:
String
,
var
translation
:
String
,
var
time
:
Date
?)
:
Serializable
{
...
...
@@ -13,11 +13,13 @@ class WordItem(word: String, translation: String, time: Date?, var id: String, p
}
}
constructor
(
pojo
:
Pojo
,
id
:
String
,
vocabularyId
:
String
)
constructor
(
pojo
:
Pojo
,
id
:
String
?,
vocabularyId
:
String
?
)
:
this
(
pojo
.
word
,
pojo
.
translation
,
pojo
.
time
,
id
,
vocabularyId
)
constructor
(
pojo
:
Pojo
)
:
this
(
pojo
,
null
,
null
)
fun
delete
()
{
FirestoreManager
().
deleteWord
(
id
)
FirestoreManager
().
deleteWord
(
id
!!
)
}
fun
contains
(
string
:
String
):
Boolean
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/AddWordFragment.kt
View file @
632ea2a0
...
...
@@ -3,7 +3,6 @@ package com.paktalin.vocabularynotebook.ui.fragments
import
android.os.Bundle
import
android.text.Editable
import
android.text.TextWatcher
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.utils.*
import
kotlinx.android.synthetic.main.content_main.*
...
...
@@ -37,14 +36,11 @@ class AddWordFragment : WordFragment() {
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
}
override
fun
save
ToFirestore
(
word
:
String
,
translation
:
String
,
vocabularyId
:
String
)
{
override
fun
save
(
word
:
String
,
translation
:
String
)
{
// TODO add entry point
val
wordPojo
=
WordItem
.
Pojo
(
word
,
translation
,
null
)
FirestoreManager
().
saveNewWord
(
{
documentId
->
onSuccessfulSave
(
wordPojo
,
vocabularyId
,
documentId
)
},
{
shortToast
(
mainActivity
,
getString
(
R
.
string
.
toast_new_word_fail
))
},
wordPojo
)
clearFields
()
mainActivity
.
vocabularyAdapter
.
addWord
(
WordItem
(
WordItem
.
Pojo
(
word
,
translation
,
null
)))
this
.
word
.
requestFocus
()
}
private
fun
textWatcher
(
setEmpty
:
()
->
Unit
):
TextWatcher
{
...
...
@@ -60,13 +56,5 @@ class AddWordFragment : WordFragment() {
if
(
wordEmpty
&&
translationEmpty
)
invisible
(
btnClear
)
}
private
fun
onSuccessfulSave
(
wordPojo
:
WordItem
.
Pojo
,
vocabularyId
:
String
,
documentId
:
String
)
{
clearFields
()
mainActivity
.
removeProgressBar
()
val
wordItem
=
WordItem
(
wordPojo
,
documentId
,
vocabularyId
)
mainActivity
.
vocabularyAdapter
.
addWord
(
wordItem
)
word
.
requestFocus
()
}
companion
object
{
private
val
TAG
=
"VN/"
+
AddWordFragment
::
class
.
java
.
simpleName
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/EditWordFragment.kt
View file @
632ea2a0
...
...
@@ -64,28 +64,13 @@ class EditWordFragment : WordFragment() {
visible
(
container
!!
.
translation
)
}
override
fun
save
ToFirestore
(
word
:
String
,
translation
:
String
,
vocabularyId
:
String
)
{
override
fun
save
(
word
:
String
,
translation
:
String
)
{
// TODO edit entry point
val
wordPojo
=
WordItem
.
Pojo
(
word
,
translation
,
wordItem
.
pojo
.
time
)
FirestoreManager
().
updateWord
(
{
onSuccessfulSave
(
wordPojo
)
},
{
onFailure
()
},
wordItem
,
wordPojo
)
}
private
fun
onSuccessfulSave
(
wordPojo
:
WordItem
.
Pojo
)
{
gone
(
mainActivity
.
btnSubmitLayout
)
mainActivity
.
removeProgressBar
()
wordItem
.
pojo
=
wordPojo
wordItem
.
pojo
=
WordItem
.
Pojo
(
word
,
translation
,
wordItem
.
pojo
.
time
)
mainActivity
.
vocabularyAdapter
.
updateWord
(
wordItem
)
stop
()
}
private
fun
onFailure
()
{
/*shortToast(mainActivity, getString(R.string.toast_update_word_failed))
stop()*/
}
private
fun
stop
()
{
// set onClickListener from AddWordFragment
mainActivity
.
btnSubmit
.
setOnClickListener
{
(
mainActivity
.
fragmentAddWord
as
AddWordFragment
).
submitWord
()
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/WordFragment.kt
View file @
632ea2a0
...
...
@@ -2,17 +2,13 @@ package com.paktalin.vocabularynotebook.ui.fragments
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.text.Editable
import
android.text.TextWatcher
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.FirestoreManager
import
com.paktalin.vocabularynotebook.utils.gone
import
com.paktalin.vocabularynotebook.utils.visible
import
kotlinx.android.synthetic.main.fragment_editable_word.*
import
kotlinx.android.synthetic.main.content_main.*
...
...
@@ -34,8 +30,7 @@ abstract class WordFragment : Fragment() {
fun
submitWord
()
{
gone
(
mainActivity
.
btnSubmitLayout
)
mainActivity
.
addProgressBar
()
saveToFirestore
(
word
.
text
.
toString
(),
translation
.
text
.
toString
(),
FirestoreManager
.
vocabularyId
!!
)
save
(
word
.
text
.
toString
(),
translation
.
text
.
toString
())
return
}
...
...
@@ -45,5 +40,5 @@ abstract class WordFragment : Fragment() {
}
protected
abstract
fun
cancelEditing
()
protected
abstract
fun
save
ToFirestore
(
word
:
String
,
translation
:
String
,
vocabularyId
:
String
)
protected
abstract
fun
save
(
word
:
String
,
translation
:
String
)
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/utils/FirestoreManager.kt
View file @
632ea2a0
...
...
@@ -63,7 +63,7 @@ class FirestoreManager {
fun
updateWord
(
onSuccess
:
()
->
Unit
,
onFailure
:
()
->
Unit
,
wordItem
:
WordItem
,
wordPojo
:
WordItem
.
Pojo
)
{
vocabularyDocument
()
.
collection
(
WORDS
).
document
(
wordItem
.
id
).
set
(
wordPojo
)
.
collection
(
WORDS
).
document
(
wordItem
.
id
!!
).
set
(
wordPojo
)
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully updated the word"
)
onSuccess
()
...
...
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