fix #351, show search results the same way as on Event List view

This commit is contained in:
tibbi 2023-01-08 20:51:11 +01:00
parent 6da24c261a
commit 80234487da
4 changed files with 25 additions and 42 deletions

View File

@ -1184,22 +1184,31 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
search_placeholder_2.beVisibleIf(text.length == 1)
if (text.length >= 2) {
eventsHelper.getEventsWithSearchQuery(text, this) { searchedText, events ->
if (searchedText == mLatestSearchQuery) {
search_results_list.beVisibleIf(events.isNotEmpty())
search_placeholder.beVisibleIf(events.isEmpty())
val listItems = getEventListItems(events)
val eventsAdapter = EventListAdapter(this, listItems, true, this, search_results_list) {
hideKeyboard()
if (it is ListEvent) {
Intent(applicationContext, getActivityToOpen(it.isTask)).apply {
putExtra(EVENT_ID, it.id)
startActivity(this)
val minFetchedTS = DateTime().minusMinutes(config.displayPastEvents).seconds()
val maxFetchedTS = DateTime().plusMonths(6).seconds()
eventsHelper.getEvents(minFetchedTS, maxFetchedTS) { events ->
if (text == mLatestSearchQuery) {
runOnUiThread {
val filtered = events.filter {
it.title.contains(text, true) || it.location.contains(text, true) || it.description.contains(text, true)
}
search_results_list.beVisibleIf(filtered.isNotEmpty())
search_placeholder.beVisibleIf(filtered.isEmpty())
val listItems = getEventListItems(filtered)
val eventsAdapter = EventListAdapter(this, listItems, true, this, search_results_list) {
hideKeyboard()
if (it is ListEvent) {
Intent(applicationContext, getActivityToOpen(it.isTask)).apply {
putExtra(EVENT_ID, it.id)
startActivity(this)
}
}
}
}
search_results_list.adapter = eventsAdapter
search_results_list.adapter = eventsAdapter
}
}
}
} else if (text.length == 1) {

View File

@ -86,9 +86,9 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
maxFetchedTS = DateTime().plusMonths(6).seconds()
}
requireContext().eventsHelper.getEvents(minFetchedTS, maxFetchedTS) {
if (it.size >= MIN_EVENTS_TRESHOLD) {
receivedEvents(it, NOT_UPDATING)
requireContext().eventsHelper.getEvents(minFetchedTS, maxFetchedTS) { events ->
if (events.size >= MIN_EVENTS_TRESHOLD) {
receivedEvents(events, NOT_UPDATING)
} else {
if (!wereInitialEventsAdded) {
maxFetchedTS += FETCH_INTERVAL

View File

@ -232,29 +232,6 @@ class EventsHelper(val context: Context) {
}
}
fun getEventsWithSearchQuery(text: String, activity: Activity, callback: (searchedText: String, events: List<Event>) -> Unit) {
ensureBackgroundThread {
val searchQuery = "%$text%"
val events = eventsDB.getEventsForSearch(searchQuery)
val displayEventTypes = config.displayEventTypes
val filteredEvents = events.filter { displayEventTypes.contains(it.eventType.toString()) }
val eventTypeColors = LongSparseArray<Int>()
eventTypesDB.getEventTypes().forEach {
eventTypeColors.put(it.id!!, it.color)
}
filteredEvents.forEach {
it.updateIsPastEvent()
it.color = eventTypeColors.get(it.eventType) ?: context.getProperPrimaryColor()
}
activity.runOnUiThread {
callback(text, filteredEvents)
}
}
}
fun addEventRepetitionException(parentEventId: Long, occurrenceTS: Long, addToCalDAV: Boolean) {
ensureBackgroundThread {
val parentEvent = eventsDB.getEventOrTaskWithId(parentEventId) ?: return@ensureBackgroundThread

View File

@ -57,9 +57,6 @@ interface EventsDao {
@Query("SELECT * FROM events WHERE id IN (:ids) AND import_id != \"\" AND type = $TYPE_EVENT")
fun getEventsByIdsWithImportIds(ids: List<Long>): List<Event>
@Query("SELECT * FROM events WHERE title LIKE :searchQuery OR location LIKE :searchQuery OR description LIKE :searchQuery AND type = $TYPE_EVENT")
fun getEventsForSearch(searchQuery: String): List<Event>
@Query("SELECT * FROM events WHERE source = \'$SOURCE_CONTACT_BIRTHDAY\' AND type = $TYPE_EVENT")
fun getBirthdays(): List<Event>