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