Commit 16f12c22 by Paktalin

TagFragment is removed on sumbit, words can be searched by tags

parent 9b78a83f
...@@ -6,8 +6,8 @@ import java.util.* ...@@ -6,8 +6,8 @@ import java.util.*
class WordPojo(var word: String, class WordPojo(var word: String,
var translation: String, var translation: String,
var time:Date? = null, var time:Date? = null,
var id: String? = null, var tag: String? = null,
var tag: String? = null) var id: String? = null)
: Serializable { : Serializable {
init { init {
......
...@@ -23,7 +23,7 @@ class TagFragment : Fragment() { ...@@ -23,7 +23,7 @@ class TagFragment : Fragment() {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
mainActivity = activity as MainActivity mainActivity = activity as MainActivity
btnSubmitTag.setOnClickListener { submit() } btnSubmitTag.setOnClickListener { submit() }
btnCancelTag.setOnClickListener { cancel() } btnCancelTag.setOnClickListener { finish() }
} }
fun setSelection(selectionList: List<Long>) { fun setSelection(selectionList: List<Long>) {
...@@ -32,14 +32,15 @@ class TagFragment : Fragment() { ...@@ -32,14 +32,15 @@ class TagFragment : Fragment() {
private fun submit() { private fun submit() {
tag_et.text.toString().let { tag_et.text.toString().let {
if (it.isBlank()) if (it.isBlank()) shortToast(mainActivity, mainActivity.getString(R.string.toast_tag_cannot_be_empty))
shortToast(mainActivity, mainActivity.getString(R.string.toast_tag_cannot_be_empty)) else {
else
mainActivity.vocabularyAdapter?.addTagToSelected(it, selectionList) mainActivity.vocabularyAdapter?.addTagToSelected(it, selectionList)
finish()
}
} }
} }
private fun cancel() { private fun finish() {
mainActivity.vocabularyAdapter?.selectionTracker?.clearSelection() mainActivity.vocabularyAdapter?.selectionTracker?.clearSelection()
removeFragment(mainActivity.supportFragmentManager, this) removeFragment(mainActivity.supportFragmentManager, this)
} }
......
...@@ -128,10 +128,8 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi ...@@ -128,10 +128,8 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
fun filter(query: String) { fun filter(query: String) {
vocabulary.clearDisplayed() vocabulary.clearDisplayed()
if (query.isEmpty()) if (query.isEmpty()) vocabulary.displayAll()
vocabulary.displayAll() else vocabulary.displayByQuery(query)
else
vocabulary.displayByQuery(query.toLowerCase())
notifyDataSetChanged() notifyDataSetChanged()
} }
......
...@@ -18,7 +18,12 @@ class DisplayedVocabulary(wordList: MutableList<WordPojo>): BasicVocabulary(word ...@@ -18,7 +18,12 @@ class DisplayedVocabulary(wordList: MutableList<WordPojo>): BasicVocabulary(word
} }
fun byQuery(query: String, allWords: MutableList<WordPojo>) { 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) { fun sort(sort: Sort) {
...@@ -47,4 +52,8 @@ class DisplayedVocabulary(wordList: MutableList<WordPojo>): BasicVocabulary(word ...@@ -47,4 +52,8 @@ class DisplayedVocabulary(wordList: MutableList<WordPojo>): BasicVocabulary(word
return wordPojo.word.toLowerCase().contains(string) || return wordPojo.word.toLowerCase().contains(string) ||
wordPojo.translation.toLowerCase().contains(string) wordPojo.translation.toLowerCase().contains(string)
} }
companion object {
private val TAG = "VN/" + DisplayedVocabulary::class.simpleName
}
} }
...@@ -23,6 +23,7 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary { ...@@ -23,6 +23,7 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
snapshot["word"].toString(), snapshot["word"].toString(),
snapshot["translation"].toString(), snapshot["translation"].toString(),
(snapshot["time"] as Timestamp).toDate(), (snapshot["time"] as Timestamp).toDate(),
snapshot["tag"].toString(),
snapshot.id) snapshot.id)
} }
...@@ -58,7 +59,7 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary { ...@@ -58,7 +59,7 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
} }
fun displayByQuery(query: String) { fun displayByQuery(query: String) {
displayedVocabulary.byQuery(query, wordList) displayedVocabulary.byQuery(query.toLowerCase(), wordList)
} }
fun displayedAt(position: Int): WordPojo { fun displayedAt(position: Int): WordPojo {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment