package fr.free.nrw.commons.upload;


import android.os.AsyncTask;
import android.util.Log;

import org.mediawiki.api.ApiResult;
import org.mediawiki.api.MWApi;

import java.io.IOException;
import java.util.ArrayList;

import fr.free.nrw.commons.CommonsApplication;

/**
 * Sends asynchronous queries to the Commons MediaWiki API to check that file doesn't already exist
 */
public class ExistingFileAsync extends AsyncTask<Void, Void, ArrayList<String>> {

    private static final String TAG = fr.free.nrw.commons.upload.ExistingFileAsync.class.getName();
    private String fileSHA1;

    public ExistingFileAsync(String fileSHA1) {
        super();
        this.fileSHA1 = fileSHA1;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected ArrayList<String> doInBackground(Void... voids) {

        MWApi api = CommonsApplication.createMWApi();
        ApiResult result;

        ArrayList<String> items = new ArrayList<>();

        // https://commons.wikimedia.org/w/api.php?action=query&list=allimages&aisha1=801957214aba50cb63bb6eb1b0effa50188900ba
        
        try {
            result = api.action("query")
                    .param("format", "xml")
                    .param("list", "search")
                    .param("srwhat", "text")
                    .param("srnamespace", "14")
                    .param("srlimit", SEARCH_CATS_LIMIT)
                    .param("srsearch", title)
                    .get();
            Log.d(TAG, "Searching for cats for title: " + result.toString());
        } catch (IOException e) {
            Log.e(TAG, "IO Exception: ", e);
            //Return empty arraylist
            return items;
        }

        ArrayList<ApiResult> categoryNodes = result.getNodes("/api/query/search/p/@title");
        for(ApiResult categoryNode: categoryNodes) {
            String cat = categoryNode.getDocument().getTextContent();
            String catString = cat.replace("Category:", "");
            items.add(catString);
        }

        Log.d(TAG, "Title cat query results: " + items);

        return items;
    }

}
@@ -429,33 +429,23 @@
 , Void, 
-ArrayList%3CString%3E
+Boolean
 %3E %7B%0A%0A   
@@ -792,33 +792,23 @@
 otected 
-ArrayList%3CString%3E
+Boolean
  doInBac
@@ -918,62 +918,8 @@
 t;%0A%0A
-        ArrayList%3CString%3E items = new ArrayList%3C%3E();%0A%0A
     
@@ -1045,17 +1045,8 @@
 0ba%0A
-        %0A
     
@@ -1180,211 +1180,65 @@
 %22, %22
-search%22)%0A                    .param(%22srwhat%22, %22text%22)%0A                    .param(%22srnamespace%22, %2214%22)%0A                    .param(%22srlimit%22, SEARCH_CATS_LIMIT)%0A                    .param(%22srsearch%22, title
+allimages%22)%0A                    .param(%22aisha1%22, fileSHA1
 )%0A  
@@ -1301,24 +1301,35 @@
 ing 
-for cats for tit
+Commons API for existing fi
 le: 

Change result type to Boolean