From 5bba8e02a6589ad301b2032d1b869e566dbfcb36 Mon Sep 17 00:00:00 2001 From: fr3ts0n Date: Sun, 6 Nov 2016 21:08:57 +0100 Subject: [PATCH] add media scanner notification after successful download --- .../newpipe/download/DownloadDialog.java | 13 +++++- .../newpipe/download/DownloadListener.java | 46 +++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/download/DownloadListener.java diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java index 5669a3308..2d2159768 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -32,6 +32,7 @@ import java.util.ArrayList; import java.util.List; import us.shandian.giga.get.DownloadManager; +import us.shandian.giga.get.DownloadMission; import us.shandian.giga.service.DownloadManagerService; @@ -227,7 +228,11 @@ public class DownloadDialog extends DialogFragment { fName + arguments.getString(FILE_SUFFIX_AUDIO), audioButton.isChecked(), threads.getProgress() + 1); - mBinder.onMissionAdded(mManager.getMission(res)); + DownloadMission mission = mManager.getMission(res); + mBinder.onMissionAdded(mission); + // add download listener to allow media scan notification + DownloadListener listener = new DownloadListener(getContext(), mission); + mission.addListener(listener); } if(videoButton.isChecked()){ @@ -236,7 +241,11 @@ public class DownloadDialog extends DialogFragment { fName + arguments.getString(FILE_SUFFIX_VIDEO), audioButton.isChecked(), threads.getProgress() + 1); - mBinder.onMissionAdded(mManager.getMission(res)); + DownloadMission mission = mManager.getMission(res); + mBinder.onMissionAdded(mission); + // add download listener to allow media scan notification + DownloadListener listener = new DownloadListener(getContext(), mission); + mission.addListener(listener); } getDialog().dismiss(); diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadListener.java b/app/src/main/java/org/schabi/newpipe/download/DownloadListener.java new file mode 100644 index 000000000..189ececbb --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadListener.java @@ -0,0 +1,46 @@ +package org.schabi.newpipe.download; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; + +import us.shandian.giga.get.DownloadMission; +import us.shandian.giga.get.DownloadMission.MissionListener; + +/** + * Created by erwin on 06.11.16. + */ + +class DownloadListener implements MissionListener +{ + DownloadMission mMission; + Context mContext; + + public DownloadListener(Context context, DownloadMission mission) + { + super(); + mMission = mission; + mContext = context; + } + + @Override + public void onProgressUpdate(long done, long total) + { + // do nothing special ... + } + + @Override + public void onFinish() + { + // notify media scanner on downloaded media file ... + mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, + Uri.parse( "file://" + mMission.location + + "/" + mMission.name))); + } + + @Override + public void onError(int errCode) + { + // do nothing special ... + } +}