2011-12-02 09:27:56 -08:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-12-02 09:27:56 -08:00
|
|
|
|
|
|
|
package org.mozilla.gecko.db;
|
|
|
|
|
2012-12-28 13:46:06 -08:00
|
|
|
import org.mozilla.gecko.db.BrowserContract.Bookmarks;
|
2013-04-08 00:51:56 -07:00
|
|
|
import org.mozilla.gecko.db.BrowserContract.ExpirePriority;
|
2012-10-19 17:35:37 -07:00
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
import android.content.ContentResolver;
|
2012-02-14 16:23:06 -08:00
|
|
|
import android.database.ContentObserver;
|
2011-12-02 09:27:56 -08:00
|
|
|
import android.database.Cursor;
|
2012-12-28 13:45:58 -08:00
|
|
|
import android.database.CursorWrapper;
|
2012-11-05 03:42:25 -08:00
|
|
|
import android.graphics.Bitmap;
|
2011-12-02 09:27:56 -08:00
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
2012-12-28 13:46:06 -08:00
|
|
|
import android.util.SparseArray;
|
2011-12-02 09:27:56 -08:00
|
|
|
|
2012-10-31 05:34:31 -07:00
|
|
|
import java.util.List;
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public class BrowserDB {
|
2012-01-19 09:23:10 -08:00
|
|
|
public static String ABOUT_PAGES_URL_FILTER = "about:%";
|
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
public static interface URLColumns {
|
|
|
|
public static String URL = "url";
|
|
|
|
public static String TITLE = "title";
|
|
|
|
public static String FAVICON = "favicon";
|
|
|
|
public static String THUMBNAIL = "thumbnail";
|
|
|
|
public static String DATE_LAST_VISITED = "date-last-visited";
|
|
|
|
public static String VISITS = "visits";
|
|
|
|
public static String KEYWORD = "keyword";
|
2011-12-02 09:27:56 -08:00
|
|
|
}
|
|
|
|
|
2012-06-15 09:02:11 -07:00
|
|
|
private static BrowserDBIface sDb = null;
|
2011-12-02 09:27:56 -08:00
|
|
|
|
|
|
|
public interface BrowserDBIface {
|
2012-03-19 11:22:33 -07:00
|
|
|
public void invalidateCachedState();
|
|
|
|
|
2012-01-19 09:23:10 -08:00
|
|
|
public Cursor filter(ContentResolver cr, CharSequence constraint, int limit);
|
|
|
|
|
2012-12-28 13:46:06 -08:00
|
|
|
// This should onlyl return frecent sites, BrowserDB.getTopSites will do the
|
|
|
|
// work to combine that list with the pinned sites list
|
2012-01-19 09:23:10 -08:00
|
|
|
public Cursor getTopSites(ContentResolver cr, int limit);
|
2011-12-02 09:27:56 -08:00
|
|
|
|
|
|
|
public void updateVisitedHistory(ContentResolver cr, String uri);
|
|
|
|
|
|
|
|
public void updateHistoryTitle(ContentResolver cr, String uri, String title);
|
|
|
|
|
2012-01-25 13:10:01 -08:00
|
|
|
public void updateHistoryEntry(ContentResolver cr, String uri, String title,
|
|
|
|
long date, int visits);
|
2011-12-19 13:56:11 -08:00
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public Cursor getAllVisitedHistory(ContentResolver cr);
|
|
|
|
|
|
|
|
public Cursor getRecentHistory(ContentResolver cr, int limit);
|
|
|
|
|
2012-10-19 17:35:37 -07:00
|
|
|
public void expireHistory(ContentResolver cr, ExpirePriority priority);
|
|
|
|
|
2012-05-14 11:44:34 -07:00
|
|
|
public void removeHistoryEntry(ContentResolver cr, int id);
|
|
|
|
|
2013-01-30 07:20:35 -08:00
|
|
|
public void removeHistoryEntry(ContentResolver cr, String url);
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public void clearHistory(ContentResolver cr);
|
|
|
|
|
2012-02-23 10:48:47 -08:00
|
|
|
public Cursor getBookmarksInFolder(ContentResolver cr, long folderId);
|
2012-02-07 11:03:02 -08:00
|
|
|
|
2013-01-30 09:26:07 -08:00
|
|
|
public boolean isVisited(ContentResolver cr, String uri);
|
|
|
|
|
2013-06-10 09:25:35 -07:00
|
|
|
public int getReadingListCount(ContentResolver cr);
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public boolean isBookmark(ContentResolver cr, String uri);
|
|
|
|
|
2012-06-20 11:10:08 -07:00
|
|
|
public boolean isReadingListItem(ContentResolver cr, String uri);
|
|
|
|
|
2012-02-07 17:55:12 -08:00
|
|
|
public String getUrlForKeyword(ContentResolver cr, String keyword);
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public void addBookmark(ContentResolver cr, String title, String uri);
|
|
|
|
|
2012-02-09 10:01:57 -08:00
|
|
|
public void removeBookmark(ContentResolver cr, int id);
|
|
|
|
|
|
|
|
public void removeBookmarksWithURL(ContentResolver cr, String uri);
|
2011-12-02 09:27:56 -08:00
|
|
|
|
2012-05-07 15:33:07 -07:00
|
|
|
public void updateBookmark(ContentResolver cr, int id, String uri, String title, String keyword);
|
2012-02-07 17:55:12 -08:00
|
|
|
|
2012-06-02 11:23:45 -07:00
|
|
|
public void addReadingListItem(ContentResolver cr, String title, String uri);
|
|
|
|
|
2012-06-20 11:10:08 -07:00
|
|
|
public void removeReadingListItemWithURL(ContentResolver cr, String uri);
|
|
|
|
|
2012-11-05 03:42:25 -08:00
|
|
|
public Bitmap getFaviconForUrl(ContentResolver cr, String uri);
|
2011-12-02 09:27:56 -08:00
|
|
|
|
2012-10-31 05:34:31 -07:00
|
|
|
public Cursor getFaviconsForUrls(ContentResolver cr, List<String> urls);
|
|
|
|
|
2012-11-13 10:56:58 -08:00
|
|
|
public String getFaviconUrlForHistoryUrl(ContentResolver cr, String url);
|
|
|
|
|
|
|
|
public void updateFaviconForUrl(ContentResolver cr, String pageUri, Bitmap favicon, String faviconUri);
|
2011-12-02 09:27:56 -08:00
|
|
|
|
|
|
|
public void updateThumbnailForUrl(ContentResolver cr, String uri, BitmapDrawable thumbnail);
|
2012-01-31 14:13:33 -08:00
|
|
|
|
|
|
|
public byte[] getThumbnailForUrl(ContentResolver cr, String uri);
|
2012-02-14 16:23:06 -08:00
|
|
|
|
2012-10-31 05:34:32 -07:00
|
|
|
public Cursor getThumbnailsForUrls(ContentResolver cr, List<String> urls);
|
|
|
|
|
2012-10-16 07:07:06 -07:00
|
|
|
public void removeThumbnails(ContentResolver cr);
|
|
|
|
|
2012-02-14 16:23:06 -08:00
|
|
|
public void registerBookmarkObserver(ContentResolver cr, ContentObserver observer);
|
2012-05-14 11:44:37 -07:00
|
|
|
|
|
|
|
public void registerHistoryObserver(ContentResolver cr, ContentObserver observer);
|
2012-11-02 17:44:20 -07:00
|
|
|
|
|
|
|
public int getCount(ContentResolver cr, String database);
|
2012-12-28 13:46:04 -08:00
|
|
|
|
|
|
|
public void pinSite(ContentResolver cr, String url, String title, int position);
|
|
|
|
|
|
|
|
public void unpinSite(ContentResolver cr, int position);
|
|
|
|
|
|
|
|
public void unpinAllSites(ContentResolver cr);
|
|
|
|
|
|
|
|
public Cursor getPinnedSites(ContentResolver cr, int limit);
|
2013-05-30 17:03:18 -07:00
|
|
|
|
|
|
|
public Cursor getBookmarkForUrl(ContentResolver cr, String url);
|
2011-12-02 09:27:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static {
|
2012-01-11 11:47:19 -08:00
|
|
|
// Forcing local DB no option to switch to Android DB for now
|
2012-06-15 09:02:11 -07:00
|
|
|
sDb = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void initialize(String profile) {
|
|
|
|
sDb = new LocalBrowserDB(profile);
|
2011-12-02 09:27:56 -08:00
|
|
|
}
|
2012-03-19 11:22:33 -07:00
|
|
|
|
|
|
|
public static void invalidateCachedState() {
|
|
|
|
sDb.invalidateCachedState();
|
|
|
|
}
|
2011-12-02 09:27:56 -08:00
|
|
|
|
2012-01-19 09:23:10 -08:00
|
|
|
public static Cursor filter(ContentResolver cr, CharSequence constraint, int limit) {
|
|
|
|
return sDb.filter(cr, constraint, limit);
|
2012-01-04 21:34:06 -08:00
|
|
|
}
|
|
|
|
|
2012-01-19 09:23:10 -08:00
|
|
|
public static Cursor getTopSites(ContentResolver cr, int limit) {
|
2012-12-28 13:46:06 -08:00
|
|
|
// Note this is not a single query anymore, but actually returns a mixture of two queries, one for topSites
|
|
|
|
// and one for pinned sites
|
|
|
|
Cursor topSites = sDb.getTopSites(cr, limit);
|
|
|
|
Cursor pinnedSites = sDb.getPinnedSites(cr, limit);
|
|
|
|
return new TopSitesCursorWrapper(pinnedSites, topSites, limit);
|
2011-12-02 09:27:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void updateVisitedHistory(ContentResolver cr, String uri) {
|
|
|
|
sDb.updateVisitedHistory(cr, uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void updateHistoryTitle(ContentResolver cr, String uri, String title) {
|
|
|
|
sDb.updateHistoryTitle(cr, uri, title);
|
|
|
|
}
|
|
|
|
|
2012-01-25 13:10:01 -08:00
|
|
|
public static void updateHistoryEntry(ContentResolver cr, String uri, String title,
|
|
|
|
long date, int visits) {
|
|
|
|
sDb.updateHistoryEntry(cr, uri, title, date, visits);
|
2011-12-19 13:56:11 -08:00
|
|
|
}
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public static Cursor getAllVisitedHistory(ContentResolver cr) {
|
|
|
|
return sDb.getAllVisitedHistory(cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Cursor getRecentHistory(ContentResolver cr, int limit) {
|
|
|
|
return sDb.getRecentHistory(cr, limit);
|
|
|
|
}
|
|
|
|
|
2012-10-19 17:35:37 -07:00
|
|
|
public static void expireHistory(ContentResolver cr, ExpirePriority priority) {
|
2012-11-13 11:34:11 -08:00
|
|
|
if (sDb == null)
|
|
|
|
return;
|
|
|
|
|
2012-10-19 17:35:37 -07:00
|
|
|
if (priority == null)
|
|
|
|
priority = ExpirePriority.NORMAL;
|
|
|
|
sDb.expireHistory(cr, priority);
|
|
|
|
}
|
|
|
|
|
2012-05-14 11:44:34 -07:00
|
|
|
public static void removeHistoryEntry(ContentResolver cr, int id) {
|
|
|
|
sDb.removeHistoryEntry(cr, id);
|
|
|
|
}
|
|
|
|
|
2013-01-30 07:20:35 -08:00
|
|
|
public static void removeHistoryEntry(ContentResolver cr, String url) {
|
|
|
|
sDb.removeHistoryEntry(cr, url);
|
|
|
|
}
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public static void clearHistory(ContentResolver cr) {
|
|
|
|
sDb.clearHistory(cr);
|
|
|
|
}
|
|
|
|
|
2012-02-23 10:48:47 -08:00
|
|
|
public static Cursor getBookmarksInFolder(ContentResolver cr, long folderId) {
|
|
|
|
return sDb.getBookmarksInFolder(cr, folderId);
|
2012-02-07 11:03:02 -08:00
|
|
|
}
|
|
|
|
|
2012-02-07 17:55:12 -08:00
|
|
|
public static String getUrlForKeyword(ContentResolver cr, String keyword) {
|
|
|
|
return sDb.getUrlForKeyword(cr, keyword);
|
|
|
|
}
|
2013-01-30 09:26:07 -08:00
|
|
|
|
|
|
|
public static boolean isVisited(ContentResolver cr, String uri) {
|
|
|
|
return sDb.isVisited(cr, uri);
|
|
|
|
}
|
|
|
|
|
2013-06-10 09:25:35 -07:00
|
|
|
public static int getReadingListCount(ContentResolver cr) {
|
|
|
|
return sDb.getReadingListCount(cr);
|
|
|
|
}
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public static boolean isBookmark(ContentResolver cr, String uri) {
|
|
|
|
return sDb.isBookmark(cr, uri);
|
|
|
|
}
|
|
|
|
|
2012-06-20 11:10:08 -07:00
|
|
|
public static boolean isReadingListItem(ContentResolver cr, String uri) {
|
|
|
|
return sDb.isReadingListItem(cr, uri);
|
|
|
|
}
|
|
|
|
|
2011-12-02 09:27:56 -08:00
|
|
|
public static void addBookmark(ContentResolver cr, String title, String uri) {
|
|
|
|
sDb.addBookmark(cr, title, uri);
|
|
|
|
}
|
|
|
|
|
2012-02-09 10:01:57 -08:00
|
|
|
public static void removeBookmark(ContentResolver cr, int id) {
|
|
|
|
sDb.removeBookmark(cr, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void removeBookmarksWithURL(ContentResolver cr, String uri) {
|
|
|
|
sDb.removeBookmarksWithURL(cr, uri);
|
2011-12-02 09:27:56 -08:00
|
|
|
}
|
|
|
|
|
2012-05-07 15:33:07 -07:00
|
|
|
public static void updateBookmark(ContentResolver cr, int id, String uri, String title, String keyword) {
|
|
|
|
sDb.updateBookmark(cr, id, uri, title, keyword);
|
2012-02-07 17:55:12 -08:00
|
|
|
}
|
|
|
|
|
2012-06-02 11:23:45 -07:00
|
|
|
public static void addReadingListItem(ContentResolver cr, String title, String uri) {
|
|
|
|
sDb.addReadingListItem(cr, title, uri);
|
|
|
|
}
|
|
|
|
|
2012-06-20 11:10:08 -07:00
|
|
|
public static void removeReadingListItemWithURL(ContentResolver cr, String uri) {
|
|
|
|
sDb.removeReadingListItemWithURL(cr, uri);
|
|
|
|
}
|
|
|
|
|
2012-11-05 03:42:25 -08:00
|
|
|
public static Bitmap getFaviconForUrl(ContentResolver cr, String uri) {
|
2011-12-02 09:27:56 -08:00
|
|
|
return sDb.getFaviconForUrl(cr, uri);
|
|
|
|
}
|
|
|
|
|
2012-10-31 05:34:31 -07:00
|
|
|
public static Cursor getFaviconsForUrls(ContentResolver cr, List<String> urls) {
|
|
|
|
return sDb.getFaviconsForUrls(cr, urls);
|
|
|
|
}
|
|
|
|
|
2012-11-13 10:56:58 -08:00
|
|
|
public static String getFaviconUrlForHistoryUrl(ContentResolver cr, String url) {
|
|
|
|
return sDb.getFaviconUrlForHistoryUrl(cr, url);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void updateFaviconForUrl(ContentResolver cr, String pageUri, Bitmap favicon, String faviconUri) {
|
|
|
|
sDb.updateFaviconForUrl(cr, pageUri, favicon, faviconUri);
|
2011-12-02 09:27:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void updateThumbnailForUrl(ContentResolver cr, String uri, BitmapDrawable thumbnail) {
|
|
|
|
sDb.updateThumbnailForUrl(cr, uri, thumbnail);
|
|
|
|
}
|
2012-01-31 14:13:33 -08:00
|
|
|
|
|
|
|
public static byte[] getThumbnailForUrl(ContentResolver cr, String uri) {
|
|
|
|
return sDb.getThumbnailForUrl(cr, uri);
|
|
|
|
}
|
2012-02-14 16:23:06 -08:00
|
|
|
|
2012-10-31 05:34:32 -07:00
|
|
|
public static Cursor getThumbnailsForUrls(ContentResolver cr, List<String> urls) {
|
|
|
|
return sDb.getThumbnailsForUrls(cr, urls);
|
|
|
|
}
|
|
|
|
|
2012-10-16 07:07:06 -07:00
|
|
|
public static void removeThumbnails(ContentResolver cr) {
|
|
|
|
sDb.removeThumbnails(cr);
|
|
|
|
}
|
|
|
|
|
2012-02-14 16:23:06 -08:00
|
|
|
public static void registerBookmarkObserver(ContentResolver cr, ContentObserver observer) {
|
|
|
|
sDb.registerBookmarkObserver(cr, observer);
|
|
|
|
}
|
|
|
|
|
2012-05-14 11:44:37 -07:00
|
|
|
public static void registerHistoryObserver(ContentResolver cr, ContentObserver observer) {
|
|
|
|
sDb.registerHistoryObserver(cr, observer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void unregisterContentObserver(ContentResolver cr, ContentObserver observer) {
|
2012-02-14 16:23:06 -08:00
|
|
|
cr.unregisterContentObserver(observer);
|
|
|
|
}
|
2012-11-02 17:44:20 -07:00
|
|
|
|
|
|
|
public static int getCount(ContentResolver cr, String database) {
|
|
|
|
return sDb.getCount(cr, database);
|
|
|
|
}
|
2012-12-28 13:45:58 -08:00
|
|
|
|
2012-12-28 13:46:04 -08:00
|
|
|
public static void pinSite(ContentResolver cr, String url, String title, int position) {
|
|
|
|
sDb.pinSite(cr, url, title, position);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void unpinSite(ContentResolver cr, int position) {
|
|
|
|
sDb.unpinSite(cr, position);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void unpinAllSites(ContentResolver cr) {
|
|
|
|
sDb.unpinAllSites(cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Cursor getPinnedSites(ContentResolver cr, int limit) {
|
|
|
|
return sDb.getPinnedSites(cr, limit);
|
|
|
|
}
|
|
|
|
|
2013-05-30 17:03:18 -07:00
|
|
|
public static Cursor getBookmarkForUrl(ContentResolver cr, String url) {
|
|
|
|
return sDb.getBookmarkForUrl(cr, url);
|
|
|
|
}
|
|
|
|
|
2012-12-28 13:46:08 -08:00
|
|
|
public static class PinnedSite {
|
2012-12-28 13:46:06 -08:00
|
|
|
public String title = "";
|
|
|
|
public String url = "";
|
|
|
|
|
|
|
|
public PinnedSite(String aTitle, String aUrl) {
|
|
|
|
title = aTitle;
|
|
|
|
url = aUrl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-28 13:45:58 -08:00
|
|
|
/* Cursor wrapper that forces top sites to contain at least
|
|
|
|
* mNumberOfTopSites entries. For rows outside the wrapped cursor
|
|
|
|
* will return empty strings and zero.
|
|
|
|
*/
|
2012-12-28 13:46:06 -08:00
|
|
|
public static class TopSitesCursorWrapper extends CursorWrapper {
|
|
|
|
int mIndex = -1; // Current position of the cursor
|
2012-12-28 13:45:58 -08:00
|
|
|
Cursor mCursor = null;
|
|
|
|
int mSize = 0;
|
2012-12-28 13:46:06 -08:00
|
|
|
private SparseArray<PinnedSite> mPinnedSites = null;
|
|
|
|
|
|
|
|
public TopSitesCursorWrapper(Cursor pinnedCursor, Cursor normalCursor, int size) {
|
|
|
|
super(normalCursor);
|
|
|
|
|
|
|
|
setPinnedSites(pinnedCursor);
|
|
|
|
mCursor = normalCursor;
|
2012-12-28 13:45:58 -08:00
|
|
|
mSize = size;
|
|
|
|
}
|
|
|
|
|
2012-12-28 13:46:06 -08:00
|
|
|
public void setPinnedSites(Cursor c) {
|
|
|
|
mPinnedSites = new SparseArray<PinnedSite>();
|
|
|
|
if (c != null && c.getCount() > 0) {
|
|
|
|
c.moveToPosition(0);
|
|
|
|
do {
|
|
|
|
int pos = c.getInt(c.getColumnIndex(Bookmarks.POSITION));
|
|
|
|
String url = c.getString(c.getColumnIndex(URLColumns.URL));
|
|
|
|
String title = c.getString(c.getColumnIndex(URLColumns.TITLE));
|
|
|
|
mPinnedSites.put(pos, new PinnedSite(title, url));
|
|
|
|
} while (c.moveToNext());
|
2013-01-24 13:58:53 -08:00
|
|
|
}
|
|
|
|
if (c != null && !c.isClosed()) {
|
2013-01-02 11:49:42 -08:00
|
|
|
c.close();
|
2012-12-28 13:46:06 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasPinnedSites() {
|
|
|
|
return mPinnedSites != null && mPinnedSites.size() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PinnedSite getPinnedSite(int position) {
|
|
|
|
if (!hasPinnedSites()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return mPinnedSites.get(position);
|
|
|
|
}
|
|
|
|
|
2013-01-09 14:07:32 -08:00
|
|
|
public boolean isPinned() {
|
|
|
|
return mPinnedSites.get(mIndex) != null;
|
|
|
|
}
|
|
|
|
|
2012-12-28 13:46:06 -08:00
|
|
|
private int getPinnedBefore(int position) {
|
|
|
|
int numFound = 0;
|
|
|
|
if (!hasPinnedSites()) {
|
|
|
|
return numFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < position; i++) {
|
|
|
|
if (mPinnedSites.get(i) != null) {
|
|
|
|
numFound++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return numFound;
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-28 13:45:58 -08:00
|
|
|
public int getPosition() { return mIndex; }
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-28 13:45:58 -08:00
|
|
|
public int getCount() { return mSize; }
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-28 13:45:58 -08:00
|
|
|
public boolean isAfterLast() { return mIndex >= mSize; }
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-28 13:45:58 -08:00
|
|
|
public boolean isBeforeFirst() { return mIndex < 0; }
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-28 13:45:58 -08:00
|
|
|
public boolean isLast() { return mIndex == mSize - 1; }
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-28 13:45:58 -08:00
|
|
|
public boolean moveToNext() { return moveToPosition(mIndex + 1); }
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-28 13:45:58 -08:00
|
|
|
public boolean moveToPrevious() { return moveToPosition(mIndex - 1); }
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-28 13:45:58 -08:00
|
|
|
public boolean moveToPosition(int position) {
|
|
|
|
mIndex = position;
|
2012-12-28 13:46:06 -08:00
|
|
|
|
|
|
|
// move the real cursor as if we were stepping through it to this position
|
|
|
|
// be careful not to move it to far, and to account for any pinned sites
|
|
|
|
int before = getPinnedBefore(position);
|
|
|
|
int p2 = position - before;
|
|
|
|
if (p2 >= -1 && p2 <= mCursor.getCount()) {
|
|
|
|
super.moveToPosition(p2);
|
|
|
|
}
|
|
|
|
|
2012-12-28 13:45:58 -08:00
|
|
|
return !(isBeforeFirst() || isAfterLast());
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-28 13:45:58 -08:00
|
|
|
public long getLong(int columnIndex) {
|
2012-12-28 13:46:06 -08:00
|
|
|
if (hasPinnedSites()) {
|
|
|
|
PinnedSite site = getPinnedSite(mIndex);
|
|
|
|
if (site != null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!super.isBeforeFirst() && !super.isAfterLast())
|
2012-12-28 13:45:58 -08:00
|
|
|
return super.getLong(columnIndex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-28 13:45:58 -08:00
|
|
|
public String getString(int columnIndex) {
|
2012-12-28 13:46:06 -08:00
|
|
|
if (hasPinnedSites()) {
|
|
|
|
PinnedSite site = getPinnedSite(mIndex);
|
|
|
|
if (site != null) {
|
|
|
|
if (columnIndex == mCursor.getColumnIndex(URLColumns.URL)) {
|
|
|
|
return site.url;
|
|
|
|
} else if (columnIndex == mCursor.getColumnIndex(URLColumns.TITLE)) {
|
|
|
|
return site.title;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!super.isBeforeFirst() && !super.isAfterLast())
|
2012-12-28 13:45:58 -08:00
|
|
|
return super.getString(columnIndex);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-28 13:45:58 -08:00
|
|
|
public boolean move(int offset) {
|
|
|
|
return moveToPosition(mIndex + offset);
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-28 13:45:58 -08:00
|
|
|
public boolean moveToFirst() {
|
|
|
|
return moveToPosition(0);
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-28 13:45:58 -08:00
|
|
|
public boolean moveToLast() {
|
|
|
|
return moveToPosition(mSize-1);
|
|
|
|
}
|
|
|
|
}
|
2012-01-04 21:34:06 -08:00
|
|
|
}
|