fix some issues around updating event calendar ids

This commit is contained in:
tibbi 2017-10-07 20:42:02 +02:00
parent b6c635ffd9
commit 873d68181f
3 changed files with 21 additions and 16 deletions

View File

@ -24,6 +24,10 @@ import org.joda.time.DateTime
import java.util.*
class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
companion object {
val STORED_LOCALLY_ONLY = 0
}
private var mReminder1Minutes = 0
private var mReminder2Minutes = 0
private var mReminder3Minutes = 0
@ -33,6 +37,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
private var mEventTypeId = DBHelper.REGULAR_EVENT_TYPE_ID
private var mDialogTheme = 0
private var mEventOccurrenceTS = 0
private var mEventCalendarId = STORED_LOCALLY_ONLY
private var wasActivityInitialized = false
lateinit var mEventStartDateTime: DateTime
@ -120,6 +125,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
mRepeatLimit = mEvent.repeatLimit
mRepeatRule = mEvent.repeatRule
mEventTypeId = mEvent.eventType
mEventCalendarId = mEvent.getCalDAVCalendarId()
checkRepeatTexts(mRepeatInterval)
}
@ -397,7 +403,12 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
event_caldav_calendar_holder.setOnClickListener {
hideKeyboard()
SelectEventCalendarDialog(this, calendars, getCalendarId()) {
SelectEventCalendarDialog(this, calendars, mEventCalendarId) {
if (mEventCalendarId != STORED_LOCALLY_ONLY && it == STORED_LOCALLY_ONLY) {
mEventTypeId = DBHelper.REGULAR_EVENT_TYPE_ID
updateEventType()
}
mEventCalendarId = it
config.lastUsedCaldavCalendar = it
updateCurrentCalendarInfo(getCalendarWithId(calendars, it))
}
@ -421,17 +432,13 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
if (currentCalendar == null) {
event_caldav_calendar_name.apply {
text = getString(R.string.store_locally_only)
apply {
setPadding(paddingLeft, paddingTop, paddingRight, resources.getDimension(R.dimen.medium_margin).toInt())
}
setPadding(paddingLeft, paddingTop, paddingRight, resources.getDimension(R.dimen.medium_margin).toInt())
}
} else {
event_caldav_calendar_email.text = currentCalendar.accountName
event_caldav_calendar_name.apply {
text = currentCalendar.displayName
apply {
setPadding(paddingLeft, paddingTop, paddingRight, resources.getDimension(R.dimen.tiny_margin).toInt())
}
setPadding(paddingLeft, paddingTop, paddingRight, resources.getDimension(R.dimen.tiny_margin).toInt())
}
}
}

View File

@ -7,6 +7,7 @@ import android.view.ViewGroup
import android.widget.RadioButton
import android.widget.RadioGroup
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.EventActivity.Companion.STORED_LOCALLY_ONLY
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.models.CalDAVCalendar
@ -17,8 +18,6 @@ import kotlinx.android.synthetic.main.dialog_select_radio_group.view.*
import kotlinx.android.synthetic.main.radio_button_with_color.view.*
class SelectEventCalendarDialog(val activity: Activity, val calendars: List<CalDAVCalendar>, val currCalendarId: Int, val callback: (id: Int) -> Unit) {
private val STORE_LOCALLY_ONLY = 0
private val dialog: AlertDialog?
private val radioGroup: RadioGroup
private var wasInit = false
@ -32,7 +31,7 @@ class SelectEventCalendarDialog(val activity: Activity, val calendars: List<CalD
calendars.forEach {
addRadioButton(it.getFullTitle(), it.id, it.color)
}
addRadioButton(activity.getString(R.string.store_locally_only), STORE_LOCALLY_ONLY, Color.TRANSPARENT)
addRadioButton(activity.getString(R.string.store_locally_only), STORED_LOCALLY_ONLY, Color.TRANSPARENT)
wasInit = true
activity.updateTextColors(view.dialog_radio_holder)
}
@ -60,10 +59,9 @@ class SelectEventCalendarDialog(val activity: Activity, val calendars: List<CalD
}
private fun viewClicked(typeId: Int) {
if (!wasInit)
return
callback(typeId)
dialog?.dismiss()
if (wasInit) {
callback(typeId)
dialog?.dismiss()
}
}
}

View File

@ -109,5 +109,5 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
}
}
fun getCalDAVCalendarId() = if (source.contains("-") && source != SOURCE_IMPORTED_ICS) (source.split("-").lastOrNull() ?: "0").toString().toInt() else 0
fun getCalDAVCalendarId() = if (source.startsWith(CALDAV)) (source.split("-").lastOrNull() ?: "0").toString().toInt() else 0
}