1.16 -> 1.17
Breaking Changes
In 1.17 release, listed are the breaking changes
Removed
interface Callback<T>in favour of Kotlin lambda functions.Removed
interface ResultCallback<T>in favour of Kotlin lambda functions.Migrated
interface MonitorCallbacksto Kotlin which changes the way to access below members while inheriting/implementing the interface.CONFIDENCE_LOW, CONFIDENCE_MID, CONFIDENCE_HIGH
Migrating Your Code
Updating Callback interface with a lambda function
Remove the following imports
import com.intellimec.mobile.android.common.CallbackUpdate the code to lambda
// SDK 1.16 Callback<T> // SDK 1.17 (T) -> Unit)
The following shows typical code from SDK 1.16
// SDK 1.16
override var tripStatusCallback: Callback<Status>
tripStatusCallback.execute(Status.from(tdStatus))Instead of Callback<Status> we will pass a lambda function((Status) -> Unit)
The following is the migrated version of above code to SDK 1.17
// SDK 1.17
override var tripStatusCallback: ((Status) -> Unit)
tripStatusCallback(Status.from(tdStatus))Basically swap Callback<Status> with a lambda which takes a Status type parameter and returns Unit and remove the .execute call and directly call the lambda.
You could also call the lambda like tripStatusCallback?.invoke(Status.from(tdStatus)) in case if callback is nullable. Below is the example for the same.
// SDK 1.17
// The callback parameter is nullable
override var tripStatusCallback: Callback<Status>? = null
tripStatusCallback?.invoke(Status.from(tdStatus))Updating ResultCallback interface with a lambda function
Remove the following imports
import com.intellimec.mobile.android.common.ResultCallbackUpdate the code to lambda
// SDK 1.16 ResultCallback<T> // SDK 1.17 (Result<T>) -> Unit)
The following shows typical code from SDK 1.16
// SDK 1.16
override fun sign(unsignedToken: String, callback: ResultCallback<String>) {
val components = unsignedToken.split(".")
if ((components.size != 2) || (privateKey == null)) {
callback.execute(Result.Failure(Throwable()))
} else {
val signedToken = Jwts.builder()
.setHeaderParams(decode(components[0]))
.setClaims(decode(components[1]))
.signWith(SignatureAlgorithm.RS256, privateKey)
.compact()
callback.execute(Result.Success(signedToken))
}
}Instead of ResultCallback<String> we will pass a lambda (Result<T>) -> Unit)
The following is the migrated version of above code to SDK 1.17
// SDK 1.17
override fun sign(unsignedToken: String, callback: ((Result<String>) -> Unit)) {
val components = unsignedToken.split(".")
if ((components.size != 2) || (privateKey == null)) {
callback(Result.Failure(Throwable()))
} else {
val signedToken = Jwts.builder()
.setHeaderParams(decode(components[0]))
.setClaims(decode(components[1]))
.signWith(SignatureAlgorithm.RS256, privateKey)
.compact()
callback(Result.Success(signedToken))
}
}Basically swap ResultCallback<String> with a lambda which takes a Result<String> type parameter and returns Unit and remove the .execute call and directly call the lambda.
You could also call the lambda like callback?.invoke(Result.Success(signedToken)) in case if callback is nullable. Below is the example for the same.
// SDK 1.17
// The callback parameter is nullable
override fun sign(unsignedToken: String, callback: ((Result<String>) -> Unit)?) {
val components = unsignedToken.split(".")
if ((components.size != 2) || (privateKey == null)) {
callback?.invoke(Result.Failure(Throwable()))
} else {
val signedToken = Jwts.builder()
.setHeaderParams(decode(components[0]))
.setClaims(decode(components[1]))
.signWith(SignatureAlgorithm.RS256, privateKey)
.compact()
callback?.invoke(Result.Success(signedToken))
}
}Accessing members from MonitorCallbacks
This only affects you, if you’re inheriting/implementing the MonitorCallbacks interface.
If you are inheriting/implementing the interface MonitorCallbacks , you won't be able to access the following members directly in the child class.
CONFIDENCE_LOW, CONFIDENCE_MID, CONFIDENCE_HIGHSolution:
import the reference directly
import com.intellimec.mobile.android.tripdetection.MonitorCallbacks.Companion.CONFIDENCE_HIGH
OR
Access using
MonitorCallbacks.CONFIDENCE_HIGH
The following shows typical code from SDK 1.16
// SDK 1.16
internal class MotionMonitor : MonitorCallbacks {
....
// other overrides
....
fun detectMotion(confidence: Int ){
if(confidence == CONFIDENCE_HIGH){
// do something
}
}
}The following is the migrated version of above code to SDK 1.17
// SDK 1.17
import com.intellimec.mobile.android.tripdetection.MonitorCallbacks.Companion.CONFIDENCE_HIGH
internal class MotionMonitor : MonitorCallbacks {
....
// other overrides
....
fun detectMotion(confidence: Int ){
// accessing using import
if(confidence == CONFIDENCE_HIGH){
// do something
}
// accessing using interface name
else if(confidence == MonitorCallbacks.CONFIDENCE_MID){
// do something else
}
}
}Last updated