Search in sources :

Example 6 with EpisodeAction

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;
}
Also used : EpisodeAction(de.danoeh.antennapod.net.sync.model.EpisodeAction) Pair(androidx.core.util.Pair)

Example 7 with EpisodeAction

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());
}
Also used : ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) EpisodeAction(de.danoeh.antennapod.net.sync.model.EpisodeAction) Pair(androidx.core.util.Pair)

Example 8 with EpisodeAction

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());
}
Also used : ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) EpisodeAction(de.danoeh.antennapod.net.sync.model.EpisodeAction) Pair(androidx.core.util.Pair)

Example 9 with EpisodeAction

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());
}
Also used : ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) EpisodeAction(de.danoeh.antennapod.net.sync.model.EpisodeAction) Pair(androidx.core.util.Pair)

Example 10 with EpisodeAction

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());
}
Also used : ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) EpisodeAction(de.danoeh.antennapod.net.sync.model.EpisodeAction) Pair(androidx.core.util.Pair)

Aggregations

EpisodeAction (de.danoeh.antennapod.net.sync.model.EpisodeAction)17 ArrayList (java.util.ArrayList)8 Pair (androidx.core.util.Pair)7 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)5 Date (java.util.Date)5 SimpleDateFormat (java.text.SimpleDateFormat)4 JSONArray (org.json.JSONArray)4 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)3 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 DownloadStatus (de.danoeh.antennapod.core.service.download.DownloadStatus)2 EpisodeActionChanges (de.danoeh.antennapod.net.sync.model.EpisodeActionChanges)2 SyncServiceException (de.danoeh.antennapod.net.sync.model.SyncServiceException)2 File (java.io.File)2 MalformedURLException (java.net.MalformedURLException)2 ExecutionException (java.util.concurrent.ExecutionException)2 RequestBody (okhttp3.RequestBody)2 Context (android.content.Context)1 MediaMetadataRetriever (android.media.MediaMetadataRetriever)1 NonNull (androidx.annotation.NonNull)1