import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
+import android.media.MediaLibraryService2.MediaLibrarySession;
+import android.media.MediaSession2.ControllerInfo;
import android.media.update.ApiLoader;
import android.media.update.MediaBrowser2Provider;
import android.os.Bundle;
/**
* Called when there's change in the parent's children.
+ * <p>
+ * This API is called when the library service called
+ * {@link MediaLibrarySession#notifyChildrenChanged(ControllerInfo, String, int, Bundle)} or
+ * {@link MediaLibrarySession#notifyChildrenChanged(String, int, Bundle)} for the parent.
*
* @param parentId parent id that you've specified with {@link #subscribe(String, Bundle)}
- * @param extras extra bundle from the library service
+ * @param childCount number of children
+ * @param extras extra bundle from the library service. Can be differ from extras that
+ * you've specified with {@link #subscribe(String, Bundle)}.
*/
- public void onChildrenChanged(@NonNull String parentId, @Nullable Bundle extras) { }
+ public void onChildrenChanged(@NonNull String parentId, int childCount,
+ @Nullable Bundle extras) { }
/**
* Called when the list of items has been returned by the library service for the previous
/**
* Subscribe to a parent id for the change in its children. When there's a change,
- * {@link BrowserCallback#onChildrenChanged(String, Bundle)} will be called with the bundle
+ * {@link BrowserCallback#onChildrenChanged(String, int, Bundle)} will be called with the bundle
* that you've specified. You should call {@link #getChildren(String, int, int, Bundle)} to get
* the actual contents for the parent.
*
}
/**
- * Notify subscribed controller about change in a parent's children.
+ * Notify the controller of the change in a parent's children.
+ * <p>
+ * If the controller hasn't subscribed to the parent, the API will do nothing.
+ * <p>
+ * Controllers will use {@link MediaBrowser2#getChildren(String, int, int, Bundle)} to get
+ * the list of children.
*
* @param controller controller to notify
- * @param parentId
- * @param extras
+ * @param parentId parent id with changes in its children
+ * @param childCount number of children.
+ * @param extras extra information from session to controller
*/
public void notifyChildrenChanged(@NonNull ControllerInfo controller,
- @NonNull String parentId, @NonNull Bundle extras) {
- mProvider.notifyChildrenChanged_impl(controller, parentId, extras);
+ @NonNull String parentId, int childCount, @Nullable Bundle extras) {
+ mProvider.notifyChildrenChanged_impl(controller, parentId, childCount, extras);
}
/**
- * Notify subscribed controller about change in a parent's children.
+ * Notify all controllers that subscribed to the parent about change in the parent's
+ * children, regardless of the extra bundle supplied by
+ * {@link MediaBrowser2#subscribe(String, Bundle)}.
*
* @param parentId parent id
- * @param extras extra bundle
+ * @param childCount number of children
+ * @param extras extra information from session to controller
*/
// This is for the backward compatibility.
- public void notifyChildrenChanged(@NonNull String parentId, @Nullable Bundle extras) {
- mProvider.notifyChildrenChanged_impl(parentId, extras);
+ public void notifyChildrenChanged(@NonNull String parentId, int childCount,
+ @Nullable Bundle extras) {
+ mProvider.notifyChildrenChanged_impl(parentId, childCount, extras);
}
/**
// Nothing new for now
interface MediaLibrarySessionProvider extends MediaSession2Provider {
- void notifyChildrenChanged_impl(ControllerInfo controller, String parentId, Bundle extras);
- void notifyChildrenChanged_impl(String parentId, Bundle extras);
+ void notifyChildrenChanged_impl(ControllerInfo controller, String parentId,
+ int childCount, Bundle extras);
+ void notifyChildrenChanged_impl(String parentId, int childCount, Bundle extras);
void notifySearchResultChanged_impl(ControllerInfo controller, String query, int itemCount,
Bundle extras);
}