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
38404f70
authored
Apr 29, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring
parent
60bd38c2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
52 deletions
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.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 @
38404f70
package
com.paktalin.vocabularynotebook.ui.recycler_view
import
android.annotation.SuppressLint
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
...
...
@@ -54,8 +53,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
}
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
ViewHolder
{
val
view
=
LayoutInflater
.
from
(
parent
.
context
).
inflate
(
R
.
layout
.
word_item
,
parent
,
false
)
return
ViewHolder
(
view
)
return
ViewHolder
(
LayoutInflater
.
from
(
parent
.
context
).
inflate
(
R
.
layout
.
word_item
,
parent
,
false
))
}
override
fun
getItemCount
():
Int
{
...
...
@@ -72,6 +70,32 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
// TODO not allow to edit when tag is being selected
}
fun
refresh
()
{}
fun
addWord
(
newWord
:
WordPojo
)
{
Log
.
d
(
TAG
,
"vocabularyAdapter addWord"
)
vocabulary
.
addWord
(
newWord
)
this
.
sort
()
}
fun
updateWord
(
wordPojo
:
WordPojo
)
{
vocabulary
.
updateWord
(
wordPojo
)
this
.
sort
()
}
fun
filter
(
query
:
String
)
{
vocabulary
.
displayByQuery
(
query
)
notifyDataSetChanged
()
}
fun
getModifiedWords
():
MutableMap
<
WordPojo
,
Boolean
>
{
return
vocabulary
.
getModified
()
}
fun
addTagToSelected
(
tag
:
String
,
selectionList
:
MutableList
<
Long
>)
{
vocabulary
.
addTag
(
selectionList
,
tag
)
}
private
fun
showPopupMenu
(
v
:
View
,
position
:
Int
)
{
if
(
state
==
State
.
NONE
)
{
val
popup
=
PopupMenu
(
mainActivity
,
v
)
...
...
@@ -89,8 +113,6 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
}
}
fun
refresh
()
{}
private
fun
deleteWord
(
wordPojo
:
WordPojo
,
position
:
Int
)
{
vocabulary
.
deleteWord
(
wordPojo
)
recyclerView
.
removeViewAt
(
position
)
...
...
@@ -98,23 +120,11 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
this
.
notifyItemRangeChanged
(
position
,
vocabulary
.
displayedSize
())
}
fun
addWord
(
newWord
:
WordPojo
)
{
Log
.
d
(
TAG
,
"vocabularyAdapter addWord"
)
vocabulary
.
addWord
(
newWord
)
this
.
sort
()
}
fun
updateWord
(
wordPojo
:
WordPojo
)
{
vocabulary
.
updateWord
(
wordPojo
)
this
.
sort
()
}
private
fun
sort
()
{
vocabulary
.
sort
(
sort
)
this
.
notifyDataSetChanged
()
}
@SuppressLint
(
"ResourceType"
)
private
fun
editWord
(
container
:
View
,
wordPosition
:
Int
)
{
addSubmitFragment
(
mainActivity
.
supportFragmentManager
,
SubmitEditedFragment
().
apply
{
...
...
@@ -127,22 +137,5 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
R
.
id
.
main_activity_container
)
}
fun
filter
(
query
:
String
)
{
vocabulary
.
clearDisplayed
()
if
(
query
.
isEmpty
())
vocabulary
.
displayAll
()
else
vocabulary
.
displayByQuery
(
query
)
notifyDataSetChanged
()
}
fun
getModifiedWords
():
MutableMap
<
WordPojo
,
Boolean
>
{
return
vocabulary
.
getModified
()
}
fun
addTagToSelected
(
tag
:
String
,
selectionList
:
MutableList
<
Long
>)
{
vocabulary
.
addTag
(
selectionList
,
tag
)
}
companion
object
{
private
val
TAG
=
"VN/"
+
VocabularyAdapter
::
class
.
java
.
simpleName
}
val
TAG
=
"VN/"
+
VocabularyAdapter
::
class
.
java
.
simpleName
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/VocabSet.kt
View file @
38404f70
...
...
@@ -65,12 +65,25 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
displayedVocabulary
.
sort
(
sort
)
}
fun
displayAll
()
{
displayedVocabulary
.
addAll
(
wordList
)
fun
getModified
():
MutableMap
<
WordPojo
,
Boolean
>
{
return
modifiedVocabulary
.
get
()
}
fun
addTag
(
selectionList
:
MutableList
<
Long
>,
tag
:
String
)
{
selectionList
.
forEach
{
position
->
displayedAt
(
position
.
toInt
()).
tag
=
tag
modifiedVocabulary
.
addWord
(
displayedAt
(
position
.
toInt
()))
}
}
fun
getColorForTag
(
tag
:
String
?):
Int
{
return
colorMap
[
tag
]
?:
Color
.
TRANSPARENT
}
fun
displayByQuery
(
query
:
String
)
{
displayedVocabulary
.
byQuery
(
query
.
toLowerCase
(),
wordList
)
clearDisplayed
()
if
(
query
.
isEmpty
())
displayAll
()
else
displayedVocabulary
.
byQuery
(
query
.
toLowerCase
(),
wordList
)
}
fun
displayedAt
(
position
:
Int
):
WordPojo
{
...
...
@@ -81,22 +94,11 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
return
displayedVocabulary
.
size
()
}
fun
clearDisplayed
()
{
private
fun
clearDisplayed
()
{
displayedVocabulary
.
clear
()
}
fun
getModified
():
MutableMap
<
WordPojo
,
Boolean
>
{
return
modifiedVocabulary
.
get
()
}
fun
addTag
(
selectionList
:
MutableList
<
Long
>,
tag
:
String
)
{
selectionList
.
forEach
{
position
->
displayedAt
(
position
.
toInt
()).
tag
=
tag
modifiedVocabulary
.
addWord
(
displayedAt
(
position
.
toInt
()))
}
}
fun
getColorForTag
(
tag
:
String
?):
Int
{
return
colorMap
[
tag
]
?:
Color
.
TRANSPARENT
private
fun
displayAll
()
{
displayedVocabulary
.
addAll
(
wordList
)
}
}
\ No newline at end of file
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