blob: 11f9aa710349446c9e225536bfcfb5e55975d4c9 [file] [log] [blame]
Ben Kwad8391492015-12-17 10:37:00 -08001/*
2 * Copyright (C) 2015 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 static com.android.documentsui.model.DocumentInfo.getCursorInt;
20import static com.android.documentsui.model.DocumentInfo.getCursorLong;
21import static com.android.documentsui.model.DocumentInfo.getCursorString;
Ben Kwad8391492015-12-17 10:37:00 -080022
23import android.content.Context;
24import android.database.Cursor;
25import android.net.Uri;
26import android.provider.DocumentsContract;
27import android.provider.DocumentsContract.Document;
28import android.text.format.Formatter;
29import android.view.View;
30import android.view.ViewGroup;
31import android.widget.ImageView;
Steve McKay8b8a6fd2016-03-01 11:26:00 -080032import android.widget.LinearLayout;
Ben Kwad8391492015-12-17 10:37:00 -080033import android.widget.TextView;
34
35import com.android.documentsui.R;
36import com.android.documentsui.RootCursorWrapper;
37import com.android.documentsui.Shared;
38import com.android.documentsui.State;
39
40final class ListDocumentHolder extends DocumentHolder {
Ben Kwaf8a51f62015-12-22 14:03:30 -080041 final TextView mTitle;
Steve McKay8b8a6fd2016-03-01 11:26:00 -080042 final LinearLayout mDetails; // Container of date/size/summary
Ben Kwaf8a51f62015-12-22 14:03:30 -080043 final TextView mDate;
44 final TextView mSize;
Steve McKay8b8a6fd2016-03-01 11:26:00 -080045 final TextView mSummary;
Ben Kwad8391492015-12-17 10:37:00 -080046 final ImageView mIconMime;
47 final ImageView mIconThumb;
Ben Kwaddc3d212016-01-07 18:50:34 -080048 final ImageView mIconCheck;
Ben Kwaf8a51f62015-12-22 14:03:30 -080049 final IconHelper mIconHelper;
Ben Kwad8391492015-12-17 10:37:00 -080050
Ben Kwaf8a51f62015-12-22 14:03:30 -080051 public ListDocumentHolder(Context context, ViewGroup parent, IconHelper iconHelper) {
52 super(context, parent, R.layout.item_doc_list);
Ben Kwad8391492015-12-17 10:37:00 -080053
Ben Kwaf8a51f62015-12-22 14:03:30 -080054 mTitle = (TextView) itemView.findViewById(android.R.id.title);
Steve McKay8b8a6fd2016-03-01 11:26:00 -080055 mDetails = (LinearLayout) itemView.findViewById(R.id.line2);
Ben Kwaf8a51f62015-12-22 14:03:30 -080056 mDate = (TextView) itemView.findViewById(R.id.date);
57 mSize = (TextView) itemView.findViewById(R.id.size);
Steve McKay8b8a6fd2016-03-01 11:26:00 -080058 mSummary = (TextView) itemView.findViewById(android.R.id.summary);
Ben Kwad8391492015-12-17 10:37:00 -080059 mIconMime = (ImageView) itemView.findViewById(R.id.icon_mime);
60 mIconThumb = (ImageView) itemView.findViewById(R.id.icon_thumb);
Ben Kwaddc3d212016-01-07 18:50:34 -080061 mIconCheck = (ImageView) itemView.findViewById(R.id.icon_check);
Ben Kwaf8a51f62015-12-22 14:03:30 -080062
63 mIconHelper = iconHelper;
Ben Kwad8391492015-12-17 10:37:00 -080064 }
65
Ben Kwaddc3d212016-01-07 18:50:34 -080066 @Override
67 public void setSelected(boolean selected) {
68 super.setSelected(selected);
69 float checkAlpha = selected ? 1f : 0f;
70
71 mIconCheck.animate().alpha(checkAlpha).start();
72 mIconMime.animate().alpha(1f - checkAlpha).start();
73 mIconThumb.animate().alpha(1f - checkAlpha).start();
74 }
75
Ben Kwad8391492015-12-17 10:37:00 -080076 /**
77 * Bind this view to the given document for display.
78 * @param cursor Pointing to the item to be bound.
79 * @param modelId The model ID of the item.
80 * @param state Current display state.
81 */
82 @Override
83 public void bind(Cursor cursor, String modelId, State state) {
Steve McKaya1f76802016-02-25 13:34:03 -080084 assert(cursor != null);
Ben Kwad8391492015-12-17 10:37:00 -080085
Steve McKaya1f76802016-02-25 13:34:03 -080086 this.modelId = modelId;
Ben Kwad8391492015-12-17 10:37:00 -080087
88 final String docAuthority = getCursorString(cursor, RootCursorWrapper.COLUMN_AUTHORITY);
89 final String docId = getCursorString(cursor, Document.COLUMN_DOCUMENT_ID);
90 final String docMimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
91 final String docDisplayName = getCursorString(cursor, Document.COLUMN_DISPLAY_NAME);
92 final long docLastModified = getCursorLong(cursor, Document.COLUMN_LAST_MODIFIED);
93 final int docIcon = getCursorInt(cursor, Document.COLUMN_ICON);
94 final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
95 final String docSummary = getCursorString(cursor, Document.COLUMN_SUMMARY);
96 final long docSize = getCursorLong(cursor, Document.COLUMN_SIZE);
Steve McKay8b8a6fd2016-03-01 11:26:00 -080097 final boolean isDirectory = Document.MIME_TYPE_DIR.equals(docMimeType);
Ben Kwad8391492015-12-17 10:37:00 -080098
Ben Kwad8391492015-12-17 10:37:00 -080099 mIconHelper.stopLoading(mIconThumb);
100
101 mIconMime.animate().cancel();
Ben Kwaddc3d212016-01-07 18:50:34 -0800102 mIconMime.setAlpha(1f);
Ben Kwad8391492015-12-17 10:37:00 -0800103 mIconThumb.animate().cancel();
Ben Kwaddc3d212016-01-07 18:50:34 -0800104 mIconThumb.setAlpha(0f);
Ben Kwad8391492015-12-17 10:37:00 -0800105
106 final Uri uri = DocumentsContract.buildDocumentUri(docAuthority, docId);
Tomasz Mikolajewski4e708cb2016-02-16 12:28:43 +0900107 mIconHelper.loadThumbnail(uri, docMimeType, docFlags, docIcon, mIconThumb, mIconMime, null);
Ben Kwad8391492015-12-17 10:37:00 -0800108
Ben Kwaa4acc902016-02-10 15:48:25 -0800109 mTitle.setText(docDisplayName, TextView.BufferType.SPANNABLE);
Ben Kwaf8a51f62015-12-22 14:03:30 -0800110 mTitle.setVisibility(View.VISIBLE);
Ben Kwad8391492015-12-17 10:37:00 -0800111
Ben Kwad8391492015-12-17 10:37:00 -0800112
Steve McKay8b8a6fd2016-03-01 11:26:00 -0800113 // Note, we don't show any details for any directory...ever.
114 if (isDirectory) {
115 mDetails.setVisibility(View.GONE);
Ben Kwad8391492015-12-17 10:37:00 -0800116 } else {
Steve McKay8b8a6fd2016-03-01 11:26:00 -0800117 boolean hasDetails = false;
118 if (docSummary != null) {
119 hasDetails = true;
120 mSummary.setText(docSummary);
121 mSummary.setVisibility(View.VISIBLE);
122 } else {
123 mSummary.setVisibility(View.INVISIBLE);
124 }
Ben Kwad8391492015-12-17 10:37:00 -0800125
Steve McKay8b8a6fd2016-03-01 11:26:00 -0800126 if (docLastModified == -1) {
127 hasDetails = true;
128 mDate.setText(null);
129 } else {
130 mDate.setText(Shared.formatTime(mContext, docLastModified));
131 }
132
133 if (!state.showSize || docSize == -1) {
134 hasDetails = true;
135 mSize.setVisibility(View.GONE);
136 mDetails.setVisibility(View.GONE);
137 } else {
138 mSize.setVisibility(View.VISIBLE);
139 mSize.setText(Formatter.formatFileSize(mContext, docSize));
140 }
141 mDetails.setVisibility(hasDetails ? View.VISIBLE : View.GONE);
Ben Kwad8391492015-12-17 10:37:00 -0800142 }
143 }
144
145 @Override
146 public void setEnabled(boolean enabled) {
147 super.setEnabled(enabled);
148 final float iconAlpha = enabled ? 1f : 0.5f;
149 mIconMime.setAlpha(iconAlpha);
150 mIconThumb.setAlpha(iconAlpha);
Ben Kwad8391492015-12-17 10:37:00 -0800151 }
152}