package com.newsblur.network;

import java.util.ArrayList;

import android.content.Context;
import android.support.v4.content.AsyncTaskLoader;

import com.newsblur.domain.FeedResult;

public class SearchAsyncTaskLoader extends AsyncTaskLoader<SearchLoaderResponse> {

	public static final String SEARCH_TERM = "searchTerm";
	
	private String searchTerm;
	private APIManager apiManager;

	public SearchAsyncTaskLoader(Context context, String searchTerm) {
		super(context);
		this.searchTerm = searchTerm;
		apiManager = new APIManager(context);
	}

	@Override
	public SearchLoaderResponse loadInBackground() {
		SearchLoaderResponse response;
		try {
			ArrayList<FeedResult> list = new ArrayList<FeedResult>();
			for (FeedResult result : apiManager.searchForFeed(searchTerm)) {
				list.add(result);
			}
			response = new SearchLoaderResponse(list);
		} catch (ServerErrorException ex) {
			response = new SearchLoaderResponse(ex.getMessage());
		}
		return response;
	}

}

@@ -709,16 +709,20 @@
 ();%0A
-%09%09%09for (
+            
 Feed
@@ -731,17 +731,20 @@
 sult
+%5B%5D
  result
- :
+s =
  api
@@ -780,37 +780,165 @@
 erm)
-) %7B%0A%09%09%09%09list.add(result);%0A%09%09%09
+;%0A            if (results != null) %7B%0A                for (FeedResult result : results) %7B%0A                    list.add(result);%0A                %7D%0A            
 %7D%0A%09%09

Fix crash on feed search.