add event item clicks
This commit is contained in:
parent
94930e653f
commit
d47c755189
|
@ -16,7 +16,7 @@ import com.simplemobiletools.calendar.models.ListSection
|
|||
import kotlinx.android.synthetic.main.event_item.view.*
|
||||
import java.util.*
|
||||
|
||||
class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>, val listener: EventListAdapter.ItemOperationsListener?, val itemClick: (ListItem) -> Unit) :
|
||||
class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>, val listener: EventListAdapter.ItemOperationsListener?, val itemClick: (Int) -> Unit) :
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
val multiSelector = MultiSelector()
|
||||
val views = ArrayList<View>()
|
||||
|
@ -96,7 +96,7 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
|
|||
|
||||
override fun getItemCount() = mItems.size
|
||||
|
||||
class ViewHolder(val activity: SimpleActivity, view: View, val itemClick: (ListItem) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
||||
class ViewHolder(val activity: SimpleActivity, view: View, val itemClick: (Int) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
||||
fun bindView(multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, listItem: ListItem, pos: Int): View {
|
||||
val item = listItem as ListEvent
|
||||
itemView.apply {
|
||||
|
@ -122,10 +122,30 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
|
|||
event_item_end.setTextColor(currTextColor)
|
||||
event_item_title.setTextColor(currTextColor)
|
||||
event_item_description.setTextColor(currTextColor)
|
||||
|
||||
setOnClickListener { viewClicked(multiSelector, listItem, pos) }
|
||||
}
|
||||
|
||||
return itemView
|
||||
}
|
||||
|
||||
fun viewClicked(multiSelector: MultiSelector, listItem: ListItem, pos: Int) {
|
||||
if (multiSelector.isSelectable) {
|
||||
val isSelected = multiSelector.selectedPositions.contains(layoutPosition)
|
||||
multiSelector.setSelected(this, !isSelected)
|
||||
EventsAdapter.toggleItemSelection(itemView, !isSelected, pos)
|
||||
|
||||
val selectedCnt = multiSelector.selectedPositions.size
|
||||
if (selectedCnt == 0) {
|
||||
actMode?.finish()
|
||||
} else {
|
||||
actMode?.title = selectedCnt.toString()
|
||||
}
|
||||
EventsAdapter.actMode?.invalidate()
|
||||
} else {
|
||||
itemClick((listItem as ListEvent).id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SectionHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
|
|
|
@ -73,8 +73,8 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event
|
|||
|
||||
mAllEvents = events
|
||||
val eventsAdapter = EventListAdapter(activity as SimpleActivity, mListItems, this) {
|
||||
/*(activity as MainActivity).checkDeleteEvents()
|
||||
(mListItems[position] as ListEvent).id*/
|
||||
(activity as MainActivity).checkDeleteEvents()
|
||||
editEvent(it)
|
||||
}
|
||||
activity?.runOnUiThread {
|
||||
mView.calendar_events_list.apply {
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/event_item_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:foreground="@drawable/selector">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/event_item_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -47,4 +54,5 @@
|
|||
android:text="Event description"
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
||||
|
|
Loading…
Reference in New Issue