From 0c29a875ddb65bc563cda1451073f0a1dfc2f088 Mon Sep 17 00:00:00 2001 From: misaochan Date: Thu, 21 Jan 2016 16:08:22 +1300 Subject: [PATCH] Refactored recent + gps cat block --- .../category/CategorizationFragment.java | 66 ++++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/commons/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java b/commons/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java index 45eedef71..5815c1e9a 100644 --- a/commons/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java +++ b/commons/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java @@ -256,41 +256,45 @@ public class CategorizationFragment extends SherlockFragment{ } } + private ArrayList recentCatQuery() { + ArrayList items = new ArrayList(); + ArrayList mergedItems= new ArrayList(); + + try { + Cursor cursor = client.query( + CategoryContentProvider.BASE_URI, + Category.Table.ALL_FIELDS, + null, + new String[]{}, + Category.Table.COLUMN_LAST_USED + " DESC"); + // fixme add a limit on the original query instead of falling out of the loop? + while (cursor.moveToNext() && cursor.getPosition() < SEARCH_CATS_LIMIT) { + Category cat = Category.fromCursor(cursor); + items.add(cat.getName()); + } + + if (MwVolleyApi.GpsCatExists.getGpsCatExists() == true){ + //Log.d(TAG, "GPS cats found in CategorizationFragment.java" + MwVolleyApi.getGpsCat().toString()); + List gpsItems = new ArrayList(MwVolleyApi.getGpsCat()); + //Log.d(TAG, "GPS items: " + gpsItems.toString()); + + mergedItems.addAll(gpsItems); + } + + mergedItems.addAll(items); + } + catch (RemoteException e) { + throw new RuntimeException(e); + } + //Log.d(TAG, "Merged items: " + mergedItems.toString()); + return mergedItems; + } + @Override protected ArrayList doInBackground(Void... voids) { //If user hasn't typed anything in yet, get GPS and recent items if(TextUtils.isEmpty(filter)) { - ArrayList items = new ArrayList(); - ArrayList mergedItems= new ArrayList(); - - try { - Cursor cursor = client.query( - CategoryContentProvider.BASE_URI, - Category.Table.ALL_FIELDS, - null, - new String[]{}, - Category.Table.COLUMN_LAST_USED + " DESC"); - // fixme add a limit on the original query instead of falling out of the loop? - while (cursor.moveToNext() && cursor.getPosition() < SEARCH_CATS_LIMIT) { - Category cat = Category.fromCursor(cursor); - items.add(cat.getName()); - } - - if (MwVolleyApi.GpsCatExists.getGpsCatExists() == true){ - //Log.d(TAG, "GPS cats found in CategorizationFragment.java" + MwVolleyApi.getGpsCat().toString()); - List gpsItems = new ArrayList(MwVolleyApi.getGpsCat()); - //Log.d(TAG, "GPS items: " + gpsItems.toString()); - - mergedItems.addAll(gpsItems); - } - - mergedItems.addAll(items); - } - catch (RemoteException e) { - throw new RuntimeException(e); - } - //Log.d(TAG, "Merged items: " + mergedItems.toString()); - return mergedItems; + return recentCatQuery(); } //if user types in something that is in cache, return cached category