Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from brightec/task/#8
Browse files Browse the repository at this point in the history
Task/#8
  • Loading branch information
NickHolcombe authored Apr 1, 2019
2 parents 5bacb27 + 8400d30 commit 8b7c330
Show file tree
Hide file tree
Showing 13 changed files with 396 additions and 17 deletions.
68 changes: 51 additions & 17 deletions kbarcode/src/main/java/uk/co/brightec/kbarcode/Barcode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,62 @@ import android.graphics.Point
import android.graphics.Rect
import androidx.annotation.IntDef
import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode
import uk.co.brightec.kbarcode.model.CalendarEvent
import uk.co.brightec.kbarcode.model.ContactInfo
import uk.co.brightec.kbarcode.model.DrivingLicense
import uk.co.brightec.kbarcode.model.Email
import uk.co.brightec.kbarcode.model.GeoPoint
import uk.co.brightec.kbarcode.model.Phone
import uk.co.brightec.kbarcode.model.Sms
import uk.co.brightec.kbarcode.model.UrlBookmark
import uk.co.brightec.kbarcode.model.WiFi
import uk.co.brightec.kbarcode.model.convert
import uk.co.brightec.kbarcode.util.OpenForTesting

@Suppress("unused") // API class
/**
* Main data class to represent a barcode
*
* This class wraps the underlying FirebaseVisionBarcode
* https://firebase.google.com/docs/reference/android/com/google/firebase/ml/vision/barcode/FirebaseVisionBarcode
*/
@OpenForTesting
data class Barcode internal constructor(
private val fbBarcode: FirebaseVisionBarcode
) {

val boundingBox: Rect?
get() = fbBarcode.boundingBox
val cornerPoints: Array<Point>?
get() = fbBarcode.cornerPoints
val displayValue: String?
get() = fbBarcode.displayValue
data class Barcode(
val boundingBox: Rect?,
val calendarEvent: CalendarEvent?,
val contactInfo: ContactInfo?,
val cornerPoints: List<Point>?,
val displayValue: String?,
val driverLicense: DrivingLicense?,
val email: Email?,
@BarcodeFormat
val format: Int
get() = fbBarcode.format
val rawValue: String?
get() = fbBarcode.rawValue
val format: Int,
val geoPoint: GeoPoint?,
val phone: Phone?,
val rawValue: String?,
val sms: Sms?,
val url: UrlBookmark?,
@BarcodeValueType
val valueType: Int
get() = fbBarcode.valueType
val valueType: Int,
val wifi: WiFi?
) {

internal constructor(fbBarcode: FirebaseVisionBarcode) : this(
boundingBox = fbBarcode.boundingBox,
calendarEvent = fbBarcode.calendarEvent?.convert(),
contactInfo = fbBarcode.contactInfo?.convert(),
cornerPoints = fbBarcode.cornerPoints?.toList(),
displayValue = fbBarcode.displayValue,
driverLicense = fbBarcode.driverLicense?.convert(),
email = fbBarcode.email?.convert(),
format = fbBarcode.format,
geoPoint = fbBarcode.geoPoint?.convert(),
phone = fbBarcode.phone?.convert(),
rawValue = fbBarcode.rawValue,
sms = fbBarcode.sms?.convert(),
url = fbBarcode.url?.convert(),
valueType = fbBarcode.valueType,
wifi = fbBarcode.wifi?.convert()
)

override fun toString() = displayValue ?: super.toString()

Expand Down
34 changes: 34 additions & 0 deletions kbarcode/src/main/java/uk/co/brightec/kbarcode/model/Address.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package uk.co.brightec.kbarcode.model

import androidx.annotation.IntDef
import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode

data class Address(
val addressLines: List<String>,
@AddressType
val type: Int
) {

internal constructor(fbAddress: FirebaseVisionBarcode.Address) : this(
addressLines = fbAddress.addressLines.toList(),
type = fbAddress.type
)

companion object {

const val TYPE_HOME =
FirebaseVisionBarcode.Address.TYPE_HOME
const val TYPE_UNKNOWN =
FirebaseVisionBarcode.Address.TYPE_UNKNOWN
const val TYPE_WORK =
FirebaseVisionBarcode.Address.TYPE_WORK

@IntDef(
TYPE_HOME,
TYPE_UNKNOWN,
TYPE_WORK
)
@Retention(AnnotationRetention.SOURCE)
annotation class AddressType
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package uk.co.brightec.kbarcode.model

import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode

data class CalendarDateTime(
val day: Int,
val hours: Int,
val minutes: Int,
val month: Int,
val rawValue: String?,
val seconds: Int,
val year: Int,
val isUtc: Boolean
) {

internal constructor(fbDateTime: FirebaseVisionBarcode.CalendarDateTime) : this(
day = fbDateTime.day,
hours = fbDateTime.hours,
minutes = fbDateTime.minutes,
month = fbDateTime.month,
rawValue = fbDateTime.rawValue,
seconds = fbDateTime.seconds,
year = fbDateTime.year,
isUtc = fbDateTime.isUtc
)
}

internal fun FirebaseVisionBarcode.CalendarDateTime.convert() = CalendarDateTime(this)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package uk.co.brightec.kbarcode.model

import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode

data class CalendarEvent(
val description: String?,
val end: CalendarDateTime?,
val location: String?,
val organizer: String?,
val start: CalendarDateTime?,
val status: String?,
val summary: String?
) {

internal constructor(fbEvent: FirebaseVisionBarcode.CalendarEvent) : this(
description = fbEvent.description,
end = fbEvent.end?.convert(),
location = fbEvent.location,
organizer = fbEvent.organizer,
start = fbEvent.start?.convert(),
status = fbEvent.status,
summary = fbEvent.summary
)
}

internal fun FirebaseVisionBarcode.CalendarEvent.convert() = CalendarEvent(this)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package uk.co.brightec.kbarcode.model

import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode

data class ContactInfo(
val addresses: List<Address>,
val emails: List<Email>,
val name: PersonName?,
val organization: String?,
val phones: List<Phone>,
val title: String?,
val urls: List<String>?
) {

internal constructor(fbEvent: FirebaseVisionBarcode.ContactInfo) : this(
addresses = fbEvent.addresses.map { Address(it) },
emails = fbEvent.emails.map { Email(it) },
name = fbEvent.name?.convert(),
organization = fbEvent.organization,
phones = fbEvent.phones.map { Phone(it) },
title = fbEvent.title,
urls = fbEvent.urls?.toList()
)
}

internal fun FirebaseVisionBarcode.ContactInfo.convert() = ContactInfo(this)
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package uk.co.brightec.kbarcode.model

import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode

data class DrivingLicense(
val addressCity: String?,
val addressState: String?,
val addressStreet: String?,
val addressZip: String?,
val birthDate: String?,
val documentType: String?,
val expiryDate: String?,
val firstName: String?,
val gender: String?,
val issueDate: String?,
val issuingCountry: String?,
val lastName: String?,
val licenseNumber: String?,
val middleName: String?
) {

internal constructor(fbDrivingLicense: FirebaseVisionBarcode.DriverLicense) : this(
addressCity = fbDrivingLicense.addressCity,
addressState = fbDrivingLicense.addressState,
addressStreet = fbDrivingLicense.addressStreet,
addressZip = fbDrivingLicense.addressZip,
birthDate = fbDrivingLicense.birthDate,
documentType = fbDrivingLicense.documentType,
expiryDate = fbDrivingLicense.expiryDate,
firstName = fbDrivingLicense.firstName,
gender = fbDrivingLicense.gender,
issueDate = fbDrivingLicense.issueDate,
issuingCountry = fbDrivingLicense.issuingCountry,
lastName = fbDrivingLicense.lastName,
licenseNumber = fbDrivingLicense.licenseNumber,
middleName = fbDrivingLicense.middleName
)
}

internal fun FirebaseVisionBarcode.DriverLicense.convert() = DrivingLicense(this)
40 changes: 40 additions & 0 deletions kbarcode/src/main/java/uk/co/brightec/kbarcode/model/Email.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package uk.co.brightec.kbarcode.model

import androidx.annotation.IntDef
import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode

data class Email(
val address: String?,
val body: String?,
val subject: String?,
@EmailType
val type: Int
) {

internal constructor(fbEmail: FirebaseVisionBarcode.Email) : this(
address = fbEmail.address,
body = fbEmail.body,
subject = fbEmail.subject,
type = fbEmail.type
)

companion object {

const val TYPE_HOME =
FirebaseVisionBarcode.Email.TYPE_HOME
const val TYPE_UNKNOWN =
FirebaseVisionBarcode.Email.TYPE_UNKNOWN
const val TYPE_WORK =
FirebaseVisionBarcode.Email.TYPE_WORK

@IntDef(
TYPE_HOME,
TYPE_UNKNOWN,
TYPE_WORK
)
@Retention(AnnotationRetention.SOURCE)
annotation class EmailType
}
}

internal fun FirebaseVisionBarcode.Email.convert() = Email(this)
16 changes: 16 additions & 0 deletions kbarcode/src/main/java/uk/co/brightec/kbarcode/model/GeoPoint.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package uk.co.brightec.kbarcode.model

import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode

data class GeoPoint(
val lat: Double,
val lng: Double
) {

internal constructor(fbGeoPoint: FirebaseVisionBarcode.GeoPoint) : this(
lat = fbGeoPoint.lat,
lng = fbGeoPoint.lng
)
}

internal fun FirebaseVisionBarcode.GeoPoint.convert() = GeoPoint(this)
26 changes: 26 additions & 0 deletions kbarcode/src/main/java/uk/co/brightec/kbarcode/model/PersonName.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package uk.co.brightec.kbarcode.model

import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode

data class PersonName(
val first: String?,
val formattedName: String?,
val last: String?,
val middle: String?,
val prefix: String?,
val pronunciation: String?,
val suffix: String?
) {

internal constructor(fbPersonName: FirebaseVisionBarcode.PersonName) : this(
first = fbPersonName.first,
formattedName = fbPersonName.formattedName,
last = fbPersonName.last,
middle = fbPersonName.middle,
prefix = fbPersonName.prefix,
pronunciation = fbPersonName.pronunciation,
suffix = fbPersonName.suffix
)
}

internal fun FirebaseVisionBarcode.PersonName.convert() = PersonName(this)
42 changes: 42 additions & 0 deletions kbarcode/src/main/java/uk/co/brightec/kbarcode/model/Phone.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package uk.co.brightec.kbarcode.model

import androidx.annotation.IntDef
import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode

data class Phone(
val number: String?,
@PhoneType
val type: Int
) {

internal constructor(fbPhone: FirebaseVisionBarcode.Phone) : this(
number = fbPhone.number,
type = fbPhone.type
)

companion object {

const val TYPE_FAX =
FirebaseVisionBarcode.Phone.TYPE_FAX
const val TYPE_HOME =
FirebaseVisionBarcode.Phone.TYPE_HOME
const val TYPE_MOBILE =
FirebaseVisionBarcode.Phone.TYPE_MOBILE
const val TYPE_UNKNOWN =
FirebaseVisionBarcode.Phone.TYPE_UNKNOWN
const val TYPE_WORK =
FirebaseVisionBarcode.Phone.TYPE_WORK

@IntDef(
TYPE_FAX,
TYPE_HOME,
TYPE_MOBILE,
TYPE_UNKNOWN,
TYPE_WORK
)
@Retention(AnnotationRetention.SOURCE)
annotation class PhoneType
}
}

internal fun FirebaseVisionBarcode.Phone.convert() = Phone(this)
16 changes: 16 additions & 0 deletions kbarcode/src/main/java/uk/co/brightec/kbarcode/model/Sms.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package uk.co.brightec.kbarcode.model

import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode

data class Sms(
val message: String?,
val phoneNumber: String?
) {

internal constructor(fbSms: FirebaseVisionBarcode.Sms) : this(
message = fbSms.message,
phoneNumber = fbSms.phoneNumber
)
}

internal fun FirebaseVisionBarcode.Sms.convert() = Sms(this)
Loading

0 comments on commit 8b7c330

Please sign in to comment.