Commit eb49dc29 authored by Ricki Hirner's avatar Ricki Hirner

Minor cleanup

parent 4da2606a
Pipeline #21256183 passed with stages
in 2 minutes and 40 seconds
......@@ -29,7 +29,7 @@ class AndroidAddressBookTest {
val permissionRule = GrantPermissionRule.grant(Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS)!!
private val testAccount = Account("AndroidAddressBookTest", "at.bitfire.vcard4android")
lateinit var provider: ContentProviderClient
private lateinit var provider: ContentProviderClient
@Before
fun connect() {
......
......@@ -40,8 +40,8 @@ class AndroidContactTest {
private val testAccount = Account("AndroidContactTest", "at.bitfire.vcard4android")
lateinit var provider: ContentProviderClient
lateinit var addressBook: TestAddressBook
private lateinit var provider: ContentProviderClient
private lateinit var addressBook: TestAddressBook
@Before
fun connect() {
......@@ -127,7 +127,7 @@ class AndroidContactTest {
val vcard = Contact()
vcard.displayName = "Large Transaction (many rows)"
for (i in 0 until 4000)
vcard.emails += LabeledProperty<Email>(Email("test$i@example.com"))
vcard.emails += LabeledProperty(Email("test$i@example.com"))
val contact = AndroidContact(addressBook, vcard, null, null)
contact.add()
......@@ -160,7 +160,7 @@ class AndroidContactTest {
address.label = "My \"Label\"\nLine 2"
address.streetAddress = "Street \"Address\""
val contact = Contact()
contact.addresses += LabeledProperty<Address>(address)
contact.addresses += LabeledProperty(address)
/* label-param = "LABEL=" param-value
* param-values must not contain DQUOTE and should be encoded as defined in RFC 6868
......
......@@ -28,7 +28,7 @@ class AndroidGroupTest {
@Rule
val permissionRule = GrantPermissionRule.grant(Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS)!!
private val testAccount = Account("AndroidContactGroupTest", "at.bitfire.vcard4android")!!
private val testAccount = Account("AndroidContactGroupTest", "at.bitfire.vcard4android")
private lateinit var provider: ContentProviderClient
private lateinit var addressBook: TestAddressBook
......
......@@ -22,8 +22,8 @@ import java.util.*
open class AndroidAddressBook<T1: AndroidContact, T2: AndroidGroup>(
var account: Account,
val provider: ContentProviderClient?,
val contactFactory: AndroidContactFactory<T1>,
val groupFactory: AndroidGroupFactory<T2>
protected val contactFactory: AndroidContactFactory<T1>,
protected val groupFactory: AndroidGroupFactory<T2>
) {
var settings: ContentValues
......@@ -57,7 +57,7 @@ open class AndroidAddressBook<T1: AndroidContact, T2: AndroidGroup>(
var syncState: ByteArray?
get() = ContactsContract.SyncState.get(provider, account)
set(data: ByteArray?) = ContactsContract.SyncState.set(provider, account, data)
set(data) = ContactsContract.SyncState.set(provider, account, data)
fun queryContacts(where: String?, whereArgs: Array<String>?): List<T1> {
......
......@@ -6,7 +6,7 @@
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.vcard4android;
package at.bitfire.vcard4android
import android.content.ContentProviderOperation
import android.content.ContentUris
......
......@@ -67,7 +67,7 @@ class BatchOperation(
try {
val ops = toCPO(start, end)
Constants.log.fine("Running {${ops.size}} operations ($start .. ${end-1})")
Constants.log.fine("Running ${ops.size} operations ($start .. ${end-1})")
val partResults = providerClient.applyBatch(ops)
val n = end - start
......
......@@ -240,9 +240,9 @@ class Contact {
private fun uriToUID(uriString: String?): String? {
if (uriString == null)
return null
try {
return try {
val uri = URI(uriString)
return when {
when {
uri.scheme == null ->
uri.schemeSpecificPart
uri.scheme.equals("urn", true) && uri.schemeSpecificPart.startsWith("uuid:", true) ->
......@@ -252,7 +252,7 @@ class Contact {
}
} catch(e: URISyntaxException) {
Constants.log.warning("Invalid URI for UID: $uriString")
return uriString
uriString
}
}
......@@ -285,7 +285,7 @@ class Contact {
@Throws(IOException::class)
fun write(vCardVersion: VCardVersion, groupMethod: GroupMethod, os: OutputStream) {
var vCard: VCard = VCard()
var vCard = VCard()
try {
unknownProperties?.let { vCard = Ezvcard.parse(unknownProperties).first() }
} catch (e: Exception) {
......@@ -426,16 +426,16 @@ class Contact {
else prop.partialDate?.let { partial ->
// VCard 3: partial date with month and day, but without year
if (partial.date != null && partial.month != null) {
if (partial.year != null)
return if (partial.year != null)
// partial date is a complete date
return prop
prop
else {
// VCard 3: partial date with month and day, but without year
val fakeCal = GregorianCalendar.getInstance()
fakeCal.set(DATE_PARAMETER_OMIT_YEAR_DEFAULT, partial.month - 1, partial.date)
val fakeProp = generator(fakeCal.time)
fakeProp.addParameter(DATE_PARAMETER_OMIT_YEAR, Integer.toString(DATE_PARAMETER_OMIT_YEAR_DEFAULT))
return fakeProp
fakeProp
}
}
}
......
......@@ -33,7 +33,7 @@ class ContactTest {
private fun regenerate(c: Contact, vCardVersion: VCardVersion): Contact {
val os = ByteArrayOutputStream()
c.write(vCardVersion, GroupMethod.CATEGORIES, os)
return Contact.fromReader(InputStreamReader(ByteArrayInputStream(os.toByteArray()), Charsets.UTF_8), null).get(0)
return Contact.fromReader(InputStreamReader(ByteArrayInputStream(os.toByteArray()), Charsets.UTF_8), null).first()
}
private fun toString(c: Contact, groupMethod: GroupMethod, vCardVersion: VCardVersion): String {
......@@ -156,11 +156,11 @@ class ContactTest {
assertFalse(vCard.contains("\nN:"))
// phone number available
c.phoneNumbers += LabeledProperty<Telephone>(Telephone("12345"))
c.phoneNumbers += LabeledProperty(Telephone("12345"))
assertTrue(toString(c, GroupMethod.GROUP_VCARDS, VCardVersion.V3_0).contains("\nFN:12345\r\n"))
// email address available
c.emails += LabeledProperty<Email>(Email("test@example.com"))
c.emails += LabeledProperty(Email("test@example.com"))
assertTrue(toString(c, GroupMethod.GROUP_VCARDS, VCardVersion.V3_0).contains("\nFN:test@example.com\r\n"))
// nick name available
......@@ -173,7 +173,7 @@ class ContactTest {
fun testGenerateLabeledProperty() {
var c = Contact()
c.uid = UUID.randomUUID().toString()
c.phoneNumbers += LabeledProperty<Telephone>(Telephone("12345"), "My Phone")
c.phoneNumbers += LabeledProperty(Telephone("12345"), "My Phone")
val vCard = toString(c, GroupMethod.GROUP_VCARDS, VCardVersion.V3_0)
assertTrue(vCard.contains("\ndavdroid1.TEL:12345\r\n"))
assertTrue(vCard.contains("\ndavdroid1.X-ABLabel:My Phone\r\n"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment