• 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.text.TextUtils;
22 import android.view.View;
23 import android.view.ViewGroup;
24 import android.widget.ImageView;
25 import android.widget.ProgressBar;
26 import android.widget.TextView;
27 
28 import com.android.documentsui.R;
29 import com.android.documentsui.util.VersionUtils;
30 
31 /**
32  * RecyclerView.ViewHolder class that displays a message when there are no contents
33  * in the directory, whether due to no items, no search results or an error.
34  * Used by {@link DirectoryAddonsAdapter}.
35  */
36 final class InflateMessageDocumentHolder extends MessageHolder {
37     public static final int LAYOUT_CROSS_PROFILE_ERROR = 1;
38 
39     private Message mMessage;
40 
41     private TextView mContentMessage;
42     private ImageView mContentImage;
43 
44     private TextView mCrossProfileTitle;
45     private TextView mCrossProfileMessage;
46     private ImageView mCrossProfileImage;
47     private TextView mCrossProfileButton;
48 
49 
50     private View mContentView;
51     private View mCrossProfileView;
52     private View mCrossProfileContent;
53     private ProgressBar mCrossProfileProgress;
54 
InflateMessageDocumentHolder(Context context, ViewGroup parent)55     public InflateMessageDocumentHolder(Context context, ViewGroup parent) {
56         super(context, parent, R.layout.item_doc_inflated_message);
57         mContentView = itemView.findViewById(R.id.content);
58         mCrossProfileView = itemView.findViewById(R.id.cross_profile);
59         mCrossProfileContent = mCrossProfileView.findViewById(R.id.cross_profile_content);
60         mCrossProfileProgress = mCrossProfileView.findViewById(R.id.cross_profile_progress);
61 
62         mContentMessage = mContentView.findViewById(R.id.message);
63         mContentImage = mContentView.findViewById(R.id.artwork);
64 
65         mCrossProfileTitle = mCrossProfileView.findViewById(R.id.title);
66         mCrossProfileMessage = mCrossProfileView.findViewById(R.id.message);
67         mCrossProfileImage = mCrossProfileView.findViewById(R.id.artwork);
68         mCrossProfileButton = mCrossProfileView.findViewById(R.id.button);
69     }
70 
bind(Message message)71     public void bind(Message message) {
72         mMessage = message;
73         bind(null, null);
74     }
75 
76     @Override
bind(Cursor cursor, String modelId)77     public void bind(Cursor cursor, String modelId) {
78         if (mMessage.getLayout() == LAYOUT_CROSS_PROFILE_ERROR) {
79             bindCrossProfileMessageView();
80         } else {
81             bindContentMessageView();
82         }
83     }
84 
onCrossProfileButtonClick(View button)85     private void onCrossProfileButtonClick(View button) {
86         mCrossProfileContent.setVisibility(View.GONE);
87         mCrossProfileProgress.setVisibility(View.VISIBLE);
88         mMessage.runCallback();
89     }
90 
bindContentMessageView()91     private void bindContentMessageView() {
92         mContentView.setVisibility(View.VISIBLE);
93         mCrossProfileView.setVisibility(View.GONE);
94 
95         mContentMessage.setText(mMessage.getMessageString());
96         mContentImage.setImageDrawable(mMessage.getIcon());
97     }
98 
bindCrossProfileMessageView()99     private void bindCrossProfileMessageView() {
100         mContentView.setVisibility(View.GONE);
101         mCrossProfileView.setVisibility(View.VISIBLE);
102         mCrossProfileContent.setVisibility(View.VISIBLE);
103         mCrossProfileProgress.setVisibility(View.GONE);
104 
105         mCrossProfileTitle.setText(mMessage.getTitleString());
106         if (!TextUtils.isEmpty(mMessage.getMessageString())) {
107             mCrossProfileMessage.setVisibility(View.VISIBLE);
108             mCrossProfileMessage.setText(mMessage.getMessageString());
109         } else {
110             mCrossProfileMessage.setVisibility(View.GONE);
111         }
112         if (VersionUtils.isAtLeastS()) {
113             mCrossProfileImage.setVisibility(View.GONE);
114         } else {
115             mCrossProfileImage.setImageDrawable(mMessage.getIcon());
116         }
117         if (!TextUtils.isEmpty(mMessage.getButtonString())) {
118             mCrossProfileButton.setVisibility(View.VISIBLE);
119             mCrossProfileButton.setText(mMessage.getButtonString());
120             mCrossProfileButton.setOnClickListener(this::onCrossProfileButtonClick);
121         } else {
122             mCrossProfileButton.setVisibility(View.GONE);
123         }
124     }
125 }
126