summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Reck <jreck@android.com>2013-07-02 12:41:32 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-07-02 12:41:32 -0700
commit5d4ba4ad1f5b2bdf95534ed38c220a7f2f6b542f (patch)
tree87023b61d9842c10106792903785d220cd1e5eb8
parenta8f7ecea29f024813a52be2cc17777bfc8e59dfb (diff)
parentb3ad6cd78079322805eb9407dca75886a28706c6 (diff)
downloadpackages_apps_Browser-5d4ba4ad1f5b2bdf95534ed38c220a7f2f6b542f.zip
packages_apps_Browser-5d4ba4ad1f5b2bdf95534ed38c220a7f2f6b542f.tar.gz
packages_apps_Browser-5d4ba4ad1f5b2bdf95534ed38c220a7f2f6b542f.tar.bz2
am b3ad6cd7: am 0505bfe1: Merge "Fixed delete function for bookmark folder"
* commit 'b3ad6cd78079322805eb9407dca75886a28706c6': Fixed delete function for bookmark folder
-rw-r--r--src/com/android/browser/provider/BrowserProvider2.java54
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) {