Search in sources :

Example 6 with PlaybackServiceTaskManager

use of de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager in project AntennaPod by AntennaPod.

the class PlaybackServiceTaskManagerTest method testIsWidgetUpdaterActive.

public void testIsWidgetUpdaterActive() {
    final Context c = getInstrumentation().getTargetContext();
    PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, defaultPSTM);
    pstm.startWidgetUpdater();
    assertTrue(pstm.isWidgetUpdaterActive());
    pstm.shutdown();
}
Also used : Context(android.content.Context) PlaybackServiceTaskManager(de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager)

Example 7 with PlaybackServiceTaskManager

use of de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager in project AntennaPod by AntennaPod.

the class PlaybackServiceTaskManagerTest method testCancelAllTasksNoTasksStarted.

public void testCancelAllTasksNoTasksStarted() {
    final Context c = getInstrumentation().getTargetContext();
    PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, defaultPSTM);
    pstm.cancelAllTasks();
    assertFalse(pstm.isPositionSaverActive());
    assertFalse(pstm.isWidgetUpdaterActive());
    assertFalse(pstm.isSleepTimerActive());
    pstm.shutdown();
}
Also used : Context(android.content.Context) PlaybackServiceTaskManager(de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager)

Example 8 with PlaybackServiceTaskManager

use of de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager in project AntennaPod by AntennaPod.

the class PlaybackServiceTaskManagerTest method testStartWidgetUpdater.

public void testStartWidgetUpdater() throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final int NUM_COUNTDOWNS = 2;
    final int TIMEOUT = 3 * PlaybackServiceTaskManager.WIDGET_UPDATER_NOTIFICATION_INTERVAL;
    final CountDownLatch countDownLatch = new CountDownLatch(NUM_COUNTDOWNS);
    PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, new PlaybackServiceTaskManager.PSTMCallback() {

        @Override
        public void positionSaverTick() {
        }

        @Override
        public void onSleepTimerAlmostExpired() {
        }

        @Override
        public void onSleepTimerExpired() {
        }

        @Override
        public void onSleepTimerReset() {
        }

        @Override
        public void onWidgetUpdaterTick() {
            countDownLatch.countDown();
        }

        @Override
        public void onChapterLoaded(Playable media) {
        }
    });
    pstm.startWidgetUpdater();
    countDownLatch.await(TIMEOUT, TimeUnit.MILLISECONDS);
    pstm.shutdown();
}
Also used : Context(android.content.Context) Playable(de.danoeh.antennapod.core.util.playback.Playable) PlaybackServiceTaskManager(de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 9 with PlaybackServiceTaskManager

use of de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager in project AntennaPod by AntennaPod.

the class PlaybackServiceTaskManagerTest method testCancelPositionSaver.

public void testCancelPositionSaver() {
    final Context c = getInstrumentation().getTargetContext();
    PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, defaultPSTM);
    pstm.startPositionSaver();
    pstm.cancelPositionSaver();
    assertFalse(pstm.isPositionSaverActive());
    pstm.shutdown();
}
Also used : Context(android.content.Context) PlaybackServiceTaskManager(de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager)

Example 10 with PlaybackServiceTaskManager

use of de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager in project AntennaPod by AntennaPod.

the class PlaybackServiceTaskManagerTest method testGetQueueWriteAfterCreation.

public void testGetQueueWriteAfterCreation() throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, defaultPSTM);
    List<FeedItem> testQueue = pstm.getQueue();
    assertNotNull(testQueue);
    assertTrue(testQueue.isEmpty());
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    EventDistributor.EventListener queueListener = new EventDistributor.EventListener() {

        @Override
        public void update(EventDistributor eventDistributor, Integer arg) {
            countDownLatch.countDown();
        }
    };
    EventDistributor.getInstance().register(queueListener);
    List<FeedItem> queue = writeTestQueue("a");
    EventBus.getDefault().post(QueueEvent.setQueue(queue));
    countDownLatch.await(5000, TimeUnit.MILLISECONDS);
    assertNotNull(queue);
    testQueue = pstm.getQueue();
    assertNotNull(testQueue);
    assertTrue(queue.size() == testQueue.size());
    for (int i = 0; i < queue.size(); i++) {
        assertTrue(queue.get(i).getId() == testQueue.get(i).getId());
    }
    pstm.shutdown();
}
Also used : Context(android.content.Context) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) EventDistributor(de.danoeh.antennapod.core.feed.EventDistributor) PlaybackServiceTaskManager(de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

PlaybackServiceTaskManager (de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager)15 Context (android.content.Context)14 CountDownLatch (java.util.concurrent.CountDownLatch)5 Playable (de.danoeh.antennapod.core.util.playback.Playable)4 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)2 EventDistributor (de.danoeh.antennapod.core.feed.EventDistributor)1