Skip to content

Android Favorites#

Step 1: Initializing and Using User Favourites Service for handling favourites#

To use the favourites service, you must first initialize it using the FavoritesListV1 class. Here’s how you can perform this initialization:

// Initialize the favoritesListV1 object using the application context
FavoritesListV1 favoritesListV1 = new FavoritesListV1(getApplicationContext());

Initialization:

The FavoritesListV1 constructor initializes the favorites list object using the provided application context.

  • It takes a Context parameter (appContext), which should ideally be the application context to ensure the object has a lifecycle tied to the application rather than an activity or other component.

Error Handling:

  • If an invalid or null appContext is passed, it may result in runtime issues. This should be validated and logged during initialization to avoid crashes or unexpected behavior.

Successful Initialization:

  • Upon successful initialization, the favoritesListV1 object is ready to manage favorite items and perform operations like:

  • Fetching Favorites: Retrieving favorite items from a local database or remote source.

  • Updating Favorites: Adding, editing, or removing items in the favorites list.

Favourite Object Initialization via Seat Pairing#

Initialize the seat pairing service between the passenger’s personal device and the in-flight entertainment (IFE) system. This pairing allows the phone (PED) to interact with the seatback monitor, including managing the media queue.

a.Property Declaration

FavoritesTransferV1 mFavoritesTransfer;

mFavoritesTransfer is declared as a property of the class. This object represents the service responsible for managing the transfer of favorite items between the Passenger Entertainment Device (PED) and the In-Flight Entertainment (IFE) system.

b.Seat Pairing Initialization

The following block initializes the seat pairing service, which is necessary for enabling communication between the PED and the seatback monitor.

SeatPairingV1.initService(this,
        new IInFlightCallback() {
            @Override
            public void onInitServiceComplete(Object o, String s) {
                // If the initialization succeeds, cast the returned object into SeatPairingV1
                mSeatPairingV1 = (SeatPairingV1) o;
                if (mSeatPairingV1 != null) { // Check if mSeatPairingV1 is not null before proceeding with pairing-related operations

                // - Retrieve the current seat pairing status and set listeners for:
                // - Seat remote controller information
                // - Media queue changes
                // - Playback state changes

                // Initialize mFavoritesTransfer to manage the transfer of favorite items
                // between the Passenger Entertainment Device (PED) and the In-Flight Entertainment (IFE) system
                       mFavoritesTransfer = mSeatPairingV1.getFavoritesTransfer();
                }
            }
            @Override
            public void onInitServiceFailed(String s, InFlight.Error error) {
                // Handle initialization failure
            }
        }, new InFlight());

Step 2: Methods for Managing Favourites locally in PED#

Passengers add or remove media items from their favorites list on the PED. These actions remain local until synchronization with the IFE system is triggered.

The FavoriteItem class represents a media item that can be added to a FavoritesListV1 in an inflight entertainment system. It stores metadata like URIs, title, duration, ratings, and playback details while supporting JSON import/export for seamless data transfer.

1. Add single item in favourite list in PED locally :

Method: add(FavoriteItem favoriteItem)

// Create a new FavoriteItem with the media URI
val item = FavoriteItem(media.mediaUri!!)
// Set the content type for the item
item.contentType = media.contentType

// Assign a tag based on content type (either "VIDEO" or "AUDIO")
if (media.contentSubtype != null) {
    item.tag = media.contentSubtype
} else {
    item.tag = TAG_VIDEO
}

// Initialize the FavoritesListV1 object
val favoritesListV1 = FavoritesListV1(context)

// Add the item to the list
favoritesListV1.add(favoriteItems)

// Save the updated list to disk
favoritesListV1.saveToDisk(getApplicationContext());

Description:

The add method adds a single media item to the end of the media queue. Before adding the item, the method checks whether the media content is already present in the Favorites List. If the content is already in the list, it will not be added again, ensuring that the list does not contain duplicate media. The method returns true if the item is successfully added, and false if the content is identical to the existing content in the list.

Parameters:

  • favoriteItem: The media item to be added to the list.

Returns:

  • boolean: true if the item was added, and false if the item was not added due to being a duplicate.

