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
16f12c22
authored
Apr 25, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TagFragment is removed on sumbit, words can be searched by tags
parent
9b78a83f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
13 deletions
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/WordPojo.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/TagFragment.kt
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/firestoreitems/WordPojo.kt
View file @
16f12c22
...
...
@@ -6,8 +6,8 @@ import java.util.*
class
WordPojo
(
var
word
:
String
,
var
translation
:
String
,
var
time
:
Date
?
=
null
,
var
id
:
String
?
=
null
,
var
tag
:
String
?
=
null
)
var
tag
:
String
?
=
null
,
var
id
:
String
?
=
null
)
:
Serializable
{
init
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/TagFragment.kt
View file @
16f12c22
...
...
@@ -23,7 +23,7 @@ class TagFragment : Fragment() {
super
.
onActivityCreated
(
savedInstanceState
)
mainActivity
=
activity
as
MainActivity
btnSubmitTag
.
setOnClickListener
{
submit
()
}
btnCancelTag
.
setOnClickListener
{
cancel
()
}
btnCancelTag
.
setOnClickListener
{
finish
()
}
}
fun
setSelection
(
selectionList
:
List
<
Long
>)
{
...
...
@@ -32,14 +32,15 @@ class TagFragment : Fragment() {
private
fun
submit
()
{
tag_et
.
text
.
toString
().
let
{
if
(
it
.
isBlank
())
shortToast
(
mainActivity
,
mainActivity
.
getString
(
R
.
string
.
toast_tag_cannot_be_empty
))
else
if
(
it
.
isBlank
())
shortToast
(
mainActivity
,
mainActivity
.
getString
(
R
.
string
.
toast_tag_cannot_be_empty
))
else
{
mainActivity
.
vocabularyAdapter
?.
addTagToSelected
(
it
,
selectionList
)
finish
()
}
}
}
private
fun
cancel
()
{
private
fun
finish
()
{
mainActivity
.
vocabularyAdapter
?.
selectionTracker
?.
clearSelection
()
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
View file @
16f12c22
...
...
@@ -128,10 +128,8 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
fun
filter
(
query
:
String
)
{
vocabulary
.
clearDisplayed
()
if
(
query
.
isEmpty
())
vocabulary
.
displayAll
()
else
vocabulary
.
displayByQuery
(
query
.
toLowerCase
())
if
(
query
.
isEmpty
())
vocabulary
.
displayAll
()
else
vocabulary
.
displayByQuery
(
query
)
notifyDataSetChanged
()
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/DisplayedVocabulary.kt
View file @
16f12c22
...
...
@@ -18,7 +18,12 @@ class DisplayedVocabulary(wordList: MutableList<WordPojo>): BasicVocabulary(word
}
fun
byQuery
(
query
:
String
,
allWords
:
MutableList
<
WordPojo
>)
{
allWords
.
filter
{
wordItem
->
contains
(
wordItem
,
query
)
}.
toCollection
(
wordList
)
// TODO make tag search more flexible
if
(
query
[
0
]
==
'#'
)
{
allWords
.
filter
{
w
->
w
.
tag
?.
toLowerCase
()
?.
contains
(
query
.
substring
(
1
,
query
.
length
))
==
true
}.
toCollection
(
wordList
)
}
else
allWords
.
filter
{
w
->
contains
(
w
,
query
)
}.
toCollection
(
wordList
)
}
fun
sort
(
sort
:
Sort
)
{
...
...
@@ -47,4 +52,8 @@ class DisplayedVocabulary(wordList: MutableList<WordPojo>): BasicVocabulary(word
return
wordPojo
.
word
.
toLowerCase
().
contains
(
string
)
||
wordPojo
.
translation
.
toLowerCase
().
contains
(
string
)
}
companion
object
{
private
val
TAG
=
"VN/"
+
DisplayedVocabulary
::
class
.
simpleName
}
}
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/VocabSet.kt
View file @
16f12c22
...
...
@@ -23,6 +23,7 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
snapshot
[
"word"
].
toString
(),
snapshot
[
"translation"
].
toString
(),
(
snapshot
[
"time"
]
as
Timestamp
).
toDate
(),
snapshot
[
"tag"
].
toString
(),
snapshot
.
id
)
}
...
...
@@ -58,7 +59,7 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
}
fun
displayByQuery
(
query
:
String
)
{
displayedVocabulary
.
byQuery
(
query
,
wordList
)
displayedVocabulary
.
byQuery
(
query
.
toLowerCase
()
,
wordList
)
}
fun
displayedAt
(
position
:
Int
):
WordPojo
{
...
...
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