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 android.support.v17.leanback.widget;
15
16import android.content.Context;
17import android.support.v17.leanback.R;
18import android.view.LayoutInflater;
19import android.view.View;
20import android.view.ViewGroup;
21import android.widget.ImageView;
22
23/**
24 * The presenter displaying a custom action in {@link AbstractMediaItemPresenter}.
25 * This is the default presenter for actions in media rows if no action presenter is provided by the
26 * user.
27 *
28 * Binds to items of type {@link MultiActionsProvider.MultiAction}.
29 */
30class MediaItemActionPresenter extends Presenter {
31
32    MediaItemActionPresenter() {
33    }
34
35    static class ViewHolder extends Presenter.ViewHolder {
36        final ImageView mIcon;
37
38        public ViewHolder(View view) {
39            super(view);
40            mIcon = (ImageView) view.findViewById(R.id.actionIcon);
41        }
42
43        public ImageView getIcon() {
44            return mIcon;
45        }
46    }
47
48    @Override
49    public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
50        Context context = parent.getContext();
51        View actionView = LayoutInflater.from(context).
52                inflate(R.layout.lb_row_media_item_action, parent,
53                        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