Bug 994734 - Pass dataset id as query argument in HomeProvider (r=margaret)

This commit is contained in:
Lucas Rocha 2014-04-23 15:22:34 +01:00
parent 7c2d8b20f3
commit 770170801c
3 changed files with 24 additions and 6 deletions

View File

@ -42,6 +42,7 @@ public class BrowserContract {
public static final String PARAM_INSERT_IF_NEEDED = "insert_if_needed";
public static final String PARAM_INCREMENT_VISITS = "increment_visits";
public static final String PARAM_EXPIRE_PRIORITY = "priority";
public static final String PARAM_DATASET_ID = "dataset_id";
static public enum ExpirePriority {
NORMAL,

View File

@ -11,6 +11,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.R;
import org.mozilla.gecko.db.BrowserContract.HomeItems;
import org.mozilla.gecko.db.DBUtils;
import org.mozilla.gecko.sqlite.SQLiteBridge;
import org.mozilla.gecko.util.RawResource;
@ -73,6 +74,15 @@ public class HomeProvider extends SQLiteBridgeContentProvider {
return queryFakeItems(uri, projection, selection, selectionArgs, sortOrder);
}
final String datasetId = uri.getQueryParameter(BrowserContract.PARAM_DATASET_ID);
if (datasetId == null) {
throw new IllegalArgumentException("All queries should contain a dataset ID parameter");
}
selection = DBUtils.concatenateWhere(selection, HomeItems.DATASET_ID + " = ?");
selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
new String[] { datasetId });
// Otherwise, let the SQLiteContentProvider implementation take care of this query for us!
return super.query(uri, projection, selection, selectionArgs, sortOrder);
}

View File

@ -9,6 +9,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserContract.HomeItems;
import org.mozilla.gecko.db.DBUtils;
import org.mozilla.gecko.home.HomeConfig.PanelConfig;
@ -403,15 +404,21 @@ public class DynamicPanel extends HomeFragment
// Null represents the root filter
if (mRequest.getFilter() == null) {
selection = DBUtils.concatenateWhere(HomeItems.DATASET_ID + " = ?", HomeItems.FILTER + " IS NULL");
selectionArgs = new String[] { mRequest.getDatasetId() };
selection = HomeItems.FILTER + " IS NULL";
selectionArgs = null;
} else {
selection = DBUtils.concatenateWhere(HomeItems.DATASET_ID + " = ?", HomeItems.FILTER + " = ?");
selectionArgs = new String[] { mRequest.getDatasetId(), mRequest.getFilter() };
selection = HomeItems.FILTER + " = ?";
selectionArgs = new String[] { mRequest.getFilter() };
}
// XXX: You can use CONTENT_FAKE_URI for development to pull items from fake_home_items.json.
final Cursor c = cr.query(HomeItems.CONTENT_URI, null, selection, selectionArgs, null);
final Uri queryUri = HomeItems.CONTENT_URI.buildUpon()
.appendQueryParameter(BrowserContract.PARAM_DATASET_ID,
mRequest.getDatasetId())
.build();
// XXX: You can use HomeItems.CONTENT_FAKE_URI for development
// to pull items from fake_home_items.json.
final Cursor c = cr.query(queryUri, null, selection, selectionArgs, null);
// SQLiteBridgeContentProvider may return a null Cursor if the database hasn't been created yet.
if (c != null) {