# 1.16 -> 1.17

## Breaking Changes

In 1.17 release, listed are the breaking changes

1. Removed **`interface Callback<T>`** in favour of Kotlin lambda functions.
2. Removed **`interface ResultCallback<T>`** in favour of Kotlin lambda functions.
3. Migrated **`interface MonitorCallbacks`** to Kotlin which changes the way to access below members while inheriting/implementing the interface.

   ```kotlin
   CONFIDENCE_LOW, CONFIDENCE_MID, CONFIDENCE_HIGH
   ```

## Migrating Your Code

### Updating Callback interface with a lambda function

1. **Remove** the following imports

   ```kotlin
   import com.intellimec.mobile.android.common.Callback
   ```
2. **Update** the code to lambda

   ```kotlin
   // SDK 1.16
   Callback<T>

   // SDK 1.17
   (T) -> Unit)
   ```

The following shows typical code from SDK `1.16`

```kotlin
// SDK 1.16
override var tripStatusCallback: Callback<Status>

tripStatusCallback.execute(Status.from(tdStatus))
```

Instead of **`Callback<Status>`** we will pass a lambda functio&#x6E;**`((Status) -> Unit)`**

The following is the migrated version of above code to SDK `1.17`

<pre class="language-kotlin"><code class="lang-kotlin"><strong>// SDK 1.17
</strong> override var tripStatusCallback: ((Status) -> Unit)

 tripStatusCallback(Status.from(tdStatus))
</code></pre>

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.

```kotlin
// 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

1. **Remove** the following imports

   ```kotlin
   import com.intellimec.mobile.android.common.ResultCallback
   ```
2. **Update** the code to lambda

   ```kotlin
   // SDK 1.16
   ResultCallback<T>

   // SDK 1.17
   (Result<T>) -> Unit)
   ```

The following shows typical code from SDK `1.16`

```kotlin
// 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`

<pre class="language-kotlin"><code class="lang-kotlin"><strong>// SDK 1.17
</strong>override fun sign(unsignedToken: String, callback: ((Result&#x3C;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))
            }
        }
</code></pre>

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.

```kotlin
// 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_HIGH
```

**Solution:**

* import the reference directly

  ```kotlin
  import com.intellimec.mobile.android.tripdetection.MonitorCallbacks.Companion.CONFIDENCE_HIGH
  ```

OR

* Access using&#x20;

  ```
  MonitorCallbacks.CONFIDENCE_HIGH
  ```

The following shows typical code from SDK `1.16`

```kotlin
// 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`&#x20;

```kotlin
// 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
        }
    }
}
```
