Skip to content

Commit

Permalink
Removed byteCountToDisplaySize
Browse files Browse the repository at this point in the history
Signed-off-by: Arnau Mora <[email protected]>
  • Loading branch information
ArnyminerZ committed Jul 15, 2024
1 parent 279db1f commit 3f3bfc0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 21 deletions.
16 changes: 0 additions & 16 deletions lib/src/main/java/at/bitfire/vcard4android/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@ object Utils {
return values
}

fun Long.byteCountToDisplaySize(): String {
val gb = this / 1_073_741_824 // 2^30
if (gb > 0) {
return "$gb GB"
}
val mb = this / 1_048_576 // 2^20
if (mb > 0) {
return "$mb MB"
}
val kb = this / 1024 // 2^10
if (kb > 0) {
return "$kb KB"
}
return "$this B"
}

fun String.capitalize(): String = split(' ').joinToString(" ") { word ->
word.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import at.bitfire.vcard4android.BatchOperation
import at.bitfire.vcard4android.Constants
import at.bitfire.vcard4android.Contact
import at.bitfire.vcard4android.Utils.asSyncAdapter
import at.bitfire.vcard4android.Utils.byteCountToDisplaySize
import java.io.IOException
import java.util.logging.Level

Expand Down Expand Up @@ -56,7 +55,7 @@ class PhotoBuilder(dataRowUri: Uri, rawContactId: Long?, contact: Contact, readO
.appendPath(rawContactId.toString())
.appendPath(RawContacts.DisplayPhoto.CONTENT_DIRECTORY)
.build()
Constants.log.log(Level.FINE, "Writing photo to $uri (${data.size.toLong().byteCountToDisplaySize()})")
Constants.log.log(Level.FINE, "Writing photo to $uri (${data.size} bytes)")
provider.openAssetFile(uri, "w")?.use { fd ->
try {
fd.createOutputStream()?.use { os ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import android.provider.ContactsContract
import android.provider.ContactsContract.CommonDataKinds.Photo
import at.bitfire.vcard4android.Constants
import at.bitfire.vcard4android.Contact
import at.bitfire.vcard4android.Utils.byteCountToDisplaySize
import java.io.ByteArrayOutputStream
import java.io.IOException
import java.util.logging.Level
Expand Down Expand Up @@ -73,7 +72,7 @@ class PhotoHandler(val provider: ContentProviderClient?): DataRowHandler() {
file.createInputStream().use {
// Samsung Android 12 bug: they return a PNG image with MIME type image/jpeg
convertToJpeg(it.readBytes(), 75)?.let { jpeg ->
Constants.log.log(Level.FINE, "Got high-res contact photo (${jpeg.size.toLong().byteCountToDisplaySize()})")
Constants.log.log(Level.FINE, "Got high-res contact photo (${jpeg.size} bytes)")
contact.photo = jpeg
}
}
Expand All @@ -87,7 +86,7 @@ class PhotoHandler(val provider: ContentProviderClient?): DataRowHandler() {
values.getAsByteArray(Photo.PHOTO)?.let { thumbnail ->
// Samsung Android 12 bug: even the thumbnail is a PNG image
convertToJpeg(thumbnail, 95)?.let { jpeg ->
Constants.log.log(Level.FINE, "Got contact photo thumbnail (${jpeg.size.toLong().byteCountToDisplaySize()})")
Constants.log.log(Level.FINE, "Got contact photo thumbnail (${jpeg.size} bytes)")
contact.photo = jpeg
}
}
Expand Down

0 comments on commit 3f3bfc0

Please sign in to comment.