public static Uri appendDirtyQueryParam(CapsuleContract.SyncStateAction syncAction, Uri uri) { if (syncAction.equals(CapsuleContract.SyncStateAction.DIRTY)) { uri = uri.buildUpon() .appendQueryParameter( CapsuleContract.Query.Parameters.SET_DIRTY, CapsuleContract.Query.Values.TRUE) .build(); } else if (syncAction.equals(CapsuleContract.SyncStateAction.CLEAN)) { uri = uri.buildUpon() .appendQueryParameter( CapsuleContract.Query.Parameters.SET_DIRTY, CapsuleContract.Query.Values.FALSE) .build(); } return uri; }
public static ArrayList<CapsuleOwnership> get( ContentResolver resolver, Account account, CapsuleContract.SyncStateAction syncAction) { // Build the query URI Uri uri = CapsuleContract.Ownerships.CONTENT_URI .buildUpon() .appendQueryParameter( CapsuleContract.Query.Parameters.INNER_JOIN, CapsuleContract.Capsules.TABLE_NAME) .build(); // Build the selection string String selection = CapsuleContract.Ownerships.TABLE_NAME + "." + CapsuleContract.Ownerships.ACCOUNT_NAME + " = ?"; if (syncAction.equals(CapsuleContract.SyncStateAction.DIRTY)) { selection += " AND " + CapsuleContract.Ownerships.DIRTY + " = 1"; } else if (syncAction.equals(CapsuleContract.SyncStateAction.CLEAN)) { selection += " AND " + CapsuleContract.Ownerships.DIRTY + " = 0"; } // Query Cursor c = resolver.query( uri, CapsuleContract.Ownerships.CAPSULE_JOIN_PROJECTION, selection, new String[] {account.name}, null); // Get the results from the cursor ArrayList<CapsuleOwnership> capsules = new ArrayList<CapsuleOwnership>(); if (c.getCount() > 0) { while (c.moveToNext()) { capsules.add(new CapsuleOwnership(c)); } } // Close the cursor c.close(); return capsules; }