Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java |
| index b4151f27bcb592e6ddb8005a09d1304d1274742d..4098480e532b3c34513c5690f6230635df2e33b6 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java |
| @@ -21,14 +21,14 @@ import org.chromium.chrome.browser.widget.selection.SelectableListLayout; |
| import org.chromium.chrome.browser.widget.selection.SelectionDelegate; |
| import org.chromium.ui.PhotoPickerListener; |
| -import java.util.ArrayList; |
| import java.util.List; |
| /** |
| * A class for keeping track of common data associated with showing photos in |
| * the photo picker, for example the RecyclerView and the bitmap caches. |
| */ |
| -public class PickerCategoryView extends RelativeLayout implements OnMenuItemClickListener { |
| +public class PickerCategoryView extends RelativeLayout |
| + implements FileEnumWorkerTask.FilesEnumeratedCallback, OnMenuItemClickListener { |
| // The dialog that owns us. |
| private PhotoPickerDialog mDialog; |
| @@ -69,6 +69,9 @@ public class PickerCategoryView extends RelativeLayout implements OnMenuItemClic |
| // The size of the bitmaps (equal length for width and height). |
| private int mImageSize; |
| + // A worker task for asynchronously enumerating files off the main thread. |
| + private FileEnumWorkerTask mWorkerTask; |
| + |
| public PickerCategoryView(Context context) { |
| super(context); |
| postConstruction(context); |
| @@ -119,6 +122,13 @@ public class PickerCategoryView extends RelativeLayout implements OnMenuItemClic |
| } |
| /** |
| + * Cancels any outstanding requests. |
| + */ |
| + public void teardown() { |
|
Theresa
2017/04/11 17:01:29
nit: I think teardown() is typically used in test
Finnur
2017/04/12 11:04:43
Done.
|
| + mWorkerTask.cancel(true); |
| + } |
| + |
| + /** |
| * Initializes the PickerCategoryView object. |
| * @param dialog The dialog showing us. |
| * @param listener The listener who should be notified of actions. |
| @@ -133,6 +143,16 @@ public class PickerCategoryView extends RelativeLayout implements OnMenuItemClic |
| mListener = listener; |
| } |
| + // FileEnumWorkerTask.FilesEnumeratedCallback: |
| + |
| + @Override |
| + public void filesEnumeratedCallback(List<PickerBitmap> files) { |
| + mPickerBitmaps = files; |
| + if (files != null && files.size() > 0) { |
| + mPickerAdapter.notifyDataSetChanged(); |
| + } |
| + } |
| + |
| // OnMenuItemClickListener: |
| @Override |
| @@ -202,15 +222,12 @@ public class PickerCategoryView extends RelativeLayout implements OnMenuItemClic |
| * Prepares bitmaps for loading. |
| */ |
| private void prepareBitmaps() { |
| - // TODO(finnur): Use worker thread to fetch bitmaps instead of hard-coding. |
| - mPickerBitmaps = new ArrayList<>(); |
| - mPickerBitmaps.add(0, new PickerBitmap("", 0, PickerBitmap.GALLERY)); |
| - mPickerBitmaps.add(0, new PickerBitmap("", 0, PickerBitmap.CAMERA)); |
| - mPickerBitmaps.add(new PickerBitmap("foo/bar1.jpg", 1, PickerBitmap.PICTURE)); |
| - mPickerBitmaps.add(new PickerBitmap("foo/bar2.jpg", 2, PickerBitmap.PICTURE)); |
| - mPickerBitmaps.add(new PickerBitmap("foo/bar3.jpg", 3, PickerBitmap.PICTURE)); |
| - mPickerBitmaps.add(new PickerBitmap("foo/bar4.jpg", 4, PickerBitmap.PICTURE)); |
| - mPickerAdapter.notifyDataSetChanged(); |
| + if (mWorkerTask != null) { |
| + mWorkerTask.cancel(true); |
| + } |
| + |
| + mWorkerTask = new FileEnumWorkerTask(this, new MimeTypeFileFilter("image/*")); |
| + mWorkerTask.execute(); |
| } |
| /** |