Search in sources :

Example 6 with GpodnetEpisodeAction

use of de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction in project AntennaPod by AntennaPod.

the class GpodnetPreferences method writeEpisodeActionsToString.

private static String writeEpisodeActionsToString(Collection<GpodnetEpisodeAction> c) {
    StringBuilder result = new StringBuilder();
    for (GpodnetEpisodeAction item : c) {
        result.append(item.writeToString());
        result.append("\n");
    }
    return result.toString();
}
Also used : GpodnetEpisodeAction(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction)

Example 7 with GpodnetEpisodeAction

use of de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction in project AntennaPod by AntennaPod.

the class FeedMedia method postPlaybackTasks.

private void postPlaybackTasks(Context context, boolean completed) {
    if (item != null) {
        // gpodder play action
        if (startPosition >= 0 && (completed || startPosition < position) && GpodnetPreferences.loggedIn()) {
            GpodnetEpisodeAction action = new GpodnetEpisodeAction.Builder(item, GpodnetEpisodeAction.Action.PLAY).currentDeviceId().currentTimestamp().started(startPosition / 1000).position((completed ? duration : position) / 1000).total(duration / 1000).build();
            GpodnetPreferences.enqueueEpisodeAction(action);
        }
        // Auto flattr
        float autoFlattrThreshold = UserPreferences.getAutoFlattrPlayedDurationThreshold();
        if (FlattrUtils.hasToken() && UserPreferences.isAutoFlattr() && item.getPaymentLink() != null && item.getFlattrStatus().getUnflattred() && (completed && autoFlattrThreshold <= 1.0f || played_duration >= autoFlattrThreshold * duration)) {
            DBTasks.flattrItemIfLoggedIn(context, item);
        }
    }
}
Also used : GpodnetEpisodeAction(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction)

Example 8 with GpodnetEpisodeAction

use of de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction in project AntennaPod by AntennaPod.

the class GpodnetSyncService method processEpisodeActions.

private synchronized void processEpisodeActions(List<GpodnetEpisodeAction> localActions, List<GpodnetEpisodeAction> remoteActions) throws DownloadRequestException {
    if (remoteActions.size() == 0) {
        return;
    }
    Map<Pair<String, String>, GpodnetEpisodeAction> localMostRecentPlayAction = new ArrayMap<>();
    for (GpodnetEpisodeAction action : localActions) {
        Pair<String, String> key = new Pair<>(action.getPodcast(), action.getEpisode());
        GpodnetEpisodeAction 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);
        }
    }
    // make sure more recent local actions are not overwritten by older remote actions
    Map<Pair<String, String>, GpodnetEpisodeAction> mostRecentPlayAction = new ArrayMap<>();
    for (GpodnetEpisodeAction action : remoteActions) {
        switch(action.getAction()) {
            case NEW:
                FeedItem newItem = DBReader.getFeedItem(action.getPodcast(), action.getEpisode());
                if (newItem != null) {
                    DBWriter.markItemPlayed(newItem, FeedItem.UNPLAYED, true);
                } else {
                    Log.i(TAG, "Unknown feed item: " + action);
                }
                break;
            case DOWNLOAD:
                break;
            case PLAY:
                Pair<String, String> key = new Pair<>(action.getPodcast(), action.getEpisode());
                GpodnetEpisodeAction localMostRecent = localMostRecentPlayAction.get(key);
                if (localMostRecent == null || localMostRecent.getTimestamp() == null || localMostRecent.getTimestamp().before(action.getTimestamp())) {
                    GpodnetEpisodeAction mostRecent = mostRecentPlayAction.get(key);
                    if (mostRecent == null || mostRecent.getTimestamp() == null) {
                        mostRecentPlayAction.put(key, action);
                    } else if (action.getTimestamp() != null && mostRecent.getTimestamp().before(action.getTimestamp())) {
                        mostRecentPlayAction.put(key, action);
                    } else {
                        Log.d(TAG, "No date information in action, skipping it");
                    }
                }
                break;
            case DELETE:
                // NEVER EVER call DBWriter.deleteFeedMediaOfItem() here, leads to an infinite loop
                break;
        }
    }
    for (GpodnetEpisodeAction action : mostRecentPlayAction.values()) {
        FeedItem playItem = DBReader.getFeedItem(action.getPodcast(), action.getEpisode());
        if (playItem != null) {
            FeedMedia media = playItem.getMedia();
            media.setPosition(action.getPosition() * 1000);
            DBWriter.setFeedMedia(media);
            if (playItem.getMedia().hasAlmostEnded()) {
                DBWriter.markItemPlayed(playItem, FeedItem.PLAYED, true);
                DBWriter.addItemToPlaybackHistory(playItem.getMedia());
            }
        }
    }
}
Also used : GpodnetEpisodeAction(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ArrayMap(android.support.v4.util.ArrayMap) Pair(android.util.Pair)

Example 9 with GpodnetEpisodeAction

use of de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction in project AntennaPod by AntennaPod.

the class FeedItemMenuHandler method onMenuItemClicked.

public static boolean onMenuItemClicked(Context context, int menuItemId, FeedItem selectedItem) throws DownloadRequestException {
    switch(menuItemId) {
        case R.id.skip_episode_item:
            context.sendBroadcast(new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE));
            break;
        case R.id.remove_item:
            DBWriter.deleteFeedMediaOfItem(context, selectedItem.getMedia().getId());
            break;
        case R.id.mark_read_item:
            selectedItem.setPlayed(true);
            DBWriter.markItemPlayed(selectedItem, FeedItem.PLAYED, false);
            if (GpodnetPreferences.loggedIn()) {
                FeedMedia media = selectedItem.getMedia();
                // not all items have media, Gpodder only cares about those that do
                if (media != null) {
                    GpodnetEpisodeAction actionPlay = new GpodnetEpisodeAction.Builder(selectedItem, Action.PLAY).currentDeviceId().currentTimestamp().started(media.getDuration() / 1000).position(media.getDuration() / 1000).total(media.getDuration() / 1000).build();
                    GpodnetPreferences.enqueueEpisodeAction(actionPlay);
                }
            }
            break;
        case R.id.mark_unread_item:
            selectedItem.setPlayed(false);
            DBWriter.markItemPlayed(selectedItem, FeedItem.UNPLAYED, false);
            if (GpodnetPreferences.loggedIn() && selectedItem.getMedia() != null) {
                GpodnetEpisodeAction actionNew = new GpodnetEpisodeAction.Builder(selectedItem, Action.NEW).currentDeviceId().currentTimestamp().build();
                GpodnetPreferences.enqueueEpisodeAction(actionNew);
            }
            break;
        case R.id.add_to_queue_item:
            DBWriter.addQueueItem(context, selectedItem);
            break;
        case R.id.remove_from_queue_item:
            DBWriter.removeQueueItem(context, selectedItem, true);
            break;
        case R.id.add_to_favorites_item:
            DBWriter.addFavoriteItem(selectedItem);
            break;
        case R.id.remove_from_favorites_item:
            DBWriter.removeFavoriteItem(selectedItem);
            break;
        case R.id.reset_position:
            selectedItem.getMedia().setPosition(0);
            DBWriter.markItemPlayed(selectedItem, FeedItem.UNPLAYED, true);
            break;
        case R.id.activate_auto_download:
            selectedItem.setAutoDownload(true);
            DBWriter.setFeedItemAutoDownload(selectedItem, true);
            break;
        case R.id.deactivate_auto_download:
            selectedItem.setAutoDownload(false);
            DBWriter.setFeedItemAutoDownload(selectedItem, false);
            break;
        case R.id.visit_website_item:
            Uri uri = Uri.parse(selectedItem.getLink());
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            if (IntentUtils.isCallable(context, intent)) {
                context.startActivity(intent);
            } else {
                Toast.makeText(context, context.getString(R.string.download_error_malformed_url), Toast.LENGTH_SHORT).show();
            }
            break;
        case R.id.support_item:
            DBTasks.flattrItemIfLoggedIn(context, selectedItem);
            break;
        case R.id.share_link_item:
            ShareUtils.shareFeedItemLink(context, selectedItem);
            break;
        case R.id.share_download_url_item:
            ShareUtils.shareFeedItemDownloadLink(context, selectedItem);
            break;
        case R.id.share_link_with_position_item:
            ShareUtils.shareFeedItemLink(context, selectedItem, true);
            break;
        case R.id.share_download_url_with_position_item:
            ShareUtils.shareFeedItemDownloadLink(context, selectedItem, true);
            break;
        default:
            Log.d(TAG, "Unknown menuItemId: " + menuItemId);
            return false;
    }
    return true;
}
Also used : GpodnetEpisodeAction(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Intent(android.content.Intent) Uri(android.net.Uri)

Aggregations

GpodnetEpisodeAction (de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction)9 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)3 Intent (android.content.Intent)2 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)2 GpodnetEpisodeActionGetResponse (de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeActionGetResponse)2 ArrayList (java.util.ArrayList)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 SharedPreferences (android.content.SharedPreferences)1 Uri (android.net.Uri)1 ArrayMap (android.support.v4.util.ArrayMap)1 Pair (android.util.Pair)1 GpodnetService (de.danoeh.antennapod.core.gpoddernet.GpodnetService)1 GpodnetServiceException (de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException)1 GpodnetEpisodeActionPostResponse (de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeActionPostResponse)1 DownloadRequestException (de.danoeh.antennapod.core.storage.DownloadRequestException)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1