Skip to content

Commit

Permalink
Use hashmap on AndroidTaskRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
iSoron committed Jul 29, 2016
1 parent 3a3be66 commit 3a7f277
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ public class AndroidTaskRunner implements TaskRunner
{
private final LinkedList<CustomAsyncTask> activeTasks;

private final HashMap<Task, CustomAsyncTask> taskToAsyncTask;

public AndroidTaskRunner()
{
activeTasks = new LinkedList<>();
taskToAsyncTask = new HashMap<>();
}

@Provides
Expand All @@ -54,8 +57,9 @@ public void execute(Task task)
@Override
public void publishProgress(Task task, int progress)
{
for (CustomAsyncTask asyncTask : activeTasks)
if (asyncTask.getTask() == task) asyncTask.publish(progress);
CustomAsyncTask asyncTask = taskToAsyncTask.get(task);
if(asyncTask == null) return;
asyncTask.publish(progress);
}

private class CustomAsyncTask extends AsyncTask<Void, Integer, Void>
Expand Down Expand Up @@ -89,12 +93,14 @@ protected void onPostExecute(Void aVoid)
{
task.onPostExecute();
activeTasks.remove(this);
taskToAsyncTask.remove(task);
}

@Override
protected void onPreExecute()
{
activeTasks.add(this);
taskToAsyncTask.put(task, this);
task.onPreExecute();
}

Expand Down

0 comments on commit 3a7f277

Please sign in to comment.