Ben Lin | 7b38f34 | 2016-12-14 11:52:35 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.documentsui.dirlist; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.database.Cursor; |
| 21 | import android.view.View; |
| 22 | import android.view.ViewGroup; |
| 23 | import android.widget.Button; |
| 24 | import android.widget.ImageView; |
| 25 | import android.widget.TextView; |
| 26 | |
| 27 | import 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 Lin | b62d4e5 | 2016-12-19 12:01:11 -0800 | [diff] [blame] | 34 | final class HeaderMessageDocumentHolder extends MessageHolder { |
Ben Lin | f8f06e9 | 2017-01-27 17:15:48 -0800 | [diff] [blame] | 35 | private final ImageView mIcon; |
| 36 | private final TextView mTextView; |
| 37 | private final Button mButton; |
Ben Lin | 7b38f34 | 2016-12-14 11:52:35 -0800 | [diff] [blame] | 38 | private Message mMessage; |
Ben Lin | 7b38f34 | 2016-12-14 11:52:35 -0800 | [diff] [blame] | 39 | |
Ben Lin | f8f06e9 | 2017-01-27 17:15:48 -0800 | [diff] [blame] | 40 | public HeaderMessageDocumentHolder(Context context, ViewGroup parent) { |
Ben Lin | 7b38f34 | 2016-12-14 11:52:35 -0800 | [diff] [blame] | 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); |
Ben Lin | f8f06e9 | 2017-01-27 17:15:48 -0800 | [diff] [blame] | 45 | mButton = (Button) itemView.findViewById(R.id.button_dismiss); |
Ben Lin | 7b38f34 | 2016-12-14 11:52:35 -0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | public void bind(Message message) { |
| 49 | mMessage = message; |
Ben Lin | f8f06e9 | 2017-01-27 17:15:48 -0800 | [diff] [blame] | 50 | mButton.setOnClickListener(this::onButtonClick); |
Ben Lin | 7b38f34 | 2016-12-14 11:52:35 -0800 | [diff] [blame] | 51 | bind(null, null); |
| 52 | } |
| 53 | |
Ben Lin | f8f06e9 | 2017-01-27 17:15:48 -0800 | [diff] [blame] | 54 | private void onButtonClick(View button) { |
| 55 | mMessage.runCallback(); |
| 56 | } |
| 57 | |
Ben Lin | 7b38f34 | 2016-12-14 11:52:35 -0800 | [diff] [blame] | 58 | @Override |
| 59 | public void bind(Cursor cursor, String modelId) { |
| 60 | mTextView.setText(mMessage.getMessageString()); |
Ben Lin | f8f06e9 | 2017-01-27 17:15:48 -0800 | [diff] [blame] | 61 | mIcon.setImageDrawable(mMessage.getIcon()); |
| 62 | if (mMessage.getButtonString() != null) { |
| 63 | mButton.setText(mMessage.getButtonString()); |
| 64 | } |
Ben Lin | 7b38f34 | 2016-12-14 11:52:35 -0800 | [diff] [blame] | 65 | } |
| 66 | } |