mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-30 23:03:00 +00:00 
			
		
		
		
	add media scanner notification after successful download
This commit is contained in:
		| @@ -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(); | ||||
|  | ||||
|   | ||||
| @@ -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 ... | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 fr3ts0n
					fr3ts0n