add a share menu button to some screens

This commit is contained in:
tibbi 2017-04-16 22:11:59 +02:00
parent 3c45e960ad
commit 1e70eb1cd8
7 changed files with 53 additions and 5 deletions

View File

@ -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) {

View File

@ -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<Event>, 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<Event>, va
}
}
private fun shareEvents() {
val selections = multiSelector.selectedPositions
val eventIds = ArrayList<Int>(selections.size)
selections.forEach {
eventIds.add(mItems[it].id)
}
activity.shareEvents(eventIds.distinct())
}
private fun askConfirmDelete() {
val selections = multiSelector.selectedPositions
val eventIds = ArrayList<Int>(selections.size)

View File

@ -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<ListItem>,
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<ListItem>,
}
}
private fun shareEvents() {
val selections = multiSelector.selectedPositions
val eventIds = ArrayList<Int>(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<Int>(selections.size)

View File

@ -0,0 +1,7 @@
package com.simplemobiletools.calendar.extensions
import android.app.Activity
fun Activity.shareEvents(ids: List<Int>) {
}

View File

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/cab_share"
android:icon="@drawable/ic_share"
android:title="@string/share"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/cab_delete"
android:icon="@drawable/ic_delete"

View File

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/cab_share"
android:icon="@drawable/ic_share"
android:title="@string/share"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/cab_delete"
android:icon="@drawable/ic_delete"

View File

@ -2,15 +2,18 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/cab_delete"
android:id="@+id/share"
android:icon="@drawable/ic_share"
android:title="@string/share"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/delete"
android:icon="@drawable/ic_delete"
android:title="@string/delete"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/save"
android:icon="@drawable/ic_check"
android:title="@string/save"
app:showAsAction="ifRoom"/>
</menu>