Commit a4a81629 authored by Ricki Hirner's avatar Ricki Hirner 🐑

Refactoring

parent 65db706e
Pipeline #15678936 passed with stages
in 6 minutes and 6 seconds
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
*/ */
package at.bitfire.davdroid; package at.bitfire.davdroid
object Constants { object Constants {
......
...@@ -162,13 +162,13 @@ class DavService: Service() { ...@@ -162,13 +162,13 @@ class DavService: Service() {
when (serviceType) { when (serviceType) {
Services.SERVICE_CARDDAV -> { Services.SERVICE_CARDDAV -> {
dav.propfind(0, AddressbookHomeSet.NAME, GroupMembership.NAME) dav.propfind(0, AddressbookHomeSet.NAME, GroupMembership.NAME)
for ((resource, addressbookHomeSet) in dav.findProperties(AddressbookHomeSet.NAME) as List<Pair<DavResource, AddressbookHomeSet>>) for ((resource, addressbookHomeSet) in dav.findProperties(AddressbookHomeSet::class.java))
for (href in addressbookHomeSet.hrefs) for (href in addressbookHomeSet.hrefs)
resource.location.resolve(href)?.let { homeSets += UrlUtils.withTrailingSlash(it) } resource.location.resolve(href)?.let { homeSets += UrlUtils.withTrailingSlash(it) }
} }
Services.SERVICE_CALDAV -> { Services.SERVICE_CALDAV -> {
dav.propfind(0, CalendarHomeSet.NAME, CalendarProxyReadFor.NAME, CalendarProxyWriteFor.NAME, GroupMembership.NAME) dav.propfind(0, CalendarHomeSet.NAME, CalendarProxyReadFor.NAME, CalendarProxyWriteFor.NAME, GroupMembership.NAME)
for ((resource, calendarHomeSet) in dav.findProperties(CalendarHomeSet.NAME) as List<Pair<DavResource, CalendarHomeSet>>) for ((resource, calendarHomeSet) in dav.findProperties(CalendarHomeSet::class.java))
for (href in calendarHomeSet.hrefs) for (href in calendarHomeSet.hrefs)
resource.location.resolve(href)?.let { homeSets.add(UrlUtils.withTrailingSlash(it)) } resource.location.resolve(href)?.let { homeSets.add(UrlUtils.withTrailingSlash(it)) }
} }
...@@ -213,19 +213,19 @@ class DavService: Service() { ...@@ -213,19 +213,19 @@ class DavService: Service() {
queryHomeSets(principal) queryHomeSets(principal)
// refresh home sets: calendar-proxy-read/write-for // refresh home sets: calendar-proxy-read/write-for
for ((resource, proxyRead) in principal.findProperties(CalendarProxyReadFor.NAME) as List<Pair<DavResource, CalendarProxyReadFor>>) for ((resource, proxyRead) in principal.findProperties(CalendarProxyReadFor::class.java))
for (href in proxyRead.hrefs) { for (href in proxyRead.hrefs) {
Logger.log.fine("Principal is a read-only proxy for $href, checking for home sets") Logger.log.fine("Principal is a read-only proxy for $href, checking for home sets")
resource.location.resolve(href)?.let { queryHomeSets(DavResource(httpClient, it)) } resource.location.resolve(href)?.let { queryHomeSets(DavResource(httpClient, it)) }
} }
for ((resource, proxyWrite) in principal.findProperties(CalendarProxyWriteFor.NAME) as List<Pair<DavResource, CalendarProxyWriteFor>>) for ((resource, proxyWrite) in principal.findProperties(CalendarProxyWriteFor::class.java))
for (href in proxyWrite.hrefs) { for (href in proxyWrite.hrefs) {
Logger.log.fine("Principal is a read/write proxy for $href, checking for home sets") Logger.log.fine("Principal is a read/write proxy for $href, checking for home sets")
resource.location.resolve(href)?.let { queryHomeSets(DavResource(httpClient, it)) } resource.location.resolve(href)?.let { queryHomeSets(DavResource(httpClient, it)) }
} }
// refresh home sets: direct group memberships // refresh home sets: direct group memberships
(principal.properties[GroupMembership.NAME] as GroupMembership?)?.let { groupMembership -> principal.properties[GroupMembership::class.java]?.let { groupMembership ->
for (href in groupMembership.hrefs) { for (href in groupMembership.hrefs) {
Logger.log.fine("Principal is member of group $href, checking for home sets") Logger.log.fine("Principal is member of group $href, checking for home sets")
principal.location.resolve(href)?.let { url -> principal.location.resolve(href)?.let { url ->
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
*/ */
package at.bitfire.davdroid; package at.bitfire.davdroid
import android.annotation.TargetApi import android.annotation.TargetApi
import android.content.Context import android.content.Context
...@@ -37,11 +37,7 @@ object DavUtils { ...@@ -37,11 +37,7 @@ object DavUtils {
val segments = LinkedList<String>(httpUrl.pathSegments()) val segments = LinkedList<String>(httpUrl.pathSegments())
Collections.reverse(segments) Collections.reverse(segments)
for (segment in segments) return segments.firstOrNull { it.isNotEmpty() } ?: "/"
if (segment.isNotEmpty())
return segment
return "/"
} }
fun prepareLookup(context: Context, lookup: Lookup) { fun prepareLookup(context: Context, lookup: Lookup) {
......
...@@ -50,7 +50,7 @@ class PackageChangedReceiver: BroadcastReceiver() { ...@@ -50,7 +50,7 @@ class PackageChangedReceiver: BroadcastReceiver() {
if (ContentResolver.getIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority) <= 0) { if (ContentResolver.getIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority) <= 0) {
ContentResolver.setIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority, 1) ContentResolver.setIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority, 1)
ContentResolver.setSyncAutomatically(account, TaskProvider.ProviderName.OpenTasks.authority, true) ContentResolver.setSyncAutomatically(account, TaskProvider.ProviderName.OpenTasks.authority, true)
ContentResolver.addPeriodicSync(account, TaskProvider.ProviderName.OpenTasks.authority, Bundle(), Constants.DEFAULT_SYNC_INTERVAL.toLong()) ContentResolver.addPeriodicSync(account, TaskProvider.ProviderName.OpenTasks.authority, Bundle(), Constants.DEFAULT_SYNC_INTERVAL)
} }
} else } else
ContentResolver.setIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority, 0) ContentResolver.setIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority, 0)
......
...@@ -54,7 +54,7 @@ class SSLSocketFactoryCompat( ...@@ -54,7 +54,7 @@ class SSLSocketFactoryCompat(
protocols = _protocols.toTypedArray() protocols = _protocols.toTypedArray()
/* set up reasonable cipher suites */ /* set up reasonable cipher suites */
val knownCiphers = arrayOf<String>( val knownCiphers = arrayOf(
// TLS 1.2 // TLS 1.2
"TLS_RSA_WITH_AES_256_GCM_SHA384", "TLS_RSA_WITH_AES_256_GCM_SHA384",
"TLS_RSA_WITH_AES_128_GCM_SHA256", "TLS_RSA_WITH_AES_128_GCM_SHA256",
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
package at.bitfire.davdroid.log package at.bitfire.davdroid.log
import java.util.logging.Handler; import java.util.logging.Handler
import java.util.logging.LogRecord; import java.util.logging.LogRecord
class StringHandler: Handler() { class StringHandler: Handler() {
......
...@@ -62,7 +62,7 @@ data class CollectionInfo @JvmOverloads constructor( ...@@ -62,7 +62,7 @@ data class CollectionInfo @JvmOverloads constructor(
constructor(dav: DavResource): this(dav.location.toString()) { constructor(dav: DavResource): this(dav.location.toString()) {
(dav.properties[ResourceType.NAME] as ResourceType?)?.let { type -> dav.properties[ResourceType::class.java]?.let { type ->
when { when {
type.types.contains(ResourceType.ADDRESSBOOK) -> this.type = Type.ADDRESS_BOOK type.types.contains(ResourceType.ADDRESSBOOK) -> this.type = Type.ADDRESS_BOOK
type.types.contains(ResourceType.CALENDAR) -> this.type = Type.CALENDAR type.types.contains(ResourceType.CALENDAR) -> this.type = Type.CALENDAR
...@@ -70,33 +70,33 @@ data class CollectionInfo @JvmOverloads constructor( ...@@ -70,33 +70,33 @@ data class CollectionInfo @JvmOverloads constructor(
} }
} }
(dav.properties[CurrentUserPrivilegeSet.NAME] as CurrentUserPrivilegeSet?)?.let { privilegeSet -> dav.properties[CurrentUserPrivilegeSet::class.java]?.let { privilegeSet ->
readOnly = !privilegeSet.mayWriteContent readOnly = !privilegeSet.mayWriteContent
} }
(dav.properties[DisplayName.NAME] as DisplayName?)?.let { dav.properties[DisplayName::class.java]?.let {
if (!it.displayName.isNullOrEmpty()) if (!it.displayName.isNullOrEmpty())
displayName = it.displayName displayName = it.displayName
} }
when (type) { when (type) {
Type.ADDRESS_BOOK -> { Type.ADDRESS_BOOK -> {
(dav.properties[AddressbookDescription.NAME] as AddressbookDescription?)?.let { description = it.description } dav.properties[AddressbookDescription::class.java]?.let { description = it.description }
} }
Type.CALENDAR, Type.WEBCAL -> { Type.CALENDAR, Type.WEBCAL -> {
(dav.properties[CalendarDescription.NAME] as CalendarDescription?)?.let { description = it.description } dav.properties[CalendarDescription::class.java]?.let { description = it.description }
(dav.properties[CalendarColor.NAME] as CalendarColor?)?.let { color = it.color } dav.properties[CalendarColor::class.java]?.let { color = it.color }
(dav.properties[CalendarTimezone.NAME] as CalendarTimezone?)?.let { timeZone = it.vTimeZone } dav.properties[CalendarTimezone::class.java]?.let { timeZone = it.vTimeZone }
if (type == Type.CALENDAR) { if (type == Type.CALENDAR) {
supportsVEVENT = true supportsVEVENT = true
supportsVTODO = true supportsVTODO = true
(dav.properties[SupportedCalendarComponentSet.NAME] as SupportedCalendarComponentSet?)?.let { dav.properties[SupportedCalendarComponentSet::class.java]?.let {
supportsVEVENT = it.supportsEvents supportsVEVENT = it.supportsEvents
supportsVTODO = it.supportsTasks supportsVTODO = it.supportsTasks
} }
} else { // Type.WEBCAL } else { // Type.WEBCAL
(dav.properties[Source.NAME] as Source?)?.let { source = it.hrefs.firstOrNull() } dav.properties[Source::class.java]?.let { source = it.hrefs.firstOrNull() }
supportsVEVENT = true supportsVEVENT = true
} }
} }
......
...@@ -193,7 +193,7 @@ class ServiceDB { ...@@ -193,7 +193,7 @@ class ServiceDB {
// print columns // print columns
val cols = cursor.columnCount val cols = cursor.columnCount
sb.append("\t| ") sb.append("\t| ")
for (i in 0 .. cols-1) for (i in 0 until cols)
sb .append(" ") sb .append(" ")
.append(cursor.getColumnName(i)) .append(cursor.getColumnName(i))
.append(" |") .append(" |")
...@@ -202,7 +202,7 @@ class ServiceDB { ...@@ -202,7 +202,7 @@ class ServiceDB {
// print rows // print rows
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
sb.append("\t| ") sb.append("\t| ")
for (i in 0 .. cols-1) { for (i in 0 until cols) {
sb.append(" ") sb.append(" ")
try { try {
val value = cursor.getString(i) val value = cursor.getString(i)
......
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
*/ */
package at.bitfire.davdroid.model; package at.bitfire.davdroid.model
import android.provider.ContactsContract.RawContacts; import android.provider.ContactsContract.RawContacts
object UnknownProperties { object UnknownProperties {
......
...@@ -56,9 +56,7 @@ class LocalCalendar private constructor( ...@@ -56,9 +56,7 @@ class LocalCalendar private constructor(
// flag as visible & synchronizable at creation, might be changed by user at any time // flag as visible & synchronizable at creation, might be changed by user at any time
values.put(Calendars.VISIBLE, 1) values.put(Calendars.VISIBLE, 1)
values.put(Calendars.SYNC_EVENTS, 1) values.put(Calendars.SYNC_EVENTS, 1)
val uri = create(account, provider, values) return create(account, provider, values)
return uri
} }
private fun valuesFromCollectionInfo(info: CollectionInfo, withColor: Boolean): ContentValues { private fun valuesFromCollectionInfo(info: CollectionInfo, withColor: Boolean): ContentValues {
......
...@@ -102,7 +102,7 @@ class LocalTaskList private constructor( ...@@ -102,7 +102,7 @@ class LocalTaskList private constructor(
@Throws(CalendarStorageException::class) @Throws(CalendarStorageException::class)
fun update(info: CollectionInfo, updateColor: Boolean) { fun update(info: CollectionInfo, updateColor: Boolean) {
update(valuesFromCollectionInfo(info, updateColor)); update(valuesFromCollectionInfo(info, updateColor))
} }
......
...@@ -14,18 +14,18 @@ open class DefaultsProvider( ...@@ -14,18 +14,18 @@ open class DefaultsProvider(
private val allowOverride: Boolean = true private val allowOverride: Boolean = true
): Provider { ): Provider {
open val booleanDefaults = mapOf<String, Boolean>( open val booleanDefaults = mapOf(
Pair(App.DISTRUST_SYSTEM_CERTIFICATES, false), Pair(App.DISTRUST_SYSTEM_CERTIFICATES, false),
Pair(App.OVERRIDE_PROXY, false) Pair(App.OVERRIDE_PROXY, false)
) )
open val intDefaults = mapOf<String, Int>( open val intDefaults = mapOf(
Pair(App.OVERRIDE_PROXY_PORT, App.OVERRIDE_PROXY_PORT_DEFAULT) Pair(App.OVERRIDE_PROXY_PORT, App.OVERRIDE_PROXY_PORT_DEFAULT)
) )
open val longDefaults = mapOf<String, Long>() open val longDefaults = mapOf<String, Long>()
open val stringDefaults = mapOf<String, String>( open val stringDefaults = mapOf(
Pair(App.OVERRIDE_PROXY_HOST, App.OVERRIDE_PROXY_HOST_DEFAULT) Pair(App.OVERRIDE_PROXY_HOST, App.OVERRIDE_PROXY_HOST_DEFAULT)
) )
......
...@@ -136,7 +136,7 @@ class CalendarSyncManager( ...@@ -136,7 +136,7 @@ class CalendarSyncManager(
val body = remote.get("text/calendar") val body = remote.get("text/calendar")
// CalDAV servers MUST return ETag on GET [https://tools.ietf.org/html/rfc4791#section-5.3.4] // CalDAV servers MUST return ETag on GET [https://tools.ietf.org/html/rfc4791#section-5.3.4]
val eTag = remote.properties[GetETag.NAME] as GetETag? val eTag = remote.properties[GetETag::class.java]
if (eTag == null || eTag.eTag.isNullOrEmpty()) if (eTag == null || eTag.eTag.isNullOrEmpty())
throw DavException("Received CalDAV GET response without ETag for ${remote.location}") throw DavException("Received CalDAV GET response without ETag for ${remote.location}")
...@@ -154,10 +154,10 @@ class CalendarSyncManager( ...@@ -154,10 +154,10 @@ class CalendarSyncManager(
for (remote in davCollection.members) { for (remote in davCollection.members) {
currentDavResource = remote currentDavResource = remote
val eTag = (remote.properties[GetETag.NAME] as GetETag?)?.eTag val eTag = remote.properties[GetETag::class.java]?.eTag
?: throw DavException("Received multi-get response without ETag") ?: throw DavException("Received multi-get response without ETag")
val calendarData = remote.properties[CalendarData.NAME] as CalendarData? val calendarData = remote.properties[CalendarData::class.java]
val iCalendar = calendarData?.iCalendar val iCalendar = calendarData?.iCalendar
?: throw DavException("Received multi-get response without event data") ?: throw DavException("Received multi-get response without event data")
......
...@@ -94,6 +94,7 @@ class ContactsSyncManager( ...@@ -94,6 +94,7 @@ class ContactsSyncManager(
private var numDiscarded = 0 private var numDiscarded = 0
private var hasVCard4 = false private var hasVCard4 = false
private var hasCollectionSync = false
private val groupMethod = accountSettings.getGroupMethod() private val groupMethod = accountSettings.getGroupMethod()
...@@ -125,12 +126,19 @@ class ContactsSyncManager( ...@@ -125,12 +126,19 @@ class ContactsSyncManager(
override fun queryCapabilities() { override fun queryCapabilities() {
// prepare remote address book // prepare remote address book
davCollection.propfind(0, SupportedAddressData.NAME, GetCTag.NAME) davCollection.propfind(0, SupportedAddressData.NAME, GetCTag.NAME, SupportedReportSet.NAME)
(davCollection.properties[SupportedAddressData.NAME] as SupportedAddressData?)?.let {
val properties = davCollection.properties
properties[SupportedAddressData::class.java]?.let {
hasVCard4 = it.hasVCard4() hasVCard4 = it.hasVCard4()
} }
Logger.log.info("Server advertises VCard/4 support: $hasVCard4") Logger.log.info("Server advertises VCard/4 support: $hasVCard4")
properties[SupportedReportSet::class.java]?.let {
hasCollectionSync = it.reports.contains(SupportedReportSet.SYNC_COLLECTION)
}
Logger.log.info("Server advertises collection synchronization support: $hasCollectionSync")
Logger.log.info("Contact group method: $groupMethod") Logger.log.info("Contact group method: $groupMethod")
// in case of GROUP_VCARDs, treat groups as contacts in the local address book // in case of GROUP_VCARDs, treat groups as contacts in the local address book
localAddressBook.includeGroups = groupMethod == GroupMethod.GROUP_VCARDS localAddressBook.includeGroups = groupMethod == GroupMethod.GROUP_VCARDS
...@@ -286,8 +294,12 @@ class ContactsSyncManager( ...@@ -286,8 +294,12 @@ class ContactsSyncManager(
remoteResources = HashMap(davCollection.members.size) remoteResources = HashMap(davCollection.members.size)
for (vCard in davCollection.members) { for (vCard in davCollection.members) {
// ignore member collections // ignore member collections
val type = vCard.properties[ResourceType.NAME] as ResourceType? var ignore = false
if (type != null && type.types.contains(ResourceType.COLLECTION)) vCard.properties[ResourceType::class.java]?.let { type ->
if (type.types.contains(ResourceType.COLLECTION))
ignore = true
}
if (ignore)
continue continue
val fileName = vCard.fileName() val fileName = vCard.fileName()
...@@ -319,7 +331,7 @@ class ContactsSyncManager( ...@@ -319,7 +331,7 @@ class ContactsSyncManager(
val body = remote.get("text/vcard;version=4.0, text/vcard;charset=utf-8;q=0.8, text/vcard;q=0.5") val body = remote.get("text/vcard;version=4.0, text/vcard;charset=utf-8;q=0.8, text/vcard;q=0.5")
// CardDAV servers MUST return ETag on GET [https://tools.ietf.org/html/rfc6352#section-6.3.2.3] // CardDAV servers MUST return ETag on GET [https://tools.ietf.org/html/rfc6352#section-6.3.2.3]
val eTag = remote.properties[GetETag.NAME] as GetETag? val eTag = remote.properties[GetETag::class.java]
if (eTag == null || eTag.eTag.isNullOrEmpty()) if (eTag == null || eTag.eTag.isNullOrEmpty())
throw DavException("Received CardDAV GET response without ETag for ${remote.location}") throw DavException("Received CardDAV GET response without ETag for ${remote.location}")
...@@ -337,10 +349,10 @@ class ContactsSyncManager( ...@@ -337,10 +349,10 @@ class ContactsSyncManager(
for (remote in davCollection.members) { for (remote in davCollection.members) {
currentDavResource = remote currentDavResource = remote
val eTag = (remote.properties[GetETag.NAME] as GetETag?)?.eTag val eTag = remote.properties[GetETag::class.java]?.eTag
?: throw DavException("Received multi-get response without ETag") ?: throw DavException("Received multi-get response without ETag")
val addressData = remote.properties[AddressData.NAME] as AddressData? val addressData = remote.properties[AddressData::class.java]
val vCard = addressData?.vCard val vCard = addressData?.vCard
?: throw DavException("Received multi-get response without address data") ?: throw DavException("Received multi-get response without address data")
......
...@@ -31,7 +31,7 @@ import java.util.logging.Level ...@@ -31,7 +31,7 @@ import java.util.logging.Level
abstract class SyncAdapterService: Service() { abstract class SyncAdapterService: Service() {
companion object { companion object {
val runningSyncs = Collections.synchronizedSet(mutableSetOf<Pair<String, Account>>()) val runningSyncs = Collections.synchronizedSet(mutableSetOf<Pair<String, Account>>())!!
} }
abstract protected fun syncAdapter(): AbstractThreadedSyncAdapter abstract protected fun syncAdapter(): AbstractThreadedSyncAdapter
......
...@@ -336,7 +336,7 @@ abstract class SyncManager( ...@@ -336,7 +336,7 @@ abstract class SyncManager(
Logger.log.log(Level.INFO, "Resource has been modified on the server before upload, ignoring", e) Logger.log.log(Level.INFO, "Resource has been modified on the server before upload, ignoring", e)
} }
val newETag = remote.properties[GetETag.NAME] as GetETag? val newETag = remote.properties[GetETag::class.java]
val eTag: String? val eTag: String?
if (newETag != null) { if (newETag != null) {
eTag = newETag.eTag eTag = newETag.eTag
...@@ -362,7 +362,7 @@ abstract class SyncManager( ...@@ -362,7 +362,7 @@ abstract class SyncManager(
*/ */
protected open fun checkSyncState(): Boolean { protected open fun checkSyncState(): Boolean {
// check CTag (ignore on manual sync) // check CTag (ignore on manual sync)
(davCollection.properties[GetCTag.NAME] as GetCTag?)?.let { remoteCTag = it.cTag } davCollection.properties[GetCTag::class.java]?.let { remoteCTag = it.cTag }
val localCTag = if (extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL)) { val localCTag = if (extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL)) {
Logger.log.info("Manual sync, ignoring CTag") Logger.log.info("Manual sync, ignoring CTag")
...@@ -423,7 +423,7 @@ abstract class SyncManager( ...@@ -423,7 +423,7 @@ abstract class SyncManager(
} else { } else {
// contact is still on server, check whether it has been updated remotely // contact is still on server, check whether it has been updated remotely
val localETag = local.eTag val localETag = local.eTag
val getETag = remote.properties[GetETag.NAME] as GetETag? val getETag = remote.properties[GetETag::class.java]
val remoteETag = getETag?.eTag ?: throw DavException("Server didn't provide ETag") val remoteETag = getETag?.eTag ?: throw DavException("Server didn't provide ETag")
if (remoteETag == localETag) { if (remoteETag == localETag) {
Logger.log.fine("$name has not been changed on server (ETag still $remoteETag)") Logger.log.fine("$name has not been changed on server (ETag still $remoteETag)")
......
...@@ -121,7 +121,7 @@ class TasksSyncManager( ...@@ -121,7 +121,7 @@ class TasksSyncManager(
val body = remote.get("text/calendar") val body = remote.get("text/calendar")
// CalDAV servers MUST return ETag on GET [https://tools.ietf.org/html/rfc4791#section-5.3.4] // CalDAV servers MUST return ETag on GET [https://tools.ietf.org/html/rfc4791#section-5.3.4]
val eTag = remote.properties[GetETag.NAME] as GetETag? val eTag = remote.properties[GetETag::class.java]
if (eTag == null || eTag.eTag.isNullOrEmpty()) if (eTag == null || eTag.eTag.isNullOrEmpty())
throw DavException("Received CalDAV GET response without ETag for ${remote.location}") throw DavException("Received CalDAV GET response without ETag for ${remote.location}")
...@@ -139,10 +139,10 @@ class TasksSyncManager( ...@@ -139,10 +139,10 @@ class TasksSyncManager(
for (remote in davCollection.members) { for (remote in davCollection.members) {
currentDavResource = remote currentDavResource = remote
val eTag = (remote.properties[GetETag.NAME] as GetETag?)?.eTag val eTag = remote.properties[GetETag::class.java]?.eTag
?: throw DavException("Received multi-get response without ETag") ?: throw DavException("Received multi-get response without ETag")
val calendarData = remote.properties[CalendarData.NAME] as CalendarData? val calendarData = remote.properties[CalendarData::class.java]
val iCalendar = calendarData?.iCalendar val iCalendar = calendarData?.iCalendar
?: throw DavException("Received multi-get response without task data") ?: throw DavException("Received multi-get response without task data")
......
...@@ -175,7 +175,7 @@ class AccountSettingsActivity: AppCompatActivity() { ...@@ -175,7 +175,7 @@ class AccountSettingsActivity: AppCompatActivity() {
else else
prefWifiOnlySSIDs.setSummary(R.string.settings_sync_wifi_only_ssids_off) prefWifiOnlySSIDs.setSummary(R.string.settings_sync_wifi_only_ssids_off)
prefWifiOnlySSIDs.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> prefWifiOnlySSIDs.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
accountSettings.setSyncWifiOnlySSIDs((newValue as String).split(',').map { StringUtils.trimToNull(it) }.filterNotNull().distinct()) accountSettings.setSyncWifiOnlySSIDs((newValue as String).split(',').mapNotNull { StringUtils.trimToNull(it) }.distinct())
loaderManager.restartLoader(0, arguments, this) loaderManager.restartLoader(0, arguments, this)
false false
} }
......
...@@ -121,7 +121,7 @@ class CreateCalendarActivity: AppCompatActivity(), LoaderManager.LoaderCallbacks ...@@ -121,7 +121,7 @@ class CreateCalendarActivity: AppCompatActivity(), LoaderManager.LoaderCallbacks
// select system time zone // select system time zone
val defaultTimeZone = TimeZone.getDefault().id val defaultTimeZone = TimeZone.getDefault().id
for (i in 0 .. timeZones.size - 1) for (i in 0 until timeZones.size)
if (timeZones[i] == defaultTimeZone) { if (timeZones[i] == defaultTimeZone) {
time_zone.setSelection(i) time_zone.setSelection(i)
break break
......
...@@ -35,12 +35,12 @@ class PermissionsActivity: AppCompatActivity() { ...@@ -35,12 +35,12 @@ class PermissionsActivity: AppCompatActivity() {
private fun refresh() { private fun refresh() {
val noCalendarPermissions = val noCalendarPermissions =
ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED ||
ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED; ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED
calendar_permissions.visibility = if (noCalendarPermissions) View.VISIBLE else View.GONE calendar_permissions.visibility = if (noCalendarPermissions) View.VISIBLE else View.GONE
val noContactsPermissions = val noContactsPermissions =
ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED ||
ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_CONTACTS) != PackageManager.PERMISSION_GRANTED; ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_CONTACTS) != PackageManager.PERMISSION_GRANTED
contacts_permissions.visibility = if (noContactsPermissions) View.VISIBLE else View.GONE contacts_permissions.visibility = if (noContactsPermissions) View.VISIBLE else View.GONE
val noTaskPermissions: Boolean val noTaskPermissions: Boolean
...@@ -50,7 +50,7 @@ class PermissionsActivity: AppCompatActivity() { ...@@ -50,7 +50,7 @@ class PermissionsActivity: AppCompatActivity() {
ActivityCompat.checkSelfPermission(this, TaskProvider.PERMISSION_WRITE_TASKS) != PackageManager.PERMISSION_GRANTED ActivityCompat.checkSelfPermission(this, TaskProvider.PERMISSION_WRITE_TASKS) != PackageManager.PERMISSION_GRANTED
findViewById<View>(R.id.opentasks_permissions).visibility = if (noTaskPermissions) View.VISIBLE else View.GONE findViewById<View>(R.id.opentasks_permissions).visibility = if (noTaskPermissions) View.VISIBLE else View.GONE
} else { } else {
findViewById<View>(R.id.opentasks_permissions).visibility = View.GONE; findViewById<View>(R.id.opentasks_permissions).visibility = View.GONE
noTaskPermissions = false noTaskPermissions = false
} }
......
...@@ -62,7 +62,7 @@ class AccountDetailsFragment: Fragment(), LoaderManager.LoaderCallbacks<CreateSe ...@@ -62,7 +62,7 @@ class AccountDetailsFragment: Fragment(), LoaderManager.LoaderCallbacks<CreateSe
val config = arguments.getSerializable(KEY_CONFIG) as DavResourceFinder.Configuration val config = arguments.getSerializable(KEY_CONFIG) as DavResourceFinder.Configuration
v.account_name.setText(if (config.calDAV != null && config.calDAV.email != null) v.account_name.setText(if (config.calDAV?.email != null)
config.calDAV.email config.calDAV.email
else else
config.userName) config.userName)
......
...@@ -131,7 +131,7 @@ class DavResourceFinder( ...@@ -131,7 +131,7 @@ class DavResourceFinder(
val davPrincipal = DavResource(httpClient.okHttpClient, HttpUrl.get(config.principal)!!, log) val davPrincipal = DavResource(httpClient.okHttpClient, HttpUrl.get(config.principal)!!, log)
try { try {
davPrincipal.propfind(0, CalendarUserAddressSet.NAME) davPrincipal.propfind(0, CalendarUserAddressSet.NAME)
(davPrincipal.properties[CalendarUserAddressSet.NAME] as CalendarUserAddressSet?)?.let { addressSet -> davPrincipal.properties[CalendarUserAddressSet::class.java]?.let { addressSet ->
for (href