summaryrefslogtreecommitdiff
path: root/storage/database
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2024-04-28 23:56:23 +0200
committerGitHub <noreply@github.com>2024-04-28 23:56:23 +0200
commit1505c50b1bdd8ccda23c80f29949a6ecf437faaf (patch)
treeaadc5fc18ba02e9de446f71b414f572f096bb773 /storage/database
parent257c3bca5e57d3e692d5f8ee086432ec2b6edf82 (diff)
downloadAntennaPod-1505c50b1bdd8ccda23c80f29949a6ecf437faaf.zip
Fix sometimes not resetting media position (#7147)
Before 5218e06904e489f77da4078de775dd0a63b94ef4, deleting an item loaded its state from the database again. Now it stores the state of that object. markItemPlayed() did not reset the object's playback position, so when auto-delete was enabled, the position was overwritten again.
Diffstat (limited to 'storage/database')
-rw-r--r--storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBWriter.java12
-rw-r--r--storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java10
2 files changed, 7 insertions, 15 deletions
diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBWriter.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBWriter.java
index a9c4f4dc3..7b4543a38 100644
--- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBWriter.java
+++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBWriter.java
@@ -728,20 +728,10 @@ public class DBWriter {
*/
@NonNull
public static Future<?> markItemPlayed(FeedItem item, int played, boolean resetMediaPosition) {
- long mediaId = (item.hasMedia()) ? item.getMedia().getId() : 0;
- return markItemPlayed(item.getId(), played, mediaId, resetMediaPosition);
- }
-
- @NonNull
- private static Future<?> markItemPlayed(final long itemId,
- final int played,
- final long mediaId,
- final boolean resetMediaPosition) {
return runOnDbThread(() -> {
final PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
- adapter.setFeedItemRead(played, itemId, mediaId,
- resetMediaPosition);
+ adapter.setFeedItemRead(item, played, resetMediaPosition);
adapter.close();
EventBus.getDefault().post(new UnreadItemsUpdateEvent());
diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java
index b77cd06d2..19660fb77 100644
--- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java
+++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java
@@ -684,19 +684,21 @@ public class PodDBAdapter {
return item.getId();
}
- public void setFeedItemRead(int played, long itemId, long mediaId,
- boolean resetMediaPosition) {
+ public void setFeedItemRead(FeedItem item, int played, boolean resetMediaPosition) {
try {
db.beginTransactionNonExclusive();
ContentValues values = new ContentValues();
values.put(KEY_READ, played);
- db.update(TABLE_NAME_FEED_ITEMS, values, KEY_ID + "=?", new String[]{String.valueOf(itemId)});
+ db.update(TABLE_NAME_FEED_ITEMS, values, KEY_ID + "=?", new String[]{String.valueOf(item.getId())});
+ item.setPlayed(played == FeedItem.PLAYED);
if (resetMediaPosition) {
values.clear();
values.put(KEY_POSITION, 0);
- db.update(TABLE_NAME_FEED_MEDIA, values, KEY_ID + "=?", new String[]{String.valueOf(mediaId)});
+ db.update(TABLE_NAME_FEED_MEDIA, values, KEY_ID + "=?",
+ new String[]{String.valueOf(item.getMedia().getId())});
+ item.getMedia().setPosition(0);
}
db.setTransactionSuccessful();