• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
34 final class HeaderMessageDocumentHolder extends MessageHolder {
35     private final ImageView mIcon;
36     private final TextView mTextView;
37     private final Button mButton;
38     private Message mMessage;
39 
HeaderMessageDocumentHolder(Context context, ViewGroup parent)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 
bind(Message message)48     public void bind(Message message) {
49         mMessage = message;
50         mButton.setOnClickListener(this::onButtonClick);
51         bind(null, null);
52     }
53 
onButtonClick(View button)54     private void onButtonClick(View button) {
55         mMessage.runCallback();
56     }
57 
58     @Override
bind(Cursor cursor, String modelId)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 }