Search in sources :

Example 21 with FeedPreferences

use of de.danoeh.antennapod.model.feed.FeedPreferences in project AntennaPod by AntennaPod.

the class LocalPSMP method playMediaObject.

/**
 * Internal implementation of playMediaObject. This method has an additional parameter that allows the caller to force a media player reset even if
 * the given playable parameter is the same object as the currently playing media.
 * <p/>
 * This method requires the playerLock and is executed on the caller's thread.
 *
 * @see #playMediaObject(Playable, boolean, boolean, boolean)
 */
private void playMediaObject(@NonNull final Playable playable, final boolean forceReset, final boolean stream, final boolean startWhenPrepared, final boolean prepareImmediately) {
    if (!playerLock.isHeldByCurrentThread()) {
        throw new IllegalStateException("method requires playerLock");
    }
    if (media != null) {
        if (!forceReset && media.getIdentifier().equals(playable.getIdentifier()) && playerStatus == PlayerStatus.PLAYING) {
            // episode is already playing -> ignore method call
            Log.d(TAG, "Method call to playMediaObject was ignored: media file already playing.");
            return;
        } else {
            // stop playback of this episode
            if (playerStatus == PlayerStatus.PAUSED || playerStatus == PlayerStatus.PLAYING || playerStatus == PlayerStatus.PREPARED) {
                mediaPlayer.stop();
            }
            // set temporarily to pause in order to update list with current position
            if (playerStatus == PlayerStatus.PLAYING) {
                callback.onPlaybackPause(media, getPosition());
            }
            if (!media.getIdentifier().equals(playable.getIdentifier())) {
                final Playable oldMedia = media;
                executor.submit(() -> callback.onPostPlayback(oldMedia, false, false, true));
            }
            setPlayerStatus(PlayerStatus.INDETERMINATE, null);
        }
    }
    this.media = playable;
    this.stream = stream;
    this.mediaType = media.getMediaType();
    this.videoSize = null;
    createMediaPlayer();
    LocalPSMP.this.startWhenPrepared.set(startWhenPrepared);
    setPlayerStatus(PlayerStatus.INITIALIZING, media);
    try {
        callback.ensureMediaInfoLoaded(media);
        callback.onMediaChanged(false);
        setPlaybackParams(PlaybackSpeedUtils.getCurrentPlaybackSpeed(media), UserPreferences.isSkipSilence());
        if (stream) {
            if (playable instanceof FeedMedia) {
                FeedMedia feedMedia = (FeedMedia) playable;
                FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences();
                mediaPlayer.setDataSource(media.getStreamUrl(), preferences.getUsername(), preferences.getPassword());
            } else {
                mediaPlayer.setDataSource(media.getStreamUrl());
            }
        } else if (media.getLocalMediaUrl() != null && new File(media.getLocalMediaUrl()).canRead()) {
            mediaPlayer.setDataSource(media.getLocalMediaUrl());
        } else {
            throw new IOException("Unable to read local file " + media.getLocalMediaUrl());
        }
        UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
        if (uiModeManager.getCurrentModeType() != Configuration.UI_MODE_TYPE_CAR) {
            setPlayerStatus(PlayerStatus.INITIALIZED, media);
        }
        if (prepareImmediately) {
            setPlayerStatus(PlayerStatus.PREPARING, media);
            mediaPlayer.prepare();
            onPrepared(startWhenPrepared);
        }
    } catch (IOException | IllegalStateException e) {
        e.printStackTrace();
        setPlayerStatus(PlayerStatus.ERROR, null);
        EventBus.getDefault().postSticky(new PlayerErrorEvent(e.getLocalizedMessage()));
    }
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) Playable(de.danoeh.antennapod.model.playback.Playable) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) UiModeManager(android.app.UiModeManager) PlayerErrorEvent(de.danoeh.antennapod.event.PlayerErrorEvent) IOException(java.io.IOException) File(java.io.File)

Example 22 with FeedPreferences

use of de.danoeh.antennapod.model.feed.FeedPreferences in project AntennaPod by AntennaPod.

the class SubscriptionsFilter method filter.

/**
 * Run a list of feed items through the filter.
 */
public List<Feed> filter(List<Feed> items, LongIntMap feedCounters) {
    if (properties.length == 0) {
        return items;
    }
    List<Feed> result = new ArrayList<>();
    for (Feed item : items) {
        FeedPreferences itemPreferences = item.getPreferences();
        // If the item does not meet a requirement, skip it.
        if (showAutoDownloadEnabled && !itemPreferences.getAutoDownload()) {
            continue;
        } else if (showAutoDownloadDisabled && itemPreferences.getAutoDownload()) {
            continue;
        }
        if (showUpdatedEnabled && !itemPreferences.getKeepUpdated()) {
            continue;
        } else if (showUpdatedDisabled && itemPreferences.getKeepUpdated()) {
            continue;
        }
        if (showEpisodeNotificationEnabled && !itemPreferences.getShowEpisodeNotification()) {
            continue;
        } else if (showEpisodeNotificationDisabled && itemPreferences.getShowEpisodeNotification()) {
            continue;
        }
        // If the item reaches here, it meets all criteria (except counter > 0)
        result.add(item);
    }
    if (showIfCounterGreaterZero) {
        for (int i = result.size() - 1; i >= 0; i--) {
            if (feedCounters.get(result.get(i).getId()) <= 0) {
                result.remove(i);
            }
        }
    }
    return result;
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) ArrayList(java.util.ArrayList) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 23 with FeedPreferences

