Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.documentsui.dirlist; |
| 18 | |
| 19 | import static com.android.documentsui.model.DocumentInfo.getCursorInt; |
| 20 | import static com.android.documentsui.model.DocumentInfo.getCursorLong; |
| 21 | import static com.android.documentsui.model.DocumentInfo.getCursorString; |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 22 | |
| 23 | import android.content.Context; |
| 24 | import android.database.Cursor; |
| 25 | import android.net.Uri; |
| 26 | import android.provider.DocumentsContract; |
| 27 | import android.provider.DocumentsContract.Document; |
| 28 | import android.text.format.Formatter; |
| 29 | import android.view.View; |
| 30 | import android.view.ViewGroup; |
| 31 | import android.widget.ImageView; |
Steve McKay | 8b8a6fd | 2016-03-01 11:26:00 -0800 | [diff] [blame] | 32 | import android.widget.LinearLayout; |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 33 | import android.widget.TextView; |
| 34 | |
| 35 | import com.android.documentsui.R; |
| 36 | import com.android.documentsui.RootCursorWrapper; |
| 37 | import com.android.documentsui.Shared; |
| 38 | import com.android.documentsui.State; |
| 39 | |
| 40 | final class ListDocumentHolder extends DocumentHolder { |
Ben Kwa | f8a51f6 | 2015-12-22 14:03:30 -0800 | [diff] [blame] | 41 | final TextView mTitle; |
Steve McKay | 8b8a6fd | 2016-03-01 11:26:00 -0800 | [diff] [blame] | 42 | final LinearLayout mDetails; // Container of date/size/summary |
Ben Kwa | f8a51f6 | 2015-12-22 14:03:30 -0800 | [diff] [blame] | 43 | final TextView mDate; |
| 44 | final TextView mSize; |
Steve McKay | 8b8a6fd | 2016-03-01 11:26:00 -0800 | [diff] [blame] | 45 | final TextView mSummary; |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 46 | final ImageView mIconMime; |
| 47 | final ImageView mIconThumb; |
Ben Kwa | ddc3d21 | 2016-01-07 18:50:34 -0800 | [diff] [blame] | 48 | final ImageView mIconCheck; |
Ben Kwa | f8a51f6 | 2015-12-22 14:03:30 -0800 | [diff] [blame] | 49 | final IconHelper mIconHelper; |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 50 | |
Ben Kwa | f8a51f6 | 2015-12-22 14:03:30 -0800 | [diff] [blame] | 51 | public ListDocumentHolder(Context context, ViewGroup parent, IconHelper iconHelper) { |
| 52 | super(context, parent, R.layout.item_doc_list); |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 53 | |
Ben Kwa | f8a51f6 | 2015-12-22 14:03:30 -0800 | [diff] [blame] | 54 | mTitle = (TextView) itemView.findViewById(android.R.id.title); |
Steve McKay | 8b8a6fd | 2016-03-01 11:26:00 -0800 | [diff] [blame] | 55 | mDetails = (LinearLayout) itemView.findViewById(R.id.line2); |
Ben Kwa | f8a51f6 | 2015-12-22 14:03:30 -0800 | [diff] [blame] | 56 | mDate = (TextView) itemView.findViewById(R.id.date); |
| 57 | mSize = (TextView) itemView.findViewById(R.id.size); |
Steve McKay | 8b8a6fd | 2016-03-01 11:26:00 -0800 | [diff] [blame] | 58 | mSummary = (TextView) itemView.findViewById(android.R.id.summary); |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 59 | mIconMime = (ImageView) itemView.findViewById(R.id.icon_mime); |
| 60 | mIconThumb = (ImageView) itemView.findViewById(R.id.icon_thumb); |
Ben Kwa | ddc3d21 | 2016-01-07 18:50:34 -0800 | [diff] [blame] | 61 | mIconCheck = (ImageView) itemView.findViewById(R.id.icon_check); |
Ben Kwa | f8a51f6 | 2015-12-22 14:03:30 -0800 | [diff] [blame] | 62 | |
| 63 | mIconHelper = iconHelper; |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Ben Kwa | ddc3d21 | 2016-01-07 18:50:34 -0800 | [diff] [blame] | 66 | @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 Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 76 | /** |
| 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 McKay | a1f7680 | 2016-02-25 13:34:03 -0800 | [diff] [blame] | 84 | assert(cursor != null); |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 85 | |
Steve McKay | a1f7680 | 2016-02-25 13:34:03 -0800 | [diff] [blame] | 86 | this.modelId = modelId; |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 87 | |
| 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 McKay | 8b8a6fd | 2016-03-01 11:26:00 -0800 | [diff] [blame] | 97 | final boolean isDirectory = Document.MIME_TYPE_DIR.equals(docMimeType); |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 98 | |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 99 | mIconHelper.stopLoading(mIconThumb); |
| 100 | |
| 101 | mIconMime.animate().cancel(); |
Ben Kwa | ddc3d21 | 2016-01-07 18:50:34 -0800 | [diff] [blame] | 102 | mIconMime.setAlpha(1f); |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 103 | mIconThumb.animate().cancel(); |
Ben Kwa | ddc3d21 | 2016-01-07 18:50:34 -0800 | [diff] [blame] | 104 | mIconThumb.setAlpha(0f); |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 105 | |
| 106 | final Uri uri = DocumentsContract.buildDocumentUri(docAuthority, docId); |
Tomasz Mikolajewski | 4e708cb | 2016-02-16 12:28:43 +0900 | [diff] [blame] | 107 | mIconHelper.loadThumbnail(uri, docMimeType, docFlags, docIcon, mIconThumb, mIconMime, null); |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 108 | |
Ben Kwa | a4acc90 | 2016-02-10 15:48:25 -0800 | [diff] [blame] | 109 | mTitle.setText(docDisplayName, TextView.BufferType.SPANNABLE); |
Ben Kwa | f8a51f6 | 2015-12-22 14:03:30 -0800 | [diff] [blame] | 110 | mTitle.setVisibility(View.VISIBLE); |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 111 | |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 112 | |
Steve McKay | 8b8a6fd | 2016-03-01 11:26:00 -0800 | [diff] [blame] | 113 | // Note, we don't show any details for any directory...ever. |
| 114 | if (isDirectory) { |
| 115 | mDetails.setVisibility(View.GONE); |
Ben Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 116 | } else { |
Steve McKay | 8b8a6fd | 2016-03-01 11:26:00 -0800 | [diff] [blame] | 117 | 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 Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 125 | |
Steve McKay | 8b8a6fd | 2016-03-01 11:26:00 -0800 | [diff] [blame] | 126 | 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 Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 142 | } |
| 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 Kwa | d839149 | 2015-12-17 10:37:00 -0800 | [diff] [blame] | 151 | } |
| 152 | } |