RecentsCreateFragment.java revision b51331116eb2ebbc41aaf69142916f9af6dffdd5
1b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey/*
2b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey * Copyright (C) 2013 The Android Open Source Project
3b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey *
4b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey * Licensed under the Apache License, Version 2.0 (the "License");
5b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey * you may not use this file except in compliance with the License.
6b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey * You may obtain a copy of the License at
7b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey *
8b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey *      http://www.apache.org/licenses/LICENSE-2.0
9b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey *
10b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey * Unless required by applicable law or agreed to in writing, software
11b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey * distributed under the License is distributed on an "AS IS" BASIS,
12b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey * See the License for the specific language governing permissions and
14b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey * limitations under the License.
15b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey */
16b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
17b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeypackage com.android.documentsui;
18b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
190c2d31bfa113c2848620ac05c916802410b71da1Jeff Sharkeyimport static com.android.documentsui.DocumentsActivity.TAG;
200c2d31bfa113c2848620ac05c916802410b71da1Jeff Sharkey
21b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.app.Fragment;
22b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.app.FragmentManager;
23b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.app.FragmentTransaction;
24b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.app.LoaderManager.LoaderCallbacks;
25b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.content.ContentResolver;
26b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.content.Context;
27b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.content.Loader;
28b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.database.Cursor;
29b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.net.Uri;
30b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.os.Bundle;
31b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.os.CancellationSignal;
32b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.text.TextUtils.TruncateAt;
330c2d31bfa113c2848620ac05c916802410b71da1Jeff Sharkeyimport android.util.Log;
34b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.view.LayoutInflater;
35b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.view.View;
36b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.view.ViewGroup;
37b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.widget.AdapterView;
38b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.widget.AdapterView.OnItemClickListener;
39b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.widget.BaseAdapter;
40b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.widget.ImageView;
41b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.widget.ListView;
42b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport android.widget.TextView;
43b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
44b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport com.android.documentsui.model.DocumentStack;
45ae9b51bfa313c51a31af30875a71255d7b6d2e61Jeff Sharkeyimport com.android.documentsui.model.RootInfo;
46b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport com.google.android.collect.Lists;
47b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
48b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport libcore.io.IoUtils;
49b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
50b51331116eb2ebbc41aaf69142916f9af6dffdd5Jeff Sharkeyimport java.io.ByteArrayInputStream;
51b51331116eb2ebbc41aaf69142916f9af6dffdd5Jeff Sharkeyimport java.io.DataInputStream;
52b51331116eb2ebbc41aaf69142916f9af6dffdd5Jeff Sharkeyimport java.io.IOException;
53b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport java.util.ArrayList;
54b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeyimport java.util.List;
55b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
56b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey/**
57b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey * Display directories where recent creates took place.
58b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey */
59b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkeypublic class RecentsCreateFragment extends Fragment {
60b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
61b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    private ListView mListView;
62b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
63b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    private DocumentStackAdapter mAdapter;
64b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    private LoaderCallbacks<List<DocumentStack>> mCallbacks;
65b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
66b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    private static final int LOADER_RECENTS = 3;
67b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
68b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    public static void show(FragmentManager fm) {
69b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        final RecentsCreateFragment fragment = new RecentsCreateFragment();
70b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        final FragmentTransaction ft = fm.beginTransaction();
71b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        ft.replace(R.id.container_directory, fragment);
72b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        ft.commitAllowingStateLoss();
73b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    }
74b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
75b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    @Override
76b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    public View onCreateView(
77b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
78b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        final Context context = inflater.getContext();
79b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
80b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        final View view = inflater.inflate(R.layout.fragment_directory, container, false);
81b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
82b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        mListView = (ListView) view.findViewById(R.id.list);
83b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        mListView.setOnItemClickListener(mItemListener);
84b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
85b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        mAdapter = new DocumentStackAdapter();
86b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        mListView.setAdapter(mAdapter);
87b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
88b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        mCallbacks = new LoaderCallbacks<List<DocumentStack>>() {
89b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            @Override
90b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            public Loader<List<DocumentStack>> onCreateLoader(int id, Bundle args) {
91b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey                return new RecentsCreateLoader(context);
92b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            }
93b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
94b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            @Override
95b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            public void onLoadFinished(
96b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey                    Loader<List<DocumentStack>> loader, List<DocumentStack> data) {
97b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey                mAdapter.swapStacks(data);
98b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            }
99b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
100b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            @Override
101b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            public void onLoaderReset(Loader<List<DocumentStack>> loader) {
102b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey                mAdapter.swapStacks(null);
103b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            }
104b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        };
105b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
106b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        return view;
107b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    }
108b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
109b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    @Override
110b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    public void onStart() {
111b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        super.onStart();
112b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        getLoaderManager().restartLoader(LOADER_RECENTS, getArguments(), mCallbacks);
113b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    }
114b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
115b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    @Override
116b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    public void onStop() {
117b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        super.onStop();
118b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        getLoaderManager().destroyLoader(LOADER_RECENTS);
119b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    }
120b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
121b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    private OnItemClickListener mItemListener = new OnItemClickListener() {
122b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        @Override
123b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
124b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            final DocumentStack stack = mAdapter.getItem(position);
125b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            ((DocumentsActivity) getActivity()).onStackPicked(stack);
126b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        }
127b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    };
128b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
129b448660a227f93d7bd5c5d019a21745e67c2f54dJeff Sharkey    public static class RecentsCreateLoader extends UriDerivativeLoader<Uri, List<DocumentStack>> {
130b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        public RecentsCreateLoader(Context context) {
131b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            super(context, RecentsProvider.buildRecentCreate());
132b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        }
133b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
134b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        @Override
135b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        public List<DocumentStack> loadInBackground(Uri uri, CancellationSignal signal) {
136b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            final ArrayList<DocumentStack> result = Lists.newArrayList();
137b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
138b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            final ContentResolver resolver = getContext().getContentResolver();
139b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            final Cursor cursor = resolver.query(
140b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey                    uri, null, null, null, RecentsProvider.COL_TIMESTAMP + " DESC", signal);
141b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            try {
142b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey                while (cursor != null && cursor.moveToNext()) {
143b51331116eb2ebbc41aaf69142916f9af6dffdd5Jeff Sharkey                    final byte[] raw = cursor.getBlob(
144b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey                            cursor.getColumnIndex(RecentsProvider.COL_PATH));
1450c2d31bfa113c2848620ac05c916802410b71da1Jeff Sharkey                    try {
146b51331116eb2ebbc41aaf69142916f9af6dffdd5Jeff Sharkey                        final DocumentStack stack = new DocumentStack();
147b51331116eb2ebbc41aaf69142916f9af6dffdd5Jeff Sharkey                        stack.read(new DataInputStream(new ByteArrayInputStream(raw)));
1480c2d31bfa113c2848620ac05c916802410b71da1Jeff Sharkey                        result.add(stack);
149b51331116eb2ebbc41aaf69142916f9af6dffdd5Jeff Sharkey                    } catch (IOException e) {
1500c2d31bfa113c2848620ac05c916802410b71da1Jeff Sharkey                        Log.w(TAG, "Failed to resolve stack: " + e);
1510c2d31bfa113c2848620ac05c916802410b71da1Jeff Sharkey                    }
152b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey                }
153b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            } finally {
154b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey                IoUtils.closeQuietly(cursor);
155b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            }
156b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
157b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            return result;
158b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        }
159b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    }
160b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
161b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    private class DocumentStackAdapter extends BaseAdapter {
162b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        private List<DocumentStack> mStacks;
163b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
164b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        public DocumentStackAdapter() {
165b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        }
166b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
167b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        public void swapStacks(List<DocumentStack> stacks) {
168b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            mStacks = stacks;
169b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            notifyDataSetChanged();
170b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        }
171b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
172b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        @Override
173b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        public View getView(int position, View convertView, ViewGroup parent) {
174b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            final Context context = parent.getContext();
1754eb407a832b7d6a2d62a535e5cab70b00a0bc8edJeff Sharkey            final RootsCache roots = DocumentsApplication.getRootsCache(context);
176b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
177b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            if (convertView == null) {
178b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey                final LayoutInflater inflater = LayoutInflater.from(context);
179b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey                convertView = inflater.inflate(R.layout.item_doc_list, parent, false);
180b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            }
181b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
182b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            final ImageView icon = (ImageView) convertView.findViewById(android.R.id.icon);
183b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            final TextView title = (TextView) convertView.findViewById(android.R.id.title);
1849fb567b59112f99e64e0bff6f343188331bad28dJeff Sharkey            final View summaryList = convertView.findViewById(R.id.summary_list);
185b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
186b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            final DocumentStack stack = getItem(position);
187ae9b51bfa313c51a31af30875a71255d7b6d2e61Jeff Sharkey            final RootInfo root = stack.getRoot(roots);
188aeb16e2435f9975b9fa1fc4b747796647a21292eJeff Sharkey            icon.setImageDrawable(root.loadIcon(context));
189b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
190b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            final StringBuilder builder = new StringBuilder();
1919fb567b59112f99e64e0bff6f343188331bad28dJeff Sharkey            for (int i = stack.size() - 1; i >= 0; i--) {
192b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey                builder.append(stack.get(i).displayName);
1939fb567b59112f99e64e0bff6f343188331bad28dJeff Sharkey                if (i > 0) {
194b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey                    builder.append(" \u232a ");
195b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey                }
196b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            }
197b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            title.setText(builder.toString());
198b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            title.setEllipsize(TruncateAt.MIDDLE);
199b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
2009fb567b59112f99e64e0bff6f343188331bad28dJeff Sharkey            summaryList.setVisibility(View.GONE);
201b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
202b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            return convertView;
203b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        }
204b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
205b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        @Override
206b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        public int getCount() {
207b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            return mStacks != null ? mStacks.size() : 0;
208b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        }
209b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
210b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        @Override
211b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        public DocumentStack getItem(int position) {
212b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            return mStacks.get(position);
213b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        }
214b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey
215b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        @Override
216b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        public long getItemId(int position) {
217b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey            return getItem(position).hashCode();
218b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey        }
219b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey    }
220b156f4bf8cdfe475a7116b627d84a281e1a281b7Jeff Sharkey}
221