diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ccd73bb..cbe7664 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -43,6 +43,7 @@
+
@@ -69,6 +70,12 @@
+
+
+
+
+
+
diff --git a/res/drawable-hdpi/ic_add_folder.png b/res/drawable-hdpi/ic_add_folder.png
new file mode 100644
index 0000000..8f8fa9f
Binary files /dev/null and b/res/drawable-hdpi/ic_add_folder.png differ
diff --git a/res/drawable-hdpi/ic_folder_mini.png b/res/drawable-hdpi/ic_folder_mini.png
new file mode 100644
index 0000000..5673da5
Binary files /dev/null and b/res/drawable-hdpi/ic_folder_mini.png differ
diff --git a/res/drawable-mdpi/ic_add_folder.png b/res/drawable-mdpi/ic_add_folder.png
new file mode 100644
index 0000000..5ff97be
Binary files /dev/null and b/res/drawable-mdpi/ic_add_folder.png differ
diff --git a/res/drawable-mdpi/ic_folder_mini.png b/res/drawable-mdpi/ic_folder_mini.png
new file mode 100644
index 0000000..1bf35f1
Binary files /dev/null and b/res/drawable-mdpi/ic_folder_mini.png differ
diff --git a/res/layout/bookmarks_fragment.xml b/res/layout/bookmarks_fragment.xml
index 78aaa24..8bb3133 100644
--- a/res/layout/bookmarks_fragment.xml
+++ b/res/layout/bookmarks_fragment.xml
@@ -49,7 +49,9 @@
android:id="@+id/BookmarksBreadCrumb"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:gravity="center_vertical|left" />
+ android:gravity="center_vertical|start"
+ android:layout_weight="1" />
+
-
+
-
-
diff --git a/res/layout/foldersonly_fragment.xml b/res/layout/foldersonly_fragment.xml
new file mode 100644
index 0000000..084481c
--- /dev/null
+++ b/res/layout/foldersonly_fragment.xml
@@ -0,0 +1,106 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/foldersonly_row.xml b/res/layout/foldersonly_row.xml
new file mode 100644
index 0000000..90ba8fa
--- /dev/null
+++ b/res/layout/foldersonly_row.xml
@@ -0,0 +1,59 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/menu/bookmarks_activity_menu.xml b/res/menu/bookmarks_activity_menu.xml
index 3fd4507..099159a 100644
--- a/res/menu/bookmarks_activity_menu.xml
+++ b/res/menu/bookmarks_activity_menu.xml
@@ -22,7 +22,13 @@
android:title="@string/AddBookmark"
android:icon="@drawable/ic_add_bookmark"
android:showAsAction="ifRoom|withText" />
-
+
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 40a405e..4c1c41c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -576,5 +576,9 @@
Redirect javascript logs to the logcat buffer.
View image in a new tab
-
+ Rename folder
+ Move folder
+ Move bookmark
+ Pick folder
+
\ No newline at end of file
diff --git a/src/org/tint/model/FoldersOnlyAdapter.java b/src/org/tint/model/FoldersOnlyAdapter.java
new file mode 100644
index 0000000..9ad098d
--- /dev/null
+++ b/src/org/tint/model/FoldersOnlyAdapter.java
@@ -0,0 +1,39 @@
+/*
+ * Tint Browser for Android
+ *
+ * Copyright (C) 2012 - to infinity and beyond J. Devauchelle and contributors.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 3 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+package org.tint.model;
+
+import android.content.Context;
+import android.database.Cursor;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.SimpleCursorAdapter;
+
+public class FoldersOnlyAdapter extends SimpleCursorAdapter {
+
+ public FoldersOnlyAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
+ super(context, layout, c, from, to, flags);
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View superView = super.getView(position, convertView, parent);
+
+ //until we have something
+
+ return superView;
+ }
+
+}
diff --git a/src/org/tint/providers/BookmarksWrapper.java b/src/org/tint/providers/BookmarksWrapper.java
index 48ba425..2a939b3 100644
--- a/src/org/tint/providers/BookmarksWrapper.java
+++ b/src/org/tint/providers/BookmarksWrapper.java
@@ -18,11 +18,10 @@
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Collections;
import java.util.Date;
-import java.util.List;
import org.tint.model.BookmarkHistoryItem;
-import org.tint.model.FolderItem;
import org.tint.utils.Constants;
import android.content.ContentResolver;
@@ -69,30 +68,51 @@ public static CursorLoader getCursorLoaderForStartPage(Context context, int limi
}
public static CursorLoader getCursorLoaderForBookmarks(Context context, long parentFolderId) {
+ return getCursorLoaderForBookmarks(context, parentFolderId, false);
+ }
+
+ public static CursorLoader getCursorLoaderForBookmarks(Context context, long parentFolderId, boolean onlyFolders) {
+ return getCursorLoaderForBookmarks(context, parentFolderId, onlyFolders, -1);
+ }
+
+ public static CursorLoader getCursorLoaderForBookmarks(Context context, long parentFolderId, boolean onlyFolders, long blacklist) {
int sortMode = PreferenceManager.getDefaultSharedPreferences(context).getInt(Constants.PREFERENCE_BOOKMARKS_SORT_MODE, 0);
-
- String whereClause = BookmarksProvider.Columns.PARENT_FOLDER_ID + " = " + parentFolderId + " AND (" + BookmarksProvider.Columns.BOOKMARK + " = 1 OR " + BookmarksProvider.Columns.IS_FOLDER + " = 1)";
-
+
+ String whereClause;
String orderClause;
+
+ if (onlyFolders) {
+ whereClause = BookmarksProvider.Columns._ID + " != ? AND "
+ + BookmarksProvider.Columns.PARENT_FOLDER_ID
+ + " = ? AND " + BookmarksProvider.Columns.IS_FOLDER + " = 1";
+ }
+ else {
+ whereClause = BookmarksProvider.Columns._ID + " != ? AND "
+ + BookmarksProvider.Columns.PARENT_FOLDER_ID + " = ? AND ("
+ + BookmarksProvider.Columns.BOOKMARK + " = 1 OR " + BookmarksProvider.Columns.IS_FOLDER + " = 1)";
+ }
+
switch (sortMode) {
- case 0:
- orderClause = BookmarksProvider.Columns.IS_FOLDER + " DESC, " + BookmarksProvider.Columns.VISITS + " DESC, " + BookmarksProvider.Columns.TITLE + " COLLATE NOCASE";
- break;
-
- case 1:
- orderClause = BookmarksProvider.Columns.IS_FOLDER + " DESC, " + BookmarksProvider.Columns.TITLE + " COLLATE NOCASE, " + BookmarksProvider.Columns.VISITS + " DESC";
- break;
-
- case 2:
- orderClause = BookmarksProvider.Columns.IS_FOLDER + " DESC, " + BookmarksProvider.Columns.VISITED_DATE + " DESC, " + BookmarksProvider.Columns.TITLE + " COLLATE NOCASE";
- break;
-
- default:
- orderClause = BookmarksProvider.Columns.IS_FOLDER + " DESC, " + BookmarksProvider.Columns.VISITS + " DESC, " + BookmarksProvider.Columns.TITLE + " COLLATE NOCASE";
- break;
- }
-
- return new CursorLoader(context, BookmarksProvider.BOOKMARKS_URI, HISTORY_BOOKMARKS_PROJECTION, whereClause, null, orderClause);
+ case 0:
+ orderClause = BookmarksProvider.Columns.IS_FOLDER + " DESC, " + BookmarksProvider.Columns.VISITS + " DESC, " + BookmarksProvider.Columns.TITLE + " COLLATE NOCASE";
+ break;
+
+ case 1:
+ orderClause = BookmarksProvider.Columns.IS_FOLDER + " DESC, " + BookmarksProvider.Columns.TITLE + " COLLATE NOCASE, " + BookmarksProvider.Columns.VISITS + " DESC";
+ break;
+
+ case 2:
+ orderClause = BookmarksProvider.Columns.IS_FOLDER + " DESC, " + BookmarksProvider.Columns.VISITED_DATE + " DESC, " + BookmarksProvider.Columns.TITLE + " COLLATE NOCASE";
+ break;
+
+ default:
+ orderClause = BookmarksProvider.Columns.IS_FOLDER + " DESC, " + BookmarksProvider.Columns.VISITS + " DESC, " + BookmarksProvider.Columns.TITLE + " COLLATE NOCASE";
+ break;
+ }
+
+ String whereArgs[] = new String[]{String.valueOf(blacklist), String.valueOf(parentFolderId)};
+
+ return new CursorLoader(context, BookmarksProvider.BOOKMARKS_URI, HISTORY_BOOKMARKS_PROJECTION, whereClause, whereArgs, orderClause);
}
public static CursorLoader getCursorLoaderForHistory(Context context) {
@@ -153,61 +173,71 @@ public static void clearHistoryAndOrBookmarks(ContentResolver contentResolver, b
contentResolver.delete(BookmarksProvider.BOOKMARKS_URI, whereClause, null);
}
-
- public static List getFirstLevelFoldersList(ContentResolver contentResolver) {
- List result = new ArrayList();
-
- String whereClause = BookmarksProvider.Columns.IS_FOLDER + " = 1 AND " + BookmarksProvider.Columns.PARENT_FOLDER_ID + " = -1";
- String orderClause = BookmarksProvider.Columns.TITLE;
-
- Cursor c = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, HISTORY_BOOKMARKS_PROJECTION, whereClause, null, orderClause);
- if ((c != null) &&
- (c.moveToFirst())) {
-
- int idIndex = c.getColumnIndex(BookmarksProvider.Columns._ID);
- int titleIndex = c.getColumnIndex(BookmarksProvider.Columns.TITLE);
-
- do {
- result.add(new FolderItem(c.getLong(idIndex), c.getString(titleIndex)));
- } while (c.moveToNext());
-
- c.close();
+
+ public static String getFolderStack(ContentResolver cr, long folderId) {
+ StringBuilder sb = new StringBuilder();
+ ArrayList cache = new ArrayList();
+
+ long fid = folderId;
+ BookmarkHistoryItem bhi;
+ String stack_fmt = "{%1$s,%2$s}";
+
+ while (fid != -1) {
+ bhi = getBookmarkById(cr, fid);
+ cache.add(String.format(stack_fmt, bhi.getId(), bhi.getTitle()));
+ fid = bhi.getFolderId();
}
-
- return result;
+ cache.add(String.format(stack_fmt, -1, null));
+
+ Collections.reverse(cache);
+
+ for (String citem: cache) {
+ sb.append(citem);
+ sb.append("//;//");
+ }
+
+ return sb.toString();
}
-
- public static long getFolderId(ContentResolver contentResolver, String folderName, boolean createIfNotPresent) {
- String escapedFolderName = DatabaseUtils.sqlEscapeString(folderName);
-
- String whereClause = BookmarksProvider.Columns.TITLE + " = " + escapedFolderName + " AND " + BookmarksProvider.Columns.IS_FOLDER + " = 1";
-
- Cursor c = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, HISTORY_BOOKMARKS_PROJECTION, whereClause, null, null);
- if ((c != null) &&
- (c.moveToFirst())) {
- return c.getLong(c.getColumnIndex(BookmarksProvider.Columns._ID));
+
+ public static void moveItem(ContentResolver cr, long itemId, long newParentId) {
+ if (itemId ==newParentId)
+ return;
+
+ String whereClause = BookmarksProvider.Columns._ID+"=?";
+ String[] whereArgs = new String[]{String.valueOf(itemId)};
+
+ ContentValues cv = new ContentValues();
+ cv.put(BookmarksProvider.Columns.PARENT_FOLDER_ID, newParentId);
+
+ cr.update(BookmarksProvider.BOOKMARKS_URI, cv, whereClause, whereArgs);
+ }
+
+ public static void renameFolder(ContentResolver cr, long folderId, String newTitle) {
+ String whereClause = BookmarksProvider.Columns._ID+"=?";
+ String[] whereArgs = new String[]{String.valueOf(folderId)};
+
+ ContentValues cv = new ContentValues();
+ cv.put(BookmarksProvider.Columns.TITLE, newTitle);
+
+ cr.update(BookmarksProvider.BOOKMARKS_URI, cv, whereClause, whereArgs);
+ }
+
+ public static long createFolder(ContentResolver cr, String folderName, long parentId) {
+ ContentValues cv = new ContentValues();
+ cv.put(BookmarksProvider.Columns.TITLE, folderName);
+ cv.putNull(BookmarksProvider.Columns.URL);
+ cv.put(BookmarksProvider.Columns.BOOKMARK, 0);
+ cv.put(BookmarksProvider.Columns.IS_FOLDER, 1);
+ cv.put(BookmarksProvider.Columns.PARENT_FOLDER_ID, parentId);
+
+ Uri result = cr.insert(BookmarksProvider.BOOKMARKS_URI, cv);
+
+ Cursor inserted = cr.query(result, HISTORY_BOOKMARKS_PROJECTION, null, null, null);
+ if ((inserted != null) &&
+ (inserted.moveToFirst())) {
+ return inserted.getLong(inserted.getColumnIndex(BookmarksProvider.Columns._ID));
} else {
- if (createIfNotPresent) {
-
- ContentValues values = new ContentValues();
- values.put(BookmarksProvider.Columns.TITLE, folderName);
- values.putNull(BookmarksProvider.Columns.URL);
- values.put(BookmarksProvider.Columns.BOOKMARK, 0);
- values.put(BookmarksProvider.Columns.IS_FOLDER, 1);
-
- Uri result = contentResolver.insert(BookmarksProvider.BOOKMARKS_URI, values);
-
- Cursor inserted = contentResolver.query(result, HISTORY_BOOKMARKS_PROJECTION, null, null, null);
- if ((inserted != null) &&
- (inserted.moveToFirst())) {
- return inserted.getLong(inserted.getColumnIndex(BookmarksProvider.Columns._ID));
- } else {
- return -1;
- }
-
- } else {
- return -1;
- }
+ return -1;
}
}
@@ -227,18 +257,18 @@ public static void setAsBookmark(ContentResolver contentResolver, long id, long
if (id != -1) {
String[] colums = new String[] { BookmarksProvider.Columns._ID };
- String whereClause = BookmarksProvider.Columns._ID + " = " + id;
+ String whereClause = BookmarksProvider.Columns._ID + " = ?";
+ String[] whereArgs = new String[]{String.valueOf(id)};
- Cursor cursor = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, colums, whereClause, null, null);
+ Cursor cursor = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, colums, whereClause, whereArgs, null);
bookmarkExist = (cursor != null) && (cursor.moveToFirst());
} else {
String[] colums = new String[] { BookmarksProvider.Columns._ID };
- String escapedUrl = DatabaseUtils.sqlEscapeString(url);
-
- String whereClause = BookmarksProvider.Columns.URL + " = " + escapedUrl;
+ String whereClause = BookmarksProvider.Columns.URL + " = ?";
+ String[] whereArgs = new String[]{url};
- Cursor cursor = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, colums, whereClause, null, null);
+ Cursor cursor = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, colums, whereClause, whereArgs, null);
bookmarkExist = (cursor != null) && (cursor.moveToFirst());
if (bookmarkExist) {
id = cursor.getLong(cursor.getColumnIndex(BookmarksProvider.Columns._ID));
@@ -265,16 +295,18 @@ public static void setAsBookmark(ContentResolver contentResolver, long id, long
}
if (bookmarkExist) {
- contentResolver.update(BookmarksProvider.BOOKMARKS_URI, values, BookmarksProvider.Columns._ID + " = " + id, null);
+ contentResolver.update(BookmarksProvider.BOOKMARKS_URI, values,
+ BookmarksProvider.Columns._ID + " = ?", new String[]{String.valueOf(id)});
} else {
contentResolver.insert(BookmarksProvider.BOOKMARKS_URI, values);
}
}
public static void deleteBookmark(ContentResolver contentResolver, long id) {
- String whereClause = BookmarksProvider.Columns._ID + " = " + id;
+ String whereClause = BookmarksProvider.Columns._ID + " = ?";
+ String[] whereArgs = new String[]{String.valueOf(id)};
- Cursor c = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, HISTORY_BOOKMARKS_PROJECTION, whereClause, null, null);
+ Cursor c = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, HISTORY_BOOKMARKS_PROJECTION, whereClause, whereArgs, null);
if (c != null) {
if (c.moveToFirst()) {
if (c.getInt(c.getColumnIndex(BookmarksProvider.Columns.BOOKMARK)) == 1) {
@@ -286,11 +318,11 @@ public static void deleteBookmark(ContentResolver contentResolver, long id) {
values.put(BookmarksProvider.Columns.PARENT_FOLDER_ID, -1);
values.putNull(BookmarksProvider.Columns.CREATION_DATE);
- contentResolver.update(BookmarksProvider.BOOKMARKS_URI, values, whereClause, null);
+ contentResolver.update(BookmarksProvider.BOOKMARKS_URI, values, whereClause, whereArgs);
} else {
// never visited, it can be deleted.
- contentResolver.delete(BookmarksProvider.BOOKMARKS_URI, whereClause, null);
+ contentResolver.delete(BookmarksProvider.BOOKMARKS_URI, whereClause, whereArgs);
}
}
}
@@ -323,8 +355,8 @@ public static void deleteFolder(ContentResolver contentResolver, long id) {
}
// Delete content of the folder.
- String whereClause = BookmarksProvider.Columns.PARENT_FOLDER_ID + " = " + id + " AND " + BookmarksProvider.Columns.BOOKMARK + " > 0";
- c = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, HISTORY_BOOKMARKS_PROJECTION, whereClause, null, null);
+ String whereClause = BookmarksProvider.Columns.PARENT_FOLDER_ID + " = ? AND " + BookmarksProvider.Columns.BOOKMARK + " > 0";
+ c = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, HISTORY_BOOKMARKS_PROJECTION, whereClause, new String[]{String.valueOf(id)}, null);
if (c != null) {
if (c.moveToFirst()) {
@@ -353,15 +385,16 @@ public static void deleteFolder(ContentResolver contentResolver, long id) {
}
// Finally delete the folder.
- contentResolver.delete(BookmarksProvider.BOOKMARKS_URI, BookmarksProvider.Columns._ID + " = " + id, null);
+ contentResolver.delete(BookmarksProvider.BOOKMARKS_URI, BookmarksProvider.Columns._ID + " = ?", new String[]{String.valueOf(id)});
provider.setNotifyChanges(true);
}
public static void deleteHistoryRecord(ContentResolver contentResolver, long id) {
- String whereClause = BookmarksProvider.Columns._ID + " = " + id;
+ String whereClause = BookmarksProvider.Columns._ID + " = ?";
+ String[] whereArgs = new String[]{String.valueOf(id)};
- Cursor c = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, HISTORY_BOOKMARKS_PROJECTION, whereClause, null, null);
+ Cursor c = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, HISTORY_BOOKMARKS_PROJECTION, whereClause, new String[]{String.valueOf(id)}, null);
if (c != null) {
if (c.moveToFirst()) {
if (c.getInt(c.getColumnIndex(BookmarksProvider.Columns.BOOKMARK)) > 0) {
@@ -370,10 +403,10 @@ public static void deleteHistoryRecord(ContentResolver contentResolver, long id)
values.put(BookmarksProvider.Columns.VISITS, 0);
values.putNull(BookmarksProvider.Columns.VISITED_DATE);
- contentResolver.update(BookmarksProvider.BOOKMARKS_URI, values, whereClause, null);
+ contentResolver.update(BookmarksProvider.BOOKMARKS_URI, values, whereClause, whereArgs);
} else {
// Not a bookmark, it can be deleted.
- contentResolver.delete(BookmarksProvider.BOOKMARKS_URI, whereClause, null);
+ contentResolver.delete(BookmarksProvider.BOOKMARKS_URI, whereClause, whereArgs);
}
}
@@ -389,14 +422,19 @@ public static void deleteHistoryRecord(ContentResolver contentResolver, long id)
* @param originalUrl The original url
*/
public static void updateHistory(ContentResolver contentResolver, String title, String url, String originalUrl) {
- String[] colums = new String[] { BookmarksProvider.Columns._ID, BookmarksProvider.Columns.URL, BookmarksProvider.Columns.BOOKMARK, BookmarksProvider.Columns.VISITS };
+ String[] colums = new String[] {
+ BookmarksProvider.Columns._ID,
+ BookmarksProvider.Columns.URL,
+ BookmarksProvider.Columns.BOOKMARK,
+ BookmarksProvider.Columns.VISITS
+ };
- String escapedUrl = url != null ? DatabaseUtils.sqlEscapeString(url) : "";
- String escapedOriginalUrl = originalUrl != null ? DatabaseUtils.sqlEscapeString(originalUrl) : "";
+ String escapedUrl = url != null ? url : "";
+ String escapedOriginalUrl = originalUrl != null ? originalUrl : "";
- String whereClause = BookmarksProvider.Columns.URL + " = " + escapedUrl + " OR " + BookmarksProvider.Columns.URL + " = " + escapedOriginalUrl;
+ String whereClause = BookmarksProvider.Columns.URL + " = ? OR " + BookmarksProvider.Columns.URL + " = ?";
- Cursor cursor = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, colums, whereClause, null, null);
+ Cursor cursor = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, colums, whereClause, new String[]{escapedUrl, escapedOriginalUrl}, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
@@ -414,7 +452,7 @@ public static void updateHistory(ContentResolver contentResolver, String title,
values.put(BookmarksProvider.Columns.VISITED_DATE, new Date().getTime());
values.put(BookmarksProvider.Columns.VISITS, visits);
- contentResolver.update(BookmarksProvider.BOOKMARKS_URI, values, BookmarksProvider.Columns._ID + " = " + id, null);
+ contentResolver.update(BookmarksProvider.BOOKMARKS_URI, values, BookmarksProvider.Columns._ID + " = ?", new String[]{String.valueOf(id)});
} else {
ContentValues values = new ContentValues();
@@ -431,8 +469,8 @@ public static void updateHistory(ContentResolver contentResolver, String title,
}
}
- private static final String TRUNCATE_HISTORY_DELETE_WHERE_PATTERN = "(" + BookmarksProvider.Columns.BOOKMARK + " = 0 OR " + BookmarksProvider.Columns.BOOKMARK + " IS NULL) AND " + BookmarksProvider.Columns.VISITED_DATE + " < %s";
- private static final String TRUNCATE_HISTORY_UPDATE_WHERE_PATTERN = BookmarksProvider.Columns.BOOKMARK + " = 1 AND " + BookmarksProvider.Columns.VISITED_DATE + " < %s";
+ private static final String TRUNCATE_HISTORY_DELETE_WHERE_PATTERN = "(" + BookmarksProvider.Columns.BOOKMARK + " = 0 OR " + BookmarksProvider.Columns.BOOKMARK + " IS NULL) AND " + BookmarksProvider.Columns.VISITED_DATE + " < ?";
+ private static final String TRUNCATE_HISTORY_UPDATE_WHERE_PATTERN = BookmarksProvider.Columns.BOOKMARK + " = 1 AND " + BookmarksProvider.Columns.VISITED_DATE + " < ?";
/**
* Remove from history values prior to now minus the number of days defined in preferences.
@@ -455,24 +493,23 @@ public static void truncateHistory(ContentResolver contentResolver, String prefH
c.set(Calendar.MILLISECOND, 0);
c.add(Calendar.DAY_OF_YEAR, - historySize);
- String whereClauseDelete = String.format(TRUNCATE_HISTORY_DELETE_WHERE_PATTERN, c.getTimeInMillis());
- String whereClauseUpdate = String.format(TRUNCATE_HISTORY_UPDATE_WHERE_PATTERN, c.getTimeInMillis());
+ String[] timeArgs = {String.valueOf(c.getTimeInMillis())};
ContentValues updateValues = new ContentValues();
updateValues.putNull(BookmarksProvider.Columns.VISITED_DATE);
updateValues.put(BookmarksProvider.Columns.VISITS, 0);
try {
- contentResolver.delete(BookmarksProvider.BOOKMARKS_URI, whereClauseDelete, null);
- contentResolver.update(BookmarksProvider.BOOKMARKS_URI, updateValues, whereClauseUpdate, null);
+ contentResolver.delete(BookmarksProvider.BOOKMARKS_URI, TRUNCATE_HISTORY_DELETE_WHERE_PATTERN, timeArgs);
+ contentResolver.update(BookmarksProvider.BOOKMARKS_URI, updateValues, TRUNCATE_HISTORY_UPDATE_WHERE_PATTERN, timeArgs);
} catch (Exception e) {
e.printStackTrace();
Log.w("BookmarksWrapper", "Unable to truncate history: " + e.getMessage());
}
}
- private static final String UPDATE_FAVICON_WHERE_PATTERN_1 = BookmarksProvider.Columns.URL + " = %s OR " + BookmarksProvider.Columns.URL + " = %s";
- private static final String UPDATE_FAVICON_WHERE_PATTERN_2 = BookmarksProvider.Columns.URL + " = %s";
+ private static final String UPDATE_FAVICON_WHERE_PATTERN_1 = BookmarksProvider.Columns.URL + " = ? OR " + BookmarksProvider.Columns.URL + " = ?";
+ private static final String UPDATE_FAVICON_WHERE_PATTERN_2 = BookmarksProvider.Columns.URL + " = ?";
/**
* Update the favicon in history/bookmarks database.
@@ -486,16 +523,15 @@ public static void updateFavicon(ContentResolver contentResolver, String url, St
(favicon != null) &&
(contentResolver != null)) {
String whereClause;
+ String whereArgs[];
if ((originalUrl != null) &&
!url.equals(originalUrl)) {
- url = DatabaseUtils.sqlEscapeString(url);
- originalUrl = DatabaseUtils.sqlEscapeString(originalUrl);
-
- whereClause = String.format(UPDATE_FAVICON_WHERE_PATTERN_1, url, originalUrl);
+ whereClause = UPDATE_FAVICON_WHERE_PATTERN_1;
+ whereArgs = new String[]{url, originalUrl};
} else {
- url = DatabaseUtils.sqlEscapeString(url);
- whereClause = String.format(UPDATE_FAVICON_WHERE_PATTERN_2, url);
+ whereClause = UPDATE_FAVICON_WHERE_PATTERN_2;
+ whereArgs = new String[]{url};
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -505,7 +541,7 @@ public static void updateFavicon(ContentResolver contentResolver, String url, St
values.put(BookmarksProvider.Columns.FAVICON, os.toByteArray());
try {
- contentResolver.update(BookmarksProvider.BOOKMARKS_URI, values, whereClause, null);
+ contentResolver.update(BookmarksProvider.BOOKMARKS_URI, values, whereClause, whereArgs);
} catch (Exception e) {
e.printStackTrace();
Log.w("BookmarksWrapper", "Unable to update favicon: " + e.getMessage());
@@ -513,24 +549,23 @@ public static void updateFavicon(ContentResolver contentResolver, String url, St
}
}
- private static final String BOOKMARK_BY_URL_WHERE_PATTERN_1 = "(" + BookmarksProvider.Columns.URL + " = %s OR " + BookmarksProvider.Columns.URL + " = %s) AND " + BookmarksProvider.Columns.BOOKMARK + " = 1";
- private static final String BOOKMARK_BY_URL_WHERE_PATTERN_2 = BookmarksProvider.Columns.URL + " = %s AND " + BookmarksProvider.Columns.BOOKMARK + " = 1";
+ private static final String BOOKMARK_BY_URL_WHERE_PATTERN_1 = "(" + BookmarksProvider.Columns.URL + " = ? OR " + BookmarksProvider.Columns.URL + " = ?) AND " + BookmarksProvider.Columns.BOOKMARK + " = 1";
+ private static final String BOOKMARK_BY_URL_WHERE_PATTERN_2 = BookmarksProvider.Columns.URL + " = ? AND " + BookmarksProvider.Columns.BOOKMARK + " = 1";
public static void updateThumbnail(ContentResolver contentResolver, String url, String originalUrl, Bitmap thumbnail) {
if ((url != null) &&
(thumbnail != null) &&
(contentResolver != null)) {
String whereClause;
+ String whereArgs[];
if ((originalUrl != null) &&
!url.equals(originalUrl)) {
- url = DatabaseUtils.sqlEscapeString(url);
- originalUrl = DatabaseUtils.sqlEscapeString(originalUrl);
-
- whereClause = String.format(BOOKMARK_BY_URL_WHERE_PATTERN_1, url, originalUrl);
+ whereClause = BOOKMARK_BY_URL_WHERE_PATTERN_1;
+ whereArgs = new String[]{url, originalUrl};
} else {
- url = DatabaseUtils.sqlEscapeString(url);
- whereClause = String.format(BOOKMARK_BY_URL_WHERE_PATTERN_2, url);
+ whereClause = BOOKMARK_BY_URL_WHERE_PATTERN_2;
+ whereArgs = new String[]{url};
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -540,7 +575,7 @@ public static void updateThumbnail(ContentResolver contentResolver, String url,
values.put(BookmarksProvider.Columns.THUMBNAIL, os.toByteArray());
try {
- contentResolver.update(BookmarksProvider.BOOKMARKS_URI, values, whereClause, null);
+ contentResolver.update(BookmarksProvider.BOOKMARKS_URI, values, whereClause, whereArgs);
} catch (Exception e) {
e.printStackTrace();
Log.w("BookmarksWrapper", "Unable to update thumbnail: " + e.getMessage());
@@ -552,19 +587,18 @@ public static boolean urlHasBookmark(ContentResolver contentResolver, String url
if ((url != null) &&
(contentResolver != null)) {
String whereClause;
+ String whereArgs[];
if ((originalUrl != null) &&
!url.equals(originalUrl)) {
- url = DatabaseUtils.sqlEscapeString(url);
- originalUrl = DatabaseUtils.sqlEscapeString(originalUrl);
-
- whereClause = String.format(BOOKMARK_BY_URL_WHERE_PATTERN_1, url, originalUrl);
+ whereArgs = new String[]{url, originalUrl};
+ whereClause = BOOKMARK_BY_URL_WHERE_PATTERN_1;
} else {
- url = DatabaseUtils.sqlEscapeString(url);
- whereClause = String.format(BOOKMARK_BY_URL_WHERE_PATTERN_2, url);
+ whereClause = BOOKMARK_BY_URL_WHERE_PATTERN_2;
+ whereArgs = new String[]{url};
}
- Cursor c = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, HISTORY_BOOKMARKS_PROJECTION, whereClause, null, null);
+ Cursor c = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, HISTORY_BOOKMARKS_PROJECTION, whereClause, whereArgs, null);
return c != null && c.getCount() > 0;
} else {
@@ -572,13 +606,14 @@ public static boolean urlHasBookmark(ContentResolver contentResolver, String url
}
}
- private static final String TOGGLE_BOOKMARK_WHERE_PATTERN = BookmarksProvider.Columns._ID + " = %s";
+ private static final String TOGGLE_BOOKMARK_WHERE_PATTERN = BookmarksProvider.Columns._ID + " = ?";
public static void toggleBookmark(ContentResolver contentResolver, long id, boolean bookmark) {
String[] colums = new String[] { BookmarksProvider.Columns._ID };
- String whereClause = String.format(TOGGLE_BOOKMARK_WHERE_PATTERN, id);
+ String whereClause = TOGGLE_BOOKMARK_WHERE_PATTERN;
+ String[] whereArgs = new String[] {String.valueOf(id)};
- Cursor cursor = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, colums, whereClause, null, null);
+ Cursor cursor = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, colums, whereClause, whereArgs, null);
boolean recordExists = (cursor != null) && (cursor.moveToFirst());
if (recordExists) {
@@ -594,7 +629,7 @@ public static void toggleBookmark(ContentResolver contentResolver, long id, bool
values.putNull(BookmarksProvider.Columns.THUMBNAIL);
}
- contentResolver.update(BookmarksProvider.BOOKMARKS_URI, values, whereClause, null);
+ contentResolver.update(BookmarksProvider.BOOKMARKS_URI, values, whereClause, whereArgs);
}
}
@@ -645,7 +680,7 @@ public static void fillDefaultBookmaks(ContentResolver contentResolver, String[]
}
private static final String SUGGESTIONS_PATTERN = "%%%s%%";
- private static final String SUGGESTIONS_WHERE_PATTERN = BookmarksProvider.Columns.TITLE + " LIKE %s OR " + BookmarksProvider.Columns.URL + " LIKE %s";
+ private static final String SUGGESTIONS_WHERE_PATTERN = BookmarksProvider.Columns.TITLE + " LIKE ? OR " + BookmarksProvider.Columns.URL + " LIKE ?";
private static final String SUGGESTIONS_ORDER = BookmarksProvider.Columns.VISITED_DATE + " DESC, " + BookmarksProvider.Columns.BOOKMARK + " DESC, " + BookmarksProvider.Columns.TITLE + " ASC";
/**
@@ -658,25 +693,25 @@ public static void fillDefaultBookmaks(ContentResolver contentResolver, String[]
public static Cursor getUrlSuggestions(ContentResolver contentResolver, String pattern) {
if ((pattern != null) &&
(pattern.length() > 0)) {
-
- String sqlPattern = DatabaseUtils.sqlEscapeString(String.format(SUGGESTIONS_PATTERN, pattern));
- String whereClause = String.format(SUGGESTIONS_WHERE_PATTERN, sqlPattern, sqlPattern);
-
+
+ String whereClause = SUGGESTIONS_WHERE_PATTERN;
+ String imLike = String.format(SUGGESTIONS_PATTERN, pattern);
+
return contentResolver.query(BookmarksProvider.BOOKMARKS_URI,
HISTORY_BOOKMARKS_PROJECTION,
whereClause,
- null,
+ new String[]{imLike, imLike},
SUGGESTIONS_ORDER);
}
return null;
}
- private static final String CHILDREN_FOLDERS_WHERE_PATTERN = BookmarksProvider.Columns.IS_FOLDER + " > 0 AND " + BookmarksProvider.Columns.PARENT_FOLDER_ID + " = %S";
+ private static final String CHILDREN_FOLDERS_WHERE_PATTERN = BookmarksProvider.Columns.IS_FOLDER + " > 0 AND " + BookmarksProvider.Columns.PARENT_FOLDER_ID + " = ?";
private static Cursor getChildrenFolders(ContentResolver contentResolver, long folderId) {
- String whereClause = String.format(CHILDREN_FOLDERS_WHERE_PATTERN, folderId);
- return contentResolver.query(BookmarksProvider.BOOKMARKS_URI, HISTORY_BOOKMARKS_PROJECTION, whereClause, null, null);
+ String whereClause = CHILDREN_FOLDERS_WHERE_PATTERN;
+ return contentResolver.query(BookmarksProvider.BOOKMARKS_URI, HISTORY_BOOKMARKS_PROJECTION, whereClause, new String[]{String.valueOf(folderId)}, null);
}
}
diff --git a/src/org/tint/ui/activities/BookmarksActivity.java b/src/org/tint/ui/activities/BookmarksActivity.java
index 101c246..c4a239d 100644
--- a/src/org/tint/ui/activities/BookmarksActivity.java
+++ b/src/org/tint/ui/activities/BookmarksActivity.java
@@ -25,6 +25,7 @@
import org.tint.tasks.HistoryBookmarksExportTask;
import org.tint.tasks.HistoryBookmarksImportTask;
import org.tint.ui.fragments.BookmarksFragment;
+import org.tint.ui.fragments.FoldersOnlyFragment;
import org.tint.ui.fragments.HistoryFragment;
import org.tint.ui.managers.UIManager;
import org.tint.ui.preferences.IHistoryBookmaksExportListener;
@@ -50,7 +51,7 @@
import android.view.Menu;
import android.view.MenuItem;
-public class BookmarksActivity extends Activity implements IHistoryBookmaksExportListener, IHistoryBookmaksImportListener {
+public class BookmarksActivity extends Activity implements IHistoryBookmaksExportListener, IHistoryBookmaksImportListener, FoldersOnlyFragment.FoldersOnlyListener {
private static final String EXTRA_SELECTED_TAB_INDEX = "EXTRA_SELECTED_TAB_INDEX";
@@ -135,6 +136,8 @@ public boolean onPrepareOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
+ BookmarksFragment bfg;
+
switch (item.getItemId()) {
case android.R.id.home:
setResult(RESULT_CANCELED);
@@ -147,7 +150,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
startActivity(i);
return true;
-
+
+ case R.id.BookmarksActivityMenuAddFolder:
+ bfg = (BookmarksFragment)getFragmentManager().findFragmentByTag("bookmarks");
+ bfg.newFolder();
+ return true;
+
case R.id.BookmarksActivityMenuSortBookmarks:
changeSortMode();
return true;
@@ -370,5 +378,10 @@ public void onClick(DialogInterface dialog, int which) {
AlertDialog alert = builder.create();
alert.show();
}
-
+
+ @Override
+ public void onSelectFolder(long folder_id, String folder_name) {
+ BookmarksFragment bfg = (BookmarksFragment)getFragmentManager().findFragmentByTag("bookmarks");
+ bfg.onSelectFolder(folder_id, folder_name);
+ }
}
diff --git a/src/org/tint/ui/activities/EditBookmarkActivity.java b/src/org/tint/ui/activities/EditBookmarkActivity.java
index 2c960b9..9afb714 100644
--- a/src/org/tint/ui/activities/EditBookmarkActivity.java
+++ b/src/org/tint/ui/activities/EditBookmarkActivity.java
@@ -15,46 +15,36 @@
package org.tint.ui.activities;
-import java.util.List;
-
import org.tint.R;
-import org.tint.model.FolderItem;
+import org.tint.model.BookmarkHistoryItem;
import org.tint.providers.BookmarksWrapper;
+import org.tint.ui.fragments.FoldersOnlyFragment;
import org.tint.utils.Constants;
import android.app.ActionBar;
import android.app.Activity;
-import android.content.Context;
+import android.app.Fragment;
+import android.app.FragmentTransaction;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemSelectedListener;
-import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
-import android.widget.Spinner;
-import android.widget.TextView;
import android.widget.Toast;
-public class EditBookmarkActivity extends Activity {
+public class EditBookmarkActivity extends Activity implements FoldersOnlyFragment.FoldersOnlyListener {
private long mId = -1;
+ private long mFolderId = -1;
private EditText mLabel;
private EditText mUrl;
- private Spinner mFoldersSpinner;
-
- private EditText mNewFolderName;
-
private Button mOk;
private Button mCancel;
-
- private List mFolders;
+ private Button mPickFolder;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -67,41 +57,10 @@ protected void onCreate(Bundle savedInstanceState) {
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
-
- mFolders = BookmarksWrapper.getFirstLevelFoldersList(getContentResolver());
- mFolders.add(0, new FolderItem(-1, getString(R.string.Bookmarks)));
- mFolders.add(0, new FolderItem(-2, getString(R.string.NewFolder)));
mLabel = (EditText) findViewById(R.id.EditBookmarkActivity_LabelEdit);
mUrl = (EditText) findViewById(R.id.EditBookmarkActivity_UrlEdit);
- mFoldersSpinner = (Spinner) findViewById(R.id.EditBookmarkActivity_FolderSpinner);
-
- FoldersAdapter adapter = new FoldersAdapter(this, mFolders);
- adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- mFoldersSpinner.setAdapter(adapter);
-
- mFoldersSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
-
- @Override
- public void onItemSelected(AdapterView> arg0, View arg1, int position, long id) {
- if (position == 0) {
- mNewFolderName.setVisibility(View.VISIBLE);
- mNewFolderName.requestFocus();
- } else {
- mNewFolderName.setVisibility(View.GONE);
- }
- }
-
- @Override
- public void onNothingSelected(AdapterView> arg0) { }
- });
-
- // Default to root folder.
- mFoldersSpinner.setSelection(1);
-
- mNewFolderName = (EditText) findViewById(R.id.EditBookmarkActivity_FolderValue);
-
mOk = (Button) findViewById(R.id.EditBookmarkActivity_OK);
mOk.setOnClickListener(new OnClickListener() {
@Override
@@ -121,7 +80,9 @@ public void onClick(View arg0) {
finish();
}
});
-
+
+ mPickFolder = (Button) findViewById(R.id.PickFolder);
+
Bundle extras = getIntent().getExtras();
if (extras != null) {
String label = extras.getString(Constants.EXTRA_LABEL);
@@ -135,15 +96,16 @@ public void onClick(View arg0) {
}
// This is a bit dirty...
- long folderId = extras.getLong(Constants.EXTRA_FOLDER_ID);
- if (folderId != -1) {
- for (int i = 0; i < mFolders.size(); i++) {
- if (mFolders.get(i).getId() == folderId) {
- mFoldersSpinner.setSelection(i);
- break;
- }
- }
+ if (extras.containsKey(Constants.EXTRA_FOLDER_ID)) {
+ mFolderId = extras.getLong(Constants.EXTRA_FOLDER_ID);
+ }
+ if (mFolderId != -1) {
+ BookmarkHistoryItem bhi = BookmarksWrapper.getBookmarkById(getContentResolver(), mFolderId);
+ mPickFolder.setText(bhi.getTitle());
}
+ else {
+ mPickFolder.setText(R.string.Bookmarks);
+ }
mId = extras.getLong(Constants.EXTRA_ID);
}
@@ -167,62 +129,42 @@ private boolean save() {
if ((!TextUtils.isEmpty(label)) &&
(!TextUtils.isEmpty(url))) {
- long folderId = -1;
- int folderSpinnerSelection = mFoldersSpinner.getSelectedItemPosition();
-
- switch (folderSpinnerSelection) {
- case 0:
- if (TextUtils.isEmpty(mNewFolderName.getText().toString())) {
- Toast.makeText(this, R.string.ProvideNewFolderName, Toast.LENGTH_SHORT).show();
- return false;
- } else {
- folderId = BookmarksWrapper.getFolderId(getContentResolver(), mNewFolderName.getText().toString(), true);
- }
- break;
-
- case 1:
- folderId = -1;
- break;
- default:
- folderId = mFolders.get(folderSpinnerSelection).getId();
- break;
- }
-
- BookmarksWrapper.setAsBookmark(getContentResolver(), mId, folderId, label, url, true);
+ BookmarksWrapper.setAsBookmark(getContentResolver(), mId, mFolderId, label, url, true);
return true;
} else {
Toast.makeText(this, R.string.AddBookmarkLabelOrUrlEmpty, Toast.LENGTH_SHORT).show();
return false;
}
}
-
- private class FoldersAdapter extends ArrayAdapter {
-
- public FoldersAdapter(Context context, List values) {
- super(context, android.R.layout.simple_spinner_item, android.R.id.text1, values);
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View v = super.getView(position, convertView, parent);
-
- TextView tv = (TextView) v.findViewById(android.R.id.text1);
- tv.setText(getItem(position).getTitle());
-
- return v;
+ public void pickFolder(View view) {
+ FragmentTransaction ft = getFragmentManager().beginTransaction();
+ //Remove fragment else it will crash as it is already added to backstack
+ Fragment prev = getFragmentManager().findFragmentByTag("dialog");
+ if (prev != null) {
+ ft.remove(prev);
}
+ ft.addToBackStack(null);
- @Override
- public View getDropDownView(int position, View convertView, ViewGroup parent) {
- View v = super.getDropDownView(position, convertView, parent);
-
- TextView tv = (TextView) v.findViewById(android.R.id.text1);
- tv.setText(getItem(position).getTitle());
-
- return v;
- }
+ final FoldersOnlyFragment newFragment = new FoldersOnlyFragment();
+ Bundle args = new Bundle();
+ args.putString(FoldersOnlyFragment.EXTRA_FOLDER_STACK,
+ BookmarksWrapper.getFolderStack(getContentResolver(), mFolderId));
+ newFragment.setArguments(args);
-
+ newFragment.show(getFragmentManager(), "dialog");
+ }
+
+ @Override
+ public void onSelectFolder(long folder_id, String folder_name) {
+ //Toast.makeText(this, "Folder id "+folder_id+" selected", Toast.LENGTH_SHORT).show();
+ mFolderId = folder_id;
+ if (folder_id == -1) {
+ mPickFolder.setText(R.string.Bookmarks);
+ }
+ else {
+ mPickFolder.setText(folder_name);
+ }
}
}
diff --git a/src/org/tint/ui/activities/TintBrowserActivity.java b/src/org/tint/ui/activities/TintBrowserActivity.java
index c8663ae..dc6b062 100644
--- a/src/org/tint/ui/activities/TintBrowserActivity.java
+++ b/src/org/tint/ui/activities/TintBrowserActivity.java
@@ -368,7 +368,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent)
if (mUIManager.getUploadMessage() == null) {
return;
}
-
+
Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();
mUIManager.getUploadMessage().onReceiveValue(result);
mUIManager.setUploadMessage(null);
diff --git a/src/org/tint/ui/fragments/BookmarksFragment.java b/src/org/tint/ui/fragments/BookmarksFragment.java
index 040176e..97a49b3 100644
--- a/src/org/tint/ui/fragments/BookmarksFragment.java
+++ b/src/org/tint/ui/fragments/BookmarksFragment.java
@@ -40,6 +40,7 @@
import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentBreadCrumbs;
+import android.app.FragmentTransaction;
import android.app.LoaderManager;
import android.app.ProgressDialog;
import android.content.DialogInterface;
@@ -53,6 +54,7 @@
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
+import android.text.TextUtils;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -62,6 +64,7 @@
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView;
+import android.widget.EditText;
import android.widget.ImageView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
@@ -81,6 +84,8 @@ public class BookmarksFragment extends Fragment implements LoaderManager.LoaderC
private static final int CONTEXT_MENU_DELETE_BOOKMARK = Menu.FIRST + 4;
private static final int CONTEXT_MENU_DELETE_FOLDER = Menu.FIRST + 5;
+ private static final int CONTEXT_MENU_RENAME_FOLDER = Menu.FIRST + 6;
+ private static final int CONTEXT_MENU_MOVE_ITEM = Menu.FIRST + 7;
private View mContainer = null;
@@ -93,6 +98,7 @@ public class BookmarksFragment extends Fragment implements LoaderManager.LoaderC
private ViewGroup mBreadCrumbGroup;
private FragmentBreadCrumbs mFoldersBreadCrumb;
private ImageView mBackBreadCrumb;
+ //private ImageView mAddFolderBreadCrumb;
private BookmarksAdapter mAdapter;
@@ -105,14 +111,20 @@ public class BookmarksFragment extends Fragment implements LoaderManager.LoaderC
private OnSharedPreferenceChangeListener mPreferenceChangeListener;
+ private long contextItemId;
+
public BookmarksFragment() {
mUIManager = Controller.getInstance().getUIManager();
}
+ public long getCurrentFolderId() {
+ return mNavigationList.get(mNavigationList.size() - 1).getId();
+ }
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
+
mPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
@Override
@@ -137,6 +149,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mIsTablet = UIFactory.isTablet(getActivity());
if (mContainer == null) {
+
mContainer = inflater.inflate(R.layout.bookmarks_fragment, container, false);
mBreadCrumbGroup = (ViewGroup) mContainer.findViewById(R.id.BookmarksBreadCrumbGroup);
@@ -145,21 +158,29 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mFoldersBreadCrumb.setMaxVisible(2);
mFoldersBreadCrumb.setActivity(getActivity());
- mFoldersBreadCrumb.setParentTitle(getString(R.string.Bookmarks), null, new OnClickListener() {
+ mFoldersBreadCrumb.setParentTitle(getString(R.string.Bookmarks), null, new OnClickListener() {
@Override
public void onClick(View v) {
- popNavigation();
+ popNavigation();
}
});
mBackBreadCrumb = (ImageView) mContainer.findViewById(R.id.BookmarksBreadCrumbBackHierarchy);
- mBackBreadCrumb.setOnClickListener(new OnClickListener() {
+ mBackBreadCrumb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
popNavigation();
}
});
+ /* mAddFolderBreadCrumb = (ImageView) mContainer.findViewById(R.id.BookmarksBreadCrumbAddFolder);
+ mAddFolderBreadCrumb.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ newFolder();
+ }
+ }); */
+
mBookmarksGrid = (GridView) mContainer.findViewById(R.id.BookmarksGridView);
mProgress = (ProgressBar) mContainer.findViewById(R.id.BookmarksProgressBar);
@@ -256,14 +277,18 @@ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuIn
}
menu.add(0, CONTEXT_MENU_OPEN_IN_TAB, 0, R.string.OpenInTab);
+ menu.add(0, CONTEXT_MENU_MOVE_ITEM, 0, R.string.MoveBookmark);
menu.add(0, CONTEXT_MENU_EDIT_BOOKMARK, 0, R.string.EditBookmark);
menu.add(0, CONTEXT_MENU_COPY_URL, 0, R.string.CopyUrl);
menu.add(0, CONTEXT_MENU_SHARE_URL, 0, R.string.ContextMenuShareUrl);
menu.add(0, CONTEXT_MENU_DELETE_BOOKMARK, 0, R.string.DeleteBookmark);
+
} else {
+ menu.add(0, CONTEXT_MENU_RENAME_FOLDER, 0, R.string.RenameFolder);
+ menu.add(0, CONTEXT_MENU_MOVE_ITEM, 0, R.string.MoveFolder);
menu.add(0, CONTEXT_MENU_DELETE_FOLDER, 0, R.string.DeleteFolder);
}
@@ -281,6 +306,8 @@ public boolean onContextItemSelected(MenuItem item) {
final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
BookmarkHistoryItem selectedItem = BookmarksWrapper.getBookmarkById(getActivity().getContentResolver(), info.id);
+ AlertDialog.Builder builder;
+ final EditText input;
Intent i;
switch (item.getItemId()) {
@@ -327,7 +354,7 @@ public boolean onContextItemSelected(MenuItem item) {
return true;
case CONTEXT_MENU_DELETE_FOLDER:
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder = new AlertDialog.Builder(getActivity());
builder.setCancelable(true);
builder.setIcon(android.R.drawable.ic_dialog_info);
builder.setTitle(R.string.DeleteFolder);
@@ -336,7 +363,7 @@ public boolean onContextItemSelected(MenuItem item) {
builder.setPositiveButton(R.string.Yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- doDeleteFolder(info.id);
+ doDeleteFolder(info.id);
}
});
@@ -346,6 +373,50 @@ public void onClick(DialogInterface dialog, int which) {
return true;
+ case CONTEXT_MENU_RENAME_FOLDER:
+ builder = new AlertDialog.Builder(getActivity());
+ builder.setCancelable(true);
+ builder.setIcon(android.R.drawable.ic_dialog_info);
+ builder.setTitle(R.string.RenameFolder);
+
+ input = new EditText(getActivity());
+ input.setText(selectedItem.getTitle());
+ builder.setView(input);
+
+ builder.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ doRenameFolder(info.id, input.getText().toString());
+ }
+ });
+ builder.setNegativeButton(R.string.Cancel, null);
+
+ builder.create().show();
+ return true;
+
+ case CONTEXT_MENU_MOVE_ITEM:
+ contextItemId = info.id;
+ FragmentTransaction ft = getFragmentManager().beginTransaction();
+ //Remove fragment else it will crash as it is already added to backstack
+ Fragment prev = getFragmentManager().findFragmentByTag("dialog");
+ if (prev != null) {
+ ft.remove(prev);
+ }
+ ft.addToBackStack(null);
+
+ final FoldersOnlyFragment newFragment = new FoldersOnlyFragment();
+ Bundle args = new Bundle();
+ String fstack = BookmarksWrapper.getFolderStack(getActivity().getContentResolver(),
+ selectedItem.getFolderId());
+ args.putString(FoldersOnlyFragment.EXTRA_FOLDER_STACK, fstack);
+ if (selectedItem.isFolder()) {
+ args.putLong(FoldersOnlyFragment.EXTRA_FOLDER_BLACKLIST, selectedItem.getId());
+ }
+ newFragment.setArguments(args);
+
+ newFragment.show(getFragmentManager(), "dialog");
+ return true;
+
default:
if (Controller.getInstance().getAddonManager().onContributedBookmarkContextMenuItemSelected(
getActivity(),
@@ -363,7 +434,8 @@ public void onClick(DialogInterface dialog, int which) {
@Override
public Loader onCreateLoader(int id, Bundle args) {
setListShown(false);
- return BookmarksWrapper.getCursorLoaderForBookmarks(getActivity(), mNavigationList.get(mNavigationList.size() - 1).getId());
+ return BookmarksWrapper.getCursorLoaderForBookmarks(getActivity(),
+ mNavigationList.get(mNavigationList.size() - 1).getId());
}
@Override
@@ -427,7 +499,7 @@ public void onAnimationEnd(Animator animation) {
getLoaderManager().restartLoader(0, null, this);
}
- mFoldersBreadCrumb.setParentTitle(getString(R.string.Bookmarks), null, new OnClickListener() {
+ mFoldersBreadCrumb.setParentTitle(getString(R.string.Bookmarks), null, new OnClickListener() {
@Override
public void onClick(View arg0) {
popNavigation();
@@ -482,6 +554,35 @@ private void popNavigation() {
updateFolderId();
}
+ public void newFolder() {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ final EditText input;
+
+ builder.setCancelable(true);
+ builder.setIcon(android.R.drawable.ic_dialog_info);
+ builder.setTitle(R.string.NewFolder);
+ builder.setMessage(R.string.NewFolderHint);
+
+ input = new EditText(getActivity());
+ builder.setView(input);
+
+ builder.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (!TextUtils.isEmpty(input.getText().toString())) {
+ new Thread(new NewFolderRunnable(getCurrentFolderId(), input.getText().toString())).start();
+ }
+ }
+ });
+ builder.setNegativeButton(R.string.Cancel, null);
+
+ builder.create().show();
+ }
+
+ private void doRenameFolder(long id, String newName) {
+ new Thread(new RenameFolderRunnable(id, newName)).start();
+ }
+
private void doDeleteFolder(long folderId) {
mProgressDialog = ProgressDialog.show(
getActivity(),
@@ -491,6 +592,81 @@ private void doDeleteFolder(long folderId) {
new Thread(new DeleteFolderRunnable(folderId)).start();
}
+ //@Override
+ public void onSelectFolder(long folder_id, String folder_name) {
+ new Thread(new MoveItemRunnable(contextItemId, folder_id)).start();
+ }
+
+ @SuppressLint("HandlerLeak")
+ private class MoveItemRunnable implements Runnable {
+ private long mParentFolderId;
+ private long mItemId;
+
+ public MoveItemRunnable(long item_id, long folder_id) {
+ mParentFolderId = folder_id;
+ mItemId = item_id;
+ }
+
+ private Handler mHandler = new Handler() {
+ public void handleMessage(Message msg) {
+ getLoaderManager().restartLoader(0, null, BookmarksFragment.this);
+ }
+ };
+
+ @Override
+ public void run() {
+ BookmarksWrapper.moveItem(getActivity().getContentResolver(), mItemId, mParentFolderId);
+ mHandler.sendEmptyMessage(0);
+ }
+ }
+
+
+ @SuppressLint("HandlerLeak")
+ private class NewFolderRunnable implements Runnable {
+ private long mParentFolderId;
+ private String mFolderName;
+
+ public NewFolderRunnable(long id, String name) {
+ mParentFolderId = id;
+ mFolderName = name;
+ }
+
+ private Handler mHandler = new Handler() {
+ public void handleMessage(Message msg) {
+ getLoaderManager().restartLoader(0, null, BookmarksFragment.this);
+ }
+ };
+
+ @Override
+ public void run() {
+ BookmarksWrapper.createFolder(getActivity().getContentResolver(), mFolderName, mParentFolderId);
+ mHandler.sendEmptyMessage(0);
+ }
+ }
+
+ @SuppressLint("HandlerLeak")
+ private class RenameFolderRunnable implements Runnable {
+ private long mFolderId;
+ private String mFolderName;
+
+ public RenameFolderRunnable(long id, String newName) {
+ mFolderId = id;
+ mFolderName = newName;
+ }
+
+ @Override
+ public void run() {
+ BookmarksWrapper.renameFolder(getActivity().getContentResolver(), mFolderId, mFolderName);
+ mHandler.sendEmptyMessage(0);
+ }
+
+ private Handler mHandler = new Handler() {
+ public void handleMessage(Message msg) {
+ getLoaderManager().restartLoader(0, null, BookmarksFragment.this);
+ }
+ };
+ }
+
@SuppressLint("HandlerLeak")
private class DeleteFolderRunnable implements Runnable {
diff --git a/src/org/tint/ui/fragments/FoldersOnlyFragment.java b/src/org/tint/ui/fragments/FoldersOnlyFragment.java
new file mode 100644
index 0000000..a160042
--- /dev/null
+++ b/src/org/tint/ui/fragments/FoldersOnlyFragment.java
@@ -0,0 +1,514 @@
+/*
+ * Tint Browser for Android
+ *
+ * Copyright (C) 2012 - to infinity and beyond J. Devauchelle and contributors.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 3 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+package org.tint.ui.fragments;
+
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.app.FragmentBreadCrumbs;
+import android.app.LoaderManager;
+import android.app.ProgressDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.Loader;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.database.Cursor;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.preference.PreferenceManager;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.ListView;
+import android.widget.ProgressBar;
+
+import org.tint.R;
+import org.tint.controllers.Controller;
+import org.tint.model.BookmarkHistoryItem;
+import org.tint.model.FoldersOnlyAdapter;
+import org.tint.providers.BookmarksProvider;
+import org.tint.providers.BookmarksWrapper;
+import org.tint.ui.managers.UIFactory;
+import org.tint.ui.managers.UIManager;
+import org.tint.utils.Constants;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class FoldersOnlyFragment extends DialogFragment implements LoaderManager.LoaderCallbacks {
+
+ public static final String EXTRA_FOLDER_STACK = "EXTRA_FOLDER_STACK";
+ public static final String EXTRA_FOLDER_BLACKLIST = "EXTRA_FOLDER_BLACKLIST";
+
+ private static final String STACK_SEPARATOR = "//;//";
+
+ private static final int CONTEXT_MENU_OPEN_IN_TAB = Menu.FIRST;
+ private static final int CONTEXT_MENU_EDIT_BOOKMARK = Menu.FIRST + 1;
+ private static final int CONTEXT_MENU_COPY_URL = Menu.FIRST + 2;
+ private static final int CONTEXT_MENU_SHARE_URL = Menu.FIRST + 3;
+ private static final int CONTEXT_MENU_DELETE_BOOKMARK = Menu.FIRST + 4;
+
+ private static final int CONTEXT_MENU_DELETE_FOLDER = Menu.FIRST + 5;
+ private static final int CONTEXT_MENU_RENAME_FOLDER = Menu.FIRST + 6;
+ private static final int CONTEXT_MENU_MOVE_ITEM = Menu.FIRST + 7;
+
+ private View mContainer = null;
+
+ private UIManager mUIManager;
+
+ private ListView mFoldersList;
+
+ private ProgressBar mProgress;
+
+ private ViewGroup mBreadCrumbGroup;
+ private FragmentBreadCrumbs mFoldersBreadCrumb;
+ private ImageView mBackBreadCrumb;
+ private ImageView mAddFolderBreadCrumb;
+
+ private FoldersOnlyAdapter mAdapter;
+
+ private List mNavigationList;
+
+ private boolean mIsTablet;
+ private boolean mIsListShown = true;
+
+ private ProgressDialog mProgressDialog;
+
+ private OnSharedPreferenceChangeListener mPreferenceChangeListener;
+
+ private long mBlacklistId = -1;
+
+
+ public interface FoldersOnlyListener {
+ void onSelectFolder(long folder_id, String folder_name);
+ }
+
+ public FoldersOnlyFragment() {
+ mUIManager = Controller.getInstance().getUIManager();
+ }
+
+ public long getCurrentFolderId() {
+ return mNavigationList.get(mNavigationList.size() - 1).getId();
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ mPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
+
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ if (Constants.PREFERENCE_BOOKMARKS_SORT_MODE.equals(key)) {
+ getLoaderManager().restartLoader(0, null, FoldersOnlyFragment.this);
+ }
+ }
+ };
+
+ PreferenceManager.getDefaultSharedPreferences(getActivity()).registerOnSharedPreferenceChangeListener(mPreferenceChangeListener);
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ PreferenceManager.getDefaultSharedPreferences(getActivity()).unregisterOnSharedPreferenceChangeListener(mPreferenceChangeListener);
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+
+ View view = makeView(getActivity().getLayoutInflater(), savedInstanceState);
+ final FoldersOnlyListener fol = (FoldersOnlyListener)getActivity();
+
+ return new AlertDialog.Builder(getActivity())
+ .setView(view)
+ .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ NavigationItem ni = mNavigationList.get(mNavigationList.size() - 1);
+ fol.onSelectFolder(ni.getId(), ni.getTitle());
+ }
+ })
+ .setNegativeButton(R.string.Cancel, null)
+ .create();
+ }
+
+
+ //@Override
+ private View makeView(LayoutInflater inflater, Bundle savedInstanceState) {
+ mIsTablet = UIFactory.isTablet(getActivity());
+
+ if (mContainer == null) {
+
+ mContainer = inflater.inflate(R.layout.foldersonly_fragment, null);
+
+ mBreadCrumbGroup = (ViewGroup) mContainer.findViewById(R.id.BookmarksBreadCrumbGroup);
+
+ mFoldersBreadCrumb = (FragmentBreadCrumbs) mContainer.findViewById(R.id.BookmarksBreadCrumb);
+ mFoldersBreadCrumb.setMaxVisible(2);
+ mFoldersBreadCrumb.setActivity(getActivity());
+
+ mFoldersBreadCrumb.setParentTitle(getString(R.string.Bookmarks), null, new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ popNavigation();
+ }
+ });
+
+ mBackBreadCrumb = (ImageView) mContainer.findViewById(R.id.BookmarksBreadCrumbBackHierarchy);
+ mBackBreadCrumb.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ popNavigation();
+ }
+ });
+
+ mAddFolderBreadCrumb = (ImageView) mContainer.findViewById(R.id.BookmarksBreadCrumbAddFolder);
+ mAddFolderBreadCrumb.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ newFolder();
+ }
+ });
+
+ mFoldersList = (ListView) mContainer.findViewById(R.id.BookmarksGridView);
+ mProgress = (ProgressBar) mContainer.findViewById(R.id.BookmarksProgressBar);
+
+ String[] from = new String[] { BookmarksProvider.Columns.TITLE, BookmarksProvider.Columns.URL };
+ int[] to = new int[] { R.id.BookmarkRow_Title, R.id.BookmarkRow_Url };
+
+ mAdapter = new FoldersOnlyAdapter(
+ getActivity(),
+ R.layout.foldersonly_row,
+ null,
+ from,
+ to,
+ 0);
+
+ mFoldersList.setAdapter(mAdapter);
+
+ mFoldersList.setOnItemClickListener(new OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> parent, View v, int position, long id) {
+ BookmarkHistoryItem item = BookmarksWrapper.getBookmarkById(getActivity().getContentResolver(), id);
+
+ if (item != null) {
+ if (item.isFolder()) {
+ mNavigationList.add(new NavigationItem(item.getId(), item.getTitle()));
+ updateFolderId();
+ } else {
+ Intent result = new Intent();
+ result.putExtra(Constants.EXTRA_URL, item.getUrl());
+
+ getActivity().setResult(Activity.RESULT_OK, result);
+ getActivity().finish();
+ }
+ }
+ }
+ });
+
+ mNavigationList = new ArrayList();
+
+ if (getArguments() != null) {
+ Bundle args = getArguments();
+ if (args.containsKey(EXTRA_FOLDER_STACK)) {
+ String folderStack = getArguments().getString(EXTRA_FOLDER_STACK);
+
+ String[] stack = folderStack.split(STACK_SEPARATOR);
+ for (int i = 0; i < stack.length; i++) {
+ mNavigationList.add(new NavigationItem(stack[i]));
+ }
+ }
+
+ if (args.containsKey(EXTRA_FOLDER_BLACKLIST)) {
+ mBlacklistId = args.getLong(EXTRA_FOLDER_BLACKLIST);
+ }
+ } else {
+ mNavigationList.add(new NavigationItem(-1, null));
+ }
+
+ setListShown(false);
+
+ updateFolderId();
+ }
+
+ return mContainer;
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+
+ StringBuilder sb = new StringBuilder();
+ for (NavigationItem item : mNavigationList) {
+ sb.append(item.toString() + STACK_SEPARATOR);
+ }
+
+ outState.putString(EXTRA_FOLDER_STACK, sb.toString());
+ }
+
+ @Override
+ public Loader onCreateLoader(int id, Bundle args) {
+ setListShown(false);
+ return BookmarksWrapper.getCursorLoaderForBookmarks(getActivity(),
+ mNavigationList.get(mNavigationList.size() - 1).getId(),
+ true, mBlacklistId);
+ }
+
+ @Override
+ public void onLoadFinished(Loader loader, Cursor data) {
+ mAdapter.swapCursor(data);
+ setListShown(true);
+ }
+
+ @Override
+ public void onLoaderReset(Loader loader) {
+ mAdapter.swapCursor(null);
+ }
+
+ private void setListShown(boolean shown) {
+ if (mIsListShown == shown) {
+ return;
+ }
+
+ mIsListShown = shown;
+
+ if (shown) {
+ mProgress.setVisibility(View.GONE);
+ mFoldersList.setVisibility(View.VISIBLE);
+ } else {
+ mProgress.setVisibility(View.VISIBLE);
+ mFoldersList.setVisibility(View.GONE);
+ }
+ }
+
+ private void updateFolderId() {
+ if (mAdapter != null) {
+ mAdapter.swapCursor(null);
+ }
+
+ NavigationItem current = mNavigationList.get(mNavigationList.size() - 1);
+ if (current.getId() == -1) {
+ mBackBreadCrumb.setVisibility(View.GONE);
+ getLoaderManager().restartLoader(0, null, this);
+
+ mFoldersBreadCrumb.setParentTitle(getString(R.string.Bookmarks), null, new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ popNavigation();
+ }
+ });
+
+ } else {
+ mBackBreadCrumb.setVisibility(View.VISIBLE);
+ getLoaderManager().restartLoader(0, null, this);
+
+ if (mNavigationList.size() > 2) {
+ NavigationItem previous = mNavigationList.get(mNavigationList.size() - 2);
+ mFoldersBreadCrumb.setParentTitle(previous.getTitle(), null, new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ popNavigation();
+ }
+ });
+ } else {
+ mFoldersBreadCrumb.setParentTitle(getString(R.string.Bookmarks), null, new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ popNavigation();
+ }
+ });
+ }
+ }
+
+ mFoldersBreadCrumb.setTitle(current.getTitle(), current.getTitle());
+ }
+
+ private void popNavigation() {
+ mNavigationList.remove(mNavigationList.size() - 1);
+ updateFolderId();
+ }
+
+ private void newFolder() {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ final EditText input;
+
+ builder.setCancelable(true);
+ builder.setIcon(android.R.drawable.ic_dialog_info);
+ builder.setTitle(R.string.NewFolder);
+ builder.setMessage(R.string.NewFolderHint);
+
+ input = new EditText(getActivity());
+ builder.setView(input);
+
+ builder.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (!TextUtils.isEmpty(input.getText().toString())) {
+ new Thread(new NewFolderRunnable(getCurrentFolderId(), input.getText().toString())).start();
+ }
+ }
+ });
+ builder.setNegativeButton(R.string.Cancel, null);
+
+ builder.create().show();
+ }
+
+ private void doRenameFolder(long id, String newName) {
+ new Thread(new RenameFolderRunnable(id, newName)).start();
+ }
+
+ private void doDeleteFolder(long folderId) {
+ mProgressDialog = ProgressDialog.show(
+ getActivity(),
+ getString(R.string.DeleteFolderTitle),
+ getString(R.string.DeleteFolderMessage));
+
+ new Thread(new DeleteFolderRunnable(folderId)).start();
+ }
+
+
+ @SuppressLint("HandlerLeak")
+ private class NewFolderRunnable implements Runnable {
+ private long mParentFolderId;
+ private String mFolderName;
+
+ public NewFolderRunnable(long id, String name) {
+ mParentFolderId = id;
+ mFolderName = name;
+ }
+
+ private Handler mHandler = new Handler() {
+ public void handleMessage(Message msg) {
+ getLoaderManager().restartLoader(0, null, FoldersOnlyFragment.this);
+ }
+ };
+
+ @Override
+ public void run() {
+ BookmarksWrapper.createFolder(getActivity().getContentResolver(), mFolderName, mParentFolderId);
+ mHandler.sendEmptyMessage(0);
+ }
+ }
+
+ @SuppressLint("HandlerLeak")
+ private class RenameFolderRunnable implements Runnable {
+ private long mFolderId;
+ private String mFolderName;
+
+ public RenameFolderRunnable(long id, String newName) {
+ mFolderId = id;
+ mFolderName = newName;
+ }
+
+ @Override
+ public void run() {
+ BookmarksWrapper.renameFolder(getActivity().getContentResolver(), mFolderId, mFolderName);
+ mHandler.sendEmptyMessage(0);
+ }
+
+ private Handler mHandler = new Handler() {
+ public void handleMessage(Message msg) {
+ getLoaderManager().restartLoader(0, null, FoldersOnlyFragment.this);
+ }
+ };
+ }
+
+ @SuppressLint("HandlerLeak")
+ private class DeleteFolderRunnable implements Runnable {
+
+ private long mFolderId;
+
+ public DeleteFolderRunnable(long folderId) {
+ mFolderId = folderId;
+ }
+
+ @Override
+ public void run() {
+ BookmarksWrapper.deleteFolder(getActivity().getContentResolver(), mFolderId);
+ mHandler.sendEmptyMessage(0);
+ }
+
+ private Handler mHandler = new Handler() {
+ public void handleMessage(Message msg) {
+ mProgressDialog.dismiss();
+ getLoaderManager().restartLoader(0, null, FoldersOnlyFragment.this);
+ }
+ };
+
+ }
+
+ private class NavigationItem {
+ private long mId;
+ private String mTitle;
+
+ public NavigationItem(long id, String title) {
+ mId = id;
+ mTitle = title;
+ }
+
+ public NavigationItem(String builder) {
+ if ((builder.startsWith("{")) &&
+ (builder.endsWith("}"))) {
+
+ try {
+ builder = builder.substring(1, builder.length() - 1);
+ String[] parts = builder.split(",");
+
+ mId = Long.parseLong(parts[0]);
+ if (mId == -1) {
+ mTitle = null;
+ } else {
+ mTitle = parts[1];
+ }
+ } catch (Exception e) {
+ mId = -1;
+ mTitle = null;
+ }
+
+ } else {
+ mId = -1;
+ mTitle = null;
+ }
+ }
+
+ public long getId() {
+ return mId;
+ }
+
+ public String getTitle() {
+ return mTitle;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("{%s,%s}", mId, mTitle);
+ }
+
+ }
+
+}
diff --git a/src/org/tint/utils/UrlUtils.java b/src/org/tint/utils/UrlUtils.java
index 84d5a47..9e531e4 100644
--- a/src/org/tint/utils/UrlUtils.java
+++ b/src/org/tint/utils/UrlUtils.java
@@ -34,7 +34,11 @@ public class UrlUtils {
*/
public static boolean isUrl(String url) {
return
- url.contains(".") ||
+ (url.contains(".") && !url.contains(" ")) || /* actually check if it begins with the proper protocol */
+ url.startsWith("http://") ||
+ url.startsWith("https://") ||
+ url.startsWith("file://") ||
+ url.startsWith("javascript:") ||
url.equals(Constants.URL_ABOUT_BLANK) ||
url.equals(Constants.URL_ABOUT_START) ||
url.equals(Constants.URL_ABOUT_TUTORIAL);
@@ -76,6 +80,7 @@ public static String checkUrl(String url) {
if ((!url.startsWith("http://")) &&
(!url.startsWith("https://")) &&
(!url.startsWith("file://")) &&
+ (!url.startsWith("javascript:")) && //add bookmarklet support
(!url.startsWith(Constants.URL_ABOUT_BLANK)) &&
(!url.startsWith(Constants.URL_ABOUT_START)) &&
(!url.startsWith(Constants.URL_ABOUT_TUTORIAL))) {