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
36c1dfbf
authored
Nov 11, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added refresh by swipe
parent
0f261e01
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
102 additions
and
145 deletions
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/Vocabulary.kt
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/VocabularyPojo.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/ui/fragments/VocabularyFragment.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/utils/PreferenceUtil.kt
app/src/main/res/layout/content_main.xml
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
36c1dfbf
...
@@ -8,10 +8,11 @@ import android.support.v7.widget.RecyclerView
...
@@ -8,10 +8,11 @@ import android.support.v7.widget.RecyclerView
import
android.view.*
import
android.view.*
import
android.widget.LinearLayout
import
android.widget.LinearLayout
import
android.widget.TextView
import
android.widget.TextView
import
com.
paktalin.vocabularynotebook.firestoreitems.Vocabulary
import
com.
google.firebase.Timestamp
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.ui.fragments.EditWordFragment
import
com.paktalin.vocabularynotebook.ui.fragments.EditWordFragment
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.FirestoreManager
import
com.paktalin.vocabularynotebook.utils.addFragment
import
com.paktalin.vocabularynotebook.utils.addFragment
import
kotlinx.android.synthetic.main.word_item.view.*
import
kotlinx.android.synthetic.main.word_item.view.*
...
@@ -74,6 +75,14 @@ class VocabularyAdapter(private val displayedVocabulary: Vocabulary, private val
...
@@ -74,6 +75,14 @@ class VocabularyAdapter(private val displayedVocabulary: Vocabulary, private val
this
.
notifyItemRangeChanged
(
position
,
displayedVocabulary
.
size
())
this
.
notifyItemRangeChanged
(
position
,
displayedVocabulary
.
size
())
}
}
fun
updateAll
()
{
displayedVocabulary
.
clear
()
FirestoreManager
().
retrieveWordsData
{
documents
->
displayedVocabulary
.
addWordsAsDocuments
(
documents
)
this
.
notifyDataSetChanged
()
}
}
fun
addWord
(
newWord
:
WordItem
)
{
fun
addWord
(
newWord
:
WordItem
)
{
displayedVocabulary
.
addWord
(
newWord
)
displayedVocabulary
.
addWord
(
newWord
)
this
.
sort
()
this
.
sort
()
...
...
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/Vocabulary.kt
deleted
100644 → 0
View file @
0f261e01
package
com.paktalin.vocabularynotebook.firestoreitems
class
Vocabulary
(
words
:
MutableList
<
WordItem
>)
{
companion
object
{
private
val
TAG
=
"VN/"
+
Vocabulary
::
class
.
java
.
simpleName
private
const
val
SORT_BY_TIME
=
0
private
const
val
SORT_BY_WORD
=
1
private
const
val
SORT_BY_TRANSLATION
=
2
}
var
pojo
:
Pojo
private
var
words
:
MutableList
<
WordItem
>
class
Pojo
(
var
title
:
String
?)
{
init
{
if
(
title
==
null
)
title
=
"Untitled vocabulary"
}
}
init
{
this
.
pojo
=
Pojo
(
null
)
this
.
words
=
words
}
fun
sort
(
sortOrder
:
Int
)
{
when
(
sortOrder
)
{
SORT_BY_TIME
->
sortByTime
()
SORT_BY_WORD
->
sortByWord
()
SORT_BY_TRANSLATION
->
sortByTranslation
()
}
}
fun
deleteWord
(
position
:
Int
)
{
words
[
position
].
delete
()
// delete word from the database
words
.
removeAt
(
position
)
// delete word from the list
}
fun
addWord
(
newWord
:
WordItem
)
{
words
.
add
(
0
,
newWord
)
}
fun
addWords
(
newWords
:
MutableList
<
WordItem
>)
{
words
.
addAll
(
newWords
)
}
fun
addWordsFittingQuery
(
newWords
:
MutableList
<
WordItem
>,
query
:
String
)
{
for
(
newWord
in
newWords
)
{
if
(
newWord
.
contains
(
query
))
this
.
addWord
(
newWord
)
}
}
fun
updateWord
(
updatedWord
:
WordItem
)
{
val
updatedItemIndex
=
words
.
indexOf
(
updatedWord
)
words
[
updatedItemIndex
]
=
updatedWord
}
fun
getAt
(
position
:
Int
):
WordItem
{
return
words
[
position
]
}
fun
get
():
MutableList
<
WordItem
>
{
return
words
}
fun
size
():
Int
{
return
words
.
size
}
fun
clear
()
{
words
.
clear
()
}
private
fun
sortByTime
()
{
words
.
sortWith
(
Comparator
{
item1
,
item2
->
-
item1
.
pojo
.
time
!!
.
compareTo
(
item2
.
pojo
.
time
)
})
}
private
fun
sortByWord
()
{
words
.
sortWith
(
Comparator
{
item1
,
item2
->
item1
.
pojo
.
word
.
compareTo
(
item2
.
pojo
.
word
)
})
}
private
fun
sortByTranslation
()
{
words
.
sortWith
(
Comparator
{
item1
,
item2
->
item1
.
pojo
.
translation
.
compareTo
(
item2
.
pojo
.
translation
)
})
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/VocabularyPojo.kt
0 → 100644
View file @
36c1dfbf
package
com.paktalin.vocabularynotebook.firestoreitems
class
VocabularyPojo
(
var
title
:
String
?)
{
init
{
if
(
title
==
null
)
title
=
"Untitled vocabulary"
}
}
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
View file @
36c1dfbf
...
@@ -11,10 +11,12 @@ import android.view.View
...
@@ -11,10 +11,12 @@ import android.view.View
import
android.view.inputmethod.InputMethodManager
import
android.view.inputmethod.InputMethodManager
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
android.util.Log
import
android.view.WindowManager
import
android.view.WindowManager
import
com.paktalin.vocabularynotebook.*
import
com.paktalin.vocabularynotebook.*
import
com.paktalin.vocabularynotebook.ui.fragments.VocabularyFragment
import
com.paktalin.vocabularynotebook.ui.fragments.VocabularyFragment
import
com.paktalin.vocabularynotebook.utils.*
import
com.paktalin.vocabularynotebook.utils.*
import
kotlinx.android.synthetic.main.content_main.*
class
MainActivity
:
AppCompatActivity
()
{
class
MainActivity
:
AppCompatActivity
()
{
...
@@ -25,6 +27,8 @@ class MainActivity : AppCompatActivity() {
...
@@ -25,6 +27,8 @@ class MainActivity : AppCompatActivity() {
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_main
)
setContentView
(
R
.
layout
.
activity_main
)
FirestoreManager
.
vocabularyId
=
getSavedVocabularyId
(
this
@MainActivity
)
swipeRefresh
.
setOnRefreshListener
{
refreshVocabulary
()
}
hideKeyboard
()
hideKeyboard
()
setUpNavigationView
()
setUpNavigationView
()
extractVocabularyData
()
extractVocabularyData
()
...
@@ -47,6 +51,11 @@ class MainActivity : AppCompatActivity() {
...
@@ -47,6 +51,11 @@ class MainActivity : AppCompatActivity() {
startActivity
(
this
@MainActivity
,
LogInActivity
::
class
.
java
)
startActivity
(
this
@MainActivity
,
LogInActivity
::
class
.
java
)
}
}
private
fun
refreshVocabulary
()
{
(
recyclerView
.
adapter
as
VocabularyAdapter
).
updateAll
()
swipeRefresh
.
isRefreshing
=
false
}
private
fun
setUpNavigationView
()
{
private
fun
setUpNavigationView
()
{
navigationView
.
setNavigationItemSelectedListener
{
menuItem
->
navigationView
.
setNavigationItemSelectedListener
{
menuItem
->
menuItem
.
isChecked
=
true
menuItem
.
isChecked
=
true
...
@@ -61,9 +70,9 @@ class MainActivity : AppCompatActivity() {
...
@@ -61,9 +70,9 @@ class MainActivity : AppCompatActivity() {
private
fun
extractVocabularyData
()
{
private
fun
extractVocabularyData
()
{
addProgressBar
()
addProgressBar
()
FirestoreManager
().
extractVocabularyId
(
FirestoreManager
().
extractVocabularyId
(
{
id
->
addVocabularyFragment
(
id
)
},
{
addVocabularyFragment
(
FirestoreManager
.
vocabularyId
!!
)
},
{
showToastNoWords
()
},
{
showToastNoWords
()
},
{
removeProgressBar
()
})
{
removeProgressBar
()
}
,
this
)
}
}
private
fun
addVocabularyFragment
(
vocabularyId
:
String
)
{
private
fun
addVocabularyFragment
(
vocabularyId
:
String
)
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/AddWordFragment.kt
View file @
36c1dfbf
...
@@ -28,7 +28,7 @@ class AddWordFragment : WordFragment() {
...
@@ -28,7 +28,7 @@ class AddWordFragment : WordFragment() {
FirestoreManager
().
saveNewWord
(
FirestoreManager
().
saveNewWord
(
{
documentId
->
onSuccessfulSave
(
wordPojo
,
vocabularyId
,
documentId
)
},
{
documentId
->
onSuccessfulSave
(
wordPojo
,
vocabularyId
,
documentId
)
},
{
shortToast
(
mainActivity
,
getString
(
R
.
string
.
toast_new_word_fail
))
},
{
shortToast
(
mainActivity
,
getString
(
R
.
string
.
toast_new_word_fail
))
},
wordPojo
,
vocabularyId
)
wordPojo
)
}
}
override
fun
updateRecycleView
(
wordItem
:
WordItem
)
{
override
fun
updateRecycleView
(
wordItem
:
WordItem
)
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/EditWordFragment.kt
View file @
36c1dfbf
...
@@ -74,7 +74,7 @@ class EditWordFragment : WordFragment() {
...
@@ -74,7 +74,7 @@ class EditWordFragment : WordFragment() {
FirestoreManager
().
updateWord
(
FirestoreManager
().
updateWord
(
{
onSuccessfulSave
(
wordPojo
)
},
{
onSuccessfulSave
(
wordPojo
)
},
{
onFailure
()
},
{
onFailure
()
},
wordItem
,
wordPojo
,
vocabularyId
)
wordItem
,
wordPojo
)
}
}
private
fun
onSuccessfulSave
(
wordPojo
:
WordItem
.
Pojo
)
{
private
fun
onSuccessfulSave
(
wordPojo
:
WordItem
.
Pojo
)
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/VocabularyFragment.kt
View file @
36c1dfbf
...
@@ -9,7 +9,7 @@ import android.view.ViewGroup
...
@@ -9,7 +9,7 @@ import android.view.ViewGroup
import
com.google.firebase.Timestamp
import
com.google.firebase.Timestamp
import
com.google.firebase.firestore.DocumentSnapshot
import
com.google.firebase.firestore.DocumentSnapshot
import
com.paktalin.vocabularynotebook.*
import
com.paktalin.vocabularynotebook.*
import
com.paktalin.vocabularynotebook.
firestoreitems.
Vocabulary
import
com.paktalin.vocabularynotebook.Vocabulary
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.ui.views.LockableLayoutManager
import
com.paktalin.vocabularynotebook.ui.views.LockableLayoutManager
...
@@ -43,8 +43,8 @@ class VocabularyFragment : Fragment() {
...
@@ -43,8 +43,8 @@ class VocabularyFragment : Fragment() {
}
}
private
fun
extractWordsData
(
vocabularyId
:
String
)
{
private
fun
extractWordsData
(
vocabularyId
:
String
)
{
FirestoreManager
().
retrieveWordsData
(
{
documents
->
FirestoreManager
().
retrieveWordsData
{
documents
->
onSuccessfulWordDataExtraction
(
documents
,
vocabularyId
)}
,
vocabularyId
)
onSuccessfulWordDataExtraction
(
documents
,
vocabularyId
)}
}
}
private
fun
onSuccessfulWordDataExtraction
(
documents
:
MutableList
<
DocumentSnapshot
>,
vocabularyId
:
String
)
{
private
fun
onSuccessfulWordDataExtraction
(
documents
:
MutableList
<
DocumentSnapshot
>,
vocabularyId
:
String
)
{
...
@@ -57,16 +57,8 @@ class VocabularyFragment : Fragment() {
...
@@ -57,16 +57,8 @@ class VocabularyFragment : Fragment() {
}
}
private
fun
setVocabularyAdapter
(
documents
:
MutableList
<
DocumentSnapshot
>,
vocabularyId
:
String
)
{
private
fun
setVocabularyAdapter
(
documents
:
MutableList
<
DocumentSnapshot
>,
vocabularyId
:
String
)
{
val
wordItems
:
MutableList
<
WordItem
>
=
mutableListOf
()
val
vocabulary
=
Vocabulary
()
vocabulary
.
addWordsAsDocuments
(
documents
)
for
(
ref
in
documents
)
{
val
word
=
ref
[
"word"
].
toString
()
val
translation
=
ref
[
"translation"
].
toString
()
val
time
=
ref
[
"time"
]
as
Timestamp
wordItems
.
add
(
WordItem
(
word
,
translation
,
time
.
toDate
(),
ref
.
id
,
vocabularyId
))
}
val
vocabulary
=
Vocabulary
(
wordItems
)
val
adapter
=
VocabularyAdapter
(
vocabulary
,
mainActivity
)
val
adapter
=
VocabularyAdapter
(
vocabulary
,
mainActivity
)
recyclerView
.
adapter
=
adapter
recyclerView
.
adapter
=
adapter
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/WordFragment.kt
View file @
36c1dfbf
...
@@ -62,9 +62,8 @@ abstract class WordFragment : Fragment() {
...
@@ -62,9 +62,8 @@ 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
=
FirestoreManager
.
vocabularyId
mainActivity
.
addProgressBar
()
mainActivity
.
addProgressBar
()
saveToFirestore
(
word
,
translation
,
vocabularyId
)
saveToFirestore
(
word
,
translation
,
FirestoreManager
.
vocabularyId
!!
)
return
return
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/utils/FirestoreManager.kt
View file @
36c1dfbf
package
com.paktalin.vocabularynotebook.utils
package
com.paktalin.vocabularynotebook.utils
import
android.content.Context
import
android.util.Log
import
android.util.Log
import
com.google.firebase.auth.FirebaseAuth
import
com.google.firebase.auth.FirebaseAuth
import
com.google.firebase.auth.FirebaseUser
import
com.google.firebase.auth.FirebaseUser
...
@@ -9,10 +10,9 @@ import com.google.firebase.firestore.FirebaseFirestore
...
@@ -9,10 +10,9 @@ import com.google.firebase.firestore.FirebaseFirestore
import
com.google.firebase.firestore.Query
import
com.google.firebase.firestore.Query
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.firestoreitems.UserPojo
import
com.paktalin.vocabularynotebook.firestoreitems.UserPojo
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary
Pojo
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.ui.activities.LogInActivity
import
com.paktalin.vocabularynotebook.ui.activities.LogInActivity
import
com.paktalin.vocabularynotebook.ui.fragments.VocabularyFragment
import
java.util.*
import
java.util.*
class
FirestoreManager
{
class
FirestoreManager
{
...
@@ -20,15 +20,15 @@ class FirestoreManager {
...
@@ -20,15 +20,15 @@ class FirestoreManager {
private
val
db
:
FirebaseFirestore
=
ConfiguredFirestore
.
instance
private
val
db
:
FirebaseFirestore
=
ConfiguredFirestore
.
instance
private
val
vocabularyCollection
=
db
.
collection
(
VOCABULARIES
)
private
val
vocabularyCollection
=
db
.
collection
(
VOCABULARIES
)
fun
extractVocabularyId
(
onSuccess
:
(
vocabularyId
:
String
)
->
Unit
,
fun
extractVocabularyId
(
onSuccess
:
()
->
Unit
,
showToastNoWords
:
()
->
Unit
,
removeProgressBar
:
()
->
Unit
)
{
showToastNoWords
:
()
->
Unit
,
removeProgressBar
:
()
->
Unit
,
mainActivity
:
Context
)
{
val
userId
=
FirebaseAuth
.
getInstance
()
!!
.
currentUser
!!
.
uid
val
userId
=
FirebaseAuth
.
getInstance
()
!!
.
currentUser
!!
.
uid
userDocument
(
userId
).
get
()
userDocument
(
userId
).
get
()
.
addOnSuccessListener
{
snapshot
->
.
addOnSuccessListener
{
snapshot
->
removeProgressBar
()
removeProgressBar
()
if
(
snapshot
.
get
(
VOCABULARIES
)
!=
null
)
{
if
(
snapshot
.
get
(
VOCABULARIES
)
!=
null
)
{
setVocabularyID
(
snapshot
)
setVocabularyID
(
snapshot
,
mainActivity
)
onSuccess
(
vocabularyId
)
onSuccess
()
}
else
{
}
else
{
Log
.
w
(
TAG
,
"There's no collection \"vocabularies\""
)
Log
.
w
(
TAG
,
"There's no collection \"vocabularies\""
)
showToastNoWords
()
showToastNoWords
()
...
@@ -38,7 +38,7 @@ class FirestoreManager {
...
@@ -38,7 +38,7 @@ class FirestoreManager {
fun
addNewUser
(
firebaseUser
:
FirebaseUser
,
logInActivity
:
LogInActivity
)
{
fun
addNewUser
(
firebaseUser
:
FirebaseUser
,
logInActivity
:
LogInActivity
)
{
//todo add condition to writing to the db in Firebase Console (request.auth.uid)
//todo add condition to writing to the db in Firebase Console (request.auth.uid)
vocabularyCollection
.
add
(
Vocabulary
.
Pojo
(
null
))
vocabularyCollection
.
add
(
VocabularyPojo
(
null
))
.
addOnSuccessListener
{
firstVocabularyRef
->
.
addOnSuccessListener
{
firstVocabularyRef
->
Log
.
d
(
TAG
,
"VocabularyPojo successfully created: "
+
firstVocabularyRef
.
path
)
Log
.
d
(
TAG
,
"VocabularyPojo successfully created: "
+
firstVocabularyRef
.
path
)
setNewUserWithVocabularyData
(
firebaseUser
,
firstVocabularyRef
,
logInActivity
)
setNewUserWithVocabularyData
(
firebaseUser
,
firstVocabularyRef
,
logInActivity
)
...
@@ -50,8 +50,8 @@ class FirestoreManager {
...
@@ -50,8 +50,8 @@ class FirestoreManager {
}
}
fun
saveNewWord
(
onSuccess
:
(
documentId
:
String
)
->
Unit
,
onFailure
:
()
->
Unit
,
fun
saveNewWord
(
onSuccess
:
(
documentId
:
String
)
->
Unit
,
onFailure
:
()
->
Unit
,
wordPojo
:
WordItem
.
Pojo
,
vocabularyId
:
String
)
{
wordPojo
:
WordItem
.
Pojo
)
{
vocabularyDocument
(
vocabularyId
)
vocabularyDocument
()
.
collection
(
WORDS
).
add
(
wordPojo
)
.
collection
(
WORDS
).
add
(
wordPojo
)
.
addOnSuccessListener
{
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully added a new word"
)
Log
.
i
(
TAG
,
"Successfully added a new word"
)
...
@@ -62,9 +62,8 @@ class FirestoreManager {
...
@@ -62,9 +62,8 @@ class FirestoreManager {
onFailure
()
}
onFailure
()
}
}
}
fun
updateWord
(
onSuccess
:
()
->
Unit
,
onFailure
:
()
->
Unit
,
fun
updateWord
(
onSuccess
:
()
->
Unit
,
onFailure
:
()
->
Unit
,
wordItem
:
WordItem
,
wordPojo
:
WordItem
.
Pojo
)
{
wordItem
:
WordItem
,
wordPojo
:
WordItem
.
Pojo
,
vocabularyId
:
String
)
{
vocabularyDocument
()
vocabularyDocument
(
vocabularyId
)
.
collection
(
WORDS
).
document
(
wordItem
.
id
).
set
(
wordPojo
)
.
collection
(
WORDS
).
document
(
wordItem
.
id
).
set
(
wordPojo
)
.
addOnSuccessListener
{
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully updated the word"
)
Log
.
i
(
TAG
,
"Successfully updated the word"
)
...
@@ -77,14 +76,14 @@ class FirestoreManager {
...
@@ -77,14 +76,14 @@ class FirestoreManager {
}
}
fun
deleteWord
(
id
:
String
)
{
fun
deleteWord
(
id
:
String
)
{
vocabularyDocument
(
vocabularyId
)
vocabularyDocument
()
.
collection
(
WORDS
).
document
(
id
).
delete
()
.
collection
(
WORDS
).
document
(
id
).
delete
()
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully deleted word with id $id"
)
}
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully deleted word with id $id"
)
}
.
addOnFailureListener
{
e
->
Log
.
w
(
TAG
,
"deleteWordWithId $id:failure"
,
e
.
fillInStackTrace
())
}
.
addOnFailureListener
{
e
->
Log
.
w
(
TAG
,
"deleteWordWithId $id:failure"
,
e
.
fillInStackTrace
())
}
}
}
fun
retrieveWordsData
(
onSuccess
:
(
documents
:
MutableList
<
DocumentSnapshot
>)
->
Unit
,
vocabularyId
:
String
)
{
fun
retrieveWordsData
(
onSuccess
:
(
documents
:
MutableList
<
DocumentSnapshot
>)
->
Unit
)
{
vocabularyDocument
(
vocabularyId
).
collection
(
WORDS
)
vocabularyDocument
().
collection
(
WORDS
)
.
orderBy
(
"time"
,
Query
.
Direction
.
DESCENDING
)
.
orderBy
(
"time"
,
Query
.
Direction
.
DESCENDING
)
.
get
()
.
get
()
.
addOnSuccessListener
{
onSuccess
(
it
.
documents
)}
.
addOnSuccessListener
{
onSuccess
(
it
.
documents
)}
...
@@ -105,9 +104,10 @@ class FirestoreManager {
...
@@ -105,9 +104,10 @@ class FirestoreManager {
}
}
}
}
private
fun
setVocabularyID
(
snapshot
:
DocumentSnapshot
)
{
private
fun
setVocabularyID
(
snapshot
:
DocumentSnapshot
,
context
:
Context
)
{
val
vocabularies
:
List
<
DocumentReference
>
=
snapshot
.
get
(
VOCABULARIES
)
as
List
<
DocumentReference
>
val
vocabularies
:
List
<
DocumentReference
>
=
snapshot
.
get
(
VOCABULARIES
)
as
List
<
DocumentReference
>
val
vocabulary
=
vocabularyDocument
(
vocabularies
[
0
].
id
)
val
vocabulary
=
vocabularyCollection
.
document
(
vocabularies
[
0
].
id
)
saveVocabularyId
(
context
,
vocabulary
.
id
)
vocabularyId
=
vocabulary
.
id
vocabularyId
=
vocabulary
.
id
}
}
...
@@ -115,8 +115,8 @@ class FirestoreManager {
...
@@ -115,8 +115,8 @@ class FirestoreManager {
return
db
.
collection
(
USERS
).
document
(
userId
)
return
db
.
collection
(
USERS
).
document
(
userId
)
}
}
private
fun
vocabularyDocument
(
vocabularyId
:
String
):
DocumentReference
{
private
fun
vocabularyDocument
():
DocumentReference
{
return
vocabularyCollection
.
document
(
vocabularyId
)
return
vocabularyCollection
.
document
(
vocabularyId
!!
)
}
}
companion
object
{
companion
object
{
...
@@ -125,6 +125,6 @@ class FirestoreManager {
...
@@ -125,6 +125,6 @@ class FirestoreManager {
private
const
val
VOCABULARIES
=
"vocabularies"
private
const
val
VOCABULARIES
=
"vocabularies"
private
const
val
TAG
=
"VN/FirestoreManager"
private
const
val
TAG
=
"VN/FirestoreManager"
lateinit
var
vocabularyId
:
String
var
vocabularyId
:
String
?
=
null
}
}
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/utils/PreferenceUtil.kt
0 → 100644
View file @
36c1dfbf
package
com.paktalin.vocabularynotebook.utils
import
android.content.Context
import
android.preference.PreferenceManager
private
const
val
vocabularyIdKey
=
"vocabularyId"
fun
saveVocabularyId
(
context
:
Context
,
vocabularyId
:
String
)
{
val
sharedPreferences
=
PreferenceManager
.
getDefaultSharedPreferences
(
context
)
sharedPreferences
.
edit
().
putString
(
vocabularyIdKey
,
vocabularyId
).
apply
()
}
fun
getSavedVocabularyId
(
context
:
Context
):
String
?
{
val
sharedPreferences
=
PreferenceManager
.
getDefaultSharedPreferences
(
context
)
return
sharedPreferences
.
getString
(
vocabularyIdKey
,
null
)
}
\ No newline at end of file
app/src/main/res/layout/content_main.xml
View file @
36c1dfbf
...
@@ -14,12 +14,12 @@
...
@@ -14,12 +14,12 @@
android:layout_marginRight=
"@dimen/small_margin"
android:layout_marginRight=
"@dimen/small_margin"
android:layout_marginStart=
"@dimen/small_margin"
android:layout_marginStart=
"@dimen/small_margin"
android:layout_marginTop=
"@dimen/small_margin"
android:layout_marginTop=
"@dimen/small_margin"
android:paddingStart=
"@dimen/small_padding"
android:background=
"@drawable/sheet_top"
android:paddingLeft=
"@dimen/small_padding"
android:paddingEnd=
"@dimen/small_padding"
android:paddingEnd=
"@dimen/small_padding"
android:paddingLeft=
"@dimen/small_padding"
android:paddingRight=
"@dimen/small_padding"
android:paddingRight=
"@dimen/small_padding"
android:paddingStart=
"@dimen/small_padding"
android:paddingTop=
"@dimen/small_padding"
android:paddingTop=
"@dimen/small_padding"
android:background=
"@drawable/sheet_top"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
>
app:layout_constraintTop_toTopOf=
"parent"
>
...
@@ -28,61 +28,66 @@
...
@@ -28,61 +28,66 @@
android:id=
"@+id/fragmentAddWord"
android:id=
"@+id/fragmentAddWord"
android:name=
"com.paktalin.vocabularynotebook.ui.fragments.AddWordFragment"
android:name=
"com.paktalin.vocabularynotebook.ui.fragments.AddWordFragment"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
android:layout_height=
"wrap_content"
/>
</FrameLayout>
</FrameLayout>
<com.paktalin.vocabularynotebook.ui.views.LockableScrollView
android:id=
"@+id/scrollView"
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/swipeRefresh"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"0dp"
android:layout_height=
"0dp"
android:layout_marginEnd=
"@dimen/small_margin"
android:layout_marginEnd=
"@dimen/small_margin"
android:layout_marginLeft=
"@dimen/small_margin"
android:layout_marginLeft=
"@dimen/small_margin"
android:layout_marginRight=
"@dimen/small_margin"
android:layout_marginRight=
"@dimen/small_margin"
android:layout_marginStart=
"@dimen/small_margin"
android:layout_marginStart=
"@dimen/small_margin"
android:scrollbars=
"vertical"
app:layout_constraintBottom_toTopOf=
"@+id/btnSubmitLayout"
app:layout_constraintBottom_toTopOf=
"@+id/btnSubmitLayout"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/container_main"
>
app:layout_constraintTop_toBottomOf=
"@+id/container_main"
>
<
LinearLayout
<
com.paktalin.vocabularynotebook.ui.views.LockableScrollView
android:id=
"@+id/
container_vocabulary
"
android:id=
"@+id/
scrollView
"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"0dp"
android:background=
"@drawable/sheet_bottom"
android:scrollbars=
"vertical"
>
android:orientation=
"vertical"
android:paddingStart=
"@dimen/small_padding"
android:paddingLeft=
"@dimen/small_padding"
android:paddingEnd=
"@dimen/small_padding"
android:paddingRight=
"@dimen/small_padding"
android:paddingBottom=
"@dimen/small_padding"
>
</LinearLayout>
</com.paktalin.vocabularynotebook.ui.views.LockableScrollView>
<LinearLayout
android:id=
"@+id/container_vocabulary"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:background=
"@drawable/sheet_bottom"
android:orientation=
"vertical"
android:paddingBottom=
"@dimen/small_padding"
android:paddingEnd=
"@dimen/small_padding"
android:paddingLeft=
"@dimen/small_padding"
android:paddingRight=
"@dimen/small_padding"
android:paddingStart=
"@dimen/small_padding"
/>
</com.paktalin.vocabularynotebook.ui.views.LockableScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
<LinearLayout
<LinearLayout
android:id=
"@+id/btnSubmitLayout"
android:id=
"@+id/btnSubmitLayout"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:background=
"@color/colorPrimary"
android:background=
"@color/colorPrimary"
android:visibility=
"gone"
android:orientation=
"horizontal"
android:orientation=
"horizontal"
android:visibility=
"gone"
app:layout_constraintBottom_toBottomOf=
"parent"
>
app:layout_constraintBottom_toBottomOf=
"parent"
>
<ImageButton
<ImageButton
android:id=
"@+id/btnCancel"
android:id=
"@+id/btnCancel"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
app:srcCompat=
"@drawable/ic_close_icon"
android:background=
"@android:color/transparent"
android:layout_gravity=
"center_vertical"
android:layout_gravity=
"center_vertical"
android:layout_margin=
"@dimen/small_margin"
android:layout_margin=
"@dimen/small_margin"
android:background=
"@android:color/transparent"
app:srcCompat=
"@drawable/ic_close_icon"
tools:ignore=
"ContentDescription"
/>
tools:ignore=
"ContentDescription"
/>
<View
<View
android:layout_width=
"0dp"
android:layout_width=
"0dp"
android:layout_height=
"0dp"
android:layout_height=
"0dp"
android:layout_weight=
"1"
/>
android:layout_weight=
"1"
/>
<ImageButton
<ImageButton
android:id=
"@+id/btnSubmit"
android:id=
"@+id/btnSubmit"
...
...
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