1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
13 */
14package androidx.leanback.widget;
15
16import android.content.Context;
17import android.view.LayoutInflater;
18import android.view.View;
19import android.view.ViewGroup;
20import android.widget.ImageView;
21
22import androidx.leanback.R;
23
24/**
25 * The presenter displaying a custom action in {@link AbstractMediaItemPresenter}.
26 * This is the default presenter for actions in media rows if no action presenter is provided by the
27 * user.
28 *
29 * Binds to items of type {@link MultiActionsProvider.MultiAction}.
30 */
31class MediaItemActionPresenter extends Presenter {
32
33    MediaItemActionPresenter() {
34    }
35
36    static class ViewHolder extends Presenter.ViewHolder {
37        final ImageView mIcon;
38
39        public ViewHolder(View view) {
40            super(view);
41            mIcon = (ImageView) view.findViewById(R.id.actionIcon);
42        }
43
44        public ImageView getIcon() {
45            return mIcon;
46        }
47    }
48
49    @Override
50    public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
51        Context context = parent.getContext();
52        View actionView = LayoutInflater.from(context)
53                .inflate(R.layout.lb_row_media_item_action, parent, false);
54        return new ViewHolder(actionView);
55    }
56
57    @Override
58    public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
59        ViewHolder actionViewHolder = (ViewHolder) viewHolder;
60        MultiActionsProvider.MultiAction action = (MultiActionsProvider.MultiAction) item;
61        actionViewHolder.getIcon().setImageDrawable(action.getCurrentDrawable());
62    }
63
64    @Override
65    public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) {
66    }
67}
68