Skip to content

Commit

Permalink
Added so that the API_KEY is ready for implementation, need to
Browse files Browse the repository at this point in the history
 add property to allow the user to set it themselves.

Change-Id: I5405bda01ffadbbdb23fccd5fed099bcd8ef4cf8
  • Loading branch information
magnusart committed Jan 9, 2011
1 parent 96603a3 commit 8478b7a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
29 changes: 18 additions & 11 deletions src/com/liato/bankdroid/provider/BankTransactionsProvider.java
Expand Up @@ -44,9 +44,9 @@ public class BankTransactionsProvider extends ContentProvider implements
IBankTransactionsProvider {

private final static String TAG = "BankTransactionsProvider";

private final static int TRANSACTIONS = 0;
private static final int BANK_ACCOUNTS = 1;
private final static int BANK_ACCOUNTS = 1;
private static final String WILD_CARD = "*";

private static final String BANK_ACCOUNT_TABLES = "banks LEFT JOIN accounts ON banks."
+ BANK_ID + " = accounts.bankid";
Expand All @@ -59,8 +59,10 @@ public class BankTransactionsProvider extends ContentProvider implements

static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(AUTHORITY, TRANSACTIONS_CAT, TRANSACTIONS);
uriMatcher.addURI(AUTHORITY, BANK_ACCOUNTS_CAT, BANK_ACCOUNTS);
uriMatcher.addURI(AUTHORITY, TRANSACTIONS_CAT + "/" + WILD_CARD,
TRANSACTIONS);
uriMatcher.addURI(AUTHORITY, BANK_ACCOUNTS_CAT + "/" + WILD_CARD,
BANK_ACCOUNTS);

// Projections are "Poor mans views" of the data.
bankAccountProjectionMap = new HashMap<String, String>();
Expand Down Expand Up @@ -102,6 +104,8 @@ public int delete(final Uri uri, final String selection,
*/
@Override
public String getType(final Uri uri) {
Log.d(TAG, "Got URI " + uri.toString());

switch (uriMatcher.match(uri)) {
case BANK_ACCOUNTS:
return BANK_ACCOUNTS_MIME;
Expand Down Expand Up @@ -138,27 +142,30 @@ public Cursor query(final Uri uri, final String[] projection,
final String selection, final String[] selectionArgs,
final String sortOrder) {

final String apiKey = uri.getPathSegments().get(1);
Log.d(TAG, "Trying to access database with " + apiKey);

if (apiKey == null) {
throw new IllegalAccessError("The supplied API_KEY does not exist");
// TODO: Implement property loader here.
}

final SQLiteDatabase db = dbHelper.getReadableDatabase();
SQLiteQueryBuilder qb;

if (BANK_ACCOUNTS_MIME.equals(getType(uri))) {
qb = new SQLiteQueryBuilder();
qb.setTables(BANK_ACCOUNT_TABLES);
qb.setProjectionMap(bankAccountProjectionMap);
qb.setDistinct(true);
Log.d(TAG, "");
} else if (TRANSACTIONS_MIME.equals(getType(uri))) {
qb = new SQLiteQueryBuilder();
qb.setTables(TRANSACTIONS_TABLE);
qb.setProjectionMap(transProjectionMap);
} else {
throw new IllegalArgumentException("Unsupported URI: " + uri);
}
/*
* Select Statement to build: SELECT banks._id, banks.custname,
* banks.banktype, banks.updated, accounts.id, accounts.name,
* accounts.acctype FROM banks, accounts WHERE banks._id =
* accounts.bankid AND accounts.hidden = 0;
*/

final Cursor cur = qb.query(db, projection, selection, selectionArgs,
null, null, sortOrder);

Expand Down
11 changes: 10 additions & 1 deletion src/com/liato/bankdroid/provider/IBankTransactionsProvider.java
Expand Up @@ -26,7 +26,9 @@
* <p>
* Uri format for querying for all transaction of a given bank/account
* combination:<br/>
* <code><b>content://{{@link #AUTHORITY}}/{{@link #TRANSACTIONS_CAT}}</code>
* <code><b>content://{{@link #AUTHORITY}}/{{@link #TRANSACTIONS_CAT}}/{{@link #API_KEY}}={yourkey}</code>
* <br>
* <code><b>Would result in: content://com.liato.bankdroid.provider.BankTransactionsProvider/transactions/API_KEY=AAABBBCCC111222</code>
* </b>
* </p>
*
Expand Down Expand Up @@ -57,6 +59,13 @@ public interface IBankTransactionsProvider {
*/
String AUTHORITY = "com.liato.bankdroid.provider.BankTransactionsProvider";

/**
* <p>
* The API Key part of the URI.
* </p>
*/
String API_KEY = "API_KEY=";

// ====================================MIME-TYPES======================================
/**
* <p>
Expand Down

0 comments on commit 8478b7a

Please sign in to comment.