Remove unused methods from DB Reader and DB Adapter
This commit is contained in:
parent
a8d72b3c6f
commit
397cd8c636
|
@ -218,58 +218,43 @@ public class DBReaderTest extends InstrumentationTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
private List<FeedItem> saveUnreadItems(int numItems) {
|
||||
if (numItems <= 0) {
|
||||
throw new IllegalArgumentException("numItems<=0");
|
||||
}
|
||||
private List<FeedItem> saveNewItems(int numItems) {
|
||||
List<Feed> feeds = saveFeedlist(numItems, numItems, true);
|
||||
List<FeedItem> items = new ArrayList<>();
|
||||
for (Feed f : feeds) {
|
||||
items.addAll(f.getItems());
|
||||
}
|
||||
List<FeedItem> unread = new ArrayList<>();
|
||||
List<FeedItem> newItems = new ArrayList<>();
|
||||
Random random = new Random();
|
||||
|
||||
while (unread.size() < numItems) {
|
||||
while (newItems.size() < numItems) {
|
||||
int i = random.nextInt(numItems);
|
||||
if (!unread.contains(items.get(i))) {
|
||||
if (!newItems.contains(items.get(i))) {
|
||||
FeedItem item = items.get(i);
|
||||
item.setPlayed(false);
|
||||
unread.add(item);
|
||||
item.setNew();
|
||||
newItems.add(item);
|
||||
}
|
||||
}
|
||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||
adapter.open();
|
||||
adapter.setFeedItemlist(unread);
|
||||
adapter.setFeedItemlist(newItems);
|
||||
adapter.close();
|
||||
return unread;
|
||||
}
|
||||
|
||||
public void testGetUnreadItemsList() {
|
||||
final int numItems = 10;
|
||||
|
||||
List<FeedItem> unread = saveUnreadItems(numItems);
|
||||
List<FeedItem> unreadSaved = DBReader.getUnreadItemsList();
|
||||
assertNotNull(unreadSaved);
|
||||
assertTrue(unread.size() == unreadSaved.size());
|
||||
for (FeedItem item : unreadSaved) {
|
||||
assertFalse(item.isPlayed());
|
||||
}
|
||||
return newItems;
|
||||
}
|
||||
|
||||
public void testGetNewItemIds() {
|
||||
final int numItems = 10;
|
||||
|
||||
List<FeedItem> unread = saveUnreadItems(numItems);
|
||||
long[] unreadIds = new long[unread.size()];
|
||||
for (int i = 0; i < unread.size(); i++) {
|
||||
unreadIds[i] = unread.get(i).getId();
|
||||
List<FeedItem> newItems = saveNewItems(numItems);
|
||||
long[] unreadIds = new long[newItems.size()];
|
||||
for (int i = 0; i < newItems.size(); i++) {
|
||||
unreadIds[i] = newItems.get(i).getId();
|
||||
}
|
||||
List<FeedItem> unreadSaved = DBReader.getUnreadItemsList();
|
||||
assertNotNull(unreadSaved);
|
||||
assertTrue(unread.size() == unreadSaved.size());
|
||||
for(int i=0; i < unreadSaved.size(); i++) {
|
||||
long savedId = unreadSaved.get(i).getId();
|
||||
List<FeedItem> newItemsSaved = DBReader.getNewItemsList();
|
||||
assertNotNull(newItemsSaved);
|
||||
assertTrue(newItems.size() == newItemsSaved.size());
|
||||
for(int i=0; i < newItemsSaved.size(); i++) {
|
||||
long savedId = newItemsSaved.get(i).getId();
|
||||
boolean found = false;
|
||||
for (long id : unreadIds) {
|
||||
if (id == savedId) {
|
||||
|
|
|
@ -371,30 +371,6 @@ public final class DBReader {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a list of FeedItems whose 'read'-attribute is set to false.
|
||||
*
|
||||
* @return A list of FeedItems whose 'read'-attribute it set to false.
|
||||
*/
|
||||
public static List<FeedItem> getUnreadItemsList() {
|
||||
Log.d(TAG, "getUnreadItemsList() called");
|
||||
|
||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||
adapter.open();
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = adapter.getUnreadItemsCursor();
|
||||
List<FeedItem> items = extractItemlistFromCursor(adapter, cursor);
|
||||
loadAdditionalFeedItemListData(items);
|
||||
return items;
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
adapter.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a list of FeedItems that are considered new.
|
||||
* Excludes items from feeds that do not have keep updated enabled.
|
||||
|
|
|
@ -1249,15 +1249,6 @@ public class PodDBAdapter {
|
|||
return db.rawQuery(query, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a cursor which contains all feed items in the unread items list.
|
||||
* The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection.
|
||||
*/
|
||||
public final Cursor getUnreadItemsCursor() {
|
||||
return db.query(TABLE_NAME_FEED_ITEMS, FEEDITEM_SEL_FI_SMALL, KEY_READ
|
||||
+ "<" + FeedItem.PLAYED, null, null, null, KEY_PUBDATE + " DESC");
|
||||
}
|
||||
|
||||
public void setFeedItems(int state) {
|
||||
setFeedItems(Integer.MIN_VALUE, state, 0);
|
||||
}
|
||||
|
@ -1282,19 +1273,6 @@ public class PodDBAdapter {
|
|||
db.execSQL(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a cursor which contains all items of a feed that are considered new.
|
||||
* The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection.
|
||||
*/
|
||||
public final Cursor getNewItemsIdsCursor(long feedId) {
|
||||
final String query = "SELECT " + KEY_ID
|
||||
+ " FROM " + TABLE_NAME_FEED_ITEMS
|
||||
+ " WHERE " + KEY_FEED + "=" + feedId
|
||||
+ " AND " + KEY_READ + "=" + FeedItem.NEW
|
||||
+ " ORDER BY " + KEY_PUBDATE + " DESC";
|
||||
return db.rawQuery(query, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a cursor which contains all feed items that are considered new.
|
||||
* Excludes those feeds that do not have 'Keep Updated' enabled.
|
||||
|
|
Loading…
Reference in New Issue