mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
remember which calendars should be checked at caldav sync
This commit is contained in:
@@ -2,8 +2,12 @@ package com.simplemobiletools.calendar.dialogs
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
|
import android.support.v7.widget.SwitchCompat
|
||||||
|
import android.text.TextUtils
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.RelativeLayout
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
|
import com.simplemobiletools.calendar.extensions.config
|
||||||
import com.simplemobiletools.calendar.extensions.getCalDAVCalendars
|
import com.simplemobiletools.calendar.extensions.getCalDAVCalendars
|
||||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
import kotlinx.android.synthetic.main.calendar_item_account.view.*
|
import kotlinx.android.synthetic.main.calendar_item_account.view.*
|
||||||
@@ -16,6 +20,7 @@ class SelectCalendarsDialog(val activity: Activity, val callback: (calendars: In
|
|||||||
var view = (activity.layoutInflater.inflate(R.layout.dialog_select_calendars, null) as ViewGroup)
|
var view = (activity.layoutInflater.inflate(R.layout.dialog_select_calendars, null) as ViewGroup)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
val ids = activity.config.caldavSyncedCalendarIDs.split(",") as ArrayList<String>
|
||||||
val calendars = activity.getCalDAVCalendars()
|
val calendars = activity.getCalDAVCalendars()
|
||||||
val sorted = calendars.sortedWith(compareBy({ it.accountName }, { it.displayName }))
|
val sorted = calendars.sortedWith(compareBy({ it.accountName }, { it.displayName }))
|
||||||
sorted.forEach {
|
sorted.forEach {
|
||||||
@@ -24,7 +29,7 @@ class SelectCalendarsDialog(val activity: Activity, val callback: (calendars: In
|
|||||||
addCalendarItem(false, it.accountName)
|
addCalendarItem(false, it.accountName)
|
||||||
}
|
}
|
||||||
|
|
||||||
addCalendarItem(true, it.displayName)
|
addCalendarItem(true, it.displayName, it.id, ids.contains(it.id.toString()))
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog = AlertDialog.Builder(activity)
|
dialog = AlertDialog.Builder(activity)
|
||||||
@@ -35,14 +40,18 @@ class SelectCalendarsDialog(val activity: Activity, val callback: (calendars: In
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addCalendarItem(isEvent: Boolean, text: String) {
|
private fun addCalendarItem(isEvent: Boolean, text: String, tag: Long = 0L, shouldCheck: Boolean = false) {
|
||||||
val calendarItem = activity.layoutInflater.inflate(if (isEvent) R.layout.calendar_item_calendar else R.layout.calendar_item_account,
|
val calendarItem = activity.layoutInflater.inflate(if (isEvent) R.layout.calendar_item_calendar else R.layout.calendar_item_account,
|
||||||
view.dialog_select_calendars_holder, false)
|
view.dialog_select_calendars_holder, false)
|
||||||
|
|
||||||
if (isEvent) {
|
if (isEvent) {
|
||||||
calendarItem.calendar_item_calendar_switch.text = text
|
calendarItem.calendar_item_calendar_switch.apply {
|
||||||
calendarItem.setOnClickListener {
|
this.tag = tag
|
||||||
calendarItem.calendar_item_calendar_switch.toggle()
|
this.text = text
|
||||||
|
isChecked = shouldCheck
|
||||||
|
calendarItem.setOnClickListener {
|
||||||
|
toggle()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
calendarItem.calendar_item_account.text = text
|
calendarItem.calendar_item_account.text = text
|
||||||
@@ -52,6 +61,18 @@ class SelectCalendarsDialog(val activity: Activity, val callback: (calendars: In
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun confirmSelection() {
|
private fun confirmSelection() {
|
||||||
|
val calendarIDs = ArrayList<Long>()
|
||||||
|
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 Long)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
activity.config.caldavSyncedCalendarIDs = TextUtils.join(",", calendarIDs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -74,6 +74,10 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
get() = prefs.getBoolean(CALDAV_SYNC, false)
|
get() = prefs.getBoolean(CALDAV_SYNC, false)
|
||||||
set(caldavSync) = prefs.edit().putBoolean(CALDAV_SYNC, caldavSync).apply()
|
set(caldavSync) = prefs.edit().putBoolean(CALDAV_SYNC, caldavSync).apply()
|
||||||
|
|
||||||
|
var caldavSyncedCalendarIDs: String
|
||||||
|
get() = prefs.getString(CALDAV_SYNCED_CALENDAR_IDS, "")
|
||||||
|
set(calendarIDs) = prefs.edit().putString(CALDAV_SYNCED_CALENDAR_IDS, calendarIDs).apply()
|
||||||
|
|
||||||
fun addDisplayEventType(type: String) {
|
fun addDisplayEventType(type: String) {
|
||||||
addDisplayEventTypes(HashSet<String>(Arrays.asList(type)))
|
addDisplayEventTypes(HashSet<String>(Arrays.asList(type)))
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,7 @@ val REMINDER_MINUTES = "reminder_minutes"
|
|||||||
val DISPLAY_EVENT_TYPES = "display_event_types"
|
val DISPLAY_EVENT_TYPES = "display_event_types"
|
||||||
val FONT_SIZE = "font_size"
|
val FONT_SIZE = "font_size"
|
||||||
val CALDAV_SYNC = "caldav_sync"
|
val CALDAV_SYNC = "caldav_sync"
|
||||||
|
val CALDAV_SYNCED_CALENDAR_IDS = "caldav_synced_calendar_ids"
|
||||||
val SYNC_ACCOUNT_NAME = "sync_account_name"
|
val SYNC_ACCOUNT_NAME = "sync_account_name"
|
||||||
val SNOOZE_DELAY = "snooze_delay"
|
val SNOOZE_DELAY = "snooze_delay"
|
||||||
val DISPLAY_PAST_EVENTS = "display_past_events"
|
val DISPLAY_PAST_EVENTS = "display_past_events"
|
||||||
|
Reference in New Issue
Block a user