Bug 704977 - (Part 1) Clean up filterAllSites to make it more readable. r=lucasr

This commit is contained in:
Margaret Leibovic 2012-03-16 11:36:31 -07:00
parent 817530eb8d
commit 1a1607b788

View File

@ -46,6 +46,7 @@ import org.mozilla.gecko.db.BrowserContract.History;
import org.mozilla.gecko.db.BrowserContract.ImageColumns;
import org.mozilla.gecko.db.BrowserContract.Images;
import org.mozilla.gecko.db.BrowserContract.URLColumns;
import org.mozilla.gecko.db.DBUtils;
import android.content.ContentResolver;
import android.content.ContentUris;
@ -119,18 +120,32 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
return uri.buildUpon().appendQueryParameter(BrowserContract.PARAM_PROFILE, mProfile).build();
}
private Cursor filterAllSites(ContentResolver cr, String[] projection, CharSequence constraint, int limit, CharSequence urlFilter) {
private Cursor filterAllSites(ContentResolver cr, String[] projection, CharSequence constraint,
int limit, CharSequence urlFilter) {
// The history selection queries for sites with a url or title
// containing the constraint string
String selection = "(" + History.URL + " LIKE ? OR " +
History.TITLE + " LIKE ?)";
final String historySelectionArg = "%" + constraint.toString() + "%";
String[] selectionArgs = new String[] { historySelectionArg, historySelectionArg };
if (urlFilter != null) {
selection = DBUtils.concatenateWhere(selection, "(" + History.URL + " NOT LIKE ?)");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs, new String[] { urlFilter.toString() });
}
// ORDER BY is number of visits times a multiplier from 1 - 120 of how recently the site
// was accessed with a site accessed today getting 120 and a site accessed 119 or more
// days ago getting 1
final String sortOrder = History.VISITS + " * MAX(1, (" +
History.DATE_LAST_VISITED + " - " + System.currentTimeMillis() + ") / 86400000 + 120) DESC";
Cursor c = cr.query(historyUriWithLimit(limit),
projection,
(urlFilter != null ? "(" + History.URL + " NOT LIKE ? ) AND " : "" ) +
"(" + History.URL + " LIKE ? OR " + History.TITLE + " LIKE ?)",
urlFilter == null ? new String[] {"%" + constraint.toString() + "%", "%" + constraint.toString() + "%"} :
new String[] {urlFilter.toString(), "%" + constraint.toString() + "%", "%" + constraint.toString() + "%"},
// ORDER BY is number of visits times a multiplier from 1 - 120 of how recently the site
// was accessed with a site accessed today getting 120 and a site accessed 119 or more
// days ago getting 1
History.VISITS + " * MAX(1, (" +
History.DATE_LAST_VISITED + " - " + System.currentTimeMillis() + ") / 86400000 + 120) DESC");
selection,
selectionArgs,
sortOrder);
return new LocalDBCursor(c);
}