Commit 16f12c22 by Paktalin

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

parent 9b78a83f
......@@ -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 {
......
......@@ -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)
}
......
......@@ -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()
}
......
......@@ -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
}
}
......@@ -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 {
......
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