add media scanner notification after successful download

This commit is contained in:
fr3ts0n 2016-11-06 21:08:57 +01:00
parent b270de3335
commit 5bba8e02a6
2 changed files with 57 additions and 2 deletions

View File

@ -32,6 +32,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import us.shandian.giga.get.DownloadManager; import us.shandian.giga.get.DownloadManager;
import us.shandian.giga.get.DownloadMission;
import us.shandian.giga.service.DownloadManagerService; import us.shandian.giga.service.DownloadManagerService;
@ -227,7 +228,11 @@ public class DownloadDialog extends DialogFragment {
fName + arguments.getString(FILE_SUFFIX_AUDIO), fName + arguments.getString(FILE_SUFFIX_AUDIO),
audioButton.isChecked(), audioButton.isChecked(),
threads.getProgress() + 1); 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()){ if(videoButton.isChecked()){
@ -236,7 +241,11 @@ public class DownloadDialog extends DialogFragment {
fName + arguments.getString(FILE_SUFFIX_VIDEO), fName + arguments.getString(FILE_SUFFIX_VIDEO),
audioButton.isChecked(), audioButton.isChecked(),
threads.getProgress() + 1); 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(); getDialog().dismiss();

View File

@ -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 ...
}
}