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,50 +1,58 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/event_item_holder"
|
||||
android:id="@+id/event_item_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
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">
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:foreground="@drawable/selector">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_item_start"
|
||||
android:layout_width="wrap_content"
|
||||
<RelativeLayout
|
||||
android:id="@+id/event_item_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="13:00"
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
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">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_item_end"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/event_item_start"
|
||||
android:text="15:00"
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
<TextView
|
||||
android:id="@+id/event_item_start"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="13:00"
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_item_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/activity_margin"
|
||||
android:layout_toRightOf="@+id/event_item_start"
|
||||
android:maxLines="1"
|
||||
android:text="Event title"
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
<TextView
|
||||
android:id="@+id/event_item_end"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/event_item_start"
|
||||
android:text="15:00"
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_item_description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/event_item_title"
|
||||
android:layout_marginLeft="@dimen/activity_margin"
|
||||
android:layout_toRightOf="@+id/event_item_end"
|
||||
android:alpha=".4"
|
||||
android:maxLines="1"
|
||||
android:text="Event description"
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
<TextView
|
||||
android:id="@+id/event_item_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/activity_margin"
|
||||
android:layout_toRightOf="@+id/event_item_start"
|
||||
android:maxLines="1"
|
||||
android:text="Event title"
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
|
||||
</RelativeLayout>
|
||||
<TextView
|
||||
android:id="@+id/event_item_description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/event_item_title"
|
||||
android:layout_marginLeft="@dimen/activity_margin"
|
||||
android:layout_toRightOf="@+id/event_item_end"
|
||||
android:alpha=".4"
|
||||
android:maxLines="1"
|
||||
android:text="Event description"
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
||||
|
|
Loading…
Reference in New Issue