blob: ac5629edd62749bce8ef52a969c5a51264abd1f0 [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 Sharkey1d890e02013-08-15 11:24:03 -0700147 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 Sharkey1d890e02013-08-15 11:24:03 -0700156 if (state.localOnly) {
157 contentsUri = DocumentsContract.setLocalOnly(contentsUri);
158 }
159
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700160 final Comparator<Document> sortOrder;
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700161 if (state.sortOrder == DisplayState.SORT_ORDER_DATE || mType == TYPE_RECENT_OPEN) {
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700162 sortOrder = new Document.DateComparator();
163 } else if (state.sortOrder == DisplayState.SORT_ORDER_NAME) {
164 sortOrder = new Document.NameComparator();
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700165 } else if (state.sortOrder == DisplayState.SORT_ORDER_SIZE) {
166 sortOrder = new Document.SizeComparator();
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700167 } else {
168 throw new IllegalArgumentException("Unknown sort order " + state.sortOrder);
169 }
170
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700171 return new DirectoryLoader(context, contentsUri, mType, null, sortOrder);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700172 }
173
174 @Override
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700175 public void onLoadFinished(Loader<List<Document>> loader, List<Document> data) {
176 mAdapter.swapDocuments(data);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700177 }
178
179 @Override
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700180 public void onLoaderReset(Loader<List<Document>> loader) {
181 mAdapter.swapDocuments(null);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700182 }
183 };
184
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700185 updateDisplayState();
186
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700187 return view;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700188 }
189
190 @Override
191 public void onStart() {
192 super.onStart();
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 Sharkeyf339f252013-08-15 16:17:41 -0700243 if (mFilter.apply(doc)) {
244 ((DocumentsActivity) getActivity()).onDocumentPicked(doc);
245 }
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700246 }
247 };
248
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700249 private MultiChoiceModeListener mMultiListener = new MultiChoiceModeListener() {
250 @Override
251 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
252 mode.getMenuInflater().inflate(R.menu.mode_directory, menu);
253 return true;
254 }
255
256 @Override
257 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
258 return true;
259 }
260
261 @Override
262 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
263 if (item.getItemId() == R.id.menu_open) {
Jeff Sharkey5b535922013-08-02 15:55:26 -0700264 final Uri uri = getArguments().getParcelable(EXTRA_URI);
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700265 final SparseBooleanArray checked = mCurrentView.getCheckedItemPositions();
266 final ArrayList<Document> docs = Lists.newArrayList();
267
268 final int size = checked.size();
269 for (int i = 0; i < size; i++) {
270 if (checked.valueAt(i)) {
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700271 final Document doc = mAdapter.getItem(checked.keyAt(i));
272 docs.add(doc);
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700273 }
274 }
275
276 ((DocumentsActivity) getActivity()).onDocumentsPicked(docs);
277 return true;
278 } else {
279 return false;
280 }
281 }
282
283 @Override
284 public void onDestroyActionMode(ActionMode mode) {
285 // ignored
286 }
287
288 @Override
289 public void onItemCheckedStateChanged(
290 ActionMode mode, int position, long id, boolean checked) {
291 if (checked) {
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700292 // Directories cannot be checked
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700293 final Document doc = mAdapter.getItem(position);
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700294 if (doc.isDirectory()) {
Jeff Sharkeyc317af82013-07-01 16:56:54 -0700295 mCurrentView.setItemChecked(position, false);
296 }
297 }
298
299 mode.setTitle(getResources()
300 .getString(R.string.mode_selected_count, mCurrentView.getCheckedItemCount()));
301 }
302 };
303
Jeff Sharkey3c28b792013-07-01 17:22:02 -0700304 private static DisplayState getDisplayState(Fragment fragment) {
305 return ((DocumentsActivity) fragment.getActivity()).getDisplayState();
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700306 }
307
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700308 private class DocumentsAdapter extends BaseAdapter {
309 private List<Document> mDocuments;
310
311 public DocumentsAdapter() {
312 }
313
314 public void swapDocuments(List<Document> documents) {
315 mDocuments = documents;
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700316
317 if (documents != null && documents.isEmpty()) {
318 mEmptyView.setVisibility(View.VISIBLE);
319 } else {
320 mEmptyView.setVisibility(View.GONE);
321 }
322
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700323 notifyDataSetChanged();
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700324 }
325
326 @Override
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700327 public View getView(int position, View convertView, ViewGroup parent) {
328 final Context context = parent.getContext();
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700329 final DisplayState state = getDisplayState(DirectoryFragment.this);
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700330
331 if (convertView == null) {
332 final LayoutInflater inflater = LayoutInflater.from(context);
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700333 if (state.mode == DisplayState.MODE_LIST) {
334 convertView = inflater.inflate(R.layout.item_doc_list, parent, false);
335 } else if (state.mode == DisplayState.MODE_GRID) {
336 convertView = inflater.inflate(R.layout.item_doc_grid, parent, false);
337 } else {
338 throw new IllegalStateException();
339 }
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700340 }
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700341
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700342 final Document doc = getItem(position);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700343
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700344 final ImageView icon = (ImageView) convertView.findViewById(android.R.id.icon);
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700345 final TextView title = (TextView) convertView.findViewById(android.R.id.title);
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700346 final View summaryGrid = convertView.findViewById(R.id.summary_grid);
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700347 final ImageView icon1 = (ImageView) convertView.findViewById(android.R.id.icon1);
348 final TextView summary = (TextView) convertView.findViewById(android.R.id.summary);
349 final TextView date = (TextView) convertView.findViewById(R.id.date);
350 final TextView size = (TextView) convertView.findViewById(R.id.size);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700351
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700352 if (doc.isThumbnailSupported()) {
353 // TODO: load thumbnails async
354 icon.setImageURI(doc.uri);
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700355 } else {
Jeff Sharkey76112212013-08-06 11:26:10 -0700356 icon.setImageDrawable(RootsCache.resolveDocumentIcon(
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700357 context, doc.uri.getAuthority(), doc.mimeType));
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700358 }
359
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700360 title.setText(doc.displayName);
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700361
362 if (mType == TYPE_NORMAL || mType == TYPE_SEARCH) {
363 icon1.setVisibility(View.GONE);
364 if (doc.summary != null) {
365 summary.setText(doc.summary);
366 summary.setVisibility(View.VISIBLE);
367 } else {
368 summary.setVisibility(View.INVISIBLE);
369 }
370 } else if (mType == TYPE_RECENT_OPEN) {
371 final Root root = RootsCache.findRoot(context, doc);
372 icon1.setVisibility(View.VISIBLE);
373 icon1.setImageDrawable(root.icon);
374 summary.setText(root.getDirectoryString());
375 summary.setVisibility(View.VISIBLE);
376 }
377
Jeff Sharkeyc6cbdf12013-08-07 16:22:02 -0700378 if (summaryGrid != null) {
379 summaryGrid.setVisibility(
380 (summary.getVisibility() == View.VISIBLE) ? View.VISIBLE : View.GONE);
381 }
382
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700383 // TODO: omit year from format
384 date.setText(DateUtils.formatSameDayTime(
385 doc.lastModified, System.currentTimeMillis(), DateFormat.SHORT,
386 DateFormat.SHORT));
387
388 if (state.showSize) {
389 size.setVisibility(View.VISIBLE);
Jeff Sharkeyf339f252013-08-15 16:17:41 -0700390 if (doc.isDirectory() || doc.size == -1) {
Jeff Sharkey2e694f82013-08-06 16:26:14 -0700391 size.setText(null);
392 } else {
393 size.setText(Formatter.formatFileSize(context, doc.size));
394 }
395 } else {
396 size.setVisibility(View.GONE);
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700397 }
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700398
399 return convertView;
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700400 }
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700401
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700402 @Override
403 public int getCount() {
404 return mDocuments != null ? mDocuments.size() : 0;
405 }
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700406
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700407 @Override
408 public Document getItem(int position) {
409 return mDocuments.get(position);
410 }
Jeff Sharkey09c10bf2013-06-30 20:02:59 -0700411
Jeff Sharkeya5defe32013-08-05 17:56:48 -0700412 @Override
413 public long getItemId(int position) {
414 return getItem(position).uri.hashCode();
415 }
Jeff Sharkeye22d02e2013-04-26 16:54:55 -0700416 }
417}