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
646fc562
authored
Apr 29, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed the problem with replaced word when adding
parent
f4a8ddf1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
27 deletions
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/DisplayedVocabulary.kt
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/VocabSet.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
View file @
646fc562
...
...
@@ -62,10 +62,10 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
override
fun
onBindViewHolder
(
viewHolder
:
ViewHolder
,
position
:
Int
)
{
viewHolder
.
bind
(
vocabulary
.
d
isplayedAt
(
position
),
vocabulary
.
getD
isplayedAt
(
position
),
position
,
(
selectionTracker
.
selected
(
position
.
toLong
()))
&&
state
.
notAddOrEdit
(),
vocabulary
.
getColorForTag
(
vocabulary
.
d
isplayedAt
(
position
).
tag
)
vocabulary
.
getColorForTag
(
vocabulary
.
getD
isplayedAt
(
position
).
tag
)
)
{
view
,
p
->
showPopupMenu
(
view
,
p
)
}
// TODO not allow to edit when tag is being selected
}
...
...
@@ -73,13 +73,15 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
fun
refresh
()
{}
fun
addWord
(
newWord
:
WordPojo
)
{
this
.
sort
=
Sort
.
BY_TIME
vocabulary
.
addWord
(
newWord
)
notifyDataSetChanged
()
recyclerView
.
smoothScrollToPosition
(
0
)
notifyItemRangeInserted
(
0
,
2
)
}
fun
updateWord
(
wordPojo
:
WordPojo
)
{
vocabulary
.
updateWord
(
wordPojo
)
notify
DataSetChanged
(
)
notify
ItemChanged
(
vocabulary
.
indexOfDisplayed
(
wordPojo
)
)
}
fun
filter
(
query
:
String
)
{
...
...
@@ -101,7 +103,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
popup
.
menuInflater
.
inflate
(
R
.
menu
.
word_item_menu
,
popup
.
menu
)
popup
.
setOnMenuItemClickListener
{
when
(
it
.
itemId
)
{
R
.
id
.
option_delete
->
deleteWord
(
vocabulary
.
d
isplayedAt
(
position
),
position
)
R
.
id
.
option_delete
->
deleteWord
(
vocabulary
.
getD
isplayedAt
(
position
),
position
)
R
.
id
.
option_edit
->
editWord
(
v
,
position
)
}
true
...
...
@@ -124,12 +126,11 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
SubmitEditedFragment
().
apply
{
setData
(
container
.
word
,
container
.
translation
,
vocabulary
.
d
isplayedAt
(
wordPosition
),
vocabulary
.
getD
isplayedAt
(
wordPosition
),
container
.
clickable_view
,
wordPosition
)
},
R
.
id
.
main_activity_container
)
}
private
val
TAG
=
"VN/"
+
VocabularyAdapter
::
class
.
java
.
simpleName
}
\ No newline at end of file
}
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/DisplayedVocabulary.kt
View file @
646fc562
...
...
@@ -18,6 +18,10 @@ class DisplayedVocabulary(wordList: MutableList<WordPojo>): BasicVocabulary(word
return
wordList
[
index
]
}
fun
indexOf
(
wordPojo
:
WordPojo
):
Int
{
return
wordList
.
indexOf
(
wordPojo
)
}
fun
byQuery
(
query
:
String
,
allWords
:
MutableList
<
WordPojo
>)
{
// TODO make tag search more flexible
if
(
query
[
0
]
==
'#'
)
{
...
...
@@ -37,7 +41,7 @@ class DisplayedVocabulary(wordList: MutableList<WordPojo>): BasicVocabulary(word
}
// TODO convert to a lambda expression
fun
contains
(
wordPojo
:
WordPojo
,
string
:
String
):
Boolean
{
private
fun
contains
(
wordPojo
:
WordPojo
,
string
:
String
):
Boolean
{
return
wordPojo
.
word
.
toLowerCase
().
contains
(
string
)
||
wordPojo
.
translation
.
toLowerCase
().
contains
(
string
)
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/VocabSet.kt
View file @
646fc562
...
...
@@ -47,8 +47,7 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
override
fun
updateWord
(
updatedWord
:
WordPojo
)
{
listOf
(
fullVocabulary
,
displayedVocabulary
,
modifiedVocabulary
)
.
forEach
{
v
->
v
.
updateWord
(
updatedWord
)
}
// TODO change this
sort
(
displayedVocabulary
.
sort
)
displayedVocabulary
.
sort
(
displayedVocabulary
.
sort
)
}
override
fun
deleteWord
(
wordPojo
:
WordPojo
)
{
...
...
@@ -59,41 +58,44 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
override
fun
addWord
(
newWord
:
WordPojo
)
{
listOf
(
fullVocabulary
,
displayedVocabulary
,
modifiedVocabulary
)
.
forEach
{
v
->
v
.
addWord
(
newWord
)
}
// TODO change this
sort
(
displayedVocabulary
.
sort
)
displayedVocabulary
.
sort
(
displayedVocabulary
.
sort
)
}
fun
sort
(
sort
:
Sort
)
{
displayedVocabulary
.
sort
(
sort
)
}
fun
getModified
():
MutableMap
<
WordPojo
,
Boolean
>
{
return
modifiedVocabulary
.
get
()
}
fun
addTag
(
selectionList
:
MutableList
<
Long
>,
tag
:
String
)
{
selectionList
.
forEach
{
position
->
d
isplayedAt
(
position
.
toInt
()).
tag
=
tag
modifiedVocabulary
.
addWord
(
d
isplayedAt
(
position
.
toInt
()))
getD
isplayedAt
(
position
.
toInt
()).
tag
=
tag
modifiedVocabulary
.
addWord
(
getD
isplayedAt
(
position
.
toInt
()))
}
}
fun
getColorForTag
(
tag
:
String
?):
Int
{
return
colorMap
[
tag
]
?:
Color
.
TRANSPARENT
}
fun
displayByQuery
(
query
:
String
)
{
clearDisplayed
()
if
(
query
.
isEmpty
())
displayAll
()
else
displayedVocabulary
.
byQuery
(
query
.
toLowerCase
(),
wordList
)
}
fun
displayedAt
(
position
:
Int
):
WordPojo
{
fun
displayedSize
():
Int
{
return
displayedVocabulary
.
size
()
}
fun
getModified
():
MutableMap
<
WordPojo
,
Boolean
>
{
return
modifiedVocabulary
.
get
()
}
fun
getColorForTag
(
tag
:
String
?):
Int
{
return
colorMap
[
tag
]
?:
Color
.
TRANSPARENT
}
fun
getDisplayedAt
(
position
:
Int
):
WordPojo
{
return
displayedVocabulary
.
at
(
position
)
}
fun
displayedSize
(
):
Int
{
return
displayedVocabulary
.
size
(
)
fun
indexOfDisplayed
(
wordPojo
:
WordPojo
):
Int
{
return
displayedVocabulary
.
indexOf
(
wordPojo
)
}
private
fun
clearDisplayed
()
{
...
...
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