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 kotlinx.android.synthetic.main.event_item.view.*
|
||||||
import java.util.*
|
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>() {
|
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||||
val multiSelector = MultiSelector()
|
val multiSelector = MultiSelector()
|
||||||
val views = ArrayList<View>()
|
val views = ArrayList<View>()
|
||||||
|
@ -96,7 +96,7 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
|
||||||
|
|
||||||
override fun getItemCount() = mItems.size
|
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 {
|
fun bindView(multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, listItem: ListItem, pos: Int): View {
|
||||||
val item = listItem as ListEvent
|
val item = listItem as ListEvent
|
||||||
itemView.apply {
|
itemView.apply {
|
||||||
|
@ -122,10 +122,30 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
|
||||||
event_item_end.setTextColor(currTextColor)
|
event_item_end.setTextColor(currTextColor)
|
||||||
event_item_title.setTextColor(currTextColor)
|
event_item_title.setTextColor(currTextColor)
|
||||||
event_item_description.setTextColor(currTextColor)
|
event_item_description.setTextColor(currTextColor)
|
||||||
|
|
||||||
|
setOnClickListener { viewClicked(multiSelector, listItem, pos) }
|
||||||
}
|
}
|
||||||
|
|
||||||
return itemView
|
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) {
|
class SectionHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||||
|
|
|
@ -73,8 +73,8 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event
|
||||||
|
|
||||||
mAllEvents = events
|
mAllEvents = events
|
||||||
val eventsAdapter = EventListAdapter(activity as SimpleActivity, mListItems, this) {
|
val eventsAdapter = EventListAdapter(activity as SimpleActivity, mListItems, this) {
|
||||||
/*(activity as MainActivity).checkDeleteEvents()
|
(activity as MainActivity).checkDeleteEvents()
|
||||||
(mListItems[position] as ListEvent).id*/
|
editEvent(it)
|
||||||
}
|
}
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
mView.calendar_events_list.apply {
|
mView.calendar_events_list.apply {
|
||||||
|
|
|
@ -1,50 +1,58 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout
|
<FrameLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
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_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/event_item_background"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:paddingBottom="@dimen/event_padding"
|
android:foreground="@drawable/selector">
|
||||||
android:paddingLeft="@dimen/activity_margin"
|
|
||||||
android:paddingRight="@dimen/activity_margin"
|
|
||||||
android:paddingTop="@dimen/small_padding">
|
|
||||||
|
|
||||||
<TextView
|
<RelativeLayout
|
||||||
android:id="@+id/event_item_start"
|
android:id="@+id/event_item_holder"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="13:00"
|
android:background="@drawable/event_item_background"
|
||||||
android:textSize="@dimen/day_text_size"/>
|
android:paddingBottom="@dimen/event_padding"
|
||||||
|
android:paddingLeft="@dimen/activity_margin"
|
||||||
|
android:paddingRight="@dimen/activity_margin"
|
||||||
|
android:paddingTop="@dimen/small_padding">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/event_item_end"
|
android:id="@+id/event_item_start"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@+id/event_item_start"
|
android:text="13:00"
|
||||||
android:text="15:00"
|
android:textSize="@dimen/day_text_size"/>
|
||||||
android:textSize="@dimen/day_text_size"/>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/event_item_title"
|
android:id="@+id/event_item_end"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="@dimen/activity_margin"
|
android:layout_below="@+id/event_item_start"
|
||||||
android:layout_toRightOf="@+id/event_item_start"
|
android:text="15:00"
|
||||||
android:maxLines="1"
|
android:textSize="@dimen/day_text_size"/>
|
||||||
android:text="Event title"
|
|
||||||
android:textSize="@dimen/day_text_size"/>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/event_item_description"
|
android:id="@+id/event_item_title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@+id/event_item_title"
|
android:layout_marginLeft="@dimen/activity_margin"
|
||||||
android:layout_marginLeft="@dimen/activity_margin"
|
android:layout_toRightOf="@+id/event_item_start"
|
||||||
android:layout_toRightOf="@+id/event_item_end"
|
android:maxLines="1"
|
||||||
android:alpha=".4"
|
android:text="Event title"
|
||||||
android:maxLines="1"
|
android:textSize="@dimen/day_text_size"/>
|
||||||
android:text="Event description"
|
|
||||||
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