fix #199, allow duplicating events

This commit is contained in:
tibbi 2018-05-04 20:28:12 +02:00
parent e8db3657ec
commit bcd20f254e
3 changed files with 22 additions and 0 deletions

View File

@ -71,6 +71,10 @@ class EventActivity : SimpleActivity() {
mEvent = event mEvent = event
mEventOccurrenceTS = intent.getIntExtra(EVENT_OCCURRENCE_TS, 0) mEventOccurrenceTS = intent.getIntExtra(EVENT_OCCURRENCE_TS, 0)
setupEditEvent() setupEditEvent()
if (intent.getBooleanExtra(IS_DUPLICATE_INTENT, false)) {
mEvent.id = 0
}
} else { } else {
mEvent = Event() mEvent = Event()
mReminder1Minutes = config.defaultReminderMinutes mReminder1Minutes = config.defaultReminderMinutes
@ -116,6 +120,7 @@ class EventActivity : SimpleActivity() {
if (wasActivityInitialized) { if (wasActivityInitialized) {
menu.findItem(R.id.delete).isVisible = mEvent.id != 0 menu.findItem(R.id.delete).isVisible = mEvent.id != 0
menu.findItem(R.id.share).isVisible = mEvent.id != 0 menu.findItem(R.id.share).isVisible = mEvent.id != 0
menu.findItem(R.id.duplicate).isVisible = mEvent.id != 0
} }
return true return true
} }
@ -124,6 +129,7 @@ class EventActivity : SimpleActivity() {
when (item.itemId) { when (item.itemId) {
R.id.save -> saveEvent() R.id.save -> saveEvent()
R.id.delete -> deleteEvent() R.id.delete -> deleteEvent()
R.id.duplicate -> duplicateEvent()
R.id.share -> shareEvent() R.id.share -> shareEvent()
else -> return super.onOptionsItemSelected(item) else -> return super.onOptionsItemSelected(item)
} }
@ -515,6 +521,16 @@ class EventActivity : SimpleActivity() {
} }
} }
private fun duplicateEvent() {
Intent(this, EventActivity::class.java).apply {
putExtra(EVENT_ID, mEvent.id)
putExtra(EVENT_OCCURRENCE_TS, mEventOccurrenceTS)
putExtra(IS_DUPLICATE_INTENT, true)
startActivity(this)
}
finish()
}
private fun saveEvent() { private fun saveEvent() {
val newTitle = event_title.value val newTitle = event_title.value
if (newTitle.isEmpty()) { if (newTitle.isEmpty()) {

View File

@ -7,6 +7,7 @@ const val STORED_LOCALLY_ONLY = 0
const val DAY_CODE = "day_code" const val DAY_CODE = "day_code"
const val YEAR_LABEL = "year" const val YEAR_LABEL = "year"
const val EVENT_ID = "event_id" const val EVENT_ID = "event_id"
const val IS_DUPLICATE_INTENT = "is_duplicate_intent"
const val EVENT_OCCURRENCE_TS = "event_occurrence_ts" const val EVENT_OCCURRENCE_TS = "event_occurrence_ts"
const val NEW_EVENT_START_TS = "new_event_start_ts" const val NEW_EVENT_START_TS = "new_event_start_ts"
const val WEEK_START_TIMESTAMP = "week_start_timestamp" const val WEEK_START_TIMESTAMP = "week_start_timestamp"

View File

@ -11,6 +11,11 @@
android:icon="@drawable/ic_delete" android:icon="@drawable/ic_delete"
android:title="@string/delete" android:title="@string/delete"
app:showAsAction="ifRoom"/> app:showAsAction="ifRoom"/>
<item
android:id="@+id/duplicate"
android:icon="@drawable/ic_copy"
android:title="@string/duplicate_event"
app:showAsAction="ifRoom"/>
<item <item
android:id="@+id/share" android:id="@+id/share"
android:icon="@drawable/ic_share" android:icon="@drawable/ic_share"