move RepeatIntervalDialog and ReminderDialog in activity extensions
This commit is contained in:
parent
0c57eb0238
commit
a9eee4ff50
|
@ -1,90 +1,5 @@
|
||||||
package com.simplemobiletools.calendar.activities
|
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.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() {
|
open class SimpleActivity : BaseSimpleActivity()
|
||||||
protected fun showEventReminderDialog(curMinutes: Int, callback: (minutes: Int) -> Unit) {
|
|
||||||
hideKeyboard()
|
|
||||||
val minutes = TreeSet<Int>()
|
|
||||||
minutes.apply {
|
|
||||||
add(-1)
|
|
||||||
add(0)
|
|
||||||
add(10)
|
|
||||||
add(30)
|
|
||||||
add(curMinutes)
|
|
||||||
}
|
|
||||||
|
|
||||||
val items = ArrayList<RadioItem>(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<Int>()
|
|
||||||
seconds.apply {
|
|
||||||
add(0)
|
|
||||||
add(DAY)
|
|
||||||
add(WEEK)
|
|
||||||
add(MONTH)
|
|
||||||
add(YEAR)
|
|
||||||
add(curSeconds)
|
|
||||||
}
|
|
||||||
|
|
||||||
val items = ArrayList<RadioItem>(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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,13 +1,21 @@
|
||||||
package com.simplemobiletools.calendar.extensions
|
package com.simplemobiletools.calendar.extensions
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import com.simplemobiletools.calendar.BuildConfig
|
import com.simplemobiletools.calendar.BuildConfig
|
||||||
import com.simplemobiletools.calendar.R
|
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.activities.BaseSimpleActivity
|
||||||
|
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||||
import com.simplemobiletools.commons.extensions.getFilePublicUri
|
import com.simplemobiletools.commons.extensions.getFilePublicUri
|
||||||
|
import com.simplemobiletools.commons.extensions.hideKeyboard
|
||||||
import com.simplemobiletools.commons.extensions.shareUri
|
import com.simplemobiletools.commons.extensions.shareUri
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.TreeSet
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
fun BaseSimpleActivity.shareEvents(ids: List<Int>) {
|
fun BaseSimpleActivity.shareEvents(ids: List<Int>) {
|
||||||
val file = getTempFile()
|
val file = getTempFile()
|
||||||
|
@ -36,3 +44,74 @@ fun BaseSimpleActivity.getTempFile(): File? {
|
||||||
|
|
||||||
return File(folder, "events.ics")
|
return File(folder, "events.ics")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Activity.showEventReminderDialog(curMinutes: Int, callback: (minutes: Int) -> Unit) {
|
||||||
|
hideKeyboard()
|
||||||
|
val minutes = TreeSet<Int>()
|
||||||
|
minutes.apply {
|
||||||
|
add(-1)
|
||||||
|
add(0)
|
||||||
|
add(10)
|
||||||
|
add(30)
|
||||||
|
add(curMinutes)
|
||||||
|
}
|
||||||
|
|
||||||
|
val items = ArrayList<RadioItem>(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<Int>()
|
||||||
|
seconds.apply {
|
||||||
|
add(0)
|
||||||
|
add(DAY)
|
||||||
|
add(WEEK)
|
||||||
|
add(MONTH)
|
||||||
|
add(YEAR)
|
||||||
|
add(curSeconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
val items = ArrayList<RadioItem>(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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue