From 0555d4c8b28ee879cc5f4b53550c99cc510f0f06 Mon Sep 17 00:00:00 2001 From: Likai Ding Date: Mon, 11 Apr 2016 15:00:30 +0800 Subject: Gallery: improve timeline loading performance MediaSet's getTotalMediaItemCount() method involves database queries which is slow. The call is not needed in time clustering as the items will be enumerated right after that. Change-Id: I8eaa68237c923486109935180247188da94f397b CRs-Fixed: 984190 --- src/com/android/gallery3d/data/TimeClustering.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/com/android/gallery3d/data/TimeClustering.java b/src/com/android/gallery3d/data/TimeClustering.java index 87111f29d..db47c40d9 100644 --- a/src/com/android/gallery3d/data/TimeClustering.java +++ b/src/com/android/gallery3d/data/TimeClustering.java @@ -98,14 +98,12 @@ public class TimeClustering extends Clustering { @Override public void run(MediaSet baseSet) { - final int total = baseSet.getTotalMediaItemCount(); - final SmallItem[] buf = new SmallItem[total]; final double[] latLng = new double[2]; + final ArrayList items = new ArrayList<>(); baseSet.enumerateTotalMediaItems(new MediaSet.ItemConsumer() { @Override public void consume(int index, MediaItem item) { - if (index < 0 || index >= total) return; SmallItem s = new SmallItem(); s.path = item.getPath(); s.mediaType = item.getMediaType(); @@ -113,17 +111,10 @@ public class TimeClustering extends Clustering { item.getLatLong(latLng); s.lat = latLng[0]; s.lng = latLng[1]; - buf[index] = s; + items.add(s); } }); - ArrayList items = new ArrayList(total); - for (int i = 0; i < total; i++) { - if (buf[i] != null) { - items.add(buf[i]); - } - } - Collections.sort(items, sDateComparator); int n = items.size(); -- cgit v1.2.3