use of de.danoeh.antennapod.net.sync.model.EpisodeAction in project AntennaPod by AntennaPod.
the class EpisodeActionFilter method createUniqueLocalMostRecentPlayActions.
private static Map<Pair<String, String>, EpisodeAction> createUniqueLocalMostRecentPlayActions(List<EpisodeAction> queuedEpisodeActions) {
Map<Pair<String, String>, EpisodeAction> localMostRecentPlayAction;
localMostRecentPlayAction = new ArrayMap<>();
for (EpisodeAction action : queuedEpisodeActions) {
Pair<String, String> key = new Pair<>(action.getPodcast(), action.getEpisode());
EpisodeAction mostRecent = localMostRecentPlayAction.get(key);
if (mostRecent == null || mostRecent.getTimestamp() == null) {
localMostRecentPlayAction.put(key, action);
} else if (mostRecent.getTimestamp().before(action.getTimestamp())) {
localMostRecentPlayAction.put(key, action);
}
}
return localMostRecentPlayAction;
}
use of de.danoeh.antennapod.net.sync.model.EpisodeAction in project AntennaPod by AntennaPod.
the class EpisodeActionFilterTest method testGetRemoteActionsHappeningBeforeLocalActions.
public void testGetRemoteActionsHappeningBeforeLocalActions() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date morning = format.parse("2021-01-01 08:00:00");
Date lateMorning = format.parse("2021-01-01 09:00:00");
List<EpisodeAction> episodeActions = new ArrayList<>();
episodeActions.add(new EpisodeAction.Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY).timestamp(morning).position(10).build());
episodeActions.add(new EpisodeAction.Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY).timestamp(lateMorning).position(20).build());
episodeActions.add(new EpisodeAction.Builder("podcast.a", "episode.2", EpisodeAction.Action.PLAY).timestamp(morning).position(5).build());
Date morningFiveMinutesEarlier = format.parse("2021-01-01 07:55:00");
List<EpisodeAction> remoteActions = new ArrayList<>();
remoteActions.add(new EpisodeAction.Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY).timestamp(morningFiveMinutesEarlier).position(10).build());
remoteActions.add(new EpisodeAction.Builder("podcast.a", "episode.2", EpisodeAction.Action.PLAY).timestamp(morningFiveMinutesEarlier).position(5).build());
Map<Pair<String, String>, EpisodeAction> uniqueList = episodeActionFilter.getRemoteActionsOverridingLocalActions(remoteActions, episodeActions);
assertSame(0, uniqueList.size());
}
use of de.danoeh.antennapod.net.sync.model.EpisodeAction in project AntennaPod by AntennaPod.
the class EpisodeActionFilterTest method testGetRemoteActionsHappeningAfterLocalActions.
public void testGetRemoteActionsHappeningAfterLocalActions() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date morning = format.parse("2021-01-01 08:00:00");
Date lateMorning = format.parse("2021-01-01 09:00:00");
List<EpisodeAction> episodeActions = new ArrayList<>();
episodeActions.add(new EpisodeAction.Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY).timestamp(morning).position(10).build());
episodeActions.add(new EpisodeAction.Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY).timestamp(lateMorning).position(20).build());
episodeActions.add(new EpisodeAction.Builder("podcast.a", "episode.2", EpisodeAction.Action.PLAY).timestamp(morning).position(5).build());
Date morningFiveMinutesLater = format.parse("2021-01-01 08:05:00");
List<EpisodeAction> remoteActions = new ArrayList<>();
remoteActions.add(new EpisodeAction.Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY).timestamp(morningFiveMinutesLater).position(10).build());
remoteActions.add(new EpisodeAction.Builder("podcast.a", "episode.2", EpisodeAction.Action.PLAY).timestamp(morningFiveMinutesLater).position(5).build());
Map<Pair<String, String>, EpisodeAction> uniqueList = episodeActionFilter.getRemoteActionsOverridingLocalActions(remoteActions, episodeActions);
assertSame(1, uniqueList.size());
}
use of de.danoeh.antennapod.net.sync.model.EpisodeAction in project AntennaPod by AntennaPod.
the class EpisodeActionFilterTest method testGetMultipleRemoteActionsHappeningBeforeLocalActions.
public void testGetMultipleRemoteActionsHappeningBeforeLocalActions() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date morning = format.parse("2021-01-01 08:00:00");
List<EpisodeAction> episodeActions = new ArrayList<>();
episodeActions.add(new EpisodeAction.Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY).timestamp(morning).position(10).build());
episodeActions.add(new EpisodeAction.Builder("podcast.a", "episode.2", EpisodeAction.Action.PLAY).timestamp(morning).position(5).build());
Date morningFiveMinutesEarlier = format.parse("2021-01-01 07:55:00");
List<EpisodeAction> remoteActions = new ArrayList<>();
remoteActions.add(new EpisodeAction.Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY).timestamp(morningFiveMinutesEarlier).position(10).build());
remoteActions.add(new EpisodeAction.Builder("podcast.a", "episode.2", EpisodeAction.Action.PLAY).timestamp(morningFiveMinutesEarlier).position(5).build());
Map<Pair<String, String>, EpisodeAction> uniqueList = episodeActionFilter.getRemoteActionsOverridingLocalActions(remoteActions, episodeActions);
assertEquals(0, uniqueList.size());
}
use of de.danoeh.antennapod.net.sync.model.EpisodeAction in project AntennaPod by AntennaPod.
the class EpisodeActionFilterTest method testGetMultipleRemoteActionsHappeningAfterLocalActions.
public void testGetMultipleRemoteActionsHappeningAfterLocalActions() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date morning = format.parse("2021-01-01 08:00:00");
List<EpisodeAction> episodeActions = new ArrayList<>();
episodeActions.add(new EpisodeAction.Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY).timestamp(morning).position(10).build());
episodeActions.add(new EpisodeAction.Builder("podcast.a", "episode.2", EpisodeAction.Action.PLAY).timestamp(morning).position(5).build());
Date morningFiveMinutesLater = format.parse("2021-01-01 08:05:00");
List<EpisodeAction> remoteActions = new ArrayList<>();
remoteActions.add(new EpisodeAction.Builder("podcast.a", "episode.1", EpisodeAction.Action.PLAY).timestamp(morningFiveMinutesLater).position(10).build());
remoteActions.add(new EpisodeAction.Builder("podcast.a", "episode.2", EpisodeAction.Action.PLAY).timestamp(morningFiveMinutesLater).position(5).build());
Map<Pair<String, String>, EpisodeAction> uniqueList = episodeActionFilter.getRemoteActionsOverridingLocalActions(remoteActions, episodeActions);
assertEquals(2, uniqueList.size());
}
Aggregations