2. Add media items to the favourite list in PED locally :

add(List<FavoriteItem> favoriteItems)

Description:

This method adds multiple new media items to the end of the media queue, ensuring that only unique items are added (i.e., no duplicates). Each item is tagged as either "VIDEO" or "AUDIO" based on its content type. If the content type is not identified as either, the item is tagged as "OTHER". After adding the items, the method returns the number of items successfully added to the list.

Parameters:

  • favoriteItems (List<FavoriteItem>): A list of FavoriteItem objects to be added to the Favorites List.

Returns:

  • int: The number of items successfully added to the Favorites List.

3. Remove single item in favourite list from PED locally :

// Create a new FavoriteItem with the media URI
FavoriteItem item = new FavoriteItem(media.getMediaUri());

// Set the content type for the item
item.setContentType(media.getContentType());

// Initialize the FavoritesListV1 object
FavoritesListV1 favoritesListV1 = new FavoritesListV1(context);

// Add the item to the list
favoritesListV1.add(favoriteItem);

// Save the updated list to disk
favoritesListV1.saveToDisk(getApplicationContext());

// Example 1: Removing a specific FavoriteItem object
boolean removedItem = favoritesListV1.remove(item);
if (removedItem) {
    Log.i(TAG, "Item successfully removed.");
} else {
    Log.w(TAG, "Failed to remove item.");
}

// Example 2: Removing a specific media URI from the list
boolean removedUri = favoritesListV1.remove(media.getMediaUri());
if (removedUri) {
    Log.i(TAG, "Item with URI successfully removed.");
} else {
    Log.w(TAG, "Failed to remove item with URI.");
}

// Example 3: Removing an item by index (e.g., remove the first item)
favoritesListV1.remove(0);
Log.i(TAG, "Item at index 0 successfully removed.");

// Save the updated list to disk after removal
favoritesListV1.saveToDisk(getApplicationContext());

remove(FavoriteItem favoriteItem)

Description:

This method removes a specified media item from the Favorites List. The item is removed based on its reference as an object. If the operation is successful, it returns true; otherwise, it returns false if no changes were made (e.g., item not found).

Parameters:

  • favoriteItem (FavoriteItem): The FavoriteItem object to be removed from the Favorites List.

Returns:

  • boolean: True if the item was successfully removed, False otherwise.

4. Remove single item at index from favourite list from PED locally :

remove(int index)

Description:

This method removes a media item from the Favorites List at a specified index. No value is returned by this method.

Parameters:

  • index (int): The index of the media item to be removed from the Favorites List.

5. Remove single item in favourite list from PED locally by mediaUri : remove(String mediaUri)

Description:

This method removes a media item from the Favorites List based on its media URI. It returns true if the item is removed successfully, otherwise false if no changes were made.

Parameters:

  • mediaUri (String): The URI of the media item to be removed from the Favorites List.

Returns:

  • boolean: True if the item was successfully removed, False otherwise

6. Clear All items in favourite list from PED locally :

clear()

// Initialize the FavoritesListV1 object
FavoritesListV1 favoritesListV1 = new FavoritesListV1(context);

// Clear all media content from the list
favoritesListV1.clear();

// Save the updated (empty) list to disk
favoritesListV1.saveToDisk(getApplicationContext());

This method clears all media content from the Favorites List, effectively resetting the list to an empty state.

  • Return Type: void

  • Parameters: None

  • Description: Removes all media items from the Favorites List. After this operation, the list will be empty.

Steps 3: Methods for Managing Favourites with Seatback Monitor#

When the passenger decides to sync changes, the PED sends a request to the IFE system to add, load, or remove favorite media items, and the IFE system updates its favorites list accordingly.

1. Loading Favourites Items to the Seatback Monitor

public void requestLoadItemsToSeat(JSONArray items, @Nullable JSONObject extras, FavoritesTransferListener listener);

// Create a new FavoriteItem with the media URI
FavoriteItem item = new FavoriteItem(media.getMediaUri());

// Set the content type for the item
item.setContentType(media.getContentType());


// Initialize the FavoritesListV1 object
FavoritesListV1 favoritesListV1 = new FavoritesListV1(context);

// Add the item to the list
favoritesListV1.add(item);

// Prepare the listener for the favorites transfer request
FavoritesTransferListener favListener = new FavoritesTransferListener() {
    @Override
    public void onFavoritesTransferError(Error error) {
        // Handle error during transfer
        Log.e("FavoritesTransfer", "Error during transfer: " + error.getMessage());
    }

    @Override
    public void onFavoritesTransferSuccess(JSONObject response) {
        // Handle successful transfer
        Log.d("FavoritesTransfer", "Favorites transferred successfully: " + response.toString());
    }
};

// Send the request to load items to the seatback monitor
mFavoritesTransfer.requestLoadItemsToSeat(favoritesListV1.toSerializedData(), null, favListener);

This method sends a request to load the favorite media items onto the seatback monitor. It uses a callback listener to handle the result of the operation.

  • Parameters:

  • items (JSONArray): The media content items to be loaded onto the seatback monitor.

  • extras (JSONObject, optional): An optional JSONObject containing additional data that will be passed through to the interactive application.

  • listener (FavoritesTransferListener): A callback listener to handle the success or failure result of the operation.

  • Return Type: void

Description: This method initiates the process of sending media content to the seatback monitor and provides feedback on the outcome through the provided listener.

2. Adding Favourites Items to the Seatback Monitor

public void requestAllItemsFromSeat(@Nullable JSONObject extras, FavoritesTransferListener listener)

// Prepare the listener to handle transfer results
FavoritesTransferListener favListener = new FavoritesTransferListener() {
    @Override
    public void onFavoritesTransferError(Error error) {
        // Handle error during transfer
        Log.e("FavoritesTransfer", "Error during transfer: " + error.getMessage());
    }

    @Override
    public void onFavoritesTransferSuccess(JSONObject response) {
        // Handle successful transfer
        Log.d("FavoritesTransfer", "Favorites added successfully: " + response.toString());
    }
};

// Create a new FavoriteItem with the media URI
FavoriteItem item = new FavoriteItem(media.getMediaUri());

// Set the content type for the item
item.setContentType(media.getContentType());


// Initialize the FavoritesListV1 object
FavoritesListV1 favoritesListV1 = new FavoritesListV1(context);

// Add the item to the list
favoritesListV1.add(item);

// Serialize the Favorites List data
JSONArray favoritesData = favoritesListV1.toSerializedData();

// Send the request to add items to the seatback monitor
mFavoritesTransfer.requestAddItemsToSeat(favoritesData, null, favListener);

Description: This method sends a request to add media items from the Favorites List to the seatback monitor. The Add method differs from Load in that it adds new items to the existing favorites on the seat, while Load clears the seat's current favorites before loading the new list. This method should be called also after receiving the onFavoritesTransferRequestFetchAllReceived(JSONObject) callback from the seat. Once the callback is received, the application can prompt the user to share their Favorites List with the seatback monitor.

Parameters:

  • items: A JSONArray containing the serialized data structure for the Favorites List to be added to the seatback monitor.

  • extras: An optional JSONObject that will be passed to the interactive application.

  • listener: A FavoritesTransferListener callback to handle the result of the request.

3. Removing Favourites Items from the Seatback Monitor

public void requestRemoveItemsFromSeat(JSONArray data, @Nullable JSONObject extras,FavoritesTransferListener listener)

Description: This method sends a request to remove media items from the Favorites List on the seatback monitor. It allows the app to request the seatback monitor to remove selected favorites. This method should be invoked when the application wants to delete certain items from the seat’s favorites list.

Parameters:

  • data: A JSONArray containing the serialized data structure for the Favorites List items to be removed from the seatback monitor.

  • extras: An optional JSONObject that will be passed to the interactive application.

  • listener: A FavoritesTransferListener callback to handle the result of the request.

4. Clearing All Favourites Items from the Seatback Monitor

public void requestClearItemsFromSeat(@Nullable JSONObject extras, FavoritesTransferListener listener)

Description: This method sends a request to remove all media items from the Favorites List on the seatback monitor. It clears the entire list of favorites on the seatback monitor. This method should be invoked when the application wants to clear all the favorites stored on the seat's monitor.

