blob: 5a6060ac44673a4e7611b4e004f5a5393989df76 [file] [log] [blame]
Jeff Sharkeye22d02e2013-04-26 16:54:55 -07001/*
2 * Copyright (C) 2013 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;
18
Jeff Sharkey09c10bf2013-06-30 20:02:59 -070019import android.app.Fragment;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070020import android.app.FragmentManager;
21import android.app.FragmentTransaction;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070022import android.app.LoaderManager.LoaderCallbacks;
23import android.content.Context;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070024import android.content.Loader;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070025import android.net.Uri;
26import android.os.Bundle;
27import android.provider.DocumentsContract;
Jeff Sharkey09c10bf2013-06-30 20:02:59 -070028import android.text.format.DateUtils;
Jeff Sharkey2e694f82013-08-06 16:26:14 -070029import android.text.format.Formatter;
Jeff Sharkeyc317af82013-07-01 16:56:54 -070030import android.util.SparseBooleanArray;
31import android.view.ActionMode;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070032import android.view.LayoutInflater;
Jeff Sharkey09c10bf2013-06-30 20:02:59 -070033import android.view.Menu;
Jeff Sharkey09c10bf2013-06-30 20:02:59 -070034import android.view.MenuItem;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070035import android.view.View;
36import android.view.ViewGroup;
Jeff Sharkeyc317af82013-07-01 16:56:54 -070037import android.widget.AbsListView;
38import android.widget.AbsListView.MultiChoiceModeListener;
Jeff Sharkey09c10bf2013-06-30 20:02:59 -070039import android.widget.AdapterView;
40import android.widget.AdapterView.OnItemClickListener;
Jeff Sharkeya5defe32013-08-05 17:56:48 -070041import android.widget.BaseAdapter;
Jeff Sharkey09c10bf2013-06-30 20:02:59 -070042import android.widget.GridView;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070043import android.widget.ImageView;
44import android.widget.ListView;
45import android.widget.TextView;
46
Jeff Sharkey3c28b792013-07-01 17:22:02 -070047import com.android.documentsui.DocumentsActivity.DisplayState;
Jeff Sharkeya5defe32013-08-05 17:56:48 -070048import com.android.documentsui.model.Document;
Jeff Sharkey2e694f82013-08-06 16:26:14 -070049import com.android.documentsui.model.Root;
Jeff Sharkeya5defe32013-08-05 17:56:48 -070050import com.android.internal.util.Predicate;
Jeff Sharkeyc317af82013-07-01 16:56:54 -070051import com.google.android.collect.Lists;
52
Jeff Sharkey2e694f82013-08-06 16:26:14 -070053import java.text.DateFormat;
Jeff Sharkeyc317af82013-07-01 16:56:54 -070054import java.util.ArrayList;
Jeff Sharkeya5defe32013-08-05 17:56:48 -070055import java.util.Comparator;
56import java.util.List;
Jeff Sharkey2e694f82013-08-06 16:26:14 -070057import java.util.concurrent.atomic.AtomicInteger;
Jeff Sharkey09c10bf2013-06-30 20:02:59 -070058
59/**
60 * Display the documents inside a single directory.
61 */
62public class DirectoryFragment extends Fragment {
63
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -070064 private View mEmptyView;
Jeff Sharkey09c10bf2013-06-30 20:02:59 -070065 private ListView mListView;
66 private GridView mGridView;
67
Jeff Sharkeyc317af82013-07-01 16:56:54 -070068 private AbsListView mCurrentView;
69
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -070070 private Predicate<Document> mFilter;
71
Jeff Sharkeya5defe32013-08-05 17:56:48 -070072 public static final int TYPE_NORMAL = 1;
73 public static final int TYPE_SEARCH = 2;
74 public static final int TYPE_RECENT_OPEN = 3;
Jeff Sharkey5b535922013-08-02 15:55:26 -070075
76 private int mType = TYPE_NORMAL;
77
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070078 private DocumentsAdapter mAdapter;
Jeff Sharkeya5defe32013-08-05 17:56:48 -070079 private LoaderCallbacks<List<Document>> mCallbacks;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070080
Jeff Sharkey2e694f82013-08-06 16:26:14 -070081 private static final String EXTRA_TYPE = "type";
Jeff Sharkey5b535922013-08-02 15:55:26 -070082 private static final String EXTRA_URI = "uri";
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070083
Jeff Sharkey2e694f82013-08-06 16:26:14 -070084 private static AtomicInteger sLoaderId = new AtomicInteger(4000);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -070085
Jeff Sharkey2e694f82013-08-06 16:26:14 -070086 private final int mLoaderId = sLoaderId.incrementAndGet();
87
88 public static void showNormal(FragmentManager fm, Uri uri) {
89 show(fm, TYPE_NORMAL, uri);
90 }
91
92 public static void showSearch(FragmentManager fm, Uri uri, String query) {
93 final Uri searchUri = DocumentsContract.buildSearchUri(uri, query);
94 show(fm, TYPE_SEARCH, searchUri);
95 }
96
97 public static void showRecentsOpen(FragmentManager fm) {
98 show(fm, TYPE_RECENT_OPEN, null);
99 }
100
101 private static void show(FragmentManager fm, int type, Uri uri) {
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700102 final Bundle args = new Bundle();
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700103 args.putInt(EXTRA_TYPE, type);
Jeff Sharkey5b535922013-08-02 15:55:26 -0700104 args.putParcelable(EXTRA_URI, uri);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700105
106 final DirectoryFragment fragment = new DirectoryFragment();
107 fragment.setArguments(args);
108
109 final FragmentTransaction ft = fm.beginTransaction();
Jeff Sharkey76112212013-08-06 11:26:10 -0700110 ft.replace(R.id.container_directory, fragment);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700111 ft.commitAllowingStateLoss();
112 }
113
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700114 public static DirectoryFragment get(FragmentManager fm) {
115 // TODO: deal with multiple directories shown at once
Jeff Sharkey76112212013-08-06 11:26:10 -0700116 return (DirectoryFragment) fm.findFragmentById(R.id.container_directory);
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700117 }
118
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700119 @Override
120 public View onCreateView(
121 LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
122 final Context context = inflater.getContext();
123
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700124 final View view = inflater.inflate(R.layout.fragment_directory, container, false);
125
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700126 mEmptyView = view.findViewById(android.R.id.empty);
127
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700128 mListView = (ListView) view.findViewById(R.id.list);
129 mListView.setOnItemClickListener(mItemListener);
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700130 mListView.setMultiChoiceModeListener(mMultiListener);
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700131
132 mGridView = (GridView) view.findViewById(R.id.grid);
133 mGridView.setOnItemClickListener(mItemListener);
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700134 mGridView.setMultiChoiceModeListener(mMultiListener);
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700135
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700136 mAdapter = new DocumentsAdapter();
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700137
Jeff Sharkey5b535922013-08-02 15:55:26 -0700138 final Uri uri = getArguments().getParcelable(EXTRA_URI);
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700139 mType = getArguments().getInt(EXTRA_TYPE);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700140
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700141 mCallbacks = new LoaderCallbacks<List<Document>>() {
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700142 @Override
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700143 public Loader<List<Document>> onCreateLoader(int id, Bundle args) {
Jeff Sharkey3c28b792013-07-01 17:22:02 -0700144 final DisplayState state = getDisplayState(DirectoryFragment.this);
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700145 mFilter = new MimePredicate(state.acceptMimes);
Jeff Sharkey3c28b792013-07-01 17:22:02 -0700146
Jeff Sharkey46165b52013-07-31 20:53:22 -0700147 final Uri contentsUri;
Jeff Sharkey5b535922013-08-02 15:55:26 -0700148 if (mType == TYPE_NORMAL) {
149 contentsUri = DocumentsContract.buildContentsUri(uri);
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700150 } else if (mType == TYPE_RECENT_OPEN) {
151 contentsUri = RecentsProvider.buildRecentOpen();
Jeff Sharkey46165b52013-07-31 20:53:22 -0700152 } else {
Jeff Sharkey5b535922013-08-02 15:55:26 -0700153 contentsUri = uri;
Jeff Sharkey46165b52013-07-31 20:53:22 -0700154 }
155
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700156 final Comparator<Document> sortOrder;
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700157 if (state.sortOrder == DisplayState.SORT_ORDER_DATE || mType == TYPE_RECENT_OPEN) {
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700158 sortOrder = new Document.DateComparator();
159 } else if (state.sortOrder == DisplayState.SORT_ORDER_NAME) {
160 sortOrder = new Document.NameComparator();
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700161 } else if (state.sortOrder == DisplayState.SORT_ORDER_SIZE) {
162 sortOrder = new Document.SizeComparator();
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700163 } else {
164 throw new IllegalArgumentException("Unknown sort order " + state.sortOrder);
165 }
166
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700167 return new DirectoryLoader(context, contentsUri, mType, null, sortOrder);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700168 }
169
170 @Override
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700171 public void onLoadFinished(Loader<List<Document>> loader, List<Document> data) {
172 mAdapter.swapDocuments(data);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700173 }
174
175 @Override
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700176 public void onLoaderReset(Loader<List<Document>> loader) {
177 mAdapter.swapDocuments(null);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700178 }
179 };
180
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700181 updateDisplayState();
182
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700183 return view;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700184 }
185
186 @Override
187 public void onStart() {
188 super.onStart();
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700189
190 final Context context = getActivity();
191 getDisplayState(this).showSize = SettingsActivity.getDisplayFileSize(context);
192
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700193 getLoaderManager().restartLoader(mLoaderId, getArguments(), mCallbacks);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700194 }
195
196 @Override
197 public void onStop() {
198 super.onStop();
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700199 getLoaderManager().destroyLoader(mLoaderId);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700200 }
201
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700202 public void updateDisplayState() {
Jeff Sharkey3c28b792013-07-01 17:22:02 -0700203 final DisplayState state = getDisplayState(this);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700204
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700205 // TODO: avoid kicking loader when nothing changed
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700206 getLoaderManager().restartLoader(mLoaderId, getArguments(), mCallbacks);
207 mListView.smoothScrollToPosition(0);
208 mGridView.smoothScrollToPosition(0);
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700209
Jeff Sharkey3c28b792013-07-01 17:22:02 -0700210 mListView.setVisibility(state.mode == DisplayState.MODE_LIST ? View.VISIBLE : View.GONE);
211 mGridView.setVisibility(state.mode == DisplayState.MODE_GRID ? View.VISIBLE : View.GONE);
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700212
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700213 final int choiceMode;
Jeff Sharkey3c28b792013-07-01 17:22:02 -0700214 if (state.allowMultiple) {
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700215 choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL;
216 } else {
217 choiceMode = ListView.CHOICE_MODE_NONE;
218 }
219
Jeff Sharkey3c28b792013-07-01 17:22:02 -0700220 if (state.mode == DisplayState.MODE_GRID) {
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700221 mListView.setAdapter(null);
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700222 mListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700223 mGridView.setAdapter(mAdapter);
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700224 mGridView.setColumnWidth(getResources().getDimensionPixelSize(R.dimen.grid_width));
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700225 mGridView.setNumColumns(GridView.AUTO_FIT);
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700226 mGridView.setChoiceMode(choiceMode);
227 mCurrentView = mGridView;
Jeff Sharkey3c28b792013-07-01 17:22:02 -0700228 } else if (state.mode == DisplayState.MODE_LIST) {
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700229 mGridView.setAdapter(null);
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700230 mGridView.setChoiceMode(ListView.CHOICE_MODE_NONE);
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700231 mListView.setAdapter(mAdapter);
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700232 mListView.setChoiceMode(choiceMode);
233 mCurrentView = mListView;
Jeff Sharkey3c28b792013-07-01 17:22:02 -0700234 } else {
235 throw new IllegalStateException();
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700236 }
237 }
238
239 private OnItemClickListener mItemListener = new OnItemClickListener() {
240 @Override
241 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700242 final Document doc = mAdapter.getItem(position);
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700243 ((DocumentsActivity) getActivity()).onDocumentPicked(doc);
244 }
245 };
246
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700247 private MultiChoiceModeListener mMultiListener = new MultiChoiceModeListener() {
248 @Override
249 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
250 mode.getMenuInflater().inflate(R.menu.mode_directory, menu);
251 return true;
252 }
253
254 @Override
255 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
256 return true;
257 }
258
259 @Override
260 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
261 if (item.getItemId() == R.id.menu_open) {
Jeff Sharkey5b535922013-08-02 15:55:26 -0700262 final Uri uri = getArguments().getParcelable(EXTRA_URI);
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700263 final SparseBooleanArray checked = mCurrentView.getCheckedItemPositions();
264 final ArrayList<Document> docs = Lists.newArrayList();
265
266 final int size = checked.size();
267 for (int i = 0; i < size; i++) {
268 if (checked.valueAt(i)) {
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700269 final Document doc = mAdapter.getItem(checked.keyAt(i));
270 docs.add(doc);
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700271 }
272 }
273
274 ((DocumentsActivity) getActivity()).onDocumentsPicked(docs);
275 return true;
276 } else {
277 return false;
278 }
279 }
280
281 @Override
282 public void onDestroyActionMode(ActionMode mode) {
283 // ignored
284 }
285
286 @Override
287 public void onItemCheckedStateChanged(
288 ActionMode mode, int position, long id, boolean checked) {
289 if (checked) {
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700290 // Directories cannot be checked
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700291 final Document doc = mAdapter.getItem(position);
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700292 if (doc.isDirectory()) {
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700293 mCurrentView.setItemChecked(position, false);
294 }
295 }
296
297 mode.setTitle(getResources()
298 .getString(R.string.mode_selected_count, mCurrentView.getCheckedItemCount()));
299 }
300 };
301
Jeff Sharkey3c28b792013-07-01 17:22:02 -0700302 private static DisplayState getDisplayState(Fragment fragment) {
303 return ((DocumentsActivity) fragment.getActivity()).getDisplayState();
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700304 }
305
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700306 private class DocumentsAdapter extends BaseAdapter {
307 private List<Document> mDocuments;
308
309 public DocumentsAdapter() {
310 }
311
312 public void swapDocuments(List<Document> documents) {
313 mDocuments = documents;
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700314
315 if (documents != null && documents.isEmpty()) {
316 mEmptyView.setVisibility(View.VISIBLE);
317 } else {
318 mEmptyView.setVisibility(View.GONE);
319 }
320
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700321 notifyDataSetChanged();
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700322 }
323
324 @Override
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700325 public View getView(int position, View convertView, ViewGroup parent) {
326 final Context context = parent.getContext();
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700327 final DisplayState state = getDisplayState(DirectoryFragment.this);
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700328
329 if (convertView == null) {
330 final LayoutInflater inflater = LayoutInflater.from(context);
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700331 if (state.mode == DisplayState.MODE_LIST) {
332 convertView = inflater.inflate(R.layout.item_doc_list, parent, false);
333 } else if (state.mode == DisplayState.MODE_GRID) {
334 convertView = inflater.inflate(R.layout.item_doc_grid, parent, false);
335 } else {
336 throw new IllegalStateException();
337 }
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700338 }
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700339
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700340 final Document doc = getItem(position);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700341
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700342 final ImageView icon = (ImageView) convertView.findViewById(android.R.id.icon);
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700343 final TextView title = (TextView) convertView.findViewById(android.R.id.title);
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700344 final View summaryGrid = convertView.findViewById(R.id.summary_grid);
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700345 final ImageView icon1 = (ImageView) convertView.findViewById(android.R.id.icon1);
346 final TextView summary = (TextView) convertView.findViewById(android.R.id.summary);
347 final TextView date = (TextView) convertView.findViewById(R.id.date);
348 final TextView size = (TextView) convertView.findViewById(R.id.size);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700349
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700350 if (doc.isThumbnailSupported()) {
351 // TODO: load thumbnails async
352 icon.setImageURI(doc.uri);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700353 } else {
Jeff Sharkey76112212013-08-06 11:26:10 -0700354 icon.setImageDrawable(RootsCache.resolveDocumentIcon(
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700355 context, doc.uri.getAuthority(), doc.mimeType));
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700356 }
357
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700358 title.setText(doc.displayName);
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700359
360 if (mType == TYPE_NORMAL || mType == TYPE_SEARCH) {
361 icon1.setVisibility(View.GONE);
362 if (doc.summary != null) {
363 summary.setText(doc.summary);
364 summary.setVisibility(View.VISIBLE);
365 } else {
366 summary.setVisibility(View.INVISIBLE);
367 }
368 } else if (mType == TYPE_RECENT_OPEN) {
369 final Root root = RootsCache.findRoot(context, doc);
370 icon1.setVisibility(View.VISIBLE);
371 icon1.setImageDrawable(root.icon);
372 summary.setText(root.getDirectoryString());
373 summary.setVisibility(View.VISIBLE);
374 }
375
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700376 if (summaryGrid != null) {
377 summaryGrid.setVisibility(
378 (summary.getVisibility() == View.VISIBLE) ? View.VISIBLE : View.GONE);
379 }
380
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700381 // TODO: omit year from format
382 date.setText(DateUtils.formatSameDayTime(
383 doc.lastModified, System.currentTimeMillis(), DateFormat.SHORT,
384 DateFormat.SHORT));
385
386 if (state.showSize) {
387 size.setVisibility(View.VISIBLE);
388 if (doc.isDirectory()) {
389 size.setText(null);
390 } else {
391 size.setText(Formatter.formatFileSize(context, doc.size));
392 }
393 } else {
394 size.setVisibility(View.GONE);
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700395 }
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700396
397 return convertView;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700398 }
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700399
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700400 @Override
401 public int getCount() {
402 return mDocuments != null ? mDocuments.size() : 0;
403 }
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700404
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700405 @Override
406 public Document getItem(int position) {
407 return mDocuments.get(position);
408 }
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700409
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700410 @Override
411 public long getItemId(int position) {
412 return getItem(position).uri.hashCode();
413 }
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700414
415 @Override
416 public boolean areAllItemsEnabled() {
417 return false;
418 }
419
420 @Override
421 public boolean isEnabled(int position) {
422 final Document doc = getItem(position);
423 return mFilter.apply(doc);
424 }
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700425 }
426}