Search in sources :

Example 6 with DownloadRequestException

use of de.danoeh.antennapod.core.storage.DownloadRequestException in project AntennaPod by AntennaPod.

the class GpodnetSyncService method syncEpisodeActions.

private synchronized void syncEpisodeActions() {
    final long timestamp = GpodnetPreferences.getLastEpisodeActionsSyncTimestamp();
    Log.d(TAG, "last episode actions sync timestamp: " + timestamp);
    try {
        GpodnetService service = tryLogin();
        // download episode actions
        GpodnetEpisodeActionGetResponse getResponse = service.getEpisodeChanges(timestamp);
        long lastUpdate = getResponse.getTimestamp();
        Log.d(TAG, "Downloaded episode actions: " + getResponse);
        List<GpodnetEpisodeAction> remoteActions = getResponse.getEpisodeActions();
        List<GpodnetEpisodeAction> localActions = GpodnetPreferences.getQueuedEpisodeActions();
        processEpisodeActions(localActions, remoteActions);
        // upload local actions
        if (localActions.size() > 0) {
            Log.d(TAG, "Uploading episode actions: " + localActions);
            GpodnetEpisodeActionPostResponse postResponse = service.uploadEpisodeActions(localActions);
            lastUpdate = postResponse.timestamp;
            Log.d(TAG, "Upload episode response: " + postResponse);
            GpodnetPreferences.removeQueuedEpisodeActions(localActions);
        }
        GpodnetPreferences.setLastEpisodeActionsSyncTimestamp(lastUpdate);
        GpodnetPreferences.setLastSyncAttempt(true, System.currentTimeMillis());
        clearErrorNotifications();
    } catch (GpodnetServiceException e) {
        e.printStackTrace();
        updateErrorNotification(e);
    } catch (DownloadRequestException e) {
        e.printStackTrace();
    }
}
Also used : GpodnetServiceException(de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException) GpodnetService(de.danoeh.antennapod.core.gpoddernet.GpodnetService) GpodnetEpisodeAction(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction) GpodnetEpisodeActionGetResponse(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeActionGetResponse) DownloadRequestException(de.danoeh.antennapod.core.storage.DownloadRequestException) GpodnetEpisodeActionPostResponse(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeActionPostResponse)

Example 7 with DownloadRequestException

use of de.danoeh.antennapod.core.storage.DownloadRequestException in project AntennaPod by AntennaPod.

the class OnlineFeedViewActivity method showFeedInformation.

/**
     * Called when feed parsed successfully.
     * This method is executed on the GUI thread.
     */
private void showFeedInformation(final Feed feed, Map<String, String> alternateFeedUrls) {
    setContentView(R.layout.listview_activity);
    this.feed = feed;
    this.selectedDownloadUrl = feed.getDownload_url();
    EventDistributor.getInstance().register(listener);
    ListView listView = (ListView) findViewById(R.id.listview);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View header = inflater.inflate(R.layout.onlinefeedview_header, listView, false);
    listView.addHeaderView(header);
    listView.setAdapter(new FeedItemlistDescriptionAdapter(this, 0, feed.getItems()));
    ImageView cover = (ImageView) header.findViewById(R.id.imgvCover);
    TextView title = (TextView) header.findViewById(R.id.txtvTitle);
    TextView author = (TextView) header.findViewById(R.id.txtvAuthor);
    TextView description = (TextView) header.findViewById(R.id.txtvDescription);
    Spinner spAlternateUrls = (Spinner) header.findViewById(R.id.spinnerAlternateUrls);
    subscribeButton = (Button) header.findViewById(R.id.butSubscribe);
    if (feed.getImage() != null && StringUtils.isNotBlank(feed.getImage().getDownload_url())) {
        Glide.with(this).load(feed.getImage().getDownload_url()).placeholder(R.color.light_gray).error(R.color.light_gray).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).fitCenter().dontAnimate().into(cover);
    }
    title.setText(feed.getTitle());
    author.setText(feed.getAuthor());
    description.setText(feed.getDescription());
    subscribeButton.setOnClickListener(v -> {
        if (feed != null && feedInFeedlist(feed)) {
            Intent intent = new Intent(OnlineFeedViewActivity.this, MainActivity.class);
            intent.putExtra(MainActivity.EXTRA_FEED_ID, getFeedId(feed));
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        } else {
            Feed f = new Feed(selectedDownloadUrl, null, feed.getTitle());
            f.setPreferences(feed.getPreferences());
            this.feed = f;
            try {
                DownloadRequester.getInstance().downloadFeed(this, f);
            } catch (DownloadRequestException e) {
                Log.e(TAG, Log.getStackTraceString(e));
                DownloadRequestErrorDialogCreator.newRequestErrorDialog(this, e.getMessage());
            }
            setSubscribeButtonState(feed);
        }
    });
    if (alternateFeedUrls.isEmpty()) {
        spAlternateUrls.setVisibility(View.GONE);
    } else {
        spAlternateUrls.setVisibility(View.VISIBLE);
        final List<String> alternateUrlsList = new ArrayList<>();
        final List<String> alternateUrlsTitleList = new ArrayList<>();
        alternateUrlsList.add(feed.getDownload_url());
        alternateUrlsTitleList.add(feed.getTitle());
        alternateUrlsList.addAll(alternateFeedUrls.keySet());
        for (String url : alternateFeedUrls.keySet()) {
            alternateUrlsTitleList.add(alternateFeedUrls.get(url));
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, alternateUrlsTitleList);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spAlternateUrls.setAdapter(adapter);
        spAlternateUrls.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                selectedDownloadUrl = alternateUrlsList.get(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
    }
    setSubscribeButtonState(feed);
}
Also used : Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) Intent(android.content.Intent) DownloadRequestException(de.danoeh.antennapod.core.storage.DownloadRequestException) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ListView(android.widget.ListView) FeedItemlistDescriptionAdapter(de.danoeh.antennapod.adapter.FeedItemlistDescriptionAdapter) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) ArrayAdapter(android.widget.ArrayAdapter) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 8 with DownloadRequestException

