Skip to content

IMLProductDelegate.java

### The MLProduct requires an object that implements the IMLProductDelegate interface. The SDK notifies you of state changes, connection state changes, and audit trail results through this delegate.

To set the delegate, use an MLProduct constructor that takes the delegate as a parameter, or set the delegate directly, e.g:

product.delegate = new MyMLProductImpl()


package com.masterlock.mlbluetoothsdk.Interfaces;

import com.masterlock.mlbluetoothsdk.MLProduct;
import com.masterlock.mlbluetoothsdk.enums.MLBroadcastState;
import com.masterlock.mlbluetoothsdk.lockstate.LockState;
import com.masterlock.mlbluetoothsdk.models.MLFirmwareUpdateStatus;
import com.masterlock.mlbluetoothsdk.models.audittrail.MLAuditTrailEntry;

/**
 * The delegate of an MLProduct implement the MLProductDelegate interface.
 * The product calls the methods of its delegate to indicate changes to its connection state and Bluetooth events.
 */
public interface IMLProductDelegate {
    /**
     * Tells the delegate that the product is connected.
     * @param product
    The MLProduct that connected.
     */
    void didConnect(MLProduct product);

    /**
     * Tells the delegate that the product is disconnected.
     * @param product The MLProduct that disconnected.
     */
    void didDisconnect(MLProduct product);

    /**
     * Tells the delegate that the product could not connect
     * @param toProduct The MLProduct that disconnected.
     */
    void didFailToConnect(MLProduct toProduct, Exception error);

    /**
     *
     * Tells the delegate that the product's state changed
     * SDK will broadcast
     *  MLBroadcastState.awake at 1 second intervals while a session with the lock is open
     *  MLBroadcastState.asleep when a session has ended
     *  MLBroadcastState.firmwareUpdate when a session is in bootloader mode
     * @param product The MLProduct that changed
     * @param newState The new state the lock is in
     */
    void didChangeState(MLProduct product, MLBroadcastState newState);

    /**
     * Tells status when a firmwareUpdate is in progress
     * @param product The MLProduct that is being updated
     * @param status State / PercentComplete / Error for firmware update
     */
    void firmwareUpdateStatusUpdate(MLProduct product, MLFirmwareUpdateStatus status);

    /**
     * The firmware version broadcast by the lock does not match the expected firmware version based
     * on the MLProduct that you have created; Sync your data with ML CPAPI and supply a different MLProduct
     * with updated data.
     * @param product The MLProduct that needs to be updated
     */
    void shouldUpdateProductData(MLProduct product);

    /**
     * called by the SDK with MLAuditTrails Entries that have been successfully uploaded
     * @param product The MLProduct for the lock that the AuditEntries are for
     * @param entries An Array of MLAuditTrailEntry objects that were successfully uploaded
     *                for this MLProduct's lock
     * use didReadAuditEntries to ensure data is returned at read time
     * when the phone is offline
     */
    void didUploadAuditEntries(MLProduct product, MLAuditTrailEntry[] entries);

    /**
     * called by the SDK with MLAuditTrails Entries that have been read from a lock
     * @param product The MLProduct for the lock that the AuditEntries are for
     * @param entries An Array of MLAuditTrailEntry objects that were successfully uploaded
     *                for this MLProduct's lock
     */
    void didReadAuditEntries(MLProduct product, MLAuditTrailEntry[] entries);

    /**
     * called by the SDK when LockState has changed
     * @param product The MLProduct that the change is for
     * @param lockState The value of the new LockState
     *
     */
    void onLockStateChange(MLProduct product, LockState lockState);
}