diff --git a/core/src/main/java/de/danoeh/antennapod/core/sync/EpisodeActionFilter.java b/core/src/main/java/de/danoeh/antennapod/core/sync/EpisodeActionFilter.java index 8250ab87e..f616b9c4e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/sync/EpisodeActionFilter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/sync/EpisodeActionFilter.java @@ -70,7 +70,8 @@ public class EpisodeActionFilter { EpisodeAction secondAction) { return secondAction != null && secondAction.getTimestamp() != null - && secondAction.getTimestamp().after(firstAction.getTimestamp()); + && (firstAction.getTimestamp() == null + || secondAction.getTimestamp().after(firstAction.getTimestamp())); } } diff --git a/core/src/test/java/de/danoeh/antennapod/core/sync/EpisodeActionFilterTest.java b/core/src/test/java/de/danoeh/antennapod/core/sync/EpisodeActionFilterTest.java index 94695ca95..1f638bf32 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/sync/EpisodeActionFilterTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/sync/EpisodeActionFilterTest.java @@ -184,4 +184,29 @@ public class EpisodeActionFilterTest extends TestCase { .getRemoteActionsOverridingLocalActions(remoteActions, episodeActions); assertEquals(0, uniqueList.size()); } -} \ No newline at end of file + + public void testPresentRemoteTimestampOverridesMissingLocalTimestamp() throws ParseException { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date arbitraryTime = format.parse("2021-01-01 08:00:00"); + + List episodeActions = new ArrayList<>(); + episodeActions.add(new EpisodeAction + .Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY) + // no timestamp + .position(10) + .build() + ); + + List remoteActions = new ArrayList<>(); + remoteActions.add(new EpisodeAction + .Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY) + .timestamp(arbitraryTime) + .position(10) + .build() + ); + + Map, EpisodeAction> uniqueList = episodeActionFilter + .getRemoteActionsOverridingLocalActions(remoteActions, episodeActions); + assertSame(1, uniqueList.size()); + } +}