adding an initial search
This commit is contained in:
parent
7fe64f4c81
commit
06d4f8f824
5 changed files with 66 additions and 46 deletions
|
@ -21,6 +21,7 @@ import android.widget.TextView
|
|||
import android.widget.Toast
|
||||
import com.simplemobiletools.calendar.BuildConfig
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.adapters.EventListAdapter
|
||||
import com.simplemobiletools.calendar.adapters.MyMonthPagerAdapter
|
||||
import com.simplemobiletools.calendar.adapters.MyWeekPagerAdapter
|
||||
import com.simplemobiletools.calendar.adapters.MyYearPagerAdapter
|
||||
|
@ -35,11 +36,13 @@ import com.simplemobiletools.calendar.helpers.Formatter
|
|||
import com.simplemobiletools.calendar.interfaces.NavigationListener
|
||||
import com.simplemobiletools.calendar.models.Event
|
||||
import com.simplemobiletools.calendar.models.EventType
|
||||
import com.simplemobiletools.calendar.models.ListEvent
|
||||
import com.simplemobiletools.calendar.views.MyScrollView
|
||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import com.simplemobiletools.commons.models.Release
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
|
@ -49,7 +52,7 @@ import java.text.SimpleDateFormat
|
|||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class MainActivity : SimpleActivity(), NavigationListener {
|
||||
class MainActivity : SimpleActivity(), NavigationListener, RefreshRecyclerViewListener {
|
||||
private val CALDAV_SYNC_DELAY = 1000L
|
||||
private val PREFILLED_MONTHS = 97
|
||||
private val PREFILLED_YEARS = 31
|
||||
|
@ -783,12 +786,35 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||
if (text.length >= 2) {
|
||||
dbHelper.getEventsWithSearchQuery(text) { searchedText, events ->
|
||||
if (searchedText == mLatestSearchQuery) {
|
||||
runOnUiThread {
|
||||
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) {
|
||||
if (it is ListEvent) {
|
||||
Intent(applicationContext, EventActivity::class.java).apply {
|
||||
putExtra(EVENT_ID, it.id)
|
||||
startActivity(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
search_results_list.adapter = eventsAdapter
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
search_placeholder.beVisible()
|
||||
search_results_list.beGone()
|
||||
}
|
||||
}
|
||||
|
||||
// only used at active search
|
||||
override fun refreshItems() {
|
||||
searchQueryChanged(mLatestSearchQuery)
|
||||
refreshViewPager()
|
||||
}
|
||||
|
||||
override fun goLeft() {
|
||||
main_view_pager.currentItem = main_view_pager.currentItem - 1
|
||||
}
|
||||
|
|
|
@ -7,10 +7,10 @@ import com.simplemobiletools.calendar.R
|
|||
import com.simplemobiletools.calendar.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.dialogs.DeleteEventDialog
|
||||
import com.simplemobiletools.calendar.extensions.config
|
||||
import com.simplemobiletools.calendar.extensions.dbHelper
|
||||
import com.simplemobiletools.calendar.extensions.getNowSeconds
|
||||
import com.simplemobiletools.calendar.extensions.shareEvents
|
||||
import com.simplemobiletools.calendar.helpers.Formatter
|
||||
import com.simplemobiletools.calendar.interfaces.DeleteEventsListener
|
||||
import com.simplemobiletools.calendar.models.ListEvent
|
||||
import com.simplemobiletools.calendar.models.ListItem
|
||||
import com.simplemobiletools.calendar.models.ListSection
|
||||
|
@ -18,11 +18,12 @@ import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
|||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.beInvisible
|
||||
import com.simplemobiletools.commons.extensions.beInvisibleIf
|
||||
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import kotlinx.android.synthetic.main.event_list_item.view.*
|
||||
import java.util.*
|
||||
|
||||
class EventListAdapter(activity: SimpleActivity, val listItems: ArrayList<ListItem>, val allowLongClick: Boolean, val listener: DeleteEventsListener?,
|
||||
class EventListAdapter(activity: SimpleActivity, val listItems: ArrayList<ListItem>, val allowLongClick: Boolean, val listener: RefreshRecyclerViewListener?,
|
||||
recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
||||
|
||||
private val ITEM_EVENT = 0
|
||||
|
@ -157,10 +158,14 @@ class EventListAdapter(activity: SimpleActivity, val listItems: ArrayList<ListIt
|
|||
listItems.removeAll(listItemsToDelete)
|
||||
|
||||
if (it) {
|
||||
listener?.deleteItems(eventIds)
|
||||
val eventIDs = Array(eventIds.size, { i -> (eventIds[i].toString()) })
|
||||
activity.dbHelper.deleteEvents(eventIDs, true)
|
||||
} else {
|
||||
listener?.addEventRepeatException(eventIds, timestamps)
|
||||
eventIds.forEachIndexed { index, value ->
|
||||
activity.dbHelper.addEventRepeatException(value, timestamps[index], true)
|
||||
}
|
||||
}
|
||||
listener?.refreshItems()
|
||||
finishActMode()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,7 @@ import com.simplemobiletools.calendar.activities.EventActivity
|
|||
import com.simplemobiletools.calendar.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.helpers.*
|
||||
import com.simplemobiletools.calendar.helpers.Formatter
|
||||
import com.simplemobiletools.calendar.models.DayMonthly
|
||||
import com.simplemobiletools.calendar.models.Event
|
||||
import com.simplemobiletools.calendar.models.*
|
||||
import com.simplemobiletools.calendar.receivers.CalDAVSyncReceiver
|
||||
import com.simplemobiletools.calendar.receivers.NotificationReceiver
|
||||
import com.simplemobiletools.calendar.services.SnoozeService
|
||||
|
@ -354,3 +353,21 @@ fun Context.addDayEvents(day: DayMonthly, linearLayout: LinearLayout, res: Resou
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.getEventListItems(events: List<Event>): ArrayList<ListItem> {
|
||||
val listItems = ArrayList<ListItem>(events.size)
|
||||
val replaceDescription = config.replaceDescription
|
||||
val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { if (replaceDescription) it.location else it.description }))
|
||||
val sublist = sorted.subList(0, Math.min(sorted.size, 100))
|
||||
var prevCode = ""
|
||||
sublist.forEach {
|
||||
val code = Formatter.getDayCodeFromTS(it.startTS)
|
||||
if (code != prevCode) {
|
||||
val day = Formatter.getDayTitle(this, code)
|
||||
listItems.add(ListSection(day))
|
||||
prevCode = code
|
||||
}
|
||||
listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.getIsAllDay(), it.color, it.location))
|
||||
}
|
||||
return listItems
|
||||
}
|
||||
|
|
|
@ -10,25 +10,19 @@ import com.simplemobiletools.calendar.R
|
|||
import com.simplemobiletools.calendar.activities.EventActivity
|
||||
import com.simplemobiletools.calendar.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.adapters.EventListAdapter
|
||||
import com.simplemobiletools.calendar.extensions.config
|
||||
import com.simplemobiletools.calendar.extensions.dbHelper
|
||||
import com.simplemobiletools.calendar.extensions.getFilteredEvents
|
||||
import com.simplemobiletools.calendar.extensions.seconds
|
||||
import com.simplemobiletools.calendar.extensions.*
|
||||
import com.simplemobiletools.calendar.helpers.EVENT_ID
|
||||
import com.simplemobiletools.calendar.helpers.EVENT_OCCURRENCE_TS
|
||||
import com.simplemobiletools.calendar.helpers.Formatter
|
||||
import com.simplemobiletools.calendar.interfaces.DeleteEventsListener
|
||||
import com.simplemobiletools.calendar.models.Event
|
||||
import com.simplemobiletools.calendar.models.ListEvent
|
||||
import com.simplemobiletools.calendar.models.ListItem
|
||||
import com.simplemobiletools.calendar.models.ListSection
|
||||
import com.simplemobiletools.commons.extensions.beGoneIf
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||
import kotlinx.android.synthetic.main.fragment_event_list.view.*
|
||||
import org.joda.time.DateTime
|
||||
import java.util.*
|
||||
|
||||
class EventListFragment : Fragment(), DeleteEventsListener {
|
||||
class EventListFragment : Fragment(), RefreshRecyclerViewListener {
|
||||
private var mEvents: List<Event> = ArrayList()
|
||||
private var prevEventsHash = 0
|
||||
private var lastHash = 0
|
||||
|
@ -71,20 +65,7 @@ class EventListFragment : Fragment(), DeleteEventsListener {
|
|||
|
||||
prevEventsHash = hash
|
||||
mEvents = filtered
|
||||
val listItems = ArrayList<ListItem>(mEvents.size)
|
||||
val replaceDescription = context!!.config.replaceDescription
|
||||
val sorted = mEvents.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { if (replaceDescription) it.location else it.description }))
|
||||
val sublist = sorted.subList(0, Math.min(sorted.size, 100))
|
||||
var prevCode = ""
|
||||
sublist.forEach {
|
||||
val code = Formatter.getDayCodeFromTS(it.startTS)
|
||||
if (code != prevCode) {
|
||||
val day = Formatter.getDayTitle(context!!, code)
|
||||
listItems.add(ListSection(day))
|
||||
prevCode = code
|
||||
}
|
||||
listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.getIsAllDay(), it.color, it.location))
|
||||
}
|
||||
val listItems = context!!.getEventListItems(mEvents)
|
||||
|
||||
val eventsAdapter = EventListAdapter(activity as SimpleActivity, listItems, true, this, mView.calendar_events_list) {
|
||||
if (it is ListEvent) {
|
||||
|
@ -93,9 +74,7 @@ class EventListFragment : Fragment(), DeleteEventsListener {
|
|||
}
|
||||
|
||||
activity?.runOnUiThread {
|
||||
mView.calendar_events_list.apply {
|
||||
this@apply.adapter = eventsAdapter
|
||||
}
|
||||
mView.calendar_events_list.adapter = eventsAdapter
|
||||
checkPlaceholderVisibility()
|
||||
}
|
||||
}
|
||||
|
@ -115,16 +94,7 @@ class EventListFragment : Fragment(), DeleteEventsListener {
|
|||
}
|
||||
}
|
||||
|
||||
override fun deleteItems(ids: ArrayList<Int>) {
|
||||
val eventIDs = Array(ids.size, { i -> (ids[i].toString()) })
|
||||
context!!.dbHelper.deleteEvents(eventIDs, true)
|
||||
checkEvents()
|
||||
}
|
||||
|
||||
override fun addEventRepeatException(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>) {
|
||||
parentIds.forEachIndexed { index, value ->
|
||||
context!!.dbHelper.addEventRepeatException(value, timestamps[index], true)
|
||||
}
|
||||
override fun refreshItems() {
|
||||
checkEvents()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,10 +110,12 @@
|
|||
android:textSize="@dimen/bigger_text_size"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/search_results"
|
||||
android:id="@+id/search_results_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:scrollbars="vertical"
|
||||
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
|
Loading…
Reference in a new issue