From a9eee4ff50ddf36751bc7c16788947f5aa72a7d6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 1 Feb 2018 14:45:32 +0100 Subject: [PATCH] move RepeatIntervalDialog and ReminderDialog in activity extensions --- .../calendar/activities/SimpleActivity.kt | 87 +------------------ .../calendar/extensions/Activity.kt | 81 ++++++++++++++++- 2 files changed, 81 insertions(+), 87 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SimpleActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SimpleActivity.kt index c66b67731..ab24d64f6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SimpleActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SimpleActivity.kt @@ -1,90 +1,5 @@ package com.simplemobiletools.calendar.activities -import com.simplemobiletools.calendar.R -import com.simplemobiletools.calendar.dialogs.CustomEventReminderDialog -import com.simplemobiletools.calendar.dialogs.CustomEventRepeatIntervalDialog -import com.simplemobiletools.calendar.extensions.getFormattedMinutes -import com.simplemobiletools.calendar.extensions.getRepetitionText -import com.simplemobiletools.calendar.helpers.DAY -import com.simplemobiletools.calendar.helpers.MONTH -import com.simplemobiletools.calendar.helpers.WEEK -import com.simplemobiletools.calendar.helpers.YEAR import com.simplemobiletools.commons.activities.BaseSimpleActivity -import com.simplemobiletools.commons.dialogs.RadioGroupDialog -import com.simplemobiletools.commons.extensions.hideKeyboard -import com.simplemobiletools.commons.models.RadioItem -import java.util.TreeSet -import kotlin.collections.ArrayList -open class SimpleActivity : BaseSimpleActivity() { - protected fun showEventReminderDialog(curMinutes: Int, callback: (minutes: Int) -> Unit) { - hideKeyboard() - val minutes = TreeSet() - minutes.apply { - add(-1) - add(0) - add(10) - add(30) - add(curMinutes) - } - - val items = ArrayList(minutes.size + 1) - minutes.mapIndexedTo(items, { index, value -> - RadioItem(index, getFormattedMinutes(value), value) - }) - - var selectedIndex = 0 - minutes.forEachIndexed { index, value -> - if (value == curMinutes) - selectedIndex = index - } - - items.add(RadioItem(-2, getString(R.string.custom))) - - RadioGroupDialog(this, items, selectedIndex) { - if (it == -2) { - CustomEventReminderDialog(this) { - callback(it) - } - } else { - callback(it as Int) - } - } - } - - protected fun showEventRepeatIntervalDialog(curSeconds: Int, callback: (minutes: Int) -> Unit) { - hideKeyboard() - val seconds = TreeSet() - seconds.apply { - add(0) - add(DAY) - add(WEEK) - add(MONTH) - add(YEAR) - add(curSeconds) - } - - val items = ArrayList(seconds.size + 1) - seconds.mapIndexedTo(items, { index, value -> - RadioItem(index, getRepetitionText(value), value) - }) - - var selectedIndex = 0 - seconds.forEachIndexed { index, value -> - if (value == curSeconds) - selectedIndex = index - } - - items.add(RadioItem(-1, getString(R.string.custom))) - - RadioGroupDialog(this, items, selectedIndex) { - if (it == -1) { - CustomEventRepeatIntervalDialog(this) { - callback(it) - } - } else { - callback(it as Int) - } - } - } -} +open class SimpleActivity : BaseSimpleActivity() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Activity.kt index ce0577fe5..d2099fae0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Activity.kt @@ -1,13 +1,21 @@ package com.simplemobiletools.calendar.extensions +import android.app.Activity import com.simplemobiletools.calendar.BuildConfig import com.simplemobiletools.calendar.R -import com.simplemobiletools.calendar.helpers.IcsExporter +import com.simplemobiletools.calendar.dialogs.CustomEventReminderDialog +import com.simplemobiletools.calendar.dialogs.CustomEventRepeatIntervalDialog +import com.simplemobiletools.calendar.helpers.* import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.getFilePublicUri +import com.simplemobiletools.commons.extensions.hideKeyboard import com.simplemobiletools.commons.extensions.shareUri import com.simplemobiletools.commons.extensions.toast +import com.simplemobiletools.commons.models.RadioItem import java.io.File +import java.util.TreeSet +import kotlin.collections.ArrayList fun BaseSimpleActivity.shareEvents(ids: List) { val file = getTempFile() @@ -36,3 +44,74 @@ fun BaseSimpleActivity.getTempFile(): File? { return File(folder, "events.ics") } + +fun Activity.showEventReminderDialog(curMinutes: Int, callback: (minutes: Int) -> Unit) { + hideKeyboard() + val minutes = TreeSet() + minutes.apply { + add(-1) + add(0) + add(10) + add(30) + add(curMinutes) + } + + val items = ArrayList(minutes.size + 1) + minutes.mapIndexedTo(items, { index, value -> + RadioItem(index, getFormattedMinutes(value), value) + }) + + var selectedIndex = 0 + minutes.forEachIndexed { index, value -> + if (value == curMinutes) + selectedIndex = index + } + + items.add(RadioItem(-2, getString(R.string.custom))) + + RadioGroupDialog(this, items, selectedIndex) { + if (it == -2) { + CustomEventReminderDialog(this) { + callback(it) + } + } else { + callback(it as Int) + } + } +} + +fun Activity.showEventRepeatIntervalDialog(curSeconds: Int, callback: (minutes: Int) -> Unit) { + hideKeyboard() + val seconds = TreeSet() + seconds.apply { + add(0) + add(DAY) + add(WEEK) + add(MONTH) + add(YEAR) + add(curSeconds) + } + + val items = ArrayList(seconds.size + 1) + seconds.mapIndexedTo(items, { index, value -> + RadioItem(index, getRepetitionText(value), value) + }) + + var selectedIndex = 0 + seconds.forEachIndexed { index, value -> + if (value == curSeconds) + selectedIndex = index + } + + items.add(RadioItem(-1, getString(R.string.custom))) + + RadioGroupDialog(this, items, selectedIndex) { + if (it == -1) { + CustomEventRepeatIntervalDialog(this) { + callback(it) + } + } else { + callback(it as Int) + } + } +}