mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
fix #351, show search results the same way as on Event List view
This commit is contained in:
@@ -1184,22 +1184,31 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
|
|
||||||
search_placeholder_2.beVisibleIf(text.length == 1)
|
search_placeholder_2.beVisibleIf(text.length == 1)
|
||||||
if (text.length >= 2) {
|
if (text.length >= 2) {
|
||||||
eventsHelper.getEventsWithSearchQuery(text, this) { searchedText, events ->
|
val minFetchedTS = DateTime().minusMinutes(config.displayPastEvents).seconds()
|
||||||
if (searchedText == mLatestSearchQuery) {
|
val maxFetchedTS = DateTime().plusMonths(6).seconds()
|
||||||
search_results_list.beVisibleIf(events.isNotEmpty())
|
|
||||||
search_placeholder.beVisibleIf(events.isEmpty())
|
eventsHelper.getEvents(minFetchedTS, maxFetchedTS) { events ->
|
||||||
val listItems = getEventListItems(events)
|
if (text == mLatestSearchQuery) {
|
||||||
val eventsAdapter = EventListAdapter(this, listItems, true, this, search_results_list) {
|
runOnUiThread {
|
||||||
hideKeyboard()
|
val filtered = events.filter {
|
||||||
if (it is ListEvent) {
|
it.title.contains(text, true) || it.location.contains(text, true) || it.description.contains(text, true)
|
||||||
Intent(applicationContext, getActivityToOpen(it.isTask)).apply {
|
}
|
||||||
putExtra(EVENT_ID, it.id)
|
|
||||||
startActivity(this)
|
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) {
|
} else if (text.length == 1) {
|
||||||
|
@@ -86,9 +86,9 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
|||||||
maxFetchedTS = DateTime().plusMonths(6).seconds()
|
maxFetchedTS = DateTime().plusMonths(6).seconds()
|
||||||
}
|
}
|
||||||
|
|
||||||
requireContext().eventsHelper.getEvents(minFetchedTS, maxFetchedTS) {
|
requireContext().eventsHelper.getEvents(minFetchedTS, maxFetchedTS) { events ->
|
||||||
if (it.size >= MIN_EVENTS_TRESHOLD) {
|
if (events.size >= MIN_EVENTS_TRESHOLD) {
|
||||||
receivedEvents(it, NOT_UPDATING)
|
receivedEvents(events, NOT_UPDATING)
|
||||||
} else {
|
} else {
|
||||||
if (!wereInitialEventsAdded) {
|
if (!wereInitialEventsAdded) {
|
||||||
maxFetchedTS += FETCH_INTERVAL
|
maxFetchedTS += FETCH_INTERVAL
|
||||||
|
@@ -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) {
|
fun addEventRepetitionException(parentEventId: Long, occurrenceTS: Long, addToCalDAV: Boolean) {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
val parentEvent = eventsDB.getEventOrTaskWithId(parentEventId) ?: return@ensureBackgroundThread
|
val parentEvent = eventsDB.getEventOrTaskWithId(parentEventId) ?: return@ensureBackgroundThread
|
||||||
|
@@ -57,9 +57,6 @@ interface EventsDao {
|
|||||||
@Query("SELECT * FROM events WHERE id IN (:ids) AND import_id != \"\" AND type = $TYPE_EVENT")
|
@Query("SELECT * FROM events WHERE id IN (:ids) AND import_id != \"\" AND type = $TYPE_EVENT")
|
||||||
fun getEventsByIdsWithImportIds(ids: List<Long>): List<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")
|
@Query("SELECT * FROM events WHERE source = \'$SOURCE_CONTACT_BIRTHDAY\' AND type = $TYPE_EVENT")
|
||||||
fun getBirthdays(): List<Event>
|
fun getBirthdays(): List<Event>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user