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
a91bfbe1
authored
Apr 20, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed modifiedLabel from WordItem, fixed paddings and duplication bug in BasicVocabulary
parent
40c0da46
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
45 additions
and
42 deletions
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/ModifiedLabel.kt
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/WordItem.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/utils/FirestoreManager.kt
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/BasicVocabulary.kt
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/ModifiedVocabulary.kt
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/VocabSet.kt
app/src/main/res/layout/fragment_editable_word.xml
app/src/main/res/layout/word_item.xml
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/ModifiedLabel.kt
deleted
100644 → 0
View file @
40c0da46
package
com.paktalin.vocabularynotebook.firestoreitems
enum
class
ModifiedLabel
{
ADDED
,
UPDATED
,
DELETED
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/WordItem.kt
View file @
a91bfbe1
...
...
@@ -5,7 +5,6 @@ import java.util.Date
class
WordItem
(
word
:
String
,
translation
:
String
,
time
:
Date
?,
var
id
:
String
?)
:
Serializable
{
var
pojo
:
Pojo
=
Pojo
(
word
,
translation
,
time
)
var
modifiedLabel
:
ModifiedLabel
?
=
null
class
Pojo
(
var
word
:
String
,
var
translation
:
String
,
var
time
:
Date
?
=
null
)
:
Serializable
{
init
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyAdapter.kt
View file @
a91bfbe1
...
...
@@ -13,6 +13,7 @@ import com.paktalin.vocabularynotebook.ui.fragments.EditWordFragment
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.Log
import
com.paktalin.vocabularynotebook.utils.addFragment
import
com.paktalin.vocabularynotebook.vocabulary.ModifiedVocabulary
import
com.paktalin.vocabularynotebook.vocabulary.Sort
import
com.paktalin.vocabularynotebook.vocabulary.VocabSet
...
...
@@ -113,7 +114,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
notifyDataSetChanged
()
}
fun
getModifiedWords
():
Mutable
Set
<
WordItem
>
{
fun
getModifiedWords
():
Mutable
Map
<
WordItem
,
ModifiedVocabulary
.
Label
>
{
return
vocabulary
.
getModified
()
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/utils/FirestoreManager.kt
View file @
a91bfbe1
...
...
@@ -5,17 +5,19 @@ import com.google.firebase.auth.FirebaseAuth
import
com.google.firebase.auth.FirebaseUser
import
com.google.firebase.firestore.*
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.firestoreitems.ModifiedLabel
import
com.paktalin.vocabularynotebook.firestoreitems.UserPojo
import
com.paktalin.vocabularynotebook.firestoreitems.VocabularyPojo
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.ui.activities.LogInActivity
import
com.paktalin.vocabularynotebook.vocabulary.ModifiedVocabulary
import
com.paktalin.vocabularynotebook.vocabulary.ModifiedVocabulary.Label
import
java.util.*
class
FirestoreManager
{
private
val
db
:
FirebaseFirestore
=
ConfiguredFirestore
.
instance
private
val
vocabularyCollection
=
db
.
collection
(
VOCABULARIES
)
private
val
wordsCollection
=
vocabularyCollection
.
document
(
vocabularyId
!!
).
collection
(
WORDS
)
fun
extractVocabularyId
(
onSuccess
:
()
->
Unit
,
showToastNoWords
:
()
->
Unit
,
removeProgressBar
:
()
->
Unit
,
mainActivity
:
Context
)
{
...
...
@@ -46,17 +48,19 @@ class FirestoreManager {
}
}
fun
saveWords
(
word
List
:
MutableSet
<
WordItem
>)
{
if
(
word
List
.
isEmpty
())
fun
saveWords
(
word
Map
:
MutableMap
<
WordItem
,
ModifiedVocabulary
.
Label
>)
{
if
(
word
Map
.
isEmpty
())
return
val
batch
=
db
.
batch
()
wordList
.
forEach
{
w
->
kotlin
.
run
{
if
(
w
.
modifiedLabel
==
ModifiedLabel
.
DELETED
)
batch
.
delete
(
vocabularyDocument
().
collection
(
WORDS
).
document
(
w
.
id
!!
))
else
if
(
w
.
modifiedLabel
==
ModifiedLabel
.
UPDATED
&&
w
.
id
!=
null
)
batch
.
set
(
vocabularyDocument
().
collection
(
WORDS
).
document
(
w
.
id
!!
),
w
.
pojo
)
wordMap
.
forEach
{
entry
->
run
{
if
(
entry
.
value
==
Label
.
DELETED
)
batch
.
delete
(
wordsCollection
.
document
(
entry
.
key
.
id
!!
))
else
if
(
entry
.
value
==
Label
.
UPDATED
&&
entry
.
key
.
id
!=
null
)
batch
.
set
(
wordsCollection
.
document
(
entry
.
key
.
id
!!
),
entry
.
key
.
pojo
)
else
batch
.
set
(
vocabularyDocument
().
collection
(
WORDS
).
document
(),
w
.
pojo
)
batch
.
set
(
wordsCollection
.
document
(),
entry
.
key
.
pojo
)
}}
batch
.
commit
().
addOnCompleteListener
{
Log
.
d
(
TAG
,
"words are successfully pushed to Firestore"
)
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/BasicVocabulary.kt
View file @
a91bfbe1
...
...
@@ -4,6 +4,10 @@ import com.paktalin.vocabularynotebook.firestoreitems.WordItem
open
class
BasicVocabulary
(
var
wordList
:
MutableList
<
WordItem
>):
Vocabulary
{
init
{
wordList
=
wordList
.
toMutableList
()
}
override
fun
addAll
(
words
:
MutableList
<
WordItem
>)
{
wordList
.
addAll
(
words
)
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/ModifiedVocabulary.kt
View file @
a91bfbe1
package
com.paktalin.vocabularynotebook.vocabulary
import
com.paktalin.vocabularynotebook.firestoreitems.ModifiedLabel
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.utils.FirestoreManager
class
ModifiedVocabulary
:
Vocabulary
{
//TODO wordMap<ModifiedLabel, WordItem>
var
wordList
=
mutableListOf
<
WordItem
>()
var
wordMap
=
mutableMapOf
<
WordItem
,
Label
>()
private
val
maxPermitted
=
9
override
fun
addWord
(
newWord
:
WordItem
)
{
add
(
newWord
,
Modified
Label
.
ADDED
)
add
(
newWord
,
Label
.
ADDED
)
}
override
fun
updateWord
(
updatedWord
:
WordItem
)
{
add
(
updatedWord
,
Modified
Label
.
UPDATED
)
add
(
updatedWord
,
Label
.
UPDATED
)
}
override
fun
deleteWord
(
wordItem
:
WordItem
)
{
add
(
wordItem
,
Modified
Label
.
DELETED
)
add
(
wordItem
,
Label
.
DELETED
)
}
override
fun
addAll
(
words
:
MutableList
<
WordItem
>)
{
}
fun
add
(
wordItem
:
WordItem
,
modifiedLabel
:
ModifiedLabel
)
{
wordItem
.
modifiedLabel
=
modifiedLabel
wordList
.
add
(
wordItem
)
if
(
wordList
.
size
==
maxPermitted
)
{
FirestoreManager
().
saveWords
(
wordList
.
toMutableSet
())
wordList
.
clear
()
fun
add
(
wordItem
:
WordItem
,
label
:
Label
)
{
wordMap
[
wordItem
]
=
label
if
(
wordMap
.
size
==
maxPermitted
)
{
FirestoreManager
().
saveWords
(
wordMap
)
wordMap
.
clear
()
}
}
fun
get
():
MutableSet
<
WordItem
>
{
return
wordList
.
toMutableSet
()
fun
get
():
MutableMap
<
WordItem
,
Label
>
{
return
wordMap
}
enum
class
Label
{
ADDED
,
UPDATED
,
DELETED
}
}
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/VocabSet.kt
View file @
a91bfbe1
...
...
@@ -67,5 +67,5 @@ class VocabSet(var wordList: MutableList<WordItem>) : Vocabulary {
fun
clearDisplayed
()
{
displayedVocabulary
.
clear
()
}
fun
getModified
():
Mutable
Set
<
WordItem
>
{
return
modifiedVocabulary
.
get
()
}
fun
getModified
():
Mutable
Map
<
WordItem
,
ModifiedVocabulary
.
Label
>
{
return
modifiedVocabulary
.
get
()
}
}
\ No newline at end of file
app/src/main/res/layout/fragment_editable_word.xml
View file @
a91bfbe1
...
...
@@ -45,9 +45,9 @@
android:textSize=
"@dimen/text_size"
app:fontFamily=
"@font/neucha"
android:textColor=
"@color/text_color"
android:
layout_marginRight
=
"@dimen/word_margin"
android:
layout_marginEnd
=
"@dimen/word_margin"
tools:ignore=
"LabelFor"
/>
android:
paddingEnd
=
"@dimen/word_margin"
android:
paddingRight
=
"@dimen/word_margin"
tools:ignore=
"LabelFor
,RtlSymmetry
"
/>
<EditText
android:id=
"@+id/translation"
...
...
@@ -60,9 +60,9 @@
android:textSize=
"@dimen/text_size"
app:fontFamily=
"@font/neucha"
android:textColor=
"@color/text_color"
android:
layout_marginRight
=
"16dp"
android:
layout_marginEnd
=
"16dp"
tools:ignore=
"LabelFor"
/>
android:
paddingEnd
=
"16dp"
android:
paddingRight
=
"16dp"
tools:ignore=
"LabelFor
,RtlSymmetry
"
/>
</LinearLayout>
<ImageButton
...
...
app/src/main/res/layout/word_item.xml
View file @
a91bfbe1
...
...
@@ -34,7 +34,6 @@
android:paddingTop=
"8dp"
android:paddingBottom=
"8dp"
>
<TextView
android:id=
"@+id/word"
android:layout_width=
"0dp"
...
...
@@ -43,9 +42,9 @@
android:textSize=
"@dimen/text_size"
app:fontFamily=
"@font/neucha"
android:textColor=
"@color/text_color"
android:
layout_marginRight
=
"@dimen/word_margin"
android:
layout_marginEnd
=
"@dimen/word_margin"
tools:ignore=
"LabelFor"
/>
android:
paddingEnd
=
"@dimen/word_margin"
android:
paddingRight
=
"@dimen/word_margin"
tools:ignore=
"LabelFor
,RtlSymmetry
"
/>
<TextView
android:id=
"@+id/translation"
...
...
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