Skip to content

Commit

Permalink
Minor refactoring (#42)
Browse files Browse the repository at this point in the history
* Update libs

* Rename Java directories to Kotlin

* Replace deprecated Logger from Constants

* Remove CodeQL configuration (will use default configuration)
  • Loading branch information
rfc2822 authored Jul 30, 2024
1 parent d5415f2 commit 505848a
Show file tree
Hide file tree
Showing 96 changed files with 147 additions and 140 deletions.
46 changes: 0 additions & 46 deletions .github/workflows/codeql.yml

This file was deleted.

2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
agp = "8.5.1"
androidx-annotation = "1.8.0"
androidx-annotation = "1.8.1"
androidx-test-runner = "1.6.1"
androidx-rest-rules = "1.6.1"
desugar = "2.0.4"
Expand Down
7 changes: 1 addition & 6 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
android {
namespace = "at.bitfire.vcard4android"

compileSdk = 33
compileSdk = 34

defaultConfig {
minSdk = 23 // Android 6
Expand All @@ -28,11 +28,6 @@ android {
jvmToolchain(17)
}

@Suppress("UnstableApiUsage")
buildFeatures {
buildConfig = true
}

buildTypes {
release {
isMinifyEnabled = false
Expand Down
14 changes: 0 additions & 14 deletions lib/src/main/java/at/bitfire/vcard4android/Constants.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@ import android.provider.ContactsContract.RawContacts
import android.provider.ContactsContract.RawContacts.Data
import androidx.annotation.CallSuper
import java.io.FileNotFoundException
import java.util.logging.Logger

open class AndroidGroup(
val addressBook: AndroidAddressBook<out AndroidContact, out AndroidGroup>
) {

companion object {

const val COLUMN_FILENAME = Groups.SOURCE_ID
const val COLUMN_UID = Groups.SYNC1
const val COLUMN_ETAG = Groups.SYNC2

}

protected val logger
get() = Logger.getLogger(javaClass.name)

var id: Long? = null

Expand Down Expand Up @@ -80,19 +86,19 @@ open class AndroidGroup(
arrayOf(GroupMembership.CONTENT_ITEM_TYPE, id.toString()), null)?.use { membershipCursor ->
while (membershipCursor.moveToNext()) {
val contactId = membershipCursor.getLong(0)
Constants.log.fine("Member ID: $contactId")
logger.fine("Member ID: $contactId")

// get UID from the member
addressBook.provider.query(addressBook.syncAdapterURI(ContentUris.withAppendedId(RawContacts.CONTENT_URI, contactId)),
arrayOf(AndroidContact.COLUMN_UID), null, null, null)?.use { rawContactCursor ->
if (rawContactCursor.moveToNext()) {
val uid = rawContactCursor.getString(0)
if (!uid.isNullOrBlank()) {
Constants.log.fine("Found member of group: $uid")
logger.fine("Found member of group: $uid")
// add UID to contact members (vCard MEMBERS field)
contact.members += uid
} else
Constants.log.severe("Couldn't add member $contactId to group contact because it doesn't have an UID (yet)")
logger.severe("Couldn't add member $contactId to group contact because it doesn't have an UID (yet)")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@

package at.bitfire.vcard4android

import android.content.*
import android.content.ContentProviderClient
import android.content.ContentProviderOperation
import android.content.ContentProviderResult
import android.content.ContentUris
import android.content.OperationApplicationException
import android.net.Uri
import android.os.RemoteException
import android.os.TransactionTooLargeException
import java.util.*
import java.util.LinkedList
import java.util.logging.Level
import java.util.logging.Logger

class BatchOperation(
private val providerClient: ContentProviderClient
private val providerClient: ContentProviderClient
) {

companion object {
Expand All @@ -26,7 +31,9 @@ class BatchOperation(

}

internal val queue = LinkedList<CpoBuilder>()
private val logger = Logger.getLogger(javaClass.name)

private val queue = LinkedList<CpoBuilder>()
private var results = arrayOfNulls<ContentProviderResult?>(0)


Expand Down Expand Up @@ -57,10 +64,10 @@ class BatchOperation(
fun commit(): Int {
var affected = 0
if (!queue.isEmpty()) {
if (Constants.log.isLoggable(Level.FINE)) {
Constants.log.log(Level.FINE, "Committing ${queue.size} operations:")
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "Committing ${queue.size} operations:")
for ((idx, op) in queue.withIndex())
Constants.log.log(Level.FINE, "#$idx: ${op.build()}")
logger.log(Level.FINE, "#$idx: ${op.build()}")
}

results = arrayOfNulls(queue.size)
Expand All @@ -71,7 +78,7 @@ class BatchOperation(
result.count != null -> affected += result.count ?: 0
result.uri != null -> affected += 1
}
Constants.log.fine("$affected record(s) affected")
logger.fine("$affected record(s) affected")
}

queue.clear()
Expand Down Expand Up @@ -103,12 +110,12 @@ class BatchOperation(

try {
val ops = toCPO(start, end)
Constants.log.fine("Running ${ops.size} operations ($start .. ${end - 1})")
logger.fine("Running ${ops.size} operations ($start .. ${end - 1})")
val partResults = providerClient.applyBatch(ops)

val n = end - start
if (partResults.size != n)
Constants.log.warning("Batch operation returned only ${partResults.size} instead of $n results")
logger.warning("Batch operation returned only ${partResults.size} instead of $n results")

System.arraycopy(partResults, 0, results, start, partResults.size)

Expand All @@ -123,7 +130,7 @@ class BatchOperation(
// only one operation, can't be split
throw ContactsStorageException("Can't transfer data to content provider (too large data row can't be split)", e)

Constants.log.warning("Transaction too large, splitting (losing atomicity)")
logger.warning("Transaction too large, splitting (losing atomicity)")
val mid = start + (end - start)/2

runBatch(start, mid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,46 @@
package at.bitfire.vcard4android

import at.bitfire.vcard4android.Utils.trimToNull
import at.bitfire.vcard4android.property.*
import at.bitfire.vcard4android.property.CustomScribes.registerCustomScribes
import at.bitfire.vcard4android.property.CustomType
import at.bitfire.vcard4android.property.XAbDate
import at.bitfire.vcard4android.property.XAbLabel
import at.bitfire.vcard4android.property.XAbRelatedNames
import at.bitfire.vcard4android.property.XPhoneticFirstName
import at.bitfire.vcard4android.property.XPhoneticLastName
import at.bitfire.vcard4android.property.XPhoneticMiddleName
import at.bitfire.vcard4android.property.XSip
import ezvcard.Ezvcard
import ezvcard.VCard
import ezvcard.parameter.RelatedType
import ezvcard.property.*
import ezvcard.property.Address
import ezvcard.property.Anniversary
import ezvcard.property.Birthday
import ezvcard.property.Categories
import ezvcard.property.DateOrTimeProperty
import ezvcard.property.Email
import ezvcard.property.FormattedName
import ezvcard.property.Impp
import ezvcard.property.Kind
import ezvcard.property.Label
import ezvcard.property.Logo
import ezvcard.property.Member
import ezvcard.property.Nickname
import ezvcard.property.Note
import ezvcard.property.Organization
import ezvcard.property.Photo
import ezvcard.property.ProductId
import ezvcard.property.Related
import ezvcard.property.Revision
import ezvcard.property.Role
import ezvcard.property.SortString
import ezvcard.property.Sound
import ezvcard.property.Source
import ezvcard.property.StructuredName
import ezvcard.property.Telephone
import ezvcard.property.Title
import ezvcard.property.Uid
import ezvcard.property.Url
import ezvcard.util.PartialDate
import java.net.URI
import java.net.URISyntaxException
Expand All @@ -22,6 +56,7 @@ import java.time.temporal.ChronoField
import java.time.temporal.Temporal
import java.util.UUID
import java.util.logging.Level
import java.util.logging.Logger

/**
* Responsible for converting a specific vCard with a specific version to
Expand All @@ -32,6 +67,9 @@ import java.util.logging.Level
class ContactReader internal constructor(val vCard: VCard, val downloader: Contact.Downloader? = null) {

companion object {

private val logger
get() = Logger.getLogger(ContactReader::class.java.name)

/**
* Maximum size for binary data like LOGO and SOUND data URIs.
Expand Down Expand Up @@ -66,7 +104,7 @@ class ContactReader internal constructor(val vCard: VCard, val downloader: Conta
val date: Temporal? = prop.date

if (arrayOf(ChronoField.YEAR, ChronoField.MONTH_OF_YEAR, ChronoField.DAY_OF_MONTH).any { date?.isSupported(it) == false }) {
Constants.log.log(Level.WARNING, "checkPartialDate: unsupported DateOrTimeProperty", prop)
logger.log(Level.WARNING, "checkPartialDate: unsupported DateOrTimeProperty", prop)
return
}

Expand Down Expand Up @@ -101,7 +139,7 @@ class ContactReader internal constructor(val vCard: VCard, val downloader: Conta
uriString
}
} catch(e: URISyntaxException) {
Constants.log.warning("Invalid URI for UID: $uriString")
logger.warning("Invalid URI for UID: $uriString")
uriString
}

Expand Down Expand Up @@ -288,7 +326,7 @@ class ContactReader internal constructor(val vCard: VCard, val downloader: Conta
}

if (c.uid == null) {
Constants.log.warning("Received vCard without UID, generating new one")
logger.warning("Received vCard without UID, generating new one")
c.uid = UUID.randomUUID().toString()
}

Expand All @@ -308,7 +346,7 @@ class ContactReader internal constructor(val vCard: VCard, val downloader: Conta
.registerCustomScribes()
.go()
} catch(e: Exception) {
Constants.log.log(Level.WARNING, "Couldn't serialize unknown properties, dropping them", e)
logger.log(Level.WARNING, "Couldn't serialize unknown properties, dropping them", e)
}

return c
Expand Down Expand Up @@ -337,7 +375,7 @@ class ContactReader internal constructor(val vCard: VCard, val downloader: Conta

val url = photo.url
if (photo.url != null && downloader != null) {
Constants.log.info("Downloading photo from $url")
logger.info("Downloading photo from $url")
return downloader.download(url, "image/*")
}

Expand Down
Loading

0 comments on commit 505848a

Please sign in to comment.