diff options
-rw-r--r-- | src/org/cyanogenmod/themes/provider/util/ProviderUtils.java | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/org/cyanogenmod/themes/provider/util/ProviderUtils.java b/src/org/cyanogenmod/themes/provider/util/ProviderUtils.java index ab98530..66db924 100644 --- a/src/org/cyanogenmod/themes/provider/util/ProviderUtils.java +++ b/src/org/cyanogenmod/themes/provider/util/ProviderUtils.java @@ -26,6 +26,7 @@ import android.provider.ThemesContract; import android.provider.ThemesContract.MixnMatchColumns; import android.provider.ThemesContract.PreviewColumns; import android.provider.ThemesContract.ThemesColumns; +import android.text.TextUtils; import org.cyanogenmod.themes.provider.ThemesOpenHelper; import java.util.ArrayList; @@ -114,6 +115,8 @@ public class ProviderUtils { } public static String[] modifyPreviewsProjection(String[] projection) { + if (projection == null) return null; + Set<String> validKeys = new HashSet<String>(Arrays.asList(ThemesContract.PreviewColumns.VALID_KEYS)); ArrayList<String> newProjection = new ArrayList<String>(); @@ -129,15 +132,28 @@ public class ProviderUtils { public static String modifyDefaultPreviewsSelection(String selection, String[] projection) { String newSelection = modifyPreviewsSelection(selection, projection); - newSelection += " AND " + PreviewColumns.COMPONENT_ID + "=0"; + if (!TextUtils.isEmpty(newSelection)) { + newSelection += " AND "; + } else { + newSelection = ""; + } + newSelection += PreviewColumns.COMPONENT_ID + "=0"; return newSelection; } public static String modifyPreviewsSelection(String selection, String[] projection) { - String newSelection = selection; + if (selection == null && projection == null) return null; + + String newSelection = ""; + if (!TextUtils.isEmpty(selection)) { + newSelection += selection; + } List<String> projectionItems = getPreviewProjectionItems(projection); - if (projectionItems.size() > 0) { - newSelection += " AND ("; + if (projectionItems != null && projectionItems.size() > 0) { + if (!TextUtils.isEmpty(newSelection)) { + newSelection += " AND "; + } + newSelection += "("; for (int i = 0; i < projectionItems.size(); i++) { newSelection += PreviewColumns.COL_KEY + "=?"; if (i < projectionItems.size() - 1) { @@ -151,16 +167,21 @@ public class ProviderUtils { public static String[] modifyPreviewsSelectionArgs(String[] selectionArgs, String[] projection) { - ArrayList<String> newSelectionArgs = - new ArrayList<String>(Arrays.asList(selectionArgs)); + if (selectionArgs == null && projection == null) return null; + + ArrayList<String> newSelectionArgs = new ArrayList<String>(); + if (selectionArgs != null) { + newSelectionArgs.addAll(Arrays.asList(selectionArgs)); + } List<String> projectionItems = getPreviewProjectionItems(projection); - for (String item : projectionItems) { - newSelectionArgs.add(item); + if (projectionItems != null) { + newSelectionArgs.addAll(projectionItems); } return newSelectionArgs.toArray(new String[newSelectionArgs.size()]); } public static List<String> getPreviewProjectionItems(String[] projection) { + if (projection == null) return null; Set<String> validKeys = new HashSet<String>(Arrays.asList(PreviewColumns.VALID_KEYS)); ArrayList<String> newProjection = new ArrayList<String>(); |