Fix mark as seen and improve mark all X [of feed Z] as Y
This commit is contained in:
parent
63bb80560b
commit
92752e7996
|
@ -241,6 +241,9 @@ public class AllEpisodesFragment extends Fragment {
|
||||||
};
|
};
|
||||||
conDialog.createNewDialog().show();
|
conDialog.createNewDialog().show();
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.mark_all_seen_item:
|
||||||
|
DBWriter.markNewItemsSeen();
|
||||||
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import android.app.backup.BackupManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
@ -649,7 +648,7 @@ public class DBWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the 'read'-attribute of all FeedItems of a specific Feed to true.
|
* Sets the 'read'-attribute of all NEW FeedItems of a specific Feed to UNPLAYED.
|
||||||
*
|
*
|
||||||
* @param feedId ID of the Feed.
|
* @param feedId ID of the Feed.
|
||||||
*/
|
*/
|
||||||
|
@ -657,15 +656,7 @@ public class DBWriter {
|
||||||
return dbExec.submit(() -> {
|
return dbExec.submit(() -> {
|
||||||
final PodDBAdapter adapter = PodDBAdapter.getInstance();
|
final PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||||
adapter.open();
|
adapter.open();
|
||||||
Cursor itemCursor = adapter.getNewItemsIdsCursor(feedId);
|
adapter.setFeedItems(FeedItem.NEW, FeedItem.UNPLAYED, feedId);
|
||||||
long[] ids = new long[itemCursor.getCount()];
|
|
||||||
itemCursor.moveToFirst();
|
|
||||||
for (int i = 0; i < ids.length; i++) {
|
|
||||||
ids[i] = itemCursor.getLong(0);
|
|
||||||
itemCursor.moveToNext();
|
|
||||||
}
|
|
||||||
itemCursor.close();
|
|
||||||
adapter.setFeedItemRead(FeedItem.UNPLAYED, ids);
|
|
||||||
adapter.close();
|
adapter.close();
|
||||||
|
|
||||||
EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast();
|
EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast();
|
||||||
|
@ -673,7 +664,7 @@ public class DBWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the 'read'-attribute of all FeedItems of a specific Feed to true.
|
* Sets the 'read'-attribute of all FeedItems of a specific Feed to PLAYED.
|
||||||
*
|
*
|
||||||
* @param feedId ID of the Feed.
|
* @param feedId ID of the Feed.
|
||||||
*/
|
*/
|
||||||
|
@ -681,16 +672,7 @@ public class DBWriter {
|
||||||
return dbExec.submit(() -> {
|
return dbExec.submit(() -> {
|
||||||
final PodDBAdapter adapter = PodDBAdapter.getInstance();
|
final PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||||
adapter.open();
|
adapter.open();
|
||||||
Cursor itemCursor = adapter.getAllItemsOfFeedCursor(feedId);
|
adapter.setFeedItems(FeedItem.PLAYED, feedId);
|
||||||
long[] itemIds = new long[itemCursor.getCount()];
|
|
||||||
itemCursor.moveToFirst();
|
|
||||||
for (int i = 0; i < itemIds.length; i++) {
|
|
||||||
int indexId = itemCursor.getColumnIndex(PodDBAdapter.KEY_ID);
|
|
||||||
itemIds[i] = itemCursor.getLong(indexId);
|
|
||||||
itemCursor.moveToNext();
|
|
||||||
}
|
|
||||||
itemCursor.close();
|
|
||||||
adapter.setFeedItemRead(FeedItem.PLAYED, itemIds);
|
|
||||||
adapter.close();
|
adapter.close();
|
||||||
|
|
||||||
EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast();
|
EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast();
|
||||||
|
@ -698,27 +680,31 @@ public class DBWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the 'read'-attribute of all FeedItems to true.
|
* Sets the 'read'-attribute of all FeedItems to PLAYED.
|
||||||
*/
|
*/
|
||||||
public static Future<?> markAllItemsRead() {
|
public static Future<?> markAllItemsRead() {
|
||||||
return dbExec.submit(() -> {
|
return dbExec.submit(() -> {
|
||||||
final PodDBAdapter adapter = PodDBAdapter.getInstance();
|
final PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||||
adapter.open();
|
adapter.open();
|
||||||
Cursor itemCursor = adapter.getUnreadItemsCursor();
|
adapter.setFeedItems(FeedItem.PLAYED);
|
||||||
long[] itemIds = new long[itemCursor.getCount()];
|
|
||||||
itemCursor.moveToFirst();
|
|
||||||
for (int i = 0; i < itemIds.length; i++) {
|
|
||||||
int indexId = itemCursor.getColumnIndex(PodDBAdapter.KEY_ID);
|
|
||||||
itemIds[i] = itemCursor.getLong(indexId);
|
|
||||||
itemCursor.moveToNext();
|
|
||||||
}
|
|
||||||
itemCursor.close();
|
|
||||||
adapter.setFeedItemRead(FeedItem.PLAYED, itemIds);
|
|
||||||
adapter.close();
|
adapter.close();
|
||||||
|
|
||||||
EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast();
|
EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the 'read'-attribute of all NEW FeedItems to UNPLAYED.
|
||||||
|
*/
|
||||||
|
public static Future<?> markNewItemsSeen() {
|
||||||
|
return dbExec.submit(() -> {
|
||||||
|
final PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||||
|
adapter.open();
|
||||||
|
adapter.setFeedItems(FeedItem.NEW, FeedItem.UNPLAYED);
|
||||||
|
adapter.close();
|
||||||
|
|
||||||
|
EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<?> addNewFeed(final Context context, final Feed... feeds) {
|
static Future<?> addNewFeed(final Context context, final Feed... feeds) {
|
||||||
|
|
|
@ -1215,6 +1215,30 @@ public class PodDBAdapter {
|
||||||
+ "<" + FeedItem.PLAYED, null, null, null, KEY_PUBDATE + " DESC");
|
+ "<" + FeedItem.PLAYED, null, null, null, KEY_PUBDATE + " DESC");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFeedItems(int state) {
|
||||||
|
setFeedItems(Integer.MIN_VALUE, state, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFeedItems(int oldState, int newState) {
|
||||||
|
setFeedItems(oldState, newState, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFeedItems(int state, long feedId) {
|
||||||
|
setFeedItems(Integer.MIN_VALUE, state, feedId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFeedItems(int oldState, int newState, long feedId) {
|
||||||
|
String sql = "UPDATE " + TABLE_NAME_FEED_ITEMS + " SET " + KEY_READ + "=" + newState;
|
||||||
|
if(feedId > 0) {
|
||||||
|
sql += " WHERE " + KEY_FEED + "=" + feedId;
|
||||||
|
}
|
||||||
|
if(FeedItem.NEW <= oldState && oldState <= FeedItem.PLAYED) {
|
||||||
|
sql += feedId > 0 ? " AND " : " WHERE ";
|
||||||
|
sql += KEY_READ + "=" + oldState;
|
||||||
|
}
|
||||||
|
db.execSQL(sql);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a cursor which contains all items of a feed that are considered new.
|
* Returns a cursor which contains all items of a feed that are considered new.
|
||||||
* The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection.
|
* The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection.
|
||||||
|
|
Loading…
Reference in New Issue