Commit 8b6376e0 authored by Ricki Hirner's avatar Ricki Hirner 🐑

Use HttpUrl whenever possible

* HttpUrl is the preferred class because we use URLs mainly for okhttp
* don't use URI or String for URLs, if possible
* HttpUrl is not Serializable, so use Parcelable for data classes with HttpUrl

X
parent 5da229ed
Pipeline #22687515 passed with stages
in 7 minutes and 28 seconds
...@@ -14,6 +14,7 @@ import at.bitfire.dav4android.DavResource ...@@ -14,6 +14,7 @@ import at.bitfire.dav4android.DavResource
import at.bitfire.dav4android.property.ResourceType import at.bitfire.dav4android.property.ResourceType
import at.bitfire.davdroid.HttpClient import at.bitfire.davdroid.HttpClient
import at.bitfire.davdroid.model.ServiceDB.Collections import at.bitfire.davdroid.model.ServiceDB.Collections
import okhttp3.HttpUrl
import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer import okhttp3.mockwebserver.MockWebServer
import org.junit.After import org.junit.After
...@@ -113,7 +114,7 @@ class CollectionInfoTest { ...@@ -113,7 +114,7 @@ class CollectionInfoTest {
assertEquals(CollectionInfo.Type.CALENDAR, info.type) assertEquals(CollectionInfo.Type.CALENDAR, info.type)
assertEquals(1.toLong(), info.id) assertEquals(1.toLong(), info.id)
assertEquals(1.toLong(), info.serviceID) assertEquals(1.toLong(), info.serviceID)
assertEquals("http://example.com", info.url) assertEquals(HttpUrl.parse("http://example.com/"), info.url)
assertTrue(info.readOnly) assertTrue(info.readOnly)
assertEquals("display name", info.displayName) assertEquals("display name", info.displayName)
assertEquals("description", info.description) assertEquals("description", info.description)
......
...@@ -75,7 +75,7 @@ class DavResourceFinderTest { ...@@ -75,7 +75,7 @@ class DavResourceFinderTest {
finder.rememberIfAddressBookOrHomeset(it, info) finder.rememberIfAddressBookOrHomeset(it, info)
assertEquals(0, info.collections.size) assertEquals(0, info.collections.size)
assertEquals(1, info.homeSets.size) assertEquals(1, info.homeSets.size)
assertEquals(server.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET/").uri(), info.homeSets.first()) assertEquals(server.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET/"), info.homeSets.first())
} }
} }
...@@ -85,7 +85,7 @@ class DavResourceFinderTest { ...@@ -85,7 +85,7 @@ class DavResourceFinderTest {
ServiceInfo().let { info -> ServiceInfo().let { info ->
finder.rememberIfAddressBookOrHomeset(it, info) finder.rememberIfAddressBookOrHomeset(it, info)
assertEquals(1, info.collections.size) assertEquals(1, info.collections.size)
assertEquals(server.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK/").uri(), info.collections.keys.first()) assertEquals(server.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK/"), info.collections.keys.first())
assertEquals(0, info.homeSets.size) assertEquals(0, info.homeSets.size)
} }
} }
...@@ -112,13 +112,13 @@ class DavResourceFinderTest { ...@@ -112,13 +112,13 @@ class DavResourceFinderTest {
assertNull(finder.getCurrentUserPrincipal(server.url(PATH_NO_DAV), DavResourceFinder.Service.CARDDAV)) assertNull(finder.getCurrentUserPrincipal(server.url(PATH_NO_DAV), DavResourceFinder.Service.CARDDAV))
assertEquals( assertEquals(
server.url(PATH_CALDAV + SUBPATH_PRINCIPAL).uri(), server.url(PATH_CALDAV + SUBPATH_PRINCIPAL),
finder.getCurrentUserPrincipal(server.url(PATH_CALDAV), DavResourceFinder.Service.CALDAV) finder.getCurrentUserPrincipal(server.url(PATH_CALDAV), DavResourceFinder.Service.CALDAV)
) )
assertNull(finder.getCurrentUserPrincipal(server.url(PATH_CALDAV), DavResourceFinder.Service.CARDDAV)) assertNull(finder.getCurrentUserPrincipal(server.url(PATH_CALDAV), DavResourceFinder.Service.CARDDAV))
assertEquals( assertEquals(
server.url(PATH_CARDDAV + SUBPATH_PRINCIPAL).uri(), server.url(PATH_CARDDAV + SUBPATH_PRINCIPAL),
finder.getCurrentUserPrincipal(server.url(PATH_CARDDAV), DavResourceFinder.Service.CARDDAV) finder.getCurrentUserPrincipal(server.url(PATH_CARDDAV), DavResourceFinder.Service.CARDDAV)
) )
assertNull(finder.getCurrentUserPrincipal(server.url(PATH_CARDDAV), DavResourceFinder.Service.CALDAV)) assertNull(finder.getCurrentUserPrincipal(server.url(PATH_CARDDAV), DavResourceFinder.Service.CALDAV))
......
...@@ -309,7 +309,7 @@ class AccountSettings( ...@@ -309,7 +309,7 @@ class AccountSettings(
parcel.unmarshall(raw, 0, raw.size) parcel.unmarshall(raw, 0, raw.size)
parcel.setDataPosition(0) parcel.setDataPosition(0)
val params = parcel.readBundle() val params = parcel.readBundle()
val url = params.getString("url") val url = params.getString("url")?.let { HttpUrl.parse(it) }
if (url == null) if (url == null)
Logger.log.info("No address book URL, ignoring account") Logger.log.info("No address book URL, ignoring account")
else { else {
...@@ -319,7 +319,7 @@ class AccountSettings( ...@@ -319,7 +319,7 @@ class AccountSettings(
info.displayName = account.name info.displayName = account.name
Logger.log.log(Level.INFO, "Creating new address book account", url) Logger.log.log(Level.INFO, "Creating new address book account", url)
val addressBookAccount = Account(LocalAddressBook.accountName(account, info), context.getString(R.string.account_type_address_book)) val addressBookAccount = Account(LocalAddressBook.accountName(account, info), context.getString(R.string.account_type_address_book))
if (!accountManager.addAccountExplicitly(addressBookAccount, null, LocalAddressBook.initialUserData(account, info.url))) if (!accountManager.addAccountExplicitly(addressBookAccount, null, LocalAddressBook.initialUserData(account, info.url.toString())))
throw ContactsStorageException("Couldn't create address book account") throw ContactsStorageException("Couldn't create address book account")
// move contacts to new address book // move contacts to new address book
......
...@@ -283,7 +283,7 @@ class DavService: Service() { ...@@ -283,7 +283,7 @@ class DavService: Service() {
val selectedCollections = HashSet<HttpUrl>() val selectedCollections = HashSet<HttpUrl>()
collections.values collections.values
.filter { it.selected } .filter { it.selected }
.forEach { (url,_) -> HttpUrl.parse(url)?.let { selectedCollections.add(it) } } .forEach { (url,_) -> selectedCollections.add(url) }
// now refresh collections (taken from home sets) // now refresh collections (taken from home sets)
val itHomeSets = homeSets.iterator() val itHomeSets = homeSets.iterator()
......
...@@ -28,11 +28,9 @@ object DavUtils { ...@@ -28,11 +28,9 @@ object DavUtils {
return String.format("#%06X%02X", color, alpha) return String.format("#%06X%02X", color, alpha)
} }
fun lastSegmentOfUrl(url: String): String { fun lastSegmentOfUrl(url: HttpUrl): String {
val httpUrl = HttpUrl.parse(url) ?: throw IllegalArgumentException("url not parsable")
// the list returned by HttpUrl.pathSegments() is unmodifiable, so we have to create a copy // the list returned by HttpUrl.pathSegments() is unmodifiable, so we have to create a copy
val segments = LinkedList<String>(httpUrl.pathSegments()) val segments = LinkedList<String>(url.pathSegments())
segments.reverse() segments.reverse()
return segments.firstOrNull { it.isNotEmpty() } ?: "/" return segments.firstOrNull { it.isNotEmpty() } ?: "/"
......
...@@ -9,14 +9,25 @@ ...@@ -9,14 +9,25 @@
package at.bitfire.davdroid.model package at.bitfire.davdroid.model
import android.content.ContentValues import android.content.ContentValues
import android.os.Parcel
import android.os.Parcelable
import at.bitfire.dav4android.DavResponse import at.bitfire.dav4android.DavResponse
import at.bitfire.dav4android.UrlUtils import at.bitfire.dav4android.UrlUtils
import at.bitfire.dav4android.property.* import at.bitfire.dav4android.property.*
import at.bitfire.davdroid.model.ServiceDB.Collections import at.bitfire.davdroid.model.ServiceDB.Collections
import java.io.Serializable import okhttp3.HttpUrl
/**
* Represents a WebDAV collection.
*
* @constructor always appends a trailing slash to the URL
*/
data class CollectionInfo( data class CollectionInfo(
val url: String,
/**
* URL of the collection (including trailing slash)
*/
val url: HttpUrl,
var id: Long? = null, var id: Long? = null,
var serviceID: Long? = null, var serviceID: Long? = null,
...@@ -39,7 +50,7 @@ data class CollectionInfo( ...@@ -39,7 +50,7 @@ data class CollectionInfo(
// non-persistent properties // non-persistent properties
var confirmed: Boolean = false var confirmed: Boolean = false
): Serializable { ): Parcelable {
enum class Type { enum class Type {
ADDRESS_BOOK, ADDRESS_BOOK,
...@@ -61,7 +72,7 @@ data class CollectionInfo( ...@@ -61,7 +72,7 @@ data class CollectionInfo(
} }
constructor(dav: DavResponse): this(UrlUtils.withTrailingSlash(dav.url).toString()) { constructor(dav: DavResponse): this(UrlUtils.withTrailingSlash(dav.url)) {
dav[ResourceType::class.java]?.let { type -> dav[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
...@@ -104,7 +115,7 @@ data class CollectionInfo( ...@@ -104,7 +115,7 @@ data class CollectionInfo(
} }
constructor(values: ContentValues): this(values.getAsString(Collections.URL)) { constructor(values: ContentValues): this(UrlUtils.withTrailingSlash(HttpUrl.parse(values.getAsString(Collections.URL))!!)) {
id = values.getAsLong(Collections.ID) id = values.getAsLong(Collections.ID)
serviceID = values.getAsLong(Collections.SERVICE_ID) serviceID = values.getAsLong(Collections.SERVICE_ID)
type = try { type = try {
...@@ -134,7 +145,7 @@ data class CollectionInfo( ...@@ -134,7 +145,7 @@ data class CollectionInfo(
// Collections.SERVICE_ID is never changed // Collections.SERVICE_ID is never changed
type?.let { values.put(Collections.TYPE, it.name) } type?.let { values.put(Collections.TYPE, it.name) }
values.put(Collections.URL, url) values.put(Collections.URL, url.toString())
values.put(Collections.READ_ONLY, if (readOnly) 1 else 0) values.put(Collections.READ_ONLY, if (readOnly) 1 else 0)
values.put(Collections.FORCE_READ_ONLY, if (forceReadOnly) 1 else 0) values.put(Collections.FORCE_READ_ONLY, if (forceReadOnly) 1 else 0)
values.put(Collections.DISPLAY_NAME, displayName) values.put(Collections.DISPLAY_NAME, displayName)
...@@ -160,4 +171,79 @@ data class CollectionInfo( ...@@ -160,4 +171,79 @@ data class CollectionInfo(
(i != 0) (i != 0)
} }
override fun describeContents(): Int = 0
override fun writeToParcel(dest: Parcel, flags: Int) {
fun<T> writeOrNull(value: T?, write: (T) -> Unit) {
if (value == null)
dest.writeByte(0)
else {
dest.writeByte(1)
write(value)
}
}
dest.writeString(url.toString())
writeOrNull(id, { dest.writeLong(it) })
writeOrNull(serviceID, { dest.writeLong(it) })
dest.writeString(type?.name)
dest.writeByte(if (readOnly) 1 else 0)
dest.writeByte(if (forceReadOnly) 1 else 0)
dest.writeString(displayName)
dest.writeString(description)
writeOrNull(color, { dest.writeInt(it) })
dest.writeString(timeZone)
dest.writeByte(if (supportsVEVENT) 1 else 0)
dest.writeByte(if (supportsVTODO) 1 else 0)
dest.writeByte(if (selected) 1 else 0)
dest.writeString(source)
dest.writeByte(if (confirmed) 1 else 0)
}
@Suppress("unused")
@JvmField
val CREATOR = object: Parcelable.Creator<CollectionInfo> {
override fun createFromParcel(parcel: Parcel): CollectionInfo {
fun<T> readOrNull(parcel: Parcel, read: () -> T): T? {
return if (parcel.readByte() == 0.toByte())
null
else
read()
}
return CollectionInfo(
HttpUrl.parse(parcel.readString())!!,
readOrNull(parcel, { parcel.readLong() }),
readOrNull(parcel, { parcel.readLong() }),
parcel.readString()?.let { Type.valueOf(it) },
parcel.readByte() != 0.toByte(),
parcel.readByte() != 0.toByte(),
parcel.readString(),
parcel.readString(),
readOrNull(parcel, { parcel.readInt() }),
parcel.readString(),
parcel.readByte() != 0.toByte(),
parcel.readByte() != 0.toByte(),
parcel.readByte() != 0.toByte(),
parcel.readString(),
parcel.readByte() != 0.toByte()
)
}
override fun newArray(size: Int) = arrayOfNulls<CollectionInfo>(size)
}
} }
\ No newline at end of file
...@@ -52,7 +52,7 @@ class LocalAddressBook( ...@@ -52,7 +52,7 @@ class LocalAddressBook(
val accountManager = AccountManager.get(context) val accountManager = AccountManager.get(context)
val account = Account(accountName(mainAccount, info), context.getString(R.string.account_type_address_book)) val account = Account(accountName(mainAccount, info), context.getString(R.string.account_type_address_book))
if (!accountManager.addAccountExplicitly(account, null, initialUserData(mainAccount, info.url))) if (!accountManager.addAccountExplicitly(account, null, initialUserData(mainAccount, info.url.toString())))
throw IllegalStateException("Couldn't create address book account") throw IllegalStateException("Couldn't create address book account")
val addressBook = LocalAddressBook(context, account, provider) val addressBook = LocalAddressBook(context, account, provider)
......
...@@ -54,7 +54,7 @@ class LocalCalendar private constructor( ...@@ -54,7 +54,7 @@ class LocalCalendar private constructor(
private fun valuesFromCollectionInfo(info: CollectionInfo, withColor: Boolean): ContentValues { private fun valuesFromCollectionInfo(info: CollectionInfo, withColor: Boolean): ContentValues {
val values = ContentValues() val values = ContentValues()
values.put(Calendars.NAME, info.url) values.put(Calendars.NAME, info.url.toString())
values.put(Calendars.CALENDAR_DISPLAY_NAME, if (info.displayName.isNullOrBlank()) DavUtils.lastSegmentOfUrl(info.url) else info.displayName) values.put(Calendars.CALENDAR_DISPLAY_NAME, if (info.displayName.isNullOrBlank()) DavUtils.lastSegmentOfUrl(info.url) else info.displayName)
if (withColor) if (withColor)
......
...@@ -73,7 +73,7 @@ class LocalTaskList private constructor( ...@@ -73,7 +73,7 @@ class LocalTaskList private constructor(
private fun valuesFromCollectionInfo(info: CollectionInfo, withColor: Boolean): ContentValues { private fun valuesFromCollectionInfo(info: CollectionInfo, withColor: Boolean): ContentValues {
val values = ContentValues(3) val values = ContentValues(3)
values.put(TaskLists._SYNC_ID, info.url) values.put(TaskLists._SYNC_ID, info.url.toString())
values.put(TaskLists.LIST_NAME, if (info.displayName.isNullOrBlank()) DavUtils.lastSegmentOfUrl(info.url) else info.displayName) values.put(TaskLists.LIST_NAME, if (info.displayName.isNullOrBlank()) DavUtils.lastSegmentOfUrl(info.url) else info.displayName)
if (withColor) if (withColor)
......
...@@ -21,6 +21,7 @@ import at.bitfire.davdroid.model.ServiceDB ...@@ -21,6 +21,7 @@ import at.bitfire.davdroid.model.ServiceDB
import at.bitfire.davdroid.model.ServiceDB.Collections import at.bitfire.davdroid.model.ServiceDB.Collections
import at.bitfire.davdroid.resource.LocalAddressBook import at.bitfire.davdroid.resource.LocalAddressBook
import at.bitfire.davdroid.settings.ISettings import at.bitfire.davdroid.settings.ISettings
import okhttp3.HttpUrl
import java.util.logging.Level import java.util.logging.Level
class AddressBooksSyncAdapterService: SyncAdapterService() { class AddressBooksSyncAdapterService: SyncAdapterService() {
...@@ -32,7 +33,7 @@ class AddressBooksSyncAdapterService: SyncAdapterService() { ...@@ -32,7 +33,7 @@ class AddressBooksSyncAdapterService: SyncAdapterService() {
context: Context context: Context
): SyncAdapter(context) { ): SyncAdapter(context) {
override fun sync(settings: ISettings, account: Account, extras: Bundle, authority: String, addressBooksProvider: ContentProviderClient, syncResult: SyncResult) { override fun sync(settings: ISettings, account: Account, extras: Bundle, authority: String, provider: ContentProviderClient, syncResult: SyncResult) {
val contactsProvider = context.contentResolver.acquireContentProviderClient(ContactsContract.AUTHORITY) val contactsProvider = context.contentResolver.acquireContentProviderClient(ContactsContract.AUTHORITY)
if (contactsProvider == null) { if (contactsProvider == null) {
Logger.log.severe("Couldn't access contacts provider") Logger.log.severe("Couldn't access contacts provider")
...@@ -81,8 +82,8 @@ class AddressBooksSyncAdapterService: SyncAdapterService() { ...@@ -81,8 +82,8 @@ class AddressBooksSyncAdapterService: SyncAdapterService() {
null null
} }
fun remoteAddressBooks(service: Long?): MutableMap<String, CollectionInfo> { fun remoteAddressBooks(service: Long?): MutableMap<HttpUrl, CollectionInfo> {
val collections = mutableMapOf<String, CollectionInfo>() val collections = mutableMapOf<HttpUrl, CollectionInfo>()
service?.let { service?.let {
db.query(Collections._TABLE, null, db.query(Collections._TABLE, null,
Collections.SERVICE_ID + "=? AND " + Collections.SYNC, arrayOf(service.toString()), null, null, null)?.use { cursor -> Collections.SERVICE_ID + "=? AND " + Collections.SYNC, arrayOf(service.toString()), null, null, null)?.use { cursor ->
...@@ -103,7 +104,7 @@ class AddressBooksSyncAdapterService: SyncAdapterService() { ...@@ -103,7 +104,7 @@ class AddressBooksSyncAdapterService: SyncAdapterService() {
// delete/update local address books // delete/update local address books
for (addressBook in LocalAddressBook.findAll(context, provider, account)) { for (addressBook in LocalAddressBook.findAll(context, provider, account)) {
val url = addressBook.url val url = HttpUrl.parse(addressBook.url)!!
val info = remote[url] val info = remote[url]
if (info == null) { if (info == null) {
Logger.log.log(Level.INFO, "Deleting obsolete local address book", url) Logger.log.log(Level.INFO, "Deleting obsolete local address book", url)
......
...@@ -20,6 +20,7 @@ import at.bitfire.davdroid.model.ServiceDB.Collections ...@@ -20,6 +20,7 @@ import at.bitfire.davdroid.model.ServiceDB.Collections
import at.bitfire.davdroid.resource.LocalCalendar import at.bitfire.davdroid.resource.LocalCalendar
import at.bitfire.davdroid.settings.ISettings import at.bitfire.davdroid.settings.ISettings
import at.bitfire.ical4android.AndroidCalendar import at.bitfire.ical4android.AndroidCalendar
import okhttp3.HttpUrl
import java.util.logging.Level import java.util.logging.Level
class CalendarsSyncAdapterService: SyncAdapterService() { class CalendarsSyncAdapterService: SyncAdapterService() {
...@@ -75,8 +76,8 @@ class CalendarsSyncAdapterService: SyncAdapterService() { ...@@ -75,8 +76,8 @@ class CalendarsSyncAdapterService: SyncAdapterService() {
null null
} }
fun remoteCalendars(service: Long?): MutableMap<String, CollectionInfo> { fun remoteCalendars(service: Long?): MutableMap<HttpUrl, CollectionInfo> {
val collections = mutableMapOf<String, CollectionInfo>() val collections = mutableMapOf<HttpUrl, CollectionInfo>()
service?.let { service?.let {
db.query(Collections._TABLE, null, db.query(Collections._TABLE, null,
"${Collections.SERVICE_ID}=? AND ${Collections.SUPPORTS_VEVENT}!=0 AND ${Collections.SYNC}", "${Collections.SERVICE_ID}=? AND ${Collections.SUPPORTS_VEVENT}!=0 AND ${Collections.SYNC}",
...@@ -100,7 +101,8 @@ class CalendarsSyncAdapterService: SyncAdapterService() { ...@@ -100,7 +101,8 @@ class CalendarsSyncAdapterService: SyncAdapterService() {
val updateColors = settings.getManageCalendarColors() val updateColors = settings.getManageCalendarColors()
for (calendar in AndroidCalendar.find(account, provider, LocalCalendar.Factory, null, null)) for (calendar in AndroidCalendar.find(account, provider, LocalCalendar.Factory, null, null))
calendar.name?.let { url -> calendar.name?.let {
val url = HttpUrl.parse(it)!!
val info = remote[url] val info = remote[url]
if (info == null) { if (info == null) {
Logger.log.log(Level.INFO, "Deleting obsolete local calendar", url) Logger.log.log(Level.INFO, "Deleting obsolete local calendar", url)
......
...@@ -29,6 +29,7 @@ import at.bitfire.davdroid.settings.ISettings ...@@ -29,6 +29,7 @@ import at.bitfire.davdroid.settings.ISettings
import at.bitfire.davdroid.ui.NotificationUtils import at.bitfire.davdroid.ui.NotificationUtils
import at.bitfire.ical4android.AndroidTaskList import at.bitfire.ical4android.AndroidTaskList
import at.bitfire.ical4android.TaskProvider import at.bitfire.ical4android.TaskProvider
import okhttp3.HttpUrl
import org.dmfs.tasks.contract.TaskContract import org.dmfs.tasks.contract.TaskContract
import java.util.logging.Level import java.util.logging.Level
...@@ -108,8 +109,8 @@ class TasksSyncAdapterService: SyncAdapterService() { ...@@ -108,8 +109,8 @@ class TasksSyncAdapterService: SyncAdapterService() {
null null
} }
fun remoteTaskLists(service: Long?): MutableMap<String, CollectionInfo> { fun remoteTaskLists(service: Long?): MutableMap<HttpUrl, CollectionInfo> {
val collections = mutableMapOf<String, CollectionInfo>() val collections = mutableMapOf<HttpUrl, CollectionInfo>()
service?.let { service?.let {
db.query(Collections._TABLE, null, db.query(Collections._TABLE, null,
"${Collections.SERVICE_ID}=? AND ${Collections.SUPPORTS_VTODO}!=0 AND ${Collections.SYNC}", "${Collections.SERVICE_ID}=? AND ${Collections.SUPPORTS_VTODO}!=0 AND ${Collections.SYNC}",
...@@ -133,7 +134,8 @@ class TasksSyncAdapterService: SyncAdapterService() { ...@@ -133,7 +134,8 @@ class TasksSyncAdapterService: SyncAdapterService() {
val updateColors = settings.getManageCalendarColors() val updateColors = settings.getManageCalendarColors()
for (list in AndroidTaskList.find(account, provider, LocalTaskList.Factory, null, null)) for (list in AndroidTaskList.find(account, provider, LocalTaskList.Factory, null, null))
list.syncId?.let { url -> list.syncId?.let {
val url = HttpUrl.parse(it)!!
val info = remote[url] val info = remote[url]
if (info == null) { if (info == null) {
Logger.log.fine("Deleting obsolete local task list $url") Logger.log.fine("Deleting obsolete local task list $url")
......
...@@ -556,7 +556,7 @@ class AccountActivity: AppCompatActivity(), Toolbar.OnMenuItemClickListener, Pop ...@@ -556,7 +556,7 @@ class AccountActivity: AppCompatActivity(), Toolbar.OnMenuItemClickListener, Pop
checked.isChecked = info.selected checked.isChecked = info.selected
var tv: TextView = v.findViewById(R.id.title) var tv: TextView = v.findViewById(R.id.title)
tv.text = if (!info.displayName.isNullOrBlank()) info.displayName else info.url tv.text = if (!info.displayName.isNullOrBlank()) info.displayName else info.url.toString()
tv = v.findViewById(R.id.description) tv = v.findViewById(R.id.description)
if (info.description.isNullOrBlank()) if (info.description.isNullOrBlank())
...@@ -600,7 +600,7 @@ class AccountActivity: AppCompatActivity(), Toolbar.OnMenuItemClickListener, Pop ...@@ -600,7 +600,7 @@ class AccountActivity: AppCompatActivity(), Toolbar.OnMenuItemClickListener, Pop
} ?: View.INVISIBLE } ?: View.INVISIBLE
var tv: TextView = v.findViewById(R.id.title) var tv: TextView = v.findViewById(R.id.title)
tv.text = if (!info.displayName.isNullOrBlank()) info.displayName else info.url tv.text = if (!info.displayName.isNullOrBlank()) info.displayName else info.url.toString()
tv = v.findViewById(R.id.description) tv = v.findViewById(R.id.description)
if (info.description.isNullOrBlank()) if (info.description.isNullOrBlank())
......
...@@ -67,7 +67,7 @@ class CreateAddressBookActivity: AppCompatActivity(), LoaderManager.LoaderCallba ...@@ -67,7 +67,7 @@ class CreateAddressBookActivity: AppCompatActivity(), LoaderManager.LoaderCallba
var ok = true var ok = true
HttpUrl.parse(homeSet)?.let { HttpUrl.parse(homeSet)?.let {
val info = CollectionInfo(it.resolve(UUID.randomUUID().toString() + "/").toString()) val info = CollectionInfo(it.resolve(UUID.randomUUID().toString() + "/")!!)
info.displayName = display_name.text.toString() info.displayName = display_name.text.toString()
if (info.displayName.isNullOrBlank()) { if (info.displayName.isNullOrBlank()) {
display_name.error = getString(R.string.create_collection_display_name_required) display_name.error = getString(R.string.create_collection_display_name_required)
......
...@@ -78,7 +78,7 @@ class CreateCalendarActivity: AppCompatActivity(), LoaderManager.LoaderCallbacks ...@@ -78,7 +78,7 @@ class CreateCalendarActivity: AppCompatActivity(), LoaderManager.LoaderCallbacks
var ok = true var ok = true
HttpUrl.parse(homeSet)?.let { HttpUrl.parse(homeSet)?.let {
val info = CollectionInfo(it.resolve(UUID.randomUUID().toString() + "/").toString()) val info = CollectionInfo(it.resolve(UUID.randomUUID().toString() + "/")!!)
info.displayName = display_name.text.toString() info.displayName = display_name.text.toString()
if (info.displayName.isNullOrBlank()) { if (info.displayName.isNullOrBlank()) {
display_name.error = getString(R.string.create_collection_display_name_required) display_name.error = getString(R.string.create_collection_display_name_required)
......
...@@ -27,7 +27,6 @@ import at.bitfire.davdroid.log.Logger ...@@ -27,7 +27,6 @@ import at.bitfire.davdroid.log.Logger
import at.bitfire.davdroid.model.CollectionInfo import at.bitfire.davdroid.model.CollectionInfo
import at.bitfire.davdroid.model.ServiceDB import at.bitfire.davdroid.model.ServiceDB
import at.bitfire.davdroid.settings.Settings import at.bitfire.davdroid.settings.Settings
import okhttp3.HttpUrl
import java.io.IOException import java.io.IOException
import java.io.StringWriter import java.io.StringWriter
import java.util.logging.Level import java.util.logging.Level
...@@ -44,7 +43,7 @@ class CreateCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks< ...@@ -44,7 +43,7 @@ class CreateCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks<
val frag = CreateCollectionFragment() val frag = CreateCollectionFragment()
val args = Bundle(2) val args = Bundle(2)
args.putParcelable(ARG_ACCOUNT, account) args.putParcelable(ARG_ACCOUNT, account)
args.putSerializable(ARG_COLLECTION_INFO, info) args.putParcelable(ARG_COLLECTION_INFO, info)
frag.arguments = args frag.arguments = args
return frag return frag
} }
...@@ -59,7 +58,7 @@ class CreateCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks< ...@@ -59,7 +58,7 @@ class CreateCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks<
val args = requireNotNull(arguments) val args = requireNotNull(arguments)
account = args.getParcelable(ARG_ACCOUNT) account = args.getParcelable(ARG_ACCOUNT)
info = args.getSerializable(ARG_COLLECTION_INFO) as CollectionInfo info = args.getParcelable(ARG_COLLECTION_INFO)
loaderManager.initLoader(0, null, this) loaderManager.initLoader(0, null, this)
} }
...@@ -190,7 +189,7 @@ class CreateCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks< ...@@ -190,7 +189,7 @@ class CreateCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks<
.setForeground(true) .setForeground(true)
.build().use { httpClient -> .build().use { httpClient ->
try { try {
val collection = DavResource(httpClient.okHttpClient, HttpUrl.parse(info.url)!!) val collection = DavResource(httpClient.okHttpClient, info.url)
// create collection on remote server // create collection on remote server
collection.mkCol(writer.toString()) collection.mkCol(writer.toString())
......
...@@ -25,7 +25,6 @@ import at.bitfire.davdroid.R ...@@ -25,7 +25,6 @@ import at.bitfire.davdroid.R
import at.bitfire.davdroid.model.CollectionInfo import at.bitfire.davdroid.model.CollectionInfo
import at.bitfire.davdroid.model.ServiceDB import at.bitfire.davdroid.model.ServiceDB
import at.bitfire.davdroid.settings.Settings import at.bitfire.davdroid.settings.Settings
import okhttp3.HttpUrl
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
class DeleteCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks<Exception> { class DeleteCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks<Exception> {
...@@ -89,7 +88,7 @@ class DeleteCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks< ...@@ -89,7 +88,7 @@ class DeleteCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks<
.setForeground(true) .setForeground(true)
.build().use { httpClient -> .build().use { httpClient ->
try { try {
val collection = DavResource(httpClient.okHttpClient, HttpUrl.parse(collectionInfo.url)!!) val collection = DavResource(httpClient.okHttpClient, collectionInfo.url)
// delete collection from server // delete collection from server
collection.delete(null) collection.delete(null)
...@@ -117,7 +116,7 @@ class DeleteCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks< ...@@ -117,7 +116,7 @@ class DeleteCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks<
val frag = ConfirmDeleteCollectionFragment() val frag = ConfirmDeleteCollectionFragment()
val args = Bundle(2) val args = Bundle(2)
args.putParcelable(ARG_ACCOUNT, account) args.putParcelable(ARG_ACCOUNT, account)
args.putSerializable(ARG_COLLECTION_INFO, collectionInfo) args.putParcelable(ARG_COLLECTION_INFO, collectionInfo)
frag.arguments = args frag.arguments = args
return frag return frag
} }
...@@ -125,9 +124,9 @@ class DeleteCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks< ...@@ -125,9 +124,9 @@ class DeleteCollectionFragment: DialogFragment(), LoaderManager.LoaderCallbacks<
} }
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {