Search in sources :

Example 1 with ShareDialog

use of de.danoeh.antennapod.dialog.ShareDialog in project AntennaPod by AntennaPod.

the class FeedItemMenuHandler method onMenuItemClicked.

/**
 * Default menu handling for the given FeedItem.
 *
 * A Fragment instance, (rather than the more generic Context), is needed as a parameter
 * to support some UI operations, e.g., creating a Snackbar.
 */
public static boolean onMenuItemClicked(@NonNull Fragment fragment, int menuItemId, @NonNull FeedItem selectedItem) {
    @NonNull Context context = fragment.requireContext();
    if (menuItemId == R.id.skip_episode_item) {
        IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SKIP_CURRENT_EPISODE);
    } else if (menuItemId == R.id.remove_item) {
        DBWriter.deleteFeedMediaOfItem(context, selectedItem.getMedia().getId());
    } else if (menuItemId == R.id.remove_new_flag_item) {
        removeNewFlagWithUndo(fragment, selectedItem);
    } else if (menuItemId == R.id.mark_read_item) {
        selectedItem.setPlayed(true);
        DBWriter.markItemPlayed(selectedItem, FeedItem.PLAYED, true);
        if (SynchronizationSettings.isProviderConnected()) {
            FeedMedia media = selectedItem.getMedia();
            // not all items have media, Gpodder only cares about those that do
            if (media != null) {
                EpisodeAction actionPlay = new EpisodeAction.Builder(selectedItem, EpisodeAction.PLAY).currentTimestamp().started(media.getDuration() / 1000).position(media.getDuration() / 1000).total(media.getDuration() / 1000).build();
                SynchronizationQueueSink.enqueueEpisodeActionIfSynchronizationIsActive(context, actionPlay);
            }
        }
    } else if (menuItemId == R.id.mark_unread_item) {
        selectedItem.setPlayed(false);
        DBWriter.markItemPlayed(selectedItem, FeedItem.UNPLAYED, false);
        if (selectedItem.getMedia() != null) {
            EpisodeAction actionNew = new EpisodeAction.Builder(selectedItem, EpisodeAction.NEW).currentTimestamp().build();
            SynchronizationQueueSink.enqueueEpisodeActionIfSynchronizationIsActive(context, actionNew);
        }
    } else if (menuItemId == R.id.add_to_queue_item) {
        DBWriter.addQueueItem(context, selectedItem);
    } else if (menuItemId == R.id.remove_from_queue_item) {
        DBWriter.removeQueueItem(context, true, selectedItem);
    } else if (menuItemId == R.id.add_to_favorites_item) {
        DBWriter.addFavoriteItem(selectedItem);
    } else if (menuItemId == R.id.remove_from_favorites_item) {
        DBWriter.removeFavoriteItem(selectedItem);
    } else if (menuItemId == R.id.reset_position) {
        selectedItem.getMedia().setPosition(0);
        if (PlaybackPreferences.getCurrentlyPlayingFeedMediaId() == selectedItem.getMedia().getId()) {
            PlaybackPreferences.writeNoMediaPlaying();
            IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
        }
        DBWriter.markItemPlayed(selectedItem, FeedItem.UNPLAYED, true);
    } else if (menuItemId == R.id.visit_website_item) {
        IntentUtils.openInBrowser(context, FeedItemUtil.getLinkWithFallback(selectedItem));
    } else if (menuItemId == R.id.share_item) {
        ShareDialog shareDialog = ShareDialog.newInstance(selectedItem);
        shareDialog.show((fragment.getActivity().getSupportFragmentManager()), "ShareEpisodeDialog");
    } else {
        Log.d(TAG, "Unknown menuItemId: " + menuItemId);
        return false;
    }
    return true;
}
Also used : Context(android.content.Context) ShareDialog(de.danoeh.antennapod.dialog.ShareDialog) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) NonNull(androidx.annotation.NonNull) EpisodeAction(de.danoeh.antennapod.net.sync.model.EpisodeAction)

Example 2 with ShareDialog

use of de.danoeh.antennapod.dialog.ShareDialog in project AntennaPod by AntennaPod.

the class VideoplayerActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.player_go_to_picture_in_picture) {
        compatEnterPictureInPicture();
        return true;
    }
    if (item.getItemId() == android.R.id.home) {
        Intent intent = new Intent(VideoplayerActivity.this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        finish();
        return true;
    }
    if (controller == null) {
        return false;
    }
    Playable media = controller.getMedia();
    if (media == null) {
        return false;
    }
    // some options option requires FeedItem
    @Nullable final FeedItem feedItem = getFeedItem(media);
    if (item.getItemId() == R.id.add_to_favorites_item && feedItem != null) {
        DBWriter.addFavoriteItem(feedItem);
        isFavorite = true;
        invalidateOptionsMenu();
    } else if (item.getItemId() == R.id.remove_from_favorites_item && feedItem != null) {
        DBWriter.removeFavoriteItem(feedItem);
        isFavorite = false;
        invalidateOptionsMenu();
    } else if (item.getItemId() == R.id.disable_sleeptimer_item || item.getItemId() == R.id.set_sleeptimer_item) {
        new SleepTimerDialog().show(getSupportFragmentManager(), "SleepTimerDialog");
    } else if (item.getItemId() == R.id.audio_controls) {
        PlaybackControlsDialog dialog = PlaybackControlsDialog.newInstance();
        dialog.show(getSupportFragmentManager(), "playback_controls");
    } else if (item.getItemId() == R.id.open_feed_item && feedItem != null) {
        Intent intent = MainActivity.getIntentToOpenFeed(this, feedItem.getFeedId());
        startActivity(intent);
    } else if (item.getItemId() == R.id.visit_website_item) {
        IntentUtils.openInBrowser(VideoplayerActivity.this, getWebsiteLinkWithFallback(media));
    } else if (item.getItemId() == R.id.share_item && feedItem != null) {
        ShareDialog shareDialog = ShareDialog.newInstance(feedItem);
        shareDialog.show(getSupportFragmentManager(), "ShareEpisodeDialog");
    } else {
        return false;
    }
    return true;
}
Also used : ShareDialog(de.danoeh.antennapod.dialog.ShareDialog) FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Playable(de.danoeh.antennapod.model.playback.Playable) PlaybackControlsDialog(de.danoeh.antennapod.dialog.PlaybackControlsDialog) SleepTimerDialog(de.danoeh.antennapod.dialog.SleepTimerDialog) Intent(android.content.Intent) Nullable(androidx.annotation.Nullable)

Aggregations

ShareDialog (de.danoeh.antennapod.dialog.ShareDialog)2 Context (android.content.Context)1 Intent (android.content.Intent)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 PlaybackControlsDialog (de.danoeh.antennapod.dialog.PlaybackControlsDialog)1 SleepTimerDialog (de.danoeh.antennapod.dialog.SleepTimerDialog)1 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)1 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)1 Playable (de.danoeh.antennapod.model.playback.Playable)1 EpisodeAction (de.danoeh.antennapod.net.sync.model.EpisodeAction)1