adding the initial search logic

This commit is contained in:
tibbi 2018-01-18 23:54:36 +01:00
parent ae48c1f899
commit c777967d7e
2 changed files with 22 additions and 2 deletions

View File

@ -58,6 +58,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
private var mIsMonthSelected = false
private var mShouldFilterBeVisible = false
private var mIsSearchOpen = false
private var mLatestSearchQuery = ""
private var mCalDAVSyncHandler = Handler()
private var mSearchMenuItem: MenuItem? = null
@ -220,8 +221,8 @@ class MainActivity : SimpleActivity(), NavigationListener {
override fun onQueryTextSubmit(query: String) = false
override fun onQueryTextChange(newText: String): Boolean {
if (mIsSearchOpen) {
if (mIsSearchOpen && newText.length >= 3) {
searchQueryChanged(newText)
}
return true
}
@ -769,6 +770,15 @@ class MainActivity : SimpleActivity(), NavigationListener {
supportFragmentManager.beginTransaction().replace(R.id.calendar_event_list_holder, EventListFragment(), "").commit()
}
private fun searchQueryChanged(text: String) {
mLatestSearchQuery = text
dbHelper.getEventsWithSearchQuery(text) { searchedText, events ->
if (searchedText == mLatestSearchQuery) {
}
}
}
override fun goLeft() {
main_view_pager.currentItem = main_view_pager.currentItem - 1
}

View File

@ -600,6 +600,16 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
}
}
fun getEventsWithSearchQuery(text: String, callback: (searchedText: String, events: List<Event>) -> Unit) {
Thread {
val searchQuery = "%$text%"
val selection = "$MAIN_TABLE_NAME.$COL_TITLE LIKE ? OR $MAIN_TABLE_NAME.$COL_LOCATION LIKE ? OR $MAIN_TABLE_NAME.$COL_DESCRIPTION LIKE ?"
val selectionArgs = arrayOf(searchQuery, searchQuery, searchQuery)
val cursor = getEventsCursor(selection, selectionArgs)
callback(text, fillEvents(cursor))
}.start()
}
fun getEvents(fromTS: Int, toTS: Int, eventId: Int = -1, callback: (events: MutableList<Event>) -> Unit) {
Thread {
getEventsInBackground(fromTS, toTS, eventId, callback)