use of de.danoeh.antennapod.core.storage.DownloadRequestException in project AntennaPod by AntennaPod.

the class EpisodesApplyActionFragment method downloadChecked.

private void downloadChecked() {
    // download the check episodes in the same order as they are currently displayed
    List<FeedItem> toDownload = new ArrayList<>(checkedIds.size());
    for (FeedItem episode : episodes) {
        if (checkedIds.contains(episode.getId())) {
            toDownload.add(episode);
        }
    }
    try {
        DBTasks.downloadFeedItems(getActivity(), toDownload.toArray(new FeedItem[toDownload.size()]));
    } catch (DownloadRequestException e) {
        e.printStackTrace();
        DownloadRequestErrorDialogCreator.newRequestErrorDialog(getActivity(), e.getMessage());
    }
    close();
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) ArrayList(java.util.ArrayList) DownloadRequestException(de.danoeh.antennapod.core.storage.DownloadRequestException)

Example 9 with DownloadRequestException

use of de.danoeh.antennapod.core.storage.DownloadRequestException in project AntennaPod by AntennaPod.

the class DefaultActionButtonCallback method confirmMobileDownload.

private void confirmMobileDownload(final Context context, final FeedItem item) {
    MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
    builder.title(R.string.confirm_mobile_download_dialog_title).content(R.string.confirm_mobile_download_dialog_message).positiveText(context.getText(R.string.confirm_mobile_download_dialog_enable_temporarily)).onPositive((dialog, which) -> {
        allowMobileDownloadsTimestamp = System.currentTimeMillis();
        try {
            DBTasks.downloadFeedItems(context, item);
            Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
        } catch (DownloadRequestException e) {
            e.printStackTrace();
            DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
        }
    });
    LongList queueIds = DBReader.getQueueIDList();
    if (!queueIds.contains(item.getId())) {
        builder.content(R.string.confirm_mobile_download_dialog_message_not_in_queue).neutralText(R.string.confirm_mobile_download_dialog_only_add_to_queue).onNeutral((dialog, which) -> {
            onlyAddToQueueTimeStamp = System.currentTimeMillis();
            DBWriter.addQueueItem(context, item);
            Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show();
        });
    }
    builder.show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) LongList(de.danoeh.antennapod.core.util.LongList) DownloadRequestException(de.danoeh.antennapod.core.storage.DownloadRequestException)

Example 10 with DownloadRequestException

use of de.danoeh.antennapod.core.storage.DownloadRequestException in project AntennaPod by AntennaPod.

the class DefaultActionButtonCallback method onActionButtonPressed.

@Override
public void onActionButtonPressed(final FeedItem item, final LongList queueIds) {
    if (item.hasMedia()) {
        final FeedMedia media = item.getMedia();
        boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media);
        if (!isDownloading && !media.isDownloaded()) {
            if (NetworkUtils.isDownloadAllowed() || userAllowedMobileDownloads()) {
                try {
                    DBTasks.downloadFeedItems(context, item);
                    Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
                } catch (DownloadRequestException e) {
                    e.printStackTrace();
                    DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
                }
            } else if (userChoseAddToQueue() && !queueIds.contains(item.getId())) {
                DBWriter.addQueueItem(context, item);
                Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show();
            } else {
                confirmMobileDownload(context, item);
            }
        } else if (isDownloading) {
            DownloadRequester.getInstance().cancelDownload(context, media);
            if (UserPreferences.isEnableAutodownload()) {
                DBWriter.setFeedItemAutoDownload(media.getItem(), false);
                Toast.makeText(context, R.string.download_canceled_autodownload_enabled_msg, Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(context, R.string.download_canceled_msg, Toast.LENGTH_LONG).show();
            }
        } else {
            // media is downloaded
            if (item.hasMedia() && item.getMedia().isCurrentlyPlaying()) {
                context.sendBroadcast(new Intent(PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
            } else if (item.hasMedia() && item.getMedia().isCurrentlyPaused()) {
                context.sendBroadcast(new Intent(PlaybackService.ACTION_RESUME_PLAY_CURRENT_EPISODE));
            } else {
                DBTasks.playMedia(context, media, false, true, false);
            }
        }
    } else {
        if (!item.isPlayed()) {
            DBWriter.markItemPlayed(item, FeedItem.PLAYED, true);
        }
    }
}
Also used : FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Intent(android.content.Intent) DownloadRequestException(de.danoeh.antennapod.core.storage.DownloadRequestException)

Aggregations

DownloadRequestException (de.danoeh.antennapod.core.storage.DownloadRequestException)13 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)4 AdapterView (android.widget.AdapterView)3 Feed (de.danoeh.antennapod.core.feed.Feed)3 Intent (android.content.Intent)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 GpodnetService (de.danoeh.antennapod.core.gpoddernet.GpodnetService)2 GpodnetServiceException (de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 DialogInterface (android.content.DialogInterface)1 SearchView (android.support.v7.widget.SearchView)1 ArrayAdapter (android.widget.ArrayAdapter)1 Spinner (android.widget.Spinner)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 IconTextView (com.joanzapata.iconify.widget.IconTextView)1