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