diff options
-rw-r--r-- | src/com/android/browser/provider/BrowserProvider2.java | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/src/com/android/browser/provider/BrowserProvider2.java b/src/com/android/browser/provider/BrowserProvider2.java index 014a32d..97efb3f 100644 --- a/src/com/android/browser/provider/BrowserProvider2.java +++ b/src/com/android/browser/provider/BrowserProvider2.java @@ -63,8 +63,10 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.List; public class BrowserProvider2 extends SQLiteContentProvider { @@ -1207,11 +1209,15 @@ public class BrowserProvider2 extends SQLiteContentProvider { int deleteBookmarks(String selection, String[] selectionArgs, boolean callerIsSyncAdapter) { - //TODO cascade deletes down from folders final SQLiteDatabase db = mOpenHelper.getWritableDatabase(); if (callerIsSyncAdapter) { return db.delete(TABLE_BOOKMARKS, selection, selectionArgs); } + + Object[] appendedBookmarks = appendBookmarksIfFolder(selection, selectionArgs); + selection = (String) appendedBookmarks[0]; + selectionArgs = (String[]) appendedBookmarks[1]; + ContentValues values = new ContentValues(); values.put(Bookmarks.DATE_MODIFIED, System.currentTimeMillis()); values.put(Bookmarks.IS_DELETED, 1); @@ -1219,6 +1225,52 @@ public class BrowserProvider2 extends SQLiteContentProvider { callerIsSyncAdapter); } + private Object[] appendBookmarksIfFolder(String selection, String[] selectionArgs) { + final SQLiteDatabase db = mOpenHelper.getReadableDatabase(); + final String[] bookmarksProjection = new String[] { + Bookmarks._ID, // 0 + Bookmarks.IS_FOLDER // 1 + }; + StringBuilder newSelection = new StringBuilder(selection); + List<String> newSelectionArgs = new ArrayList<String>(); + + Cursor cursor = null; + try { + cursor = db.query(TABLE_BOOKMARKS, bookmarksProjection, + selection, selectionArgs, null, null, null); + if (cursor != null) { + while (cursor.moveToNext()) { + String id = Long.toString(cursor.getLong(0)); + newSelectionArgs.add(id); + if (cursor.getInt(1) != 0) { + // collect bookmarks in this folder + Object[] bookmarks = appendBookmarksIfFolder( + Bookmarks.PARENT + "=?", new String[] { id }); + String[] bookmarkIds = (String[]) bookmarks[1]; + if (bookmarkIds.length > 0) { + newSelection.append(" OR " + TABLE_BOOKMARKS + "._id IN ("); + for (String bookmarkId : bookmarkIds) { + newSelection.append("?,"); + newSelectionArgs.add(bookmarkId); + } + newSelection.deleteCharAt(newSelection.length() - 1); + newSelection.append(")"); + } + } + } + } + } finally { + if (cursor != null) { + cursor.close(); + } + } + + return new Object[] { + newSelection.toString(), + newSelectionArgs.toArray(new String[newSelectionArgs.size()]) + }; + } + @Override public int deleteInTransaction(Uri uri, String selection, String[] selectionArgs, boolean callerIsSyncAdapter) { |