improve search behaviour, extend search if not enough results show
This commit is contained in:
parent
4b0ce74e48
commit
ee8e9f2ff7
3 changed files with 29 additions and 2 deletions
|
@ -1222,7 +1222,26 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
|
|
||||||
eventsHelper.getEvents(minFetchedSearchTS, maxFetchedSearchTS, searchQuery = text) { events ->
|
eventsHelper.getEvents(minFetchedSearchTS, maxFetchedSearchTS, searchQuery = text) { events ->
|
||||||
if (text == mLatestSearchQuery) {
|
if (text == mLatestSearchQuery) {
|
||||||
|
// if we have less than MIN_EVENTS_THRESHOLD events, search again by extending the time span
|
||||||
showSearchResultEvents(events, INITIAL_EVENTS)
|
showSearchResultEvents(events, INITIAL_EVENTS)
|
||||||
|
|
||||||
|
if (events.size < MIN_EVENTS_TRESHOLD) {
|
||||||
|
minFetchedSearchTS = 0L
|
||||||
|
maxFetchedSearchTS = MAX_SEARCH_YEAR
|
||||||
|
|
||||||
|
eventsHelper.getEvents(minFetchedSearchTS, maxFetchedSearchTS) { events ->
|
||||||
|
events.forEach { event ->
|
||||||
|
try {
|
||||||
|
if (searchResultEvents.firstOrNull { it.id == event.id && it.startTS == event.startTS } == null) {
|
||||||
|
searchResultEvents.add(0, event)
|
||||||
|
}
|
||||||
|
} catch (ignored: ConcurrentModificationException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
showSearchResultEvents(searchResultEvents, INITIAL_EVENTS)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (text.length == 1) {
|
} else if (text.length == 1) {
|
||||||
|
@ -1292,6 +1311,10 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchPreviousPeriod() {
|
private fun fetchPreviousPeriod() {
|
||||||
|
if (minFetchedSearchTS == 0L) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val lastPosition = (search_results_list.layoutManager as MyLinearLayoutManager).findLastVisibleItemPosition()
|
val lastPosition = (search_results_list.layoutManager as MyLinearLayoutManager).findLastVisibleItemPosition()
|
||||||
bottomItemAtRefresh = (search_results_list.adapter as EventListAdapter).listItems[lastPosition]
|
bottomItemAtRefresh = (search_results_list.adapter as EventListAdapter).listItems[lastPosition]
|
||||||
|
|
||||||
|
@ -1312,6 +1335,10 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchNextPeriod() {
|
private fun fetchNextPeriod() {
|
||||||
|
if (maxFetchedSearchTS == MAX_SEARCH_YEAR) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val oldMaxFetchedTS = maxFetchedSearchTS + 1
|
val oldMaxFetchedTS = maxFetchedSearchTS + 1
|
||||||
maxFetchedSearchTS += FETCH_INTERVAL
|
maxFetchedSearchTS += FETCH_INTERVAL
|
||||||
eventsHelper.getEvents(oldMaxFetchedTS, maxFetchedSearchTS) { events ->
|
eventsHelper.getEvents(oldMaxFetchedTS, maxFetchedSearchTS) { events ->
|
||||||
|
|
|
@ -26,8 +26,6 @@ import kotlinx.android.synthetic.main.fragment_event_list.view.*
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
|
|
||||||
class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
||||||
private var MIN_EVENTS_TRESHOLD = 30
|
|
||||||
|
|
||||||
private var mEvents = ArrayList<Event>()
|
private var mEvents = ArrayList<Event>()
|
||||||
private var minFetchedTS = 0L
|
private var minFetchedTS = 0L
|
||||||
private var maxFetchedTS = 0L
|
private var maxFetchedTS = 0L
|
||||||
|
|
|
@ -10,8 +10,10 @@ const val ROW_COUNT = 6
|
||||||
const val COLUMN_COUNT = 7
|
const val COLUMN_COUNT = 7
|
||||||
const val SCHEDULE_CALDAV_REQUEST_CODE = 10000
|
const val SCHEDULE_CALDAV_REQUEST_CODE = 10000
|
||||||
const val FETCH_INTERVAL = 3 * MONTH_SECONDS
|
const val FETCH_INTERVAL = 3 * MONTH_SECONDS
|
||||||
|
const val MAX_SEARCH_YEAR = 2051218800L // 2035, limit search results for events repeating indefinitely
|
||||||
|
|
||||||
// endless scrolling updating
|
// endless scrolling updating
|
||||||
|
const val MIN_EVENTS_TRESHOLD = 30
|
||||||
const val INITIAL_EVENTS = 0
|
const val INITIAL_EVENTS = 0
|
||||||
const val UPDATE_TOP = 1
|
const val UPDATE_TOP = 1
|
||||||
const val UPDATE_BOTTOM = 2
|
const val UPDATE_BOTTOM = 2
|
||||||
|
|
Loading…
Reference in a new issue