blob: a0e6dc1413a522adb865dc9f3f47e7bcab60ffac [file] [log] [blame]
Ben Lin7b38f342016-12-14 11:52:35 -08001/*
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 */
Ben Linb62d4e52016-12-19 12:01:11 -080034final class HeaderMessageDocumentHolder extends MessageHolder {
Ben Linf8f06e92017-01-27 17:15:48 -080035 private final ImageView mIcon;
36 private final TextView mTextView;
37 private final Button mButton;
Ben Lin7b38f342016-12-14 11:52:35 -080038 private Message mMessage;
Ben Lin7b38f342016-12-14 11:52:35 -080039
Ben Linf8f06e92017-01-27 17:15:48 -080040 public HeaderMessageDocumentHolder(Context context, ViewGroup parent) {
Ben Lin7b38f342016-12-14 11:52:35 -080041 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);
Ben Linf8f06e92017-01-27 17:15:48 -080045 mButton = (Button) itemView.findViewById(R.id.button_dismiss);
Ben Lin7b38f342016-12-14 11:52:35 -080046 }
47
48 public void bind(Message message) {
49 mMessage = message;
Ben Linf8f06e92017-01-27 17:15:48 -080050 mButton.setOnClickListener(this::onButtonClick);
Ben Lin7b38f342016-12-14 11:52:35 -080051 bind(null, null);
52 }
53
Ben Linf8f06e92017-01-27 17:15:48 -080054 private void onButtonClick(View button) {
55 mMessage.runCallback();
56 }
57
Ben Lin7b38f342016-12-14 11:52:35 -080058 @Override
59 public void bind(Cursor cursor, String modelId) {
60 mTextView.setText(mMessage.getMessageString());
Ben Linf8f06e92017-01-27 17:15:48 -080061 mIcon.setImageDrawable(mMessage.getIcon());
62 if (mMessage.getButtonString() != null) {
63 mButton.setText(mMessage.getButtonString());
64 }
Ben Lin7b38f342016-12-14 11:52:35 -080065 }
66}