package com.hewgill.android.nzsldict;

import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class DownloadReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (DownloadManager.ACTION_NOTIFICATION_CLICKED.equals(action)) {
            Intent startIntent = new Intent(context, FavouritesActivity.class);
            startIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            context.startActivity(startIntent);
            return;
        }

        if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
            Toast.makeText(context, "Download completed?", Toast.LENGTH_SHORT).show();

        }
    }
}

@@ -192,60 +192,248 @@
 oid.
-widget.Toast;%0A%0Apublic class DownloadReceiver extends
+content.IntentFilter;%0Aimport android.net.ConnectivityManager;%0Aimport android.net.NetworkInfo;%0Aimport android.widget.Toast;%0A%0Apublic class DownloadReceiver %7B%0A    private DownloadCallback callback;%0A%0A    private BroadcastReceiver receiver = new
  Bro
@@ -450,12 +450,17 @@
 iver
+()
  %7B%0A
-%0A
+    
     
@@ -473,16 +473,20 @@
 ide%0A    
+   
+ 
 public v
@@ -541,16 +541,20 @@
         
+    
 String a
@@ -581,32 +581,36 @@
 tion();%0A        
+  
+  
 if (DownloadMana
@@ -651,32 +651,36 @@
 uals(action)) %7B%0A
+    
             Inte
@@ -755,16 +755,20 @@
         
+    
 startInt
@@ -826,16 +826,20 @@
         
+   
+ 
 context.
@@ -878,16 +878,20 @@
         
+    
 return;%0A
@@ -902,11 +902,19 @@
     
+  
+  
 %7D%0A%0A
+    
     
@@ -996,23 +996,140 @@
     
-Toast.makeText(
+    if (callback != null) callback.onDownloadCompleted();%0A            %7D%0A        %7D%0A    %7D;%0A%0A%0A%0A    public void registerContext(Context 
 cont
@@ -1137,17 +1137,16 @@
 xt, 
-%22
 Download
  com
@@ -1145,60 +1145,517 @@
 load
- completed?%22, Toast.LENGTH_SHORT).show();%0A%0A        %7D
+Callback callback) %7B%0A        this.callback = callback;%0A        IntentFilter filter = new IntentFilter();%0A        filter.addAction(DownloadManager.ACTION_NOTIFICATION_CLICKED);%0A        filter.addAction(DownloadManager.ACTION_DOWNLOAD_COMPLETE);%0A        context.registerReceiver(receiver, filter);%0A    %7D%0A%0A    public void unregisterContext(Context context) %7B%0A        callback = null;%0A        context.unregisterReceiver(receiver);%0A    %7D%0A%0A    public interface DownloadCallback %7B%0A        void onDownloadCompleted();
 %0A   

Reimplement DownloadReceiver to follow the same pattern as that used for NetworkManager