use of de.danoeh.antennapod.model.feed.FeedPreferences in project AntennaPod by AntennaPod.

the class FeedMultiSelectActionHandler method autoDownloadPrefHandler.

private void autoDownloadPrefHandler() {
    PreferenceSwitchDialog preferenceSwitchDialog = new PreferenceSwitchDialog(activity, activity.getString(R.string.auto_download_settings_label), activity.getString(R.string.auto_download_label));
    preferenceSwitchDialog.setOnPreferenceChangedListener(new PreferenceSwitchDialog.OnPreferenceChangedListener() {

        @Override
        public void preferenceChanged(boolean enabled) {
            saveFeedPreferences(feedPreferences -> feedPreferences.setAutoDownload(enabled));
        }
    });
    preferenceSwitchDialog.openDialog();
}
Also used : RemoveFeedDialog(de.danoeh.antennapod.dialog.RemoveFeedDialog) AlertDialog(androidx.appcompat.app.AlertDialog) PreferenceListDialog(de.danoeh.antennapod.fragment.preferences.dialog.PreferenceListDialog) DecimalFormatSymbols(java.text.DecimalFormatSymbols) R(de.danoeh.antennapod.R) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) Consumer(androidx.core.util.Consumer) List(java.util.List) MainActivity(de.danoeh.antennapod.activity.MainActivity) FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) PlaybackSpeedFeedSettingDialogBinding(de.danoeh.antennapod.databinding.PlaybackSpeedFeedSettingDialogBinding) DBWriter(de.danoeh.antennapod.core.storage.DBWriter) Locale(java.util.Locale) PluralsRes(androidx.annotation.PluralsRes) PreferenceSwitchDialog(de.danoeh.antennapod.fragment.preferences.dialog.PreferenceSwitchDialog) TagSettingsDialog(de.danoeh.antennapod.dialog.TagSettingsDialog) Snackbar(com.google.android.material.snackbar.Snackbar) Log(android.util.Log) Feed(de.danoeh.antennapod.model.feed.Feed) PreferenceSwitchDialog(de.danoeh.antennapod.fragment.preferences.dialog.PreferenceSwitchDialog)

Example 24 with FeedPreferences

use of de.danoeh.antennapod.model.feed.FeedPreferences in project AntennaPod by AntennaPod.

the class FeedMultiSelectActionHandler method editFeedPrefTags.

private void editFeedPrefTags() {
    ArrayList<FeedPreferences> preferencesList = new ArrayList<>();
    for (Feed feed : selectedItems) {
        preferencesList.add(feed.getPreferences());
    }
    TagSettingsDialog.newInstance(preferencesList).show(activity.getSupportFragmentManager(), TagSettingsDialog.TAG);
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) ArrayList(java.util.ArrayList) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 25 with FeedPreferences

use of de.danoeh.antennapod.model.feed.FeedPreferences in project AntennaPod by AntennaPod.

the class PlaybackVolumeUpdaterTest method updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsSeeking.

@Test
public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsSeeking() {
    PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
    when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.SEEKING);
    FeedMedia feedMedia = mockFeedMedia();
    when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
    FeedPreferences feedPreferences = feedMedia.getItem().getFeed().getPreferences();
    playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.LIGHT_REDUCTION);
    verify(feedPreferences, times(1)).setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_REDUCTION);
    verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
    verify(mediaPlayer, never()).resume();
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Test(org.junit.Test)

Aggregations

FeedPreferences (de.danoeh.antennapod.model.feed.FeedPreferences)27 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)14 Feed (de.danoeh.antennapod.model.feed.Feed)8 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 NonNull (androidx.annotation.NonNull)3 Playable (de.danoeh.antennapod.model.playback.Playable)3 Context (android.content.Context)2 Toast (android.widget.Toast)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 PreferenceListDialog (de.danoeh.antennapod.fragment.preferences.dialog.PreferenceListDialog)2 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)2 VolumeAdaptionSetting (de.danoeh.antennapod.model.feed.VolumeAdaptionSetting)2 File (java.io.File)2 IOException (java.io.IOException)2 UiModeManager (android.app.UiModeManager)1 Log (android.util.Log)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 PluralsRes (androidx.annotation.PluralsRes)1