mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-21 14:10:51 +01:00
select all calendars at first Caldav Sync
This commit is contained in:
parent
e0177f355c
commit
25f38916f1
@ -98,10 +98,10 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
settings_caldav_sync.isChecked = config.caldavSync
|
settings_caldav_sync.isChecked = config.caldavSync
|
||||||
settings_caldav_sync_holder.setOnClickListener {
|
settings_caldav_sync_holder.setOnClickListener {
|
||||||
if (config.caldavSync) {
|
if (config.caldavSync) {
|
||||||
toggleCaldavSync()
|
toggleCaldavSync(false)
|
||||||
} else {
|
} else {
|
||||||
if (hasCalendarPermission()) {
|
if (hasCalendarPermission()) {
|
||||||
toggleCaldavSync()
|
toggleCaldavSync(true)
|
||||||
} else {
|
} else {
|
||||||
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_CALENDAR), CALENDAR_PERMISSION)
|
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_CALENDAR), CALENDAR_PERMISSION)
|
||||||
}
|
}
|
||||||
@ -109,12 +109,12 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleCaldavSync() {
|
private fun toggleCaldavSync(enable: Boolean) {
|
||||||
settings_caldav_sync.toggle()
|
settings_caldav_sync.isChecked = enable
|
||||||
config.caldavSync = settings_caldav_sync.isChecked
|
config.caldavSync = enable
|
||||||
if (config.caldavSync) {
|
if (enable) {
|
||||||
SelectCalendarsDialog(this) {
|
SelectCalendarsDialog(this) {
|
||||||
|
config.isFirstCaldavSync = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -298,7 +298,7 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
|
|
||||||
if (requestCode == CALENDAR_PERMISSION) {
|
if (requestCode == CALENDAR_PERMISSION) {
|
||||||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
toggleCaldavSync()
|
toggleCaldavSync(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,13 +14,14 @@ import kotlinx.android.synthetic.main.calendar_item_account.view.*
|
|||||||
import kotlinx.android.synthetic.main.calendar_item_calendar.view.*
|
import kotlinx.android.synthetic.main.calendar_item_calendar.view.*
|
||||||
import kotlinx.android.synthetic.main.dialog_select_calendars.view.*
|
import kotlinx.android.synthetic.main.dialog_select_calendars.view.*
|
||||||
|
|
||||||
class SelectCalendarsDialog(val activity: Activity, val callback: (calendars: Int) -> Unit) : AlertDialog.Builder(activity) {
|
class SelectCalendarsDialog(val activity: Activity, val callback: () -> Unit) : AlertDialog.Builder(activity) {
|
||||||
var prevAccount = ""
|
var prevAccount = ""
|
||||||
var dialog: AlertDialog
|
var dialog: AlertDialog
|
||||||
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 ids = activity.config.caldavSyncedCalendarIDs.split(",") as ArrayList<String>
|
||||||
|
val isFirstCaldavSync = activity.config.isFirstCaldavSync
|
||||||
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 {
|
||||||
@ -29,7 +30,7 @@ class SelectCalendarsDialog(val activity: Activity, val callback: (calendars: In
|
|||||||
addCalendarItem(false, it.accountName)
|
addCalendarItem(false, it.accountName)
|
||||||
}
|
}
|
||||||
|
|
||||||
addCalendarItem(true, it.displayName, it.id, ids.contains(it.id.toString()))
|
addCalendarItem(true, it.displayName, it.id, ids.contains(it.id.toString()) || isFirstCaldavSync)
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog = AlertDialog.Builder(activity)
|
dialog = AlertDialog.Builder(activity)
|
||||||
@ -74,5 +75,6 @@ class SelectCalendarsDialog(val activity: Activity, val callback: (calendars: In
|
|||||||
}
|
}
|
||||||
|
|
||||||
activity.config.caldavSyncedCalendarIDs = TextUtils.join(",", calendarIDs)
|
activity.config.caldavSyncedCalendarIDs = TextUtils.join(",", calendarIDs)
|
||||||
|
callback()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,10 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
get() = prefs.getString(CALDAV_SYNCED_CALENDAR_IDS, "")
|
get() = prefs.getString(CALDAV_SYNCED_CALENDAR_IDS, "")
|
||||||
set(calendarIDs) = prefs.edit().putString(CALDAV_SYNCED_CALENDAR_IDS, calendarIDs).apply()
|
set(calendarIDs) = prefs.edit().putString(CALDAV_SYNCED_CALENDAR_IDS, calendarIDs).apply()
|
||||||
|
|
||||||
|
var isFirstCaldavSync: Boolean
|
||||||
|
get() = prefs.getBoolean(IS_FIRST_CALDAV_SYNC, true)
|
||||||
|
set(isFirstCaldavSync) = prefs.edit().putBoolean(IS_FIRST_CALDAV_SYNC, isFirstCaldavSync).apply()
|
||||||
|
|
||||||
fun addDisplayEventType(type: String) {
|
fun addDisplayEventType(type: String) {
|
||||||
addDisplayEventTypes(HashSet<String>(Arrays.asList(type)))
|
addDisplayEventTypes(HashSet<String>(Arrays.asList(type)))
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,7 @@ 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 CALDAV_SYNCED_CALENDAR_IDS = "caldav_synced_calendar_ids"
|
||||||
|
val IS_FIRST_CALDAV_SYNC = "is_first_caldav_sync"
|
||||||
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"
|
||||||
|
@ -3,14 +3,14 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/dialog_select_calendars_scrollview"
|
android:id="@+id/dialog_select_calendars_scrollview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="@dimen/activity_margin">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/dialog_select_calendars_holder"
|
android:id="@+id/dialog_select_calendars_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical">
|
||||||
android:paddingTop="@dimen/activity_margin">
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user