mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Remove contentprovider cruft.
This commit is contained in:
parent
129a220cff
commit
909fcdf681
1 changed files with 1 additions and 369 deletions
|
@ -27,44 +27,13 @@ public class FeedProvider extends ContentProvider {
|
|||
public static final String AUTHORITY = "com.newsblur";
|
||||
public static final String VERSION = "v1";
|
||||
|
||||
public static final Uri NEWSBLUR_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION);
|
||||
public static final Uri SOCIAL_FEEDS_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/social_feeds/");
|
||||
public static final Uri FEEDS_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/feeds/");
|
||||
public static final Uri CLASSIFIER_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/classifiers/");
|
||||
public static final Uri FEED_COUNT_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/feedcount/");
|
||||
public static final Uri SOCIALCOUNT_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/socialfeedcount/");
|
||||
public static final Uri ALL_STORIES_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/stories/");
|
||||
public static final Uri USERS_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/users/");
|
||||
|
||||
public static final Uri FEED_STORIES_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/stories/feed/");
|
||||
public static final Uri MULTIFEED_STORIES_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/stories/feeds/");
|
||||
public static final Uri SOCIALFEED_STORIES_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/stories/socialfeed/");
|
||||
public static final Uri STORY_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/story/");
|
||||
public static final Uri ALL_SHARED_STORIES_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/stories/socialfeeds/");
|
||||
public static final Uri COMMENTS_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/comments/");
|
||||
public static final Uri REPLIES_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/replies/");
|
||||
public static final Uri FEED_FOLDER_MAP_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/feedfoldermap/");
|
||||
public static final Uri FOLDERS_URI = Uri.parse("content://" + AUTHORITY + "/" + VERSION + "/folders/");
|
||||
|
||||
private static final int ALL_FEEDS = 0;
|
||||
private static final int ALL_SOCIAL_FEEDS = 1;
|
||||
private static final int ALL_FOLDERS = 2;
|
||||
private static final int FEED_STORIES = 3;
|
||||
private static final int INDIVIDUAL_FOLDER = 4;
|
||||
private static final int FEED_FOLDER_MAP = 5;
|
||||
private static final int SPECIFIC_FEED_FOLDER_MAP = 6;
|
||||
private static final int SOCIALFEED_STORIES = 7;
|
||||
private static final int INDIVIDUAL_FEED = 8;
|
||||
private static final int STORY_COMMENTS = 9;
|
||||
private static final int INDIVIDUAL_STORY = 10;
|
||||
private static final int FEED_COUNT = 11;
|
||||
private static final int SOCIALFEED_COUNT = 13;
|
||||
private static final int INDIVIDUAL_SOCIAL_FEED = 14;
|
||||
private static final int REPLIES = 15;
|
||||
private static final int MULTIFEED_STORIES = 16;
|
||||
private static final int ALL_STORIES = 20;
|
||||
private static final int ALL_SHARED_STORIES = 17;
|
||||
private static final int FEED_STORIES_NO_UPDATE = 18;
|
||||
private static final int CLASSIFIERS_FOR_FEED = 19;
|
||||
private static final int USERS = 21;
|
||||
|
||||
|
@ -72,30 +41,10 @@ public class FeedProvider extends ContentProvider {
|
|||
|
||||
private static UriMatcher uriMatcher;
|
||||
static {
|
||||
// TODO: get rid of the hard-coded URL paths and replace then with the constant values in DatabaseConstants
|
||||
// that they actually represent.
|
||||
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/feeds/", ALL_FEEDS);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/social_feeds/", ALL_SOCIAL_FEEDS);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/social_feeds/#/", INDIVIDUAL_SOCIAL_FEED);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/feeds/*/", INDIVIDUAL_FEED);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/feedcount/", FEED_COUNT);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/socialfeedcount/", SOCIALFEED_COUNT);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/feed/*/", INDIVIDUAL_FEED);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/classifiers/#/", CLASSIFIERS_FOR_FEED);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/stories/socialfeed/#/", SOCIALFEED_STORIES);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/stories/socialfeeds/", ALL_SHARED_STORIES);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/stories/feed/#/", FEED_STORIES);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/stories/feed/#/noupdate", FEED_STORIES_NO_UPDATE);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/stories/", ALL_STORIES);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/stories/feeds/", MULTIFEED_STORIES);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/story/*/", INDIVIDUAL_STORY);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/comments/", STORY_COMMENTS);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/replies/", REPLIES);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/feedfoldermap/", FEED_FOLDER_MAP);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/feedfoldermap/*/", SPECIFIC_FEED_FOLDER_MAP);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/folders/", ALL_FOLDERS);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/folders/*/", INDIVIDUAL_FOLDER);
|
||||
uriMatcher.addURI(AUTHORITY, VERSION + "/users/", USERS);
|
||||
}
|
||||
|
||||
|
@ -103,40 +52,6 @@ public class FeedProvider extends ContentProvider {
|
|||
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
||||
final SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
switch (uriMatcher.match(uri)) {
|
||||
case ALL_SOCIAL_FEEDS:
|
||||
db.delete(DatabaseConstants.SOCIALFEED_TABLE, null, null);
|
||||
return 1;
|
||||
|
||||
case ALL_FEEDS:
|
||||
db.delete(DatabaseConstants.FEED_TABLE, null, null);
|
||||
db.delete(DatabaseConstants.FOLDER_TABLE, null, null);
|
||||
db.delete(DatabaseConstants.FEED_FOLDER_MAP_TABLE, null, null);
|
||||
return 1;
|
||||
|
||||
case ALL_STORIES:
|
||||
db.delete(DatabaseConstants.STORY_TABLE, null, null);
|
||||
return 1;
|
||||
|
||||
case SOCIALFEED_STORIES:
|
||||
StringBuilder socialDeleteBuilder = new StringBuilder();
|
||||
socialDeleteBuilder.append("DELETE FROM " + DatabaseConstants.STORY_TABLE);
|
||||
socialDeleteBuilder.append(" WHERE " + DatabaseConstants.STORY_ID + " IN (");
|
||||
socialDeleteBuilder.append(" SELECT " + DatabaseConstants.STORY_ID + " FROM ");
|
||||
socialDeleteBuilder.append(DatabaseConstants.SOCIALFEED_STORY_MAP_TABLE + " WHERE ");
|
||||
socialDeleteBuilder.append(DatabaseConstants.SOCIALFEED_STORY_USER_ID + " = ? )");
|
||||
db.execSQL(socialDeleteBuilder.toString(), new String[] { uri.getLastPathSegment() });
|
||||
|
||||
return db.delete(DatabaseConstants.SOCIALFEED_STORY_MAP_TABLE, DatabaseConstants.SOCIALFEED_STORY_USER_ID + " = ?", new String[] { uri.getLastPathSegment() } );
|
||||
|
||||
case INDIVIDUAL_FEED:
|
||||
db.delete(DatabaseConstants.FEED_TABLE, DatabaseConstants.FEED_ID + " = ?", new String[] { uri.getLastPathSegment() } );
|
||||
db.delete(DatabaseConstants.FEED_FOLDER_MAP_TABLE, DatabaseConstants.FEED_FOLDER_FEED_ID + " = ?", new String[] { uri.getLastPathSegment() } );
|
||||
return db.delete(DatabaseConstants.STORY_TABLE, DatabaseConstants.STORY_FEED_ID + " = ?", new String[] { uri.getLastPathSegment() } );
|
||||
|
||||
case FEED_STORIES:
|
||||
db.delete(DatabaseConstants.STORY_TABLE, DatabaseConstants.STORY_FEED_ID + " = ?", new String[] { uri.getLastPathSegment() } );
|
||||
return 1;
|
||||
|
||||
case CLASSIFIERS_FOR_FEED:
|
||||
return db.delete(DatabaseConstants.CLASSIFIER_TABLE, DatabaseConstants.CLASSIFIER_ID + " = ?", new String[] { uri.getLastPathSegment() });
|
||||
|
||||
|
@ -150,83 +65,12 @@ public class FeedProvider extends ContentProvider {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bulkInsert(Uri uri, ContentValues[] valuesArray) {
|
||||
int count = 0;
|
||||
final SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
switch (uriMatcher.match(uri)) {
|
||||
case ALL_FOLDERS:
|
||||
db.beginTransaction();
|
||||
try {
|
||||
for(ContentValues values: valuesArray) {
|
||||
db.insertWithOnConflict(DatabaseConstants.FOLDER_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
count++;
|
||||
}
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
break;
|
||||
case FEED_FOLDER_MAP:
|
||||
db.beginTransaction();
|
||||
try {
|
||||
for(ContentValues values: valuesArray) {
|
||||
db.insertWithOnConflict(DatabaseConstants.FEED_FOLDER_MAP_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
count++;
|
||||
}
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
break;
|
||||
case ALL_FEEDS:
|
||||
db.beginTransaction();
|
||||
try {
|
||||
for(ContentValues values: valuesArray) {
|
||||
db.insertWithOnConflict(DatabaseConstants.FEED_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
count++;
|
||||
}
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
break;
|
||||
case ALL_SOCIAL_FEEDS:
|
||||
db.beginTransaction();
|
||||
try {
|
||||
for(ContentValues values: valuesArray) {
|
||||
db.insertWithOnConflict(DatabaseConstants.SOCIALFEED_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
count++;
|
||||
}
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
count = super.bulkInsert(uri, valuesArray);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri insert(Uri uri, ContentValues values) {
|
||||
final SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
Uri resultUri = null;
|
||||
switch (uriMatcher.match(uri)) {
|
||||
|
||||
// Inserting a folder
|
||||
case ALL_FOLDERS:
|
||||
final long folderId = db.insertWithOnConflict(DatabaseConstants.FOLDER_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
resultUri = uri.buildUpon().appendPath("" + folderId).build();
|
||||
break;
|
||||
|
||||
// Inserting a feed to folder mapping
|
||||
case FEED_FOLDER_MAP:
|
||||
db.insertWithOnConflict(DatabaseConstants.FEED_FOLDER_MAP_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
resultUri = uri.buildUpon().appendPath(values.getAsString(DatabaseConstants.FEED_FOLDER_FOLDER_NAME)).build();
|
||||
break;
|
||||
|
||||
case USERS:
|
||||
db.insertWithOnConflict(DatabaseConstants.USER_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
resultUri = uri.buildUpon().appendPath(values.getAsString(DatabaseConstants.USER_USERID)).build();
|
||||
|
@ -238,28 +82,6 @@ public class FeedProvider extends ContentProvider {
|
|||
db.insertWithOnConflict(DatabaseConstants.CLASSIFIER_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
break;
|
||||
|
||||
// Inserting a feed
|
||||
case ALL_FEEDS:
|
||||
db.insertWithOnConflict(DatabaseConstants.FEED_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
resultUri = uri.buildUpon().appendPath(values.getAsString(DatabaseConstants.FEED_ID)).build();
|
||||
break;
|
||||
|
||||
// Inserting a social feed
|
||||
case ALL_SOCIAL_FEEDS:
|
||||
db.insertWithOnConflict(DatabaseConstants.SOCIALFEED_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
resultUri = uri.buildUpon().appendPath(values.getAsString(DatabaseConstants.SOCIAL_FEED_ID)).build();
|
||||
break;
|
||||
|
||||
// Inserting a story for a social feed
|
||||
case SOCIALFEED_STORIES:
|
||||
final ContentValues socialMapValues = new ContentValues();
|
||||
socialMapValues.put(DatabaseConstants.SOCIALFEED_STORY_USER_ID, uri.getLastPathSegment());
|
||||
socialMapValues.put(DatabaseConstants.SOCIALFEED_STORY_STORYID, values.getAsString(DatabaseConstants.STORY_ID));
|
||||
db.insertWithOnConflict(DatabaseConstants.SOCIALFEED_STORY_MAP_TABLE, null, socialMapValues, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
|
||||
resultUri = uri.buildUpon().appendPath(values.getAsString(DatabaseConstants.SOCIAL_FEED_ID)).build();
|
||||
break;
|
||||
|
||||
// Inserting a comment
|
||||
case STORY_COMMENTS:
|
||||
db.insertWithOnConflict(DatabaseConstants.COMMENT_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
|
@ -270,16 +92,6 @@ public class FeedProvider extends ContentProvider {
|
|||
db.insertWithOnConflict(DatabaseConstants.REPLY_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
break;
|
||||
|
||||
// Inserting a story
|
||||
case FEED_STORIES:
|
||||
db.insertWithOnConflict(DatabaseConstants.STORY_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
break;
|
||||
|
||||
// Inserting a story assuming it's not already in the DB
|
||||
case FEED_STORIES_NO_UPDATE:
|
||||
db.insertWithOnConflict(DatabaseConstants.STORY_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
break;
|
||||
|
||||
case UriMatcher.NO_MATCH:
|
||||
Log.e(this.getClass().getName(), "No match found for URI: " + uri.toString());
|
||||
break;
|
||||
|
@ -339,20 +151,6 @@ public class FeedProvider extends ContentProvider {
|
|||
final LoggingDatabase db = new LoggingDatabase(rdb);
|
||||
switch (uriMatcher.match(uri)) {
|
||||
|
||||
// Query for all feeds (by default only return those that have unread items in them)
|
||||
case ALL_FEEDS:
|
||||
String feedsQuery = "SELECT " + TextUtils.join(",", DatabaseConstants.FEED_COLUMNS) + " FROM " + DatabaseConstants.FEED_FOLDER_MAP_TABLE +
|
||||
" INNER JOIN " + DatabaseConstants.FEED_TABLE +
|
||||
" ON " + DatabaseConstants.FEED_TABLE + "." + DatabaseConstants.FEED_ID + " = " + DatabaseConstants.FEED_FOLDER_MAP_TABLE + "." + DatabaseConstants.FEED_FOLDER_FEED_ID +
|
||||
((selection == null) ? "" : " WHERE " + selection) +
|
||||
" ORDER BY " + DatabaseConstants.FEED_TABLE + "." + DatabaseConstants.FEED_TITLE + " COLLATE NOCASE";
|
||||
return db.rawQuery(feedsQuery, selectionArgs);
|
||||
|
||||
// Query for a specific feed
|
||||
case INDIVIDUAL_FEED:
|
||||
return db.rawQuery("SELECT " + TextUtils.join(",", DatabaseConstants.FEED_COLUMNS) + " FROM " + DatabaseConstants.FEED_TABLE +
|
||||
" WHERE " + DatabaseConstants.FEED_ID + "= '" + uri.getLastPathSegment() + "'", selectionArgs);
|
||||
|
||||
case USERS:
|
||||
return db.query(DatabaseConstants.USER_TABLE, projection, selection, selectionArgs, null, null, null);
|
||||
|
||||
|
@ -360,60 +158,6 @@ public class FeedProvider extends ContentProvider {
|
|||
case CLASSIFIERS_FOR_FEED:
|
||||
return db.query(DatabaseConstants.CLASSIFIER_TABLE, null, DatabaseConstants.CLASSIFIER_ID + " = ?", new String[] { uri.getLastPathSegment() }, null, null, null);
|
||||
|
||||
// Query for a specific folder
|
||||
case INDIVIDUAL_FOLDER:
|
||||
throw new RuntimeException("DEPRECATED");
|
||||
|
||||
// Query for total feed counts
|
||||
case FEED_COUNT:
|
||||
throw new RuntimeException("DEPRECATED");
|
||||
|
||||
case SOCIALFEED_COUNT:
|
||||
throw new RuntimeException("DEPRECATED");
|
||||
|
||||
// Querying for a stories from a feed
|
||||
case FEED_STORIES:
|
||||
if (!TextUtils.isEmpty(selection)) {
|
||||
selection = selection + " AND " + DatabaseConstants.STORY_FEED_ID + " = ?";
|
||||
} else {
|
||||
selection = DatabaseConstants.STORY_FEED_ID + " = ?";
|
||||
}
|
||||
selectionArgs = new String[] { uri.getLastPathSegment() };
|
||||
return db.query(DatabaseConstants.STORY_TABLE, DatabaseConstants.STORY_COLUMNS, selection, selectionArgs, null, null, sortOrder);
|
||||
|
||||
case INDIVIDUAL_STORY:
|
||||
selectionArgs = new String[] { uri.getLastPathSegment() };
|
||||
selection = DatabaseConstants.STORY_ID + " = ?";
|
||||
return db.query(DatabaseConstants.STORY_TABLE, DatabaseConstants.STORY_COLUMNS, selection, selectionArgs, null, null, sortOrder);
|
||||
|
||||
// Querying for all stories
|
||||
case ALL_STORIES:
|
||||
String allStoriesQuery = "SELECT " + TextUtils.join(",", DatabaseConstants.STORY_COLUMNS) + ", " + DatabaseConstants.FEED_TITLE + ", " +
|
||||
DatabaseConstants.FEED_FAVICON_URL + ", " + DatabaseConstants.FEED_FAVICON_COLOR + ", " + DatabaseConstants.FEED_FAVICON_BORDER + ", " +
|
||||
DatabaseConstants.FEED_FAVICON_FADE + ", " + DatabaseConstants.FEED_FAVICON_TEXT +
|
||||
" FROM " + DatabaseConstants.STORY_TABLE +
|
||||
" INNER JOIN " + DatabaseConstants.FEED_TABLE +
|
||||
" ON " + DatabaseConstants.STORY_TABLE + "." + DatabaseConstants.STORY_FEED_ID + " = " + DatabaseConstants.FEED_TABLE + "." + DatabaseConstants.FEED_ID +
|
||||
" WHERE " + selection + " ORDER BY " + sortOrder;
|
||||
return db.rawQuery(allStoriesQuery, null);
|
||||
|
||||
// Querying for a stories from a selection of feeds
|
||||
case MULTIFEED_STORIES:
|
||||
if (!TextUtils.isEmpty(selection)) {
|
||||
selection = selection + " AND " + DatabaseConstants.STORY_TABLE + "." + DatabaseConstants.STORY_FEED_ID + " IN ( " + TextUtils.join(",", selectionArgs) + ")";
|
||||
} else {
|
||||
selection = DatabaseConstants.STORY_TABLE + "." + DatabaseConstants.STORY_FEED_ID + " IN ( " + TextUtils.join(",", selectionArgs) + ")";
|
||||
}
|
||||
String userQuery = "SELECT " + TextUtils.join(",", DatabaseConstants.STORY_COLUMNS) + ", " + DatabaseConstants.FEED_TITLE + ", " +
|
||||
DatabaseConstants.FEED_FAVICON_URL + ", " + DatabaseConstants.FEED_FAVICON_COLOR + ", " + DatabaseConstants.FEED_FAVICON_BORDER + ", " +
|
||||
DatabaseConstants.FEED_FAVICON_FADE + ", " + DatabaseConstants.FEED_FAVICON_TEXT +
|
||||
" FROM " + DatabaseConstants.STORY_TABLE +
|
||||
" INNER JOIN " + DatabaseConstants.FEED_TABLE +
|
||||
" ON " + DatabaseConstants.STORY_TABLE + "." + DatabaseConstants.STORY_FEED_ID + " = " + DatabaseConstants.FEED_TABLE + "." + DatabaseConstants.FEED_ID +
|
||||
" WHERE " + selection + " ORDER BY " + sortOrder;
|
||||
|
||||
return db.rawQuery(userQuery, null);
|
||||
|
||||
// Querying for a stories from a feed
|
||||
case STORY_COMMENTS:
|
||||
if (selectionArgs.length == 1) {
|
||||
|
@ -428,93 +172,6 @@ public class FeedProvider extends ContentProvider {
|
|||
selection = DatabaseConstants.REPLY_COMMENTID+ " = ?";
|
||||
return db.query(DatabaseConstants.REPLY_TABLE, DatabaseConstants.REPLY_COLUMNS, selection, selectionArgs, null, null, null);
|
||||
|
||||
// Query for feeds with no folder mapping
|
||||
case FEED_FOLDER_MAP:
|
||||
String nullFolderQuery = "SELECT " + TextUtils.join(",", DatabaseConstants.FEED_COLUMNS) + " FROM " + DatabaseConstants.FEED_TABLE +
|
||||
" LEFT JOIN " + DatabaseConstants.FEED_FOLDER_MAP_TABLE +
|
||||
" ON " + DatabaseConstants.FEED_TABLE + "." + DatabaseConstants.FEED_ID + " = " + DatabaseConstants.FEED_FOLDER_MAP_TABLE + "." + DatabaseConstants.FEED_FOLDER_FEED_ID +
|
||||
" WHERE " + DatabaseConstants.FEED_FOLDER_MAP_TABLE + "." + DatabaseConstants.FEED_FOLDER_FOLDER_NAME + " IS NULL " +
|
||||
" GROUP BY " + DatabaseConstants.FEED_TABLE+ "." + DatabaseConstants.FEED_ID;
|
||||
|
||||
StringBuilder nullFolderBuilder = new StringBuilder();
|
||||
nullFolderBuilder.append(nullFolderQuery);
|
||||
if (selectionArgs != null && selectionArgs.length > 0) {
|
||||
nullFolderBuilder.append(selectionArgs[0]);
|
||||
}
|
||||
nullFolderBuilder.append(" ORDER BY " + DatabaseConstants.FEED_TABLE + "." + DatabaseConstants.FEED_TITLE + " COLLATE NOCASE");
|
||||
return db.rawQuery(nullFolderBuilder.toString(), null);
|
||||
|
||||
// Querying for feeds for a given folder
|
||||
case SPECIFIC_FEED_FOLDER_MAP:
|
||||
String[] folderArguments = new String[] { uri.getLastPathSegment() };
|
||||
|
||||
String query = "SELECT " +
|
||||
TextUtils.join(",", (projection == null ? DatabaseConstants.FEED_COLUMNS : projection)) + " FROM " + DatabaseConstants.FEED_FOLDER_MAP_TABLE +
|
||||
" INNER JOIN " + DatabaseConstants.FEED_TABLE +
|
||||
" ON " + DatabaseConstants.FEED_TABLE + "." + DatabaseConstants.FEED_ID + " = " + DatabaseConstants.FEED_FOLDER_MAP_TABLE + "." + DatabaseConstants.FEED_FOLDER_FEED_ID +
|
||||
" WHERE " + DatabaseConstants.FEED_FOLDER_MAP_TABLE + "." + DatabaseConstants.FEED_FOLDER_FOLDER_NAME + " = ? " +
|
||||
" GROUP BY " + DatabaseConstants.FEED_TABLE+ "." + DatabaseConstants.FEED_ID;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(query);
|
||||
if (selectionArgs != null && selectionArgs.length > 0) {
|
||||
builder.append(selectionArgs[0]);
|
||||
}
|
||||
builder.append(" ORDER BY " + DatabaseConstants.FEED_TABLE + "." + DatabaseConstants.FEED_TITLE + " COLLATE NOCASE");
|
||||
return db.rawQuery(builder.toString(), folderArguments);
|
||||
|
||||
// Querying for all folders with unread items
|
||||
case ALL_FOLDERS:
|
||||
throw new RuntimeException("DEPRECATED");
|
||||
case ALL_SOCIAL_FEEDS:
|
||||
return db.query(DatabaseConstants.SOCIALFEED_TABLE, null, selection, null, null, null, "UPPER(" + DatabaseConstants.SOCIAL_FEED_TITLE + ") ASC");
|
||||
case INDIVIDUAL_SOCIAL_FEED:
|
||||
return db.query(DatabaseConstants.SOCIALFEED_TABLE, null, DatabaseConstants.SOCIAL_FEED_ID + " = ?", new String[] { uri.getLastPathSegment() }, null, null, null);
|
||||
case ALL_SHARED_STORIES:
|
||||
String allSharedQuery = "SELECT " + TextUtils.join(",", DatabaseConstants.STORY_COLUMNS) + ", " + DatabaseConstants.FEED_TITLE + ", " +
|
||||
DatabaseConstants.FEED_FAVICON_URL + ", " + DatabaseConstants.FEED_FAVICON_COLOR + ", " + DatabaseConstants.FEED_FAVICON_BORDER + ", " +
|
||||
DatabaseConstants.FEED_FAVICON_FADE + ", " + DatabaseConstants.FEED_FAVICON_TEXT +
|
||||
" FROM " + DatabaseConstants.SOCIALFEED_STORY_MAP_TABLE +
|
||||
" INNER JOIN " + DatabaseConstants.STORY_TABLE +
|
||||
" ON " + DatabaseConstants.STORY_TABLE + "." + DatabaseConstants.STORY_ID + " = " + DatabaseConstants.SOCIALFEED_STORY_MAP_TABLE + "." + DatabaseConstants.SOCIALFEED_STORY_STORYID +
|
||||
" INNER JOIN " + DatabaseConstants.FEED_TABLE +
|
||||
" ON " + DatabaseConstants.STORY_TABLE + "." + DatabaseConstants.STORY_FEED_ID + " = " + DatabaseConstants.FEED_TABLE + "." + DatabaseConstants.FEED_ID;
|
||||
|
||||
StringBuilder allSharedBuilder = new StringBuilder();
|
||||
allSharedBuilder.append(allSharedQuery);
|
||||
if (!TextUtils.isEmpty(selection)) {
|
||||
allSharedBuilder.append(" WHERE ");
|
||||
allSharedBuilder.append(selection);
|
||||
}
|
||||
allSharedBuilder.append("GROUP BY " + DatabaseConstants.STORY_TABLE + "." + DatabaseConstants.STORY_ID);
|
||||
if (!TextUtils.isEmpty(sortOrder)) {
|
||||
allSharedBuilder.append(" ORDER BY " + sortOrder);
|
||||
}
|
||||
return db.rawQuery(allSharedBuilder.toString(), null);
|
||||
|
||||
case SOCIALFEED_STORIES:
|
||||
String[] userArgument = new String[] { uri.getLastPathSegment() };
|
||||
|
||||
String socialQuery = "SELECT " + TextUtils.join(",", DatabaseConstants.STORY_COLUMNS) + ", " + DatabaseConstants.FEED_TITLE + ", " +
|
||||
DatabaseConstants.FEED_FAVICON_URL + ", " + DatabaseConstants.FEED_FAVICON_COLOR + ", " + DatabaseConstants.FEED_FAVICON_BORDER + ", " +
|
||||
DatabaseConstants.FEED_FAVICON_FADE + ", " + DatabaseConstants.FEED_FAVICON_TEXT +
|
||||
" FROM " + DatabaseConstants.SOCIALFEED_STORY_MAP_TABLE +
|
||||
" INNER JOIN " + DatabaseConstants.STORY_TABLE +
|
||||
" ON " + DatabaseConstants.STORY_TABLE + "." + DatabaseConstants.STORY_ID + " = " + DatabaseConstants.SOCIALFEED_STORY_MAP_TABLE + "." + DatabaseConstants.SOCIALFEED_STORY_STORYID +
|
||||
" INNER JOIN " + DatabaseConstants.FEED_TABLE +
|
||||
" ON " + DatabaseConstants.STORY_TABLE + "." + DatabaseConstants.STORY_FEED_ID + " = " + DatabaseConstants.FEED_TABLE + "." + DatabaseConstants.FEED_ID +
|
||||
" WHERE " + DatabaseConstants.SOCIALFEED_STORY_MAP_TABLE + "." + DatabaseConstants.SOCIALFEED_STORY_USER_ID + " = ? ";
|
||||
|
||||
StringBuilder storyBuilder = new StringBuilder();
|
||||
storyBuilder.append(socialQuery);
|
||||
if (!TextUtils.isEmpty(selection)) {
|
||||
storyBuilder.append("AND ");
|
||||
storyBuilder.append(selection);
|
||||
}
|
||||
if (!TextUtils.isEmpty(sortOrder)) {
|
||||
storyBuilder.append(" ORDER BY " + sortOrder);
|
||||
}
|
||||
return db.rawQuery(storyBuilder.toString(), userArgument);
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown URI: " + uri);
|
||||
}
|
||||
|
@ -522,32 +179,7 @@ public class FeedProvider extends ContentProvider {
|
|||
|
||||
@Override
|
||||
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
||||
final SQLiteDatabase rwdb = databaseHelper.getWritableDatabase();
|
||||
final LoggingDatabase db = new LoggingDatabase(rwdb);
|
||||
|
||||
switch (uriMatcher.match(uri)) {
|
||||
case ALL_FEEDS:
|
||||
return db.update(DatabaseConstants.FEED_TABLE, values, null, null);
|
||||
case INDIVIDUAL_FEED:
|
||||
return db.update(DatabaseConstants.FEED_TABLE, values, DatabaseConstants.FEED_ID + " = ?", new String[] { uri.getLastPathSegment() });
|
||||
case INDIVIDUAL_SOCIAL_FEED:
|
||||
return db.update(DatabaseConstants.SOCIALFEED_TABLE, values, DatabaseConstants.SOCIAL_FEED_ID + " = ?", new String[] { uri.getLastPathSegment() });
|
||||
case SOCIALFEED_STORIES:
|
||||
return db.update(DatabaseConstants.SOCIALFEED_TABLE, values, DatabaseConstants.FEED_ID + " = ?", new String[] { uri.getLastPathSegment() });
|
||||
case INDIVIDUAL_STORY:
|
||||
int count = 0;
|
||||
count += db.update(DatabaseConstants.STORY_TABLE, values, DatabaseConstants.STORY_ID + " = ?", new String[] { uri.getLastPathSegment() });
|
||||
return count;
|
||||
// In order to run a raw SQL query whereby we make decrement the column we need to a dynamic reference - something the usual content provider can't easily handle. Hence this circuitous hack.
|
||||
case FEED_COUNT:
|
||||
db.execSQL("UPDATE " + DatabaseConstants.FEED_TABLE + " SET " + selectionArgs[0] + " = " + selectionArgs[0] + " " + selectionArgs[2] + " WHERE " + DatabaseConstants.FEED_ID + " = " + selectionArgs[1]);
|
||||
return 1;
|
||||
case SOCIALFEED_COUNT:
|
||||
db.execSQL("UPDATE " + DatabaseConstants.SOCIALFEED_TABLE + " SET " + selectionArgs[0] + " = " + selectionArgs[0] + " " + selectionArgs[2] + " WHERE " + DatabaseConstants.SOCIAL_FEED_ID + " = " + selectionArgs[1]);
|
||||
return 1;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown URI: " + uri);
|
||||
}
|
||||
throw new UnsupportedOperationException("Unknown URI: " + uri);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue