add a calendar picker to the event creation activity

This commit is contained in:
tibbi 2017-08-17 15:42:58 +02:00
parent 67f651adef
commit 20b6578225
4 changed files with 74 additions and 0 deletions

View File

@ -390,6 +390,9 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
event_caldav_calendar_divider.beVisible()
event_caldav_calendar_holder.setOnClickListener {
val calendars = CalDAVEventsHandler(applicationContext).getCalDAVCalendars().filter { it.canWrite() }
SelectEventCalendarDialog(this, calendars, config.lastUsedCaldavCalendar) {
config.lastUsedCaldavCalendar = it
}
}
}
}

View File

@ -0,0 +1,66 @@
package com.simplemobiletools.calendar.dialogs
import android.app.Activity
import android.graphics.Color
import android.support.v7.app.AlertDialog
import android.view.ViewGroup
import android.widget.RadioButton
import android.widget.RadioGroup
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.models.CalDAVCalendar
import com.simplemobiletools.commons.extensions.setBackgroundWithStroke
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.updateTextColors
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) {
val dialog: AlertDialog?
val radioGroup: RadioGroup
var wasInit = false
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_select_radio_group, null) as ViewGroup
radioGroup = view.dialog_radio_group
activity.dbHelper.getEventTypes {
activity.runOnUiThread {
calendars.forEach {
addRadioButton(it.displayName, it.id.toInt(), it.color)
}
wasInit = true
activity.updateTextColors(view.dialog_radio_holder)
}
}
dialog = AlertDialog.Builder(activity)
.create().apply {
activity.setupDialogStuff(view, this)
}
}
private fun addRadioButton(title: String, typeId: Int, color: Int) {
val view = activity.layoutInflater.inflate(R.layout.radio_button_with_color, null)
(view.dialog_radio_button as RadioButton).apply {
text = title
isChecked = typeId == currCalendarId
id = typeId
}
if (color != Color.TRANSPARENT)
view.dialog_radio_color.setBackgroundWithStroke(color, activity.config.backgroundColor)
view.setOnClickListener { viewClicked(typeId) }
radioGroup.addView(view, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
}
fun viewClicked(typeId: Int) {
if (!wasInit)
return
callback.invoke(typeId)
dialog?.dismiss()
}
}

View File

@ -78,6 +78,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getString(CALDAV_SYNCED_CALENDAR_IDS, "")
set(calendarIDs) = prefs.edit().putString(CALDAV_SYNCED_CALENDAR_IDS, calendarIDs).apply()
var lastUsedCaldavCalendar: Int
get() = prefs.getInt(LAST_USED_CALDAV_CALENDAR, 1)
set(calendarId) = prefs.edit().putInt(LAST_USED_CALDAV_CALENDAR, calendarId).apply()
fun getCalendarIdsAsList() = caldavSyncedCalendarIDs.split(",").filter { it.trim().isNotEmpty() } as ArrayList<String>
fun addDisplayEventType(type: String) {

View File

@ -44,6 +44,7 @@ val DISPLAY_EVENT_TYPES = "display_event_types"
val FONT_SIZE = "font_size"
val CALDAV_SYNC = "caldav_sync"
val CALDAV_SYNCED_CALENDAR_IDS = "caldav_synced_calendar_ids"
val LAST_USED_CALDAV_CALENDAR = "last_used_caldav_calendar"
val SNOOZE_DELAY = "snooze_delay"
val DISPLAY_PAST_EVENTS = "display_past_events"