diff options
author | Takeshi Aimi <takeshi.aimi@sonymobile.com> | 2013-06-27 20:38:30 +0900 |
---|---|---|
committer | Takeshi Aimi <takeshi.aimi@sonymobile.com> | 2013-07-02 13:06:31 +0900 |
commit | b588599862d180fbd9126defa7f87e0741c38a32 (patch) | |
tree | 1eeadcaef887c1985d704ccdc6d05cf41e63bc99 | |
parent | 6fae8a98d19492a44a63bcc2ae3863f33cf1a3df (diff) | |
download | packages_apps_Browser-b588599862d180fbd9126defa7f87e0741c38a32.zip packages_apps_Browser-b588599862d180fbd9126defa7f87e0741c38a32.tar.gz packages_apps_Browser-b588599862d180fbd9126defa7f87e0741c38a32.tar.bz2 |
Fixed delete function for bookmark folder
Currently only folder is deleted when one deletes bookmark folder.
Therefore, items inside in the folder are remained.
We have to delete items recursively inside the folder.
Change-Id: I17ad9656612448d8555a64ec887313db4f829174
-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) { |