From 1e70eb1cd864c4d6c4b297a36a2e7e42805dfdf7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 16 Apr 2017 22:11:59 +0200 Subject: [PATCH] add a share menu button to some screens --- .../calendar/activities/EventActivity.kt | 10 ++++++++-- .../calendar/adapters/DayEventsAdapter.kt | 11 +++++++++++ .../calendar/adapters/EventListAdapter.kt | 11 +++++++++++ .../simplemobiletools/calendar/extensions/Activity.kt | 7 +++++++ app/src/main/res/menu/cab_day.xml | 5 +++++ app/src/main/res/menu/cab_event_list.xml | 5 +++++ app/src/main/res/menu/menu_event.xml | 9 ++++++--- 7 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Activity.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt index 436fb8e74..35a688c66 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -306,19 +306,25 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_event, menu) - menu.findItem(R.id.cab_delete).isVisible = mEvent.id != 0 + menu.findItem(R.id.delete).isVisible = mEvent.id != 0 + menu.findItem(R.id.share).isVisible = mEvent.id != 0 return true } override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.cab_delete -> deleteEvent() + R.id.share -> shareEvent() + R.id.delete -> deleteEvent() R.id.save -> saveEvent() else -> return super.onOptionsItemSelected(item) } return true } + private fun shareEvent() { + shareEvents(arrayListOf(mEvent.id)) + } + private fun deleteEvent() { DeleteEventDialog(this, arrayListOf(mEvent.id)) { if (it) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt index 0c9d08af0..cb62e39c9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt @@ -10,6 +10,7 @@ import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.activities.SimpleActivity import com.simplemobiletools.calendar.dialogs.DeleteEventDialog import com.simplemobiletools.calendar.extensions.config +import com.simplemobiletools.calendar.extensions.shareEvents import com.simplemobiletools.calendar.helpers.Formatter import com.simplemobiletools.calendar.interfaces.DeleteEventsListener import com.simplemobiletools.calendar.models.Event @@ -49,6 +50,7 @@ class DayEventsAdapter(val activity: SimpleActivity, val mItems: List, va val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { when (item.itemId) { + R.id.cab_share -> shareEvents() R.id.cab_delete -> askConfirmDelete() else -> return false } @@ -71,6 +73,15 @@ class DayEventsAdapter(val activity: SimpleActivity, val mItems: List, va } } + private fun shareEvents() { + val selections = multiSelector.selectedPositions + val eventIds = ArrayList(selections.size) + selections.forEach { + eventIds.add(mItems[it].id) + } + activity.shareEvents(eventIds.distinct()) + } + private fun askConfirmDelete() { val selections = multiSelector.selectedPositions val eventIds = ArrayList(selections.size) 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 7ac2c981d..98eae7dfa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt @@ -11,6 +11,7 @@ import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.activities.SimpleActivity import com.simplemobiletools.calendar.dialogs.DeleteEventDialog import com.simplemobiletools.calendar.extensions.config +import com.simplemobiletools.calendar.extensions.shareEvents import com.simplemobiletools.calendar.helpers.Formatter import com.simplemobiletools.calendar.interfaces.DeleteEventsListener import com.simplemobiletools.calendar.models.ListEvent @@ -65,6 +66,7 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List, val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { when (item.itemId) { + R.id.cab_share -> shareEvents() R.id.cab_delete -> askConfirmDelete() else -> return false } @@ -87,6 +89,15 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List, } } + private fun shareEvents() { + val selections = multiSelector.selectedPositions + val eventIds = ArrayList(selections.size) + selections.forEach { + eventIds.add((mItems[it] as ListEvent).id) + } + activity.shareEvents(eventIds.distinct()) + } + private fun askConfirmDelete() { val selections = multiSelector.selectedPositions val eventIds = ArrayList(selections.size) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Activity.kt new file mode 100644 index 000000000..d9a9acdaa --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Activity.kt @@ -0,0 +1,7 @@ +package com.simplemobiletools.calendar.extensions + +import android.app.Activity + +fun Activity.shareEvents(ids: List) { + +} diff --git a/app/src/main/res/menu/cab_day.xml b/app/src/main/res/menu/cab_day.xml index af34568ba..6da3de415 100644 --- a/app/src/main/res/menu/cab_day.xml +++ b/app/src/main/res/menu/cab_day.xml @@ -1,6 +1,11 @@ + + + - -