1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.support.v4.media;
18
19import android.media.browse.MediaBrowser;
20import android.os.Bundle;
21import android.support.annotation.NonNull;
22
23import java.util.List;
24
25class MediaBrowserCompatApi24 {
26    public static Object createSubscriptionCallback(SubscriptionCallback callback) {
27        return new SubscriptionCallbackProxy<>(callback);
28    }
29
30    public static void subscribe(Object browserObj, String parentId, Bundle options,
31            Object subscriptionCallbackObj) {
32        ((MediaBrowser) browserObj).subscribe(parentId, options,
33                (MediaBrowser.SubscriptionCallback) subscriptionCallbackObj);
34    }
35
36    public static void unsubscribe(Object browserObj, String parentId,
37            Object subscriptionCallbackObj) {
38        ((MediaBrowser) browserObj).unsubscribe(parentId,
39                (MediaBrowser.SubscriptionCallback) subscriptionCallbackObj);
40    }
41
42    interface SubscriptionCallback extends MediaBrowserCompatApi21.SubscriptionCallback {
43        void onChildrenLoaded(@NonNull String parentId, List<?> children, @NonNull Bundle options);
44        void onError(@NonNull String parentId, @NonNull  Bundle options);
45    }
46
47    static class SubscriptionCallbackProxy<T extends SubscriptionCallback>
48            extends MediaBrowserCompatApi21.SubscriptionCallbackProxy<T> {
49        public SubscriptionCallbackProxy(T callback) {
50            super(callback);
51        }
52
53        @Override
54        public void onChildrenLoaded(@NonNull String parentId,
55                List<MediaBrowser.MediaItem> children, @NonNull Bundle options) {
56            mSubscriptionCallback.onChildrenLoaded(parentId, children, options);
57        }
58
59        @Override
60        public void onError(@NonNull String parentId, @NonNull Bundle options) {
61            mSubscriptionCallback.onError(parentId, options);
62        }
63    }
64}
65