diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt index f77c4791f..9072a501f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt @@ -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, val listener: EventListAdapter.ItemOperationsListener?, val itemClick: (ListItem) -> Unit) : +class EventListAdapter(val activity: SimpleActivity, val mItems: List, val listener: EventListAdapter.ItemOperationsListener?, val itemClick: (Int) -> Unit) : RecyclerView.Adapter() { val multiSelector = MultiSelector() val views = ArrayList() @@ -96,7 +96,7 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List, 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, 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) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt index abebc0fd2..a743230ff 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt @@ -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 { diff --git a/app/src/main/res/layout/event_list_item.xml b/app/src/main/res/layout/event_list_item.xml index df4862035..fe2c4d1cc 100644 --- a/app/src/main/res/layout/event_list_item.xml +++ b/app/src/main/res/layout/event_list_item.xml @@ -1,50 +1,58 @@ - + android:background="?attr/selectableItemBackground" + android:foreground="@drawable/selector"> - + android:background="@drawable/event_item_background" + android:paddingBottom="@dimen/event_padding" + android:paddingLeft="@dimen/activity_margin" + android:paddingRight="@dimen/activity_margin" + android:paddingTop="@dimen/small_padding"> - + - + - + - + + + +