allow clicking and selecting events
This commit is contained in:
parent
84b5152e3e
commit
cb7d83a696
|
@ -23,7 +23,13 @@ class EventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, val i
|
||||||
val markedItems = HashSet<Int>()
|
val markedItems = HashSet<Int>()
|
||||||
|
|
||||||
fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) {
|
fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) {
|
||||||
|
if (pos == -1)
|
||||||
|
return
|
||||||
|
|
||||||
|
if (select)
|
||||||
|
markedItems.add(pos)
|
||||||
|
else
|
||||||
|
markedItems.remove(pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,16 +43,16 @@ class EventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, val i
|
||||||
override fun onCreateActionMode(actionMode: ActionMode?, menu: Menu?): Boolean {
|
override fun onCreateActionMode(actionMode: ActionMode?, menu: Menu?): Boolean {
|
||||||
super.onCreateActionMode(actionMode, menu)
|
super.onCreateActionMode(actionMode, menu)
|
||||||
actMode = actionMode
|
actMode = actionMode
|
||||||
activity.menuInflater.inflate(R.menu.menu_day_cab, menu)
|
activity.menuInflater.inflate(R.menu.cab_day, menu)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu): Boolean {
|
override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu) = true
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroyActionMode(actionMode: ActionMode?) {
|
override fun onDestroyActionMode(actionMode: ActionMode?) {
|
||||||
super.onDestroyActionMode(actionMode)
|
super.onDestroyActionMode(actionMode)
|
||||||
|
views.forEach { toggleItemSelection(it, false) }
|
||||||
|
markedItems.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,9 +81,39 @@ class EventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, val i
|
||||||
event_item_end.text = Formatter.getTime(event.endTS)
|
event_item_end.text = Formatter.getTime(event.endTS)
|
||||||
event_item_end.visibility = View.VISIBLE
|
event_item_end.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setOnClickListener { viewClicked(multiSelector, event, pos) }
|
||||||
|
setOnLongClickListener {
|
||||||
|
if (!multiSelector.isSelectable) {
|
||||||
|
activity.startSupportActionMode(multiSelectorCallback)
|
||||||
|
multiSelector.setSelected(this@ViewHolder, true)
|
||||||
|
actMode?.title = multiSelector.selectedPositions.size.toString()
|
||||||
|
toggleItemSelection(itemView, true, pos)
|
||||||
|
actMode?.invalidate()
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return itemView
|
return itemView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun viewClicked(multiSelector: MultiSelector, event: Event, pos: Int) {
|
||||||
|
if (multiSelector.isSelectable) {
|
||||||
|
val isSelected = multiSelector.selectedPositions.contains(layoutPosition)
|
||||||
|
multiSelector.setSelected(this, !isSelected)
|
||||||
|
toggleItemSelection(itemView, !isSelected, pos)
|
||||||
|
|
||||||
|
val selectedCnt = multiSelector.selectedPositions.size
|
||||||
|
if (selectedCnt == 0) {
|
||||||
|
actMode?.finish()
|
||||||
|
} else {
|
||||||
|
actMode?.title = selectedCnt.toString()
|
||||||
|
}
|
||||||
|
actMode?.invalidate()
|
||||||
|
} else {
|
||||||
|
itemClick(event)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ class DayFragment : Fragment(), DBHelper.EventsListener, AbsListView.MultiChoice
|
||||||
return
|
return
|
||||||
|
|
||||||
val eventsAdapter = EventsAdapter(activity as SimpleActivity, eventsToShow) {
|
val eventsAdapter = EventsAdapter(activity as SimpleActivity, eventsToShow) {
|
||||||
|
editEvent(it.id)
|
||||||
}
|
}
|
||||||
mHolder.day_events.apply {
|
mHolder.day_events.apply {
|
||||||
this@apply.adapter = eventsAdapter
|
this@apply.adapter = eventsAdapter
|
||||||
|
@ -195,7 +195,7 @@ class DayFragment : Fragment(), DBHelper.EventsListener, AbsListView.MultiChoice
|
||||||
|
|
||||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||||
val inflater = mode.menuInflater
|
val inflater = mode.menuInflater
|
||||||
inflater.inflate(R.menu.menu_day_cab, menu)
|
inflater.inflate(R.menu.cab_day, menu)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,10 +214,6 @@ class DayFragment : Fragment(), DBHelper.EventsListener, AbsListView.MultiChoice
|
||||||
mode.invalidate()
|
mode.invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
/*override fun onItemClick(parent: AdapterView<*>, view: View, position: Int, id: Long) {
|
|
||||||
editEvent(getEventsToShow(mEvents!!)[position].id)
|
|
||||||
}*/
|
|
||||||
|
|
||||||
override fun eventInserted(event: Event) {
|
override fun eventInserted(event: Event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -163,7 +163,7 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, AdapterView.On
|
||||||
|
|
||||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu?): Boolean {
|
override fun onCreateActionMode(mode: ActionMode, menu: Menu?): Boolean {
|
||||||
val inflater = mode.menuInflater
|
val inflater = mode.menuInflater
|
||||||
inflater.inflate(R.menu.menu_day_cab, menu)
|
inflater.inflate(R.menu.cab_day, menu)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue