fix #535, allow specifying a default event type for new events
This commit is contained in:
parent
b7ef8f7f1b
commit
d92ba3b9c4
|
@ -86,7 +86,7 @@ class EventActivity : SimpleActivity() {
|
|||
config.lastUsedLocalEventTypeId = REGULAR_EVENT_TYPE_ID
|
||||
}
|
||||
|
||||
mEventTypeId = config.lastUsedLocalEventTypeId
|
||||
mEventTypeId = if (config.defaultEventTypeId == -1L) config.lastUsedLocalEventTypeId else config.defaultEventTypeId
|
||||
|
||||
if (event != null) {
|
||||
mEvent = event
|
||||
|
@ -548,7 +548,7 @@ class EventActivity : SimpleActivity() {
|
|||
|
||||
private fun showEventTypeDialog() {
|
||||
hideKeyboard()
|
||||
SelectEventTypeDialog(this, mEventTypeId, false) {
|
||||
SelectEventTypeDialog(this, mEventTypeId, false, true, false) {
|
||||
mEventTypeId = it.id!!
|
||||
updateEventType()
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.media.AudioManager
|
|||
import android.os.Bundle
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.dialogs.SelectCalendarsDialog
|
||||
import com.simplemobiletools.calendar.pro.dialogs.SelectEventTypeDialog
|
||||
import com.simplemobiletools.calendar.pro.extensions.*
|
||||
import com.simplemobiletools.calendar.pro.helpers.*
|
||||
import com.simplemobiletools.calendar.pro.models.EventType
|
||||
|
@ -611,6 +612,28 @@ class SettingsActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun setupDefaultEventType() {
|
||||
updateDefaultEventTypeText()
|
||||
settings_default_event_type.text = getString(R.string.last_used_one)
|
||||
settings_default_event_type_holder.setOnClickListener {
|
||||
SelectEventTypeDialog(this, config.defaultEventTypeId, false, false, true) {
|
||||
config.defaultEventTypeId = it.id!!
|
||||
updateDefaultEventTypeText()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateDefaultEventTypeText() {
|
||||
if (config.defaultEventTypeId == -1L) {
|
||||
settings_default_event_type.text = getString(R.string.last_used_one)
|
||||
} else {
|
||||
Thread {
|
||||
val eventType = eventTypesDB.getEventTypeWithId(config.defaultEventTypeId)
|
||||
if (eventType != null) {
|
||||
runOnUiThread {
|
||||
settings_default_event_type.text = eventType.title
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ open class SimpleActivity : BaseSimpleActivity() {
|
|||
val uri = CalendarContract.Calendars.CONTENT_URI
|
||||
contentResolver.unregisterContentObserver(calDAVSyncObserver)
|
||||
contentResolver.registerContentObserver(uri, false, calDAVSyncObserver)
|
||||
refreshCalDAVCalendars(config.caldavSyncedCalendarIDs, true)
|
||||
refreshCalDAVCalendars(config.caldavSyncedCalendarIds, true)
|
||||
}.start()
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ class ImportEventsDialog(val activity: SimpleActivity, val path: String, val cal
|
|||
val view = (activity.layoutInflater.inflate(R.layout.dialog_import_events, null) as ViewGroup).apply {
|
||||
updateEventType(this)
|
||||
import_event_type_holder.setOnClickListener {
|
||||
SelectEventTypeDialog(activity, currEventTypeId, true) {
|
||||
SelectEventTypeDialog(activity, currEventTypeId, true, true, false) {
|
||||
currEventTypeId = it.id!!
|
||||
currEventTypeCalDAVCalendarId = it.caldavCalendarId
|
||||
|
||||
|
|
|
@ -61,19 +61,19 @@ class SelectCalendarsDialog(val activity: SimpleActivity, val callback: () -> Un
|
|||
}
|
||||
|
||||
private fun confirmSelection() {
|
||||
val calendarIDs = ArrayList<Int>()
|
||||
val calendarIds = ArrayList<Int>()
|
||||
val childCnt = view.dialog_select_calendars_holder.childCount
|
||||
for (i in 0..childCnt) {
|
||||
val child = view.dialog_select_calendars_holder.getChildAt(i)
|
||||
if (child is RelativeLayout) {
|
||||
val check = child.getChildAt(0)
|
||||
if (check is SwitchCompat && check.isChecked) {
|
||||
calendarIDs.add(check.tag as Int)
|
||||
calendarIds.add(check.tag as Int)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
activity.config.caldavSyncedCalendarIDs = TextUtils.join(",", calendarIDs)
|
||||
activity.config.caldavSyncedCalendarIds = TextUtils.join(",", calendarIds)
|
||||
callback()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,10 @@ import kotlinx.android.synthetic.main.dialog_select_radio_group.view.*
|
|||
import kotlinx.android.synthetic.main.radio_button_with_color.view.*
|
||||
import java.util.*
|
||||
|
||||
class SelectEventTypeDialog(val activity: Activity, val currEventType: Long, val showCalDAVCalendars: Boolean,
|
||||
val callback: (eventType: EventType) -> Unit) {
|
||||
private val NEW_TYPE_ID = -2L
|
||||
class SelectEventTypeDialog(val activity: Activity, val currEventType: Long, val showCalDAVCalendars: Boolean, val showNewEventTypeOption: Boolean,
|
||||
val addLastUsedOneAsFirstOption: Boolean, val callback: (eventType: EventType) -> Unit) {
|
||||
private val NEW_EVENT_TYPE_ID = -2L
|
||||
private val LAST_USED_EVENT_TYPE_ID = -1L
|
||||
|
||||
private val dialog: AlertDialog?
|
||||
private val radioGroup: RadioGroup
|
||||
|
@ -34,11 +35,17 @@ class SelectEventTypeDialog(val activity: Activity, val currEventType: Long, val
|
|||
activity.eventsHelper.getEventTypes(activity) {
|
||||
eventTypes = it
|
||||
activity.runOnUiThread {
|
||||
if (addLastUsedOneAsFirstOption) {
|
||||
val lastUsedEventType = EventType(LAST_USED_EVENT_TYPE_ID, activity.getString(R.string.last_used_one), Color.TRANSPARENT, 0)
|
||||
addRadioButton(lastUsedEventType)
|
||||
}
|
||||
eventTypes.filter { showCalDAVCalendars || it.caldavCalendarId == 0 }.forEach {
|
||||
addRadioButton(it)
|
||||
}
|
||||
val newEventType = EventType(NEW_TYPE_ID, activity.getString(R.string.add_new_type), Color.TRANSPARENT, 0)
|
||||
addRadioButton(newEventType)
|
||||
if (showNewEventTypeOption) {
|
||||
val newEventType = EventType(NEW_EVENT_TYPE_ID, activity.getString(R.string.add_new_type), Color.TRANSPARENT, 0)
|
||||
addRadioButton(newEventType)
|
||||
}
|
||||
wasInit = true
|
||||
activity.updateTextColors(view.dialog_radio_holder)
|
||||
}
|
||||
|
@ -71,7 +78,7 @@ class SelectEventTypeDialog(val activity: Activity, val currEventType: Long, val
|
|||
return
|
||||
}
|
||||
|
||||
if (eventType.id == NEW_TYPE_ID) {
|
||||
if (eventType.id == NEW_EVENT_TYPE_ID) {
|
||||
EditEventTypeDialog(activity) {
|
||||
callback(it)
|
||||
activity.hideKeyboard()
|
||||
|
|
|
@ -329,7 +329,7 @@ fun Context.getNewEventTimestampFromCode(dayCode: String): Long {
|
|||
return newDateTime.withDate(dateTime.year, dateTime.monthOfYear, dateTime.dayOfMonth).seconds()
|
||||
}
|
||||
|
||||
fun Context.getSyncedCalDAVCalendars() = calDAVHelper.getCalDAVCalendars(config.caldavSyncedCalendarIDs, false)
|
||||
fun Context.getSyncedCalDAVCalendars() = calDAVHelper.getCalDAVCalendars(config.caldavSyncedCalendarIds, false)
|
||||
|
||||
fun Context.recheckCalDAVCalendars(callback: () -> Unit) {
|
||||
if (config.caldavSync) {
|
||||
|
|
|
@ -32,7 +32,7 @@ class CalDAVHelper(val context: Context) {
|
|||
|
||||
isUpdatingCalDAV = true
|
||||
try {
|
||||
val calDAVCalendars = getCalDAVCalendars(context.config.caldavSyncedCalendarIDs, showToasts)
|
||||
val calDAVCalendars = getCalDAVCalendars(context.config.caldavSyncedCalendarIds, showToasts)
|
||||
for (calendar in calDAVCalendars) {
|
||||
val localEventType = eventsHelper.getEventTypeWithCalDAVCalendarId(calendar.id) ?: continue
|
||||
localEventType.apply {
|
||||
|
|
|
@ -88,7 +88,7 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
prefs.edit().putBoolean(CALDAV_SYNC, caldavSync).apply()
|
||||
}
|
||||
|
||||
var caldavSyncedCalendarIDs: String
|
||||
var caldavSyncedCalendarIds: String
|
||||
get() = prefs.getString(CALDAV_SYNCED_CALENDAR_IDS, "")
|
||||
set(calendarIDs) = prefs.edit().putString(CALDAV_SYNCED_CALENDAR_IDS, calendarIDs).apply()
|
||||
|
||||
|
@ -120,7 +120,7 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
get() = prefs.getBoolean(DIM_PAST_EVENTS, true)
|
||||
set(dimPastEvents) = prefs.edit().putBoolean(DIM_PAST_EVENTS, dimPastEvents).apply()
|
||||
|
||||
fun getSyncedCalendarIdsAsList() = caldavSyncedCalendarIDs.split(",").filter { it.trim().isNotEmpty() }.map { Integer.parseInt(it) }.toMutableList() as ArrayList<Int>
|
||||
fun getSyncedCalendarIdsAsList() = caldavSyncedCalendarIds.split(",").filter { it.trim().isNotEmpty() }.map { Integer.parseInt(it) }.toMutableList() as ArrayList<Int>
|
||||
|
||||
fun getDisplayEventTypessAsList() = displayEventTypes.map { it.toLong() }.toMutableList() as ArrayList<Long>
|
||||
|
||||
|
@ -182,7 +182,7 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
get() = prefs.getInt(DEFAULT_DURATION, 0)
|
||||
set(defaultDuration) = prefs.edit().putInt(DEFAULT_DURATION, defaultDuration).apply()
|
||||
|
||||
var defaultEventType: Long
|
||||
get() = prefs.getLong(DEFAULT_EVENT_TYPE, REGULAR_EVENT_TYPE_ID)
|
||||
set(defaultEventType) = prefs.edit().putLong(DEFAULT_EVENT_TYPE, defaultEventType).apply()
|
||||
var defaultEventTypeId: Long
|
||||
get() = prefs.getLong(DEFAULT_EVENT_TYPE_ID, -1L)
|
||||
set(defaultEventTypeId) = prefs.edit().putLong(DEFAULT_EVENT_TYPE_ID, defaultEventTypeId).apply()
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ const val PULL_TO_REFRESH = "pull_to_refresh"
|
|||
const val LAST_VIBRATE_ON_REMINDER = "last_vibrate_on_reminder"
|
||||
const val DEFAULT_START_TIME = "default_start_time"
|
||||
const val DEFAULT_DURATION = "default_duration"
|
||||
const val DEFAULT_EVENT_TYPE = "default_event_type"
|
||||
const val DEFAULT_EVENT_TYPE_ID = "default_event_type_id"
|
||||
|
||||
// repeat_rule for monthly and yearly repetition
|
||||
const val REPEAT_SAME_DAY = 1 // i.e. 25th every month, or 3rd june (if yearly repetition)
|
||||
|
|
Loading…
Reference in New Issue