182cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim/*
2ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * Copyright 2018 The Android Open Source Project
382cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim *
482cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim * Licensed under the Apache License, Version 2.0 (the "License");
582cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim * you may not use this file except in compliance with the License.
682cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim * You may obtain a copy of the License at
782cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim *
882cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim *      http://www.apache.org/licenses/LICENSE-2.0
982cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim *
1082cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim * Unless required by applicable law or agreed to in writing, software
1182cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim * distributed under the License is distributed on an "AS IS" BASIS,
1282cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1382cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim * See the License for the specific language governing permissions and
1482cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim * limitations under the License.
1582cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim */
1682cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim
1724919ee8c30d91ec056cae6c4f578d7007cbe968Aurimas Liutikaspackage android.support.v4.media;
1882cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim
1982cf659fd8dcc28e182274b17a401023ab879deaSungsoo Limimport android.media.browse.MediaBrowser;
2082cf659fd8dcc28e182274b17a401023ab879deaSungsoo Limimport android.os.Parcel;
2189febf83e2bd3720923474006bcdf6c91a3b88f2Aurimas Liutikas
22ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.annotation.NonNull;
23ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.annotation.RequiresApi;
2482cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim
258f886fe8c7e23fe6ccb8734167c960c2ed3429c3Alan Viverette@RequiresApi(23)
2682cf659fd8dcc28e182274b17a401023ab879deaSungsoo Limclass MediaBrowserCompatApi23 {
2782cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim
2882cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim    public static Object createItemCallback(ItemCallback callback) {
2982cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim        return new ItemCallbackProxy<>(callback);
3082cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim    }
3182cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim
3282cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim    public static void getItem(Object browserObj, String mediaId, Object itemCallbackObj) {
3382cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim        ((MediaBrowser) browserObj).getItem(mediaId, ((MediaBrowser.ItemCallback) itemCallbackObj));
3482cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim    }
3582cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim
3682cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim    interface ItemCallback {
3782cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim        void onItemLoaded(Parcel itemParcel);
3882cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim        void onError(@NonNull String itemId);
3982cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim    }
4082cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim
4182cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim    static class ItemCallbackProxy<T extends ItemCallback> extends MediaBrowser.ItemCallback {
4282cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim        protected final T mItemCallback;
4382cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim
4482cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim        public ItemCallbackProxy(T callback) {
4582cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim            mItemCallback = callback;
4682cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim        }
4782cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim
4882cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim        @Override
4982cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim        public void onItemLoaded(MediaBrowser.MediaItem item) {
5017fc09080d4abeacaef1304667dd8d0006c5a3d4Hyundo Moon            if (item == null) {
5117fc09080d4abeacaef1304667dd8d0006c5a3d4Hyundo Moon                mItemCallback.onItemLoaded(null);
5217fc09080d4abeacaef1304667dd8d0006c5a3d4Hyundo Moon            } else {
5317fc09080d4abeacaef1304667dd8d0006c5a3d4Hyundo Moon                Parcel parcel = Parcel.obtain();
5417fc09080d4abeacaef1304667dd8d0006c5a3d4Hyundo Moon                item.writeToParcel(parcel, 0);
5517fc09080d4abeacaef1304667dd8d0006c5a3d4Hyundo Moon                mItemCallback.onItemLoaded(parcel);
5617fc09080d4abeacaef1304667dd8d0006c5a3d4Hyundo Moon            }
5782cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim        }
5882cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim
5982cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim        @Override
6082cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim        public void onError(@NonNull String itemId) {
6182cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim            mItemCallback.onError(itemId);
6282cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim        }
6382cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim    }
640f4ca634bbc43ddff900c35f7d2a43b55d8c830dJake Wharton
650f4ca634bbc43ddff900c35f7d2a43b55d8c830dJake Wharton    private MediaBrowserCompatApi23() {
660f4ca634bbc43ddff900c35f7d2a43b55d8c830dJake Wharton    }
6782cf659fd8dcc28e182274b17a401023ab879deaSungsoo Lim}
68