package org.commcare.android.tasks;

import android.content.Context;
import android.util.Log;

import org.commcare.android.database.SqlStorage;
import org.commcare.android.database.UserStorageClosedException;
import org.commcare.android.database.user.models.FormRecord;
import org.commcare.android.database.user.models.User;
import org.commcare.android.models.notifications.NotificationMessageFactory;
import org.commcare.android.models.notifications.NotificationMessageFactory.StockMessages;
import org.commcare.android.tasks.ProcessAndSendTask.ProcessIssues;
import org.commcare.android.tasks.templates.CommCareTask;
import org.commcare.android.util.FileUtil;
import org.commcare.android.util.FormUploadUtil;
import org.commcare.android.util.SessionUnavailableException;
import org.commcare.dalvik.application.CommCareApplication;
import org.commcare.util.CommCarePlatform;
import org.javarosa.core.services.locale.Localization;

import java.io.File;
import java.io.FileNotFoundException;

/**
 * @author ctsims
 *
 */
public abstract class SendTask<R> extends CommCareTask<Void, String, Boolean, R>{
    Context c;
    String url;
    Long[] results;
    
    DataSubmissionListener formSubmissionListener;

    File dumpDirectory;
    
    public static String MALFORMED_FILE_CATEGORY = "malformed-file";
    
    public static final int BULK_SEND_ID = 12335645;
    
     // 5MB less 1KB overhead
    
    public SendTask(Context c, String url, File dumpDirectory) {
        this.c = c;
        this.url = url;
        this.taskId = SendTask.BULK_SEND_ID;
        this.dumpDirectory = dumpDirectory;
    }
    
    protected void onProgressUpdate(String... values) {
        super.onProgressUpdate(values);
    }
    
    
    public void setListeners(DataSubmissionListener submissionListener) {
        this.formSubmissionListener = submissionListener;
    }

    @Override
    protected void onPostExecute(Boolean result) {
        super.onPostExecute(result);
        //These will never get Zero'd otherwise
        c = null;
        url = null;
        results = null;
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
        if(this.formSubmissionListener != null) {
            formSubmissionListener.endSubmissionProcess();
        }
        CommCareApplication._().reportNotificationMessage(NotificationMessageFactory.message(ProcessIssues.LoggedOut));
    }

    @Override
    protected Boolean doTaskBackground(Void... params) {
        
        publishProgress(Localization.get("bulk.form.send.start"));

        //sanity check
        if(!(dumpDirectory.isDirectory())){
            return false;
        }
        
        File[] files = dumpDirectory.listFiles();
        int counter = 0;
        
        results = new Long [files.length];
        
        for(int i = 0; i < files.length ; ++i ) {
            //Assume failure
            results[i] = FormUploadUtil.FAILURE;
        }
        
        boolean allSuccessful = true;
        
        for(int i=0;i<files.length;i++){
            
            publishProgress(Localization.get("bulk.send.dialog.progress",new String[]{""+ (i+1)}));
            
            File f = files[i];
            
            if(!(f.isDirectory())){
                Log.e("send","Encountered non form entry in file dump folder at path: " + f.getAbsolutePath());
                CommCareApplication._().reportNotificationMessage(NotificationMessageFactory.message(StockMessages.Send_MalformedFile, new String[] {null, f.getName()}, MALFORMED_FILE_CATEGORY));
                continue;
            }
            try{
                User user = CommCareApplication._().getSession().getLoggedInUser();
                results[i] = FormUploadUtil.sendInstance(counter,f,url, user);
                
                if(results[i] == FormUploadUtil.FULL_SUCCESS){
                    FileUtil.deleteFile(f);
                }
                else if(results[i] == FormUploadUtil.TRANSPORT_FAILURE){
                    allSuccessful = false;
                    publishProgress(Localization.get("bulk.send.transport.error"));
                    return false;
                }
                else{
                    allSuccessful = false;
                    CommCareApplication._().reportNotificationMessage(NotificationMessageFactory.message(StockMessages.Send_MalformedFile, new String[] {null, f.getName()}, MALFORMED_FILE_CATEGORY));
                    publishProgress(Localization.get("bulk.send.file.error", new String[] {f.getAbsolutePath()}));
                }
                counter++;
            } catch(SessionUnavailableException | FileNotFoundException fe){
                Log.e("E", Localization.get("bulk.send.file.error", new String[] {f.getAbsolutePath()}), fe);
                publishProgress(Localization.get("bulk.send.file.error", new String[] {fe.getMessage()}));
            }
        }
        return allSuccessful;
    }
}

@@ -1654,24 +1654,39 @@
    %7D%0D%0A    %0D%0A
+    @Override%0D%0A
     protecte

Add a missing @Override