Search in sources :

Example 6 with Downloader

use of de.danoeh.antennapod.core.service.download.Downloader in project AntennaPod by AntennaPod.

the class HttpDownloaderTest method testCancel.

public void testCancel() {
    final String url = HTTPBin.BASE_URL + "/delay/3";
    FeedFileImpl feedFile = setupFeedFile(url, "delay", true);
    final Downloader downloader = new HttpDownloader(new DownloadRequest(feedFile.getFile_url(), url, "delay", 0, feedFile.getTypeAsInt()));
    Thread t = new Thread() {

        @Override
        public void run() {
            downloader.call();
        }
    };
    t.start();
    downloader.cancel();
    try {
        t.join();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    DownloadStatus result = downloader.getResult();
    assertTrue(result.isDone());
    assertFalse(result.isSuccessful());
    assertTrue(result.isCancelled());
    assertFalse(new File(feedFile.getFile_url()).exists());
}
Also used : HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) Downloader(de.danoeh.antennapod.core.service.download.Downloader) HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) FeedFile(de.danoeh.antennapod.core.feed.FeedFile) File(java.io.File)

Example 7 with Downloader

use of de.danoeh.antennapod.core.service.download.Downloader in project AntennaPod by AntennaPod.

the class DownloadlistAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Holder holder;
    Downloader downloader = getItem(position);
    DownloadRequest request = downloader.getDownloadRequest();
    // Inflate layout
    if (convertView == null) {
        holder = new Holder();
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.downloadlist_item, parent, false);
        holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
        holder.downloaded = (TextView) convertView.findViewById(R.id.txtvDownloaded);
        holder.percent = (TextView) convertView.findViewById(R.id.txtvPercent);
        holder.progbar = (ProgressBar) convertView.findViewById(R.id.progProgress);
        holder.butSecondary = (ImageButton) convertView.findViewById(R.id.butSecondaryAction);
        convertView.setTag(holder);
    } else {
        holder = (Holder) convertView.getTag();
    }
    if (position == selectedItemIndex) {
        convertView.setBackgroundColor(ContextCompat.getColor(convertView.getContext(), ThemeUtils.getSelectionBackgroundColor()));
    } else {
        convertView.setBackgroundResource(0);
    }
    holder.title.setText(request.getTitle());
    holder.progbar.setIndeterminate(request.getSoFar() <= 0);
    String strDownloaded = Converter.byteToString(request.getSoFar());
    if (request.getSize() != DownloadStatus.SIZE_UNKNOWN) {
        strDownloaded += " / " + Converter.byteToString(request.getSize());
        holder.percent.setText(request.getProgressPercent() + "%");
        holder.progbar.setProgress(request.getProgressPercent());
        holder.percent.setVisibility(View.VISIBLE);
    } else {
        holder.progbar.setProgress(0);
        holder.percent.setVisibility(View.INVISIBLE);
    }
    holder.downloaded.setText(strDownloaded);
    holder.butSecondary.setFocusable(false);
    holder.butSecondary.setTag(downloader);
    holder.butSecondary.setOnClickListener(butSecondaryListener);
    return convertView;
}
Also used : LayoutInflater(android.view.LayoutInflater) Downloader(de.danoeh.antennapod.core.service.download.Downloader) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest)

Example 8 with Downloader

use of de.danoeh.antennapod.core.service.download.Downloader in project AntennaPod by AntennaPod.

the class ItemFragment method updateAppearance.

private void updateAppearance() {
    if (item == null) {
        Log.d(TAG, "updateAppearance item is null");
        return;
    }
    getActivity().supportInvalidateOptionsMenu();
    txtvPodcast.setText(item.getFeed().getTitle());
    txtvTitle.setText(item.getTitle());
    if (item.getPubDate() != null) {
        String pubDateStr = DateUtils.formatAbbrev(getActivity(), item.getPubDate());
        txtvPublished.setText(pubDateStr);
    }
    Glide.with(getActivity()).load(item.getImageLocation()).placeholder(R.color.light_gray).error(R.color.light_gray).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).fitCenter().dontAnimate().into(imgvCover);
    progbarDownload.setVisibility(View.GONE);
    if (item.hasMedia() && downloaderList != null) {
        for (Downloader downloader : downloaderList) {
            if (downloader.getDownloadRequest().getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA && downloader.getDownloadRequest().getFeedfileId() == item.getMedia().getId()) {
                progbarDownload.setVisibility(View.VISIBLE);
                progbarDownload.setProgress(downloader.getDownloadRequest().getProgressPercent());
            }
        }
    }
    FeedMedia media = item.getMedia();
    String butAction1Icon = null;
    int butAction1Text = 0;
    String butAction2Icon = null;
    int butAction2Text = 0;
    if (media == null) {
        if (!item.isPlayed()) {
            butAction1Icon = "{fa-check 24sp}";
            butAction1Text = R.string.mark_read_label;
        }
        if (item.getLink() != null) {
            butAction2Icon = "{md-web 24sp}";
            butAction2Text = R.string.visit_website_label;
        }
    } else {
        if (media.getDuration() > 0) {
            txtvDuration.setText(Converter.getDurationStringLong(media.getDuration()));
        }
        boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media);
        if (!media.isDownloaded()) {
            butAction2Icon = "{md-settings-input-antenna 24sp}";
            butAction2Text = R.string.stream_label;
        } else {
            butAction2Icon = "{md-delete 24sp}";
            butAction2Text = R.string.delete_label;
        }
        if (isDownloading) {
            butAction1Icon = "{md-cancel 24sp}";
            butAction1Text = R.string.cancel_label;
        } else if (media.isDownloaded()) {
            butAction1Icon = "{md-play-arrow 24sp}";
            butAction1Text = R.string.play_label;
        } else {
            butAction1Icon = "{md-file-download 24sp}";
            butAction1Text = R.string.download_label;
        }
    }
    if (butAction1Icon != null && butAction1Text != 0) {
        butAction1.setText(butAction1Icon + "  " + getActivity().getString(butAction1Text));
        Iconify.addIcons(butAction1);
        butAction1.setVisibility(View.VISIBLE);
    } else {
        butAction1.setVisibility(View.INVISIBLE);
    }
    if (butAction2Icon != null && butAction2Text != 0) {
        butAction2.setText(butAction2Icon + "  " + getActivity().getString(butAction2Text));
        Iconify.addIcons(butAction2);
        butAction2.setVisibility(View.VISIBLE);
    } else {
        butAction2.setVisibility(View.INVISIBLE);
    }
}
Also used : FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Downloader(de.danoeh.antennapod.core.service.download.Downloader)

Aggregations

Downloader (de.danoeh.antennapod.core.service.download.Downloader)8 HttpDownloader (de.danoeh.antennapod.core.service.download.HttpDownloader)6 File (java.io.File)5 FeedFile (de.danoeh.antennapod.core.feed.FeedFile)4 DownloadRequest (de.danoeh.antennapod.core.service.download.DownloadRequest)4 DownloadStatus (de.danoeh.antennapod.core.service.download.DownloadStatus)3 LayoutInflater (android.view.LayoutInflater)2 Dialog (android.app.Dialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Looper (android.os.Looper)1 NavUtils (android.support.v4.app.NavUtils)1 AlertDialog (android.support.v7.app.AlertDialog)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1