key lists somewhat wrapped into one, using the new database stuff, Apg cleaned up a bit, preparing to use the database there as well
This commit is contained in:
@@ -21,12 +21,10 @@ import java.util.HashMap;
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.UriMatcher;
|
||||
import android.database.Cursor;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.database.sqlite.SQLiteQueryBuilder;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
|
||||
@@ -34,9 +34,9 @@ public class Database extends SQLiteOpenHelper {
|
||||
|
||||
public static final String AUTHORITY = "org.thialfihar.android.apg.database";
|
||||
|
||||
private static HashMap<String, String> sKeyRingsProjection;
|
||||
private static HashMap<String, String> sKeysProjection;
|
||||
private static HashMap<String, String> sUserIdsProjection;
|
||||
public static HashMap<String, String> sKeyRingsProjection;
|
||||
public static HashMap<String, String> sKeysProjection;
|
||||
public static HashMap<String, String> sUserIdsProjection;
|
||||
|
||||
private SQLiteDatabase mCurrentDb = null;
|
||||
|
||||
@@ -67,11 +67,11 @@ public class Database extends SQLiteOpenHelper {
|
||||
sUserIdsProjection.put(UserIds.RANK, UserIds.RANK);
|
||||
}
|
||||
|
||||
Database(Context context) {
|
||||
public Database(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
//getWritableDatabase();
|
||||
// force upgrade to test things
|
||||
onUpgrade(getWritableDatabase(), 1, 2);
|
||||
//onUpgrade(getWritableDatabase(), 1, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -161,6 +161,7 @@ public class Database extends SQLiteOpenHelper {
|
||||
}
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
cursor = db.query(SecretKeys.TABLE_NAME,
|
||||
new String[]{
|
||||
@@ -182,6 +183,7 @@ public class Database extends SQLiteOpenHelper {
|
||||
}
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -310,6 +312,7 @@ public class Database extends SQLiteOpenHelper {
|
||||
}
|
||||
|
||||
private long insertOrUpdateKeyRing(ContentValues values) {
|
||||
boolean grabbedNewDatabase = (mCurrentDb == null);
|
||||
SQLiteDatabase db = mCurrentDb != null ? mCurrentDb : getWritableDatabase();
|
||||
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
|
||||
|
||||
@@ -332,10 +335,17 @@ public class Database extends SQLiteOpenHelper {
|
||||
rowId = db.insert(KeyRings.TABLE_NAME, KeyRings.WHO_ID, values);
|
||||
}
|
||||
|
||||
c.close();
|
||||
|
||||
if (grabbedNewDatabase) {
|
||||
db.close();
|
||||
}
|
||||
|
||||
return rowId;
|
||||
}
|
||||
|
||||
private long insertOrUpdateKey(ContentValues values) {
|
||||
boolean grabbedNewDatabase = (mCurrentDb == null);
|
||||
SQLiteDatabase db = mCurrentDb != null ? mCurrentDb : getWritableDatabase();
|
||||
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
|
||||
|
||||
@@ -358,10 +368,17 @@ public class Database extends SQLiteOpenHelper {
|
||||
rowId = db.insert(Keys.TABLE_NAME, Keys.KEY_DATA, values);
|
||||
}
|
||||
|
||||
c.close();
|
||||
|
||||
if (grabbedNewDatabase) {
|
||||
db.close();
|
||||
}
|
||||
|
||||
return rowId;
|
||||
}
|
||||
|
||||
private long insertOrUpdateUserId(ContentValues values) {
|
||||
boolean grabbedNewDatabase = (mCurrentDb == null);
|
||||
SQLiteDatabase db = mCurrentDb != null ? mCurrentDb : getWritableDatabase();
|
||||
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
|
||||
|
||||
@@ -384,6 +401,12 @@ public class Database extends SQLiteOpenHelper {
|
||||
rowId = db.insert(UserIds.TABLE_NAME, UserIds.USER_ID, values);
|
||||
}
|
||||
|
||||
c.close();
|
||||
|
||||
if (grabbedNewDatabase) {
|
||||
db.close();
|
||||
}
|
||||
|
||||
return rowId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,4 +31,14 @@ public class KeyRings implements BaseColumns {
|
||||
public static final String WHO_ID_type = "INTEGER";
|
||||
public static final String KEY_RING_DATA = "c_key_ring_data";
|
||||
public static final String KEY_RING_DATA_type = "BLOB";
|
||||
|
||||
public static final Uri CONTENT_URI =
|
||||
Uri.parse("content://" + DataProvider.AUTHORITY + "/key_ring");
|
||||
public static final Uri CONTENT_URI_BY_KEY_ID =
|
||||
Uri.parse("content://" + DataProvider.AUTHORITY + "/key_ring/key_id");
|
||||
public static final String CONTENT_TYPE =
|
||||
"vnd.android.cursor.dir/vnd.thialfihar.apg.key_ring";
|
||||
public static final String CONTENT_ITEM_TYPE =
|
||||
"vnd.android.cursor.item/vnd.thialfihar.apg.key_ring";
|
||||
public static final String DEFAULT_SORT_ORDER = _ID + " DESC";
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.thialfihar.android.apg.provider;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.provider.BaseColumns;
|
||||
|
||||
public class Keys implements BaseColumns {
|
||||
@@ -42,4 +43,12 @@ public class Keys implements BaseColumns {
|
||||
public static final String KEY_DATA_type = "BLOB";
|
||||
public static final String RANK = "c_key_data";
|
||||
public static final String RANK_type = "INTEGER";
|
||||
|
||||
public static final Uri CONTENT_URI =
|
||||
Uri.parse("content://" + DataProvider.AUTHORITY + "/keys");
|
||||
public static final String CONTENT_TYPE =
|
||||
"vnd.android.cursor.dir/vnd.thialfihar.apg.key";
|
||||
public static final String CONTENT_ITEM_TYPE =
|
||||
"vnd.android.cursor.item/vnd.thialfihar.apg.key";
|
||||
public static final String DEFAULT_SORT_ORDER = _ID + " DESC";
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.thialfihar.android.apg.provider;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.provider.BaseColumns;
|
||||
|
||||
public class UserIds implements BaseColumns {
|
||||
@@ -28,4 +29,14 @@ public class UserIds implements BaseColumns {
|
||||
public static final String USER_ID_type = "TEXT";
|
||||
public static final String RANK = "c_rank";
|
||||
public static final String RANK_type = "INTEGER";
|
||||
|
||||
public static final Uri CONTENT_URI =
|
||||
Uri.parse("content://" + DataProvider.AUTHORITY + "/user_ids");
|
||||
public static final Uri CONTENT_URI_BY_KEY_ID =
|
||||
Uri.parse("content://" + DataProvider.AUTHORITY + "/user_ids/key_id");
|
||||
public static final String CONTENT_TYPE =
|
||||
"vnd.android.cursor.dir/vnd.thialfihar.apg.user_id";
|
||||
public static final String CONTENT_ITEM_TYPE =
|
||||
"vnd.android.cursor.item/vnd.thialfihar.apg.user_id";
|
||||
public static final String DEFAULT_SORT_ORDER = _ID + " DESC";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user