#3248 Rename PlaybackVolumeAdaptor -> ..Updater

This commit is contained in:
Max Bechtold 2019-10-17 09:56:04 +02:00
parent f9cf013b16
commit 3bc55a09b1
3 changed files with 38 additions and 38 deletions

View File

@ -1482,8 +1482,8 @@ public class PlaybackService extends MediaBrowserServiceCompat {
Serializable volumeReductionExtra = intent.getSerializableExtra(EXTRA_VOLUME_REDUCTION_SETTING); Serializable volumeReductionExtra = intent.getSerializableExtra(EXTRA_VOLUME_REDUCTION_SETTING);
VolumeReductionSetting volumeReductionSetting = (VolumeReductionSetting) volumeReductionExtra; VolumeReductionSetting volumeReductionSetting = (VolumeReductionSetting) volumeReductionExtra;
PlaybackVolumeAdaptor playbackVolumeAdaptor = new PlaybackVolumeAdaptor(); PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
playbackVolumeAdaptor.adaptVolumeIfNecessary(mediaPlayer, affectedFeed, volumeReductionSetting); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, affectedFeed, volumeReductionSetting);
} }
} }
}; };

View File

@ -5,25 +5,25 @@ import de.danoeh.antennapod.core.feed.FeedPreferences;
import de.danoeh.antennapod.core.feed.VolumeReductionSetting; import de.danoeh.antennapod.core.feed.VolumeReductionSetting;
import de.danoeh.antennapod.core.util.playback.Playable; import de.danoeh.antennapod.core.util.playback.Playable;
class PlaybackVolumeAdaptor { class PlaybackVolumeUpdater {
public void adaptVolumeIfNecessary(PlaybackServiceMediaPlayer mediaPlayer, String affectedFeedIdentifier, VolumeReductionSetting volumeReductionSetting) { public void updateVolumeIfNecessary(PlaybackServiceMediaPlayer mediaPlayer, String affectedFeedIdentifier, VolumeReductionSetting volumeReductionSetting) {
Playable playable = mediaPlayer.getPlayable(); Playable playable = mediaPlayer.getPlayable();
boolean isFeedMedia = playable instanceof FeedMedia; boolean isFeedMedia = playable instanceof FeedMedia;
boolean isPlayableLoaded = isPlayableLoaded(mediaPlayer.getPlayerStatus()); boolean isPlayableLoaded = isPlayableLoaded(mediaPlayer.getPlayerStatus());
if (isPlayableLoaded && isFeedMedia) { if (isFeedMedia && isPlayableLoaded) {
adaptFeedMediaVolumeIfNecessary(mediaPlayer, affectedFeedIdentifier, volumeReductionSetting, (FeedMedia) playable); updateFeedMediaVolumeIfNecessary(mediaPlayer, affectedFeedIdentifier, volumeReductionSetting, (FeedMedia) playable);
} }
} }
private void adaptFeedMediaVolumeIfNecessary(PlaybackServiceMediaPlayer mediaPlayer, String affectedFeedIdentifier, VolumeReductionSetting volumeReductionSetting, FeedMedia feedMedia) { private void updateFeedMediaVolumeIfNecessary(PlaybackServiceMediaPlayer mediaPlayer, String affectedFeedIdentifier, VolumeReductionSetting volumeReductionSetting, FeedMedia feedMedia) {
if (mediaBelongsToAffectedFeed(feedMedia, affectedFeedIdentifier)) { if (mediaBelongsToAffectedFeed(feedMedia, affectedFeedIdentifier)) {
FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences(); FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences();
preferences.setVolumeReductionSetting(volumeReductionSetting); preferences.setVolumeReductionSetting(volumeReductionSetting);
if (mediaPlayer.getPlayerStatus() == PlayerStatus.PLAYING) { if (mediaPlayer.getPlayerStatus() == PlayerStatus.PLAYING) {
forceAdaptVolume(mediaPlayer); forceUpdateVolume(mediaPlayer);
} }
} }
} }
@ -42,7 +42,7 @@ class PlaybackVolumeAdaptor {
&& affectedFeedIdentifier.equals(feedMedia.getItem().getFeed().getIdentifyingValue()); && affectedFeedIdentifier.equals(feedMedia.getItem().getFeed().getIdentifyingValue());
} }
private static void forceAdaptVolume(PlaybackServiceMediaPlayer mediaPlayer) { private void forceUpdateVolume(PlaybackServiceMediaPlayer mediaPlayer) {
mediaPlayer.pause(false, false); mediaPlayer.pause(false, false);
mediaPlayer.resume(); mediaPlayer.resume();
} }

View File

@ -16,7 +16,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
public class PlaybackVolumeAdaptorTest { public class PlaybackVolumeUpdaterTest {
private static final String FEED_ID = "feedId"; private static final String FEED_ID = "feedId";
@ -29,14 +29,14 @@ public class PlaybackVolumeAdaptorTest {
@Test @Test
public void noChangeIfNoFeedMediaPlaying() { public void noChangeIfNoFeedMediaPlaying() {
PlaybackVolumeAdaptor playbackVolumeAdaptor = new PlaybackVolumeAdaptor(); PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PAUSED); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PAUSED);
Playable noFeedMedia = mock(Playable.class); Playable noFeedMedia = mock(Playable.class);
when(mediaPlayer.getPlayable()).thenReturn(noFeedMedia); when(mediaPlayer.getPlayable()).thenReturn(noFeedMedia);
playbackVolumeAdaptor.adaptVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.OFF); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.OFF);
verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean()); verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
verify(mediaPlayer, never()).resume(); verify(mediaPlayer, never()).resume();
@ -44,14 +44,14 @@ public class PlaybackVolumeAdaptorTest {
@Test @Test
public void noChangeIfPlayerStatusIsError() { public void noChangeIfPlayerStatusIsError() {
PlaybackVolumeAdaptor playbackVolumeAdaptor = new PlaybackVolumeAdaptor(); PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.ERROR); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.ERROR);
FeedMedia feedMedia = mock(FeedMedia.class); FeedMedia feedMedia = mock(FeedMedia.class);
when(mediaPlayer.getPlayable()).thenReturn(feedMedia); when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
playbackVolumeAdaptor.adaptVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.OFF); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.OFF);
verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean()); verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
verify(mediaPlayer, never()).resume(); verify(mediaPlayer, never()).resume();
@ -59,14 +59,14 @@ public class PlaybackVolumeAdaptorTest {
@Test @Test
public void noChangeIfPlayerStatusIsIndeterminate() { public void noChangeIfPlayerStatusIsIndeterminate() {
PlaybackVolumeAdaptor playbackVolumeAdaptor = new PlaybackVolumeAdaptor(); PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.INDETERMINATE); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.INDETERMINATE);
FeedMedia feedMedia = mock(FeedMedia.class); FeedMedia feedMedia = mock(FeedMedia.class);
when(mediaPlayer.getPlayable()).thenReturn(feedMedia); when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
playbackVolumeAdaptor.adaptVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.OFF); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.OFF);
verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean()); verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
verify(mediaPlayer, never()).resume(); verify(mediaPlayer, never()).resume();
@ -74,14 +74,14 @@ public class PlaybackVolumeAdaptorTest {
@Test @Test
public void noChangeIfPlayerStatusIsStopped() { public void noChangeIfPlayerStatusIsStopped() {
PlaybackVolumeAdaptor playbackVolumeAdaptor = new PlaybackVolumeAdaptor(); PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.STOPPED); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.STOPPED);
FeedMedia feedMedia = mock(FeedMedia.class); FeedMedia feedMedia = mock(FeedMedia.class);
when(mediaPlayer.getPlayable()).thenReturn(feedMedia); when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
playbackVolumeAdaptor.adaptVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.OFF); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.OFF);
verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean()); verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
verify(mediaPlayer, never()).resume(); verify(mediaPlayer, never()).resume();
@ -89,7 +89,7 @@ public class PlaybackVolumeAdaptorTest {
@Test @Test
public void noChangeIfPlayableIsNoItemOfAffectedFeed() { public void noChangeIfPlayableIsNoItemOfAffectedFeed() {
PlaybackVolumeAdaptor playbackVolumeAdaptor = new PlaybackVolumeAdaptor(); PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PLAYING); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PLAYING);
@ -98,15 +98,15 @@ public class PlaybackVolumeAdaptorTest {
Feed feed = mockFeed(feedMedia, FEED_ID); Feed feed = mockFeed(feedMedia, FEED_ID);
when(feed.getIdentifyingValue()).thenReturn("wrongFeedId"); when(feed.getIdentifyingValue()).thenReturn("wrongFeedId");
playbackVolumeAdaptor.adaptVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.OFF); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.OFF);
verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean()); verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
verify(mediaPlayer, never()).resume(); verify(mediaPlayer, never()).resume();
} }
@Test @Test
public void adaptsPreferencesForLoadedFeedMediaIfPlayerStatusIsPaused() { public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsPaused() {
PlaybackVolumeAdaptor playbackVolumeAdaptor = new PlaybackVolumeAdaptor(); PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PAUSED); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PAUSED);
@ -114,7 +114,7 @@ public class PlaybackVolumeAdaptorTest {
when(mediaPlayer.getPlayable()).thenReturn(feedMedia); when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID); FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID);
playbackVolumeAdaptor.adaptVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.LIGHT); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.LIGHT);
verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.LIGHT); verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.LIGHT);
@ -123,8 +123,8 @@ public class PlaybackVolumeAdaptorTest {
} }
@Test @Test
public void adaptsPreferencesForLoadedFeedMediaIfPlayerStatusIsPrepared() { public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsPrepared() {
PlaybackVolumeAdaptor playbackVolumeAdaptor = new PlaybackVolumeAdaptor(); PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PREPARED); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PREPARED);
@ -132,7 +132,7 @@ public class PlaybackVolumeAdaptorTest {
when(mediaPlayer.getPlayable()).thenReturn(feedMedia); when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID); FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID);
playbackVolumeAdaptor.adaptVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.LIGHT); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.LIGHT);
verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.LIGHT); verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.LIGHT);
@ -141,8 +141,8 @@ public class PlaybackVolumeAdaptorTest {
} }
@Test @Test
public void adaptsPreferencesForLoadedFeedMediaIfPlayerStatusIsInitializing() { public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsInitializing() {
PlaybackVolumeAdaptor playbackVolumeAdaptor = new PlaybackVolumeAdaptor(); PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.INITIALIZING); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.INITIALIZING);
@ -150,7 +150,7 @@ public class PlaybackVolumeAdaptorTest {
when(mediaPlayer.getPlayable()).thenReturn(feedMedia); when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID); FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID);
playbackVolumeAdaptor.adaptVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.LIGHT); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.LIGHT);
verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.LIGHT); verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.LIGHT);
@ -159,8 +159,8 @@ public class PlaybackVolumeAdaptorTest {
} }
@Test @Test
public void adaptsPreferencesForLoadedFeedMediaIfPlayerStatusIsPreparing() { public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsPreparing() {
PlaybackVolumeAdaptor playbackVolumeAdaptor = new PlaybackVolumeAdaptor(); PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PREPARING); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PREPARING);
@ -168,7 +168,7 @@ public class PlaybackVolumeAdaptorTest {
when(mediaPlayer.getPlayable()).thenReturn(feedMedia); when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID); FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID);
playbackVolumeAdaptor.adaptVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.LIGHT); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.LIGHT);
verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.LIGHT); verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.LIGHT);
@ -177,8 +177,8 @@ public class PlaybackVolumeAdaptorTest {
} }
@Test @Test
public void adaptsPreferencesForLoadedFeedMediaIfPlayerStatusIsSeeking() { public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsSeeking() {
PlaybackVolumeAdaptor playbackVolumeAdaptor = new PlaybackVolumeAdaptor(); PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.SEEKING); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.SEEKING);
@ -186,7 +186,7 @@ public class PlaybackVolumeAdaptorTest {
when(mediaPlayer.getPlayable()).thenReturn(feedMedia); when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID); FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID);
playbackVolumeAdaptor.adaptVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.LIGHT); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.LIGHT);
verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.LIGHT); verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.LIGHT);
@ -195,8 +195,8 @@ public class PlaybackVolumeAdaptorTest {
} }
@Test @Test
public void adaptsPreferencesAndForcesVolumeChangeForLoadedFeedMediaIfPlayerStatusIsPlaying() { public void updatesPreferencesAndForcesVolumeChangeForLoadedFeedMediaIfPlayerStatusIsPlaying() {
PlaybackVolumeAdaptor playbackVolumeAdaptor = new PlaybackVolumeAdaptor(); PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PLAYING); when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PLAYING);
@ -204,7 +204,7 @@ public class PlaybackVolumeAdaptorTest {
when(mediaPlayer.getPlayable()).thenReturn(feedMedia); when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID); FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID);
playbackVolumeAdaptor.adaptVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.HEAVY); playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.HEAVY);
verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.HEAVY); verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.HEAVY);