Parameters:

  • extras: An optional JSONObject that will be passed to the interactive application, potentially containing additional data.

  • listener: A FavoritesTransferListener callback to handle the result of the request.

5. Pulling Favorites Items from the Seatback Monitor

public void requestAllItemsFromSeat(@Nullable JSONObject extras, FavoritesTransferListener listener)

// Initialize the listener to handle the transfer results
FavoritesTransferListener favListener = new FavoritesTransferListener() {
    @Override
    public void onFavoritesTransferError(Error error) {
        // Log or display the error during transfer
        Log.e(TAG, "Error fetching favorites: " + error.getErrorMessage());
    }

    @Override
    public void onFavoritesTransferSuccess(JSONObject response) {
        // Log and process the response on successful transfer
        Log.d(TAG, "Successfully fetched favorites: " + response.toString());
    }
};


// Send the request to fetch all items from the seatback monitor
mFavoritesTransfer.requestAllItemsFromSeat(null, favListener);

Description:

This method requests the Favorites List from the seatback monitor and transfers it to the personal electronic device. The Favorites List is sent in serialized form, which can be processed by the application on the personal electronic device. The method allows developers to retrieve and display or manipulate the list of favorites stored on the seatback monitor.

Parameters:

  • extras An optional JSONObject that can contain additional data passed to the interactive application.

  • listener A FavoritesTransferListener instance that handles the results of the transfer operation, including success and error scenarios.

Step 4 : Notifications for syncing Favourites PED and Seat back Monitor#

Here is the explanation of the use case with sample code to illustrate the notification handling and integration between the PED (Personal Electronic Device) and the Seat Back Monitor for managing the favorites list.

Method Signature public void setFavoritesTransferRequestFromSeatListener(FavoritesTransferRequestFromSeatListener listener)

Description:

This method registers a listener to handle operations on the Favorites List triggered by the seatback monitor. These operations include fetching the entire list, adding items, or removing items from the Favorites List on the personal electronic device. The listener provides callbacks when items are added to or removed from the Favorites List on the seatback monitor.

Parameters

  • listener A FavoritesTransferRequestFromSeatListener instance that provides callback methods for various operations initiated by the seatback monitor.

FavoritesTransferRequestFromSeatListener

Description:

Defines callbacks for operations triggered by the seatback monitor to manage the Favorites List on the personal electronic device. The callbacks are invoked when items are added to or removed from the Favorites List on the seatback monitor.

Methods

  1. onFavoritesTransferRequestFetchAllReceived

    • Description: Triggered when the seatback monitor requests the entire Favorites List from the personal electronic device. This allows synchronization of the current Favorites List with the seatback monitor.

    • Parameters:

      • extras: A JSONObject containing additional details about the request
  2. onFavoritesTransferRequestAddItemReceived

    • Description: Triggered when items are added to the Favorites List on the seatback monitor. The personal electronic device receives this request to add corresponding items to its local Favorites List.

    • Parameters:

      • items: A JSONArray containing serialized data structures representing the media items to be added.
  3. onFavoritesTransferRequestRemoveItemReceived

    • Description: Triggered when items are removed from the Favorites List on the seatback monitor. The personal electronic device receives this request to remove corresponding items from its local Favorites List.

    • Parameters:

      • items: A JSONArray containing serialized data structures representing the media items to be removed.
FavoritesTransferRequestFromSeatListener listener = new FavoritesTransferRequestFromSeatListener() {
    @Override
    public void onFavoritesTransferRequestFetchAllReceived(JSONObject extras) {
        Log.d(TAG, "Received fetch all request: " + extras.toString());
        // Handle fetching all items logic
    }

    @Override
    public void onFavoritesTransferRequestAddItemReceived(JSONArray items) {
        Log.d(TAG, "Received add items request: " + items.toString());
        // Handle adding items logic
    }

    @Override
    public void onFavoritesTransferRequestRemoveItemReceived(JSONArray items) {
        Log.d(TAG, "Received remove items request: " + items.toString());
        // Handle removing items logic
    }
};

// Set the listener
mFavoritesTransfer.setFavoritesTransferRequestFromSeatListener(listener);

Version 1.0