add a dialog for selecting which caldav calendars to sync

This commit is contained in:
tibbi 2017-08-13 13:59:46 +02:00
parent ef25f7d352
commit 37dda42a6b
23 changed files with 167 additions and 24 deletions

View File

@ -11,6 +11,7 @@ import android.os.Parcelable
import android.support.v4.app.ActivityCompat
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.dialogs.CustomEventReminderDialog
import com.simplemobiletools.calendar.dialogs.SelectCalendarsDialog
import com.simplemobiletools.calendar.dialogs.SnoozePickerDialog
import com.simplemobiletools.calendar.extensions.*
import com.simplemobiletools.calendar.helpers.FONT_SIZE_LARGE
@ -29,10 +30,6 @@ class SettingsActivity : SimpleActivity() {
lateinit var res: Resources
private var mStoredPrimaryColor = 0
companion object {
val REQUEST_AUTHORIZATION = 5
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
@ -115,6 +112,11 @@ class SettingsActivity : SimpleActivity() {
private fun toggleCaldavSync() {
settings_caldav_sync.toggle()
config.caldavSync = settings_caldav_sync.isChecked
if (config.caldavSync) {
SelectCalendarsDialog(this) {
}
}
}
private fun setupSundayFirst() {

View File

@ -2,7 +2,6 @@ package com.simplemobiletools.calendar.dialogs
import android.app.Activity
import android.support.v7.app.AlertDialog
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import com.simplemobiletools.calendar.R
@ -13,7 +12,7 @@ import kotlinx.android.synthetic.main.dialog_custom_event_reminder.view.*
class CustomEventReminderDialog(val activity: Activity, val selectedMinutes: Int = 0, val callback: (minutes: Int) -> Unit) : AlertDialog.Builder(activity) {
var dialog: AlertDialog
var view: View = (activity.layoutInflater.inflate(R.layout.dialog_custom_event_reminder, null) as ViewGroup).apply {
var view = (activity.layoutInflater.inflate(R.layout.dialog_custom_event_reminder, null) as ViewGroup).apply {
if (selectedMinutes == 0) {
dialog_radio_view.check(R.id.dialog_radio_minutes)
} else if (selectedMinutes % 1440 == 0) {

View File

@ -2,7 +2,6 @@ package com.simplemobiletools.calendar.dialogs
import android.app.Activity
import android.support.v7.app.AlertDialog
import android.view.View
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.commons.extensions.setupDialogStuff
@ -12,7 +11,7 @@ import kotlinx.android.synthetic.main.dialog_vertical_linear_layout.view.*
class RepeatRuleWeeklyDialog(val activity: Activity, val curRepeatRule: Int, val callback: (repeatRule: Int) -> Unit) :
AlertDialog.Builder(activity) {
val dialog: AlertDialog
val view: View = activity.layoutInflater.inflate(R.layout.dialog_vertical_linear_layout, null)
val view = activity.layoutInflater.inflate(R.layout.dialog_vertical_linear_layout, null)
init {
val days = arrayOf(R.string.monday, R.string.tuesday, R.string.wednesday, R.string.thursday, R.string.friday, R.string.saturday, R.string.sunday)

View File

@ -0,0 +1,57 @@
package com.simplemobiletools.calendar.dialogs
import android.app.Activity
import android.support.v7.app.AlertDialog
import android.view.ViewGroup
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.getCalDAVCalendars
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.calendar_item_account.view.*
import kotlinx.android.synthetic.main.calendar_item_calendar.view.*
import kotlinx.android.synthetic.main.dialog_select_calendars.view.*
class SelectCalendarsDialog(val activity: Activity, val callback: (calendars: Int) -> Unit) : AlertDialog.Builder(activity) {
var prevAccount = ""
var dialog: AlertDialog
var view = (activity.layoutInflater.inflate(R.layout.dialog_select_calendars, null) as ViewGroup)
init {
val calendars = activity.getCalDAVCalendars()
val sorted = calendars.sortedWith(compareBy({ it.accountName }, { it.displayName }))
sorted.forEach {
if (prevAccount != it.accountName) {
prevAccount = it.accountName
addCalendarItem(false, it.accountName)
}
addCalendarItem(true, it.displayName)
}
dialog = AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, { dialogInterface, i -> confirmSelection() })
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.select_caldav_calendars)
}
}
private fun addCalendarItem(isEvent: Boolean, text: String) {
val calendarItem = activity.layoutInflater.inflate(if (isEvent) R.layout.calendar_item_calendar else R.layout.calendar_item_account,
view.dialog_select_calendars_holder, false)
if (isEvent) {
calendarItem.calendar_item_calendar_switch.text = text
calendarItem.setOnClickListener {
calendarItem.calendar_item_calendar_switch.toggle()
}
} else {
calendarItem.calendar_item_account.text = text
}
view.dialog_select_calendars_holder.addView(calendarItem)
}
private fun confirmSelection() {
}
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<com.simplemobiletools.commons.views.MyTextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/calendar_item_account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:layout_marginLeft="@dimen/big_margin"
android:layout_marginStart="@dimen/big_margin"
android:layout_marginTop="@dimen/activity_margin"
android:alpha="0.6"
android:textAllCaps="true"
android:textColor="@color/divider_strong"
android:textSize="@dimen/small_text_size"
tools:text="Account"/>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/calendar_item_calendar_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/calendar_item_calendar_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingBottom="@dimen/activity_margin"
android:paddingLeft="@dimen/big_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
tools:text="Calendar name"/>
</RelativeLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog_select_calendars_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/dialog_select_calendars_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="@dimen/activity_margin">
</LinearLayout>
</ScrollView>

View File

@ -190,7 +190,9 @@
<string name="display_past_events">Display events from the past</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- CalDAV sync -->
<string name="select_caldav_calendars">Select calendars to sync</string>
<plurals name="by_minutes">
<item quantity="one">%1$d minute</item>

View File

@ -190,7 +190,9 @@
<string name="display_past_events">Display events from the past</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- CalDAV sync -->
<string name="select_caldav_calendars">Select calendars to sync</string>
<plurals name="by_minutes">
<item quantity="one">%1$d minute</item>

View File

@ -190,7 +190,9 @@
<string name="display_past_events">Display events from the past</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- CalDAV sync -->
<string name="select_caldav_calendars">Select calendars to sync</string>
<plurals name="by_minutes">
<item quantity="one">%1$d minute</item>

View File

@ -190,7 +190,9 @@
<string name="display_past_events">Display events from the past</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- CalDAV sync -->
<string name="select_caldav_calendars">Select calendars to sync</string>
<plurals name="by_minutes">
<item quantity="one">%1$d minute</item>

View File

@ -190,7 +190,9 @@
<string name="display_past_events">Display events from the past</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- CalDAV sync -->
<string name="select_caldav_calendars">Select calendars to sync</string>
<plurals name="by_minutes">
<item quantity="one">%1$d minute</item>

View File

@ -190,7 +190,9 @@
<string name="display_past_events">Display events from the past</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- CalDAV sync -->
<string name="select_caldav_calendars">Select calendars to sync</string>
<plurals name="by_minutes">
<item quantity="one">%1$d minute</item>

View File

@ -190,7 +190,9 @@
<string name="display_past_events">Display events from the past</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- CalDAV sync -->
<string name="select_caldav_calendars">Select calendars to sync</string>
<plurals name="by_minutes">
<item quantity="one">%1$d minute</item>

View File

@ -190,7 +190,9 @@
<string name="display_past_events">Display events from the past</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- CalDAV sync -->
<string name="select_caldav_calendars">Select calendars to sync</string>
<plurals name="by_minutes">
<item quantity="one">%1$d minute</item>

View File

@ -195,7 +195,9 @@
<string name="display_past_events">Pokazuj wydarzenia z przeszłości</string>
<string name="snooze_delay">Opóźnij przypomnienie o</string>
<string name="widgets">Widżety</string>
<string name="cannot_while_offline">Nie możesz tego zrobić bez dostępu do internetu.</string>
<!-- CalDAV sync -->
<string name="select_caldav_calendars">Select calendars to sync</string>
<plurals name="by_minutes">
<item quantity="one">%1$d minutę</item>

View File

@ -190,7 +190,9 @@
<string name="display_past_events">Display events from the past</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- CalDAV sync -->
<string name="select_caldav_calendars">Select calendars to sync</string>
<plurals name="by_minutes">
<item quantity="one">%1$d minute</item>

View File

@ -190,7 +190,9 @@
<string name="display_past_events">Mostrar eventos passados</string>
<string name="snooze_delay">Adiar lembrete com a opção Snooze</string>
<string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- CalDAV sync -->
<string name="select_caldav_calendars">Select calendars to sync</string>
<plurals name="by_minutes">
<item quantity="one">%1$d minuto</item>

View File

@ -204,7 +204,9 @@
<string name="display_past_events">Показывать прошедшие события</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- CalDAV sync -->
<string name="select_caldav_calendars">Select calendars to sync</string>
<plurals name="by_minutes">
<item quantity="one">%1$d минута</item>

View File

@ -197,7 +197,9 @@
<string name="display_past_events">Zobraziť minulé udalosti spred</string>
<string name="snooze_delay">Posunúť pripomienku s Odložiť o</string>
<string name="widgets">Widgety</string>
<string name="cannot_while_offline">Nemôžete to urobiť bez internetu.</string>
<!-- CalDAV sync -->
<string name="select_caldav_calendars">Zvoľte kalendáre pre synchronizáciu</string>
<plurals name="by_minutes">
<item quantity="one">%1$d minútu</item>

View File

@ -190,7 +190,9 @@
<string name="display_past_events">Visa tidigare händelser</string>
<string name="snooze_delay">Skjut upp påminnelse med Snooza</string>
<string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- CalDAV sync -->
<string name="select_caldav_calendars">Select calendars to sync</string>
<plurals name="by_minutes">
<item quantity="one">%1$d minut</item>

View File

@ -190,7 +190,9 @@
<string name="display_past_events">Display events from the past</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- CalDAV sync -->
<string name="select_caldav_calendars">Select calendars to sync</string>
<plurals name="by_minutes">
<item quantity="one">%1$d minute</item>

View File

@ -190,7 +190,9 @@
<string name="display_past_events">Display events from the past</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- CalDAV sync -->
<string name="select_caldav_calendars">Select calendars to sync</string>
<plurals name="by_minutes">
<item quantity="one">%1$d minute</item>