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 com.android.documentsui.dirlist;
18
19import android.content.Context;
20import android.database.Cursor;
21import android.view.View;
22import android.view.ViewGroup;
23import android.widget.Button;
24import android.widget.ImageView;
25import android.widget.TextView;
26
27import com.android.documentsui.R;
28
29/**
30 * RecyclerView.ViewHolder class that displays at the top of the directory list when there
31 * are more information from the Provider.
32 * Used by {@link DirectoryAddonsAdapter}.
33 */
34final class HeaderMessageDocumentHolder extends MessageHolder {
35    private final ImageView mIcon;
36    private final TextView mTextView;
37    private final Button mButton;
38    private Message mMessage;
39
40    public HeaderMessageDocumentHolder(Context context, ViewGroup parent) {
41        super(context, parent, R.layout.item_doc_header_message);
42
43        mIcon = (ImageView) itemView.findViewById(R.id.message_icon);
44        mTextView = (TextView) itemView.findViewById(R.id.message_textview);
45        mButton = (Button) itemView.findViewById(R.id.button_dismiss);
46    }
47
48    public void bind(Message message) {
49        mMessage = message;
50        mButton.setOnClickListener(this::onButtonClick);
51        bind(null, null);
52    }
53
54    private void onButtonClick(View button) {
55        mMessage.runCallback();
56    }
57
58    @Override
59    public void bind(Cursor cursor, String modelId) {
60        mTextView.setText(mMessage.getMessageString());
61        mIcon.setImageDrawable(mMessage.getIcon());
62        if (mMessage.getButtonString() != null) {
63            mButton.setText(mMessage.getButtonString());
64        }
65    }
66}