Remove AsyncTask utility methods

This commit is contained in:
veyndan 2017-03-24 04:59:52 +00:00
parent ef9799ec07
commit 36fe8e3089
6 changed files with 9 additions and 34 deletions

View file

@ -109,7 +109,7 @@ public class EventLog {
return; // User has disabled tracking
}
LogTask logTask = new LogTask();
Utils.executeAsyncTask(logTask, this);
logTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, this);
}
public void log() {

View file

@ -1,7 +1,6 @@
package fr.free.nrw.commons;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.util.Log;
@ -29,7 +28,6 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.Executor;
import java.util.regex.Pattern;
import javax.xml.transform.Transformer;
@ -127,27 +125,6 @@ public class Utils {
return outputStream.toString();
}
static public <T> void executeAsyncTask(AsyncTask<T, ?, ?> task,
T... params) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}
else {
task.execute(params);
}
}
static public <T> void executeAsyncTask(AsyncTask<T, ?, ?> task, Executor executor,
T... params) {
// FIXME: We're simply ignoring the executor on older androids
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
task.executeOnExecutor(executor, params);
}
else {
task.execute(params);
}
}
private static DisplayImageOptions.Builder defaultImageOptionsBuilder;
public static DisplayImageOptions.Builder getGenericDisplayOptions() {
if(defaultImageOptionsBuilder == null) {

View file

@ -12,7 +12,6 @@ import java.io.IOException;
import fr.free.nrw.commons.theme.BaseActivity;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.Utils;
public abstract class AuthenticatedActivity extends BaseActivity {
@ -122,7 +121,7 @@ public abstract class AuthenticatedActivity extends BaseActivity {
// returns, we have a deadlock!
// Fixed by explicitly asking this to be executed in parallel
// See: https://groups.google.com/forum/?fromgroups=#!topic/android-developers/8M0RTFfO7-M
Utils.executeAsyncTask(addAccountTask);
addAccountTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
GetAuthCookieTask task = new GetAuthCookieTask(curAccount, accountManager);
task.execute();

View file

@ -43,7 +43,6 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.upload.MwVolleyApi;
/**
@ -145,7 +144,7 @@ public class CategorizationFragment extends Fragment {
}
};
Utils.executeAsyncTask(titleCategoriesSub);
titleCategoriesSub.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
Log.d(TAG, "TitleCatItems in titleCatQuery: " + titleCatItems);
//Only return titleCatItems after API call has finished
@ -322,8 +321,8 @@ public class CategorizationFragment extends Fragment {
latch.countDown();
}
};
Utils.executeAsyncTask(prefixUpdaterSub);
Utils.executeAsyncTask(methodAUpdaterSub);
prefixUpdaterSub.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
methodAUpdaterSub.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
private void startUpdatingCategoryList() {
@ -400,7 +399,7 @@ public class CategorizationFragment extends Fragment {
}
private void updateCategoryCount(String name) {
Utils.executeAsyncTask(new CategoryCountUpdater(name), executor);
new CategoryCountUpdater(name).executeOnExecutor(executor);
}
@Override

View file

@ -242,7 +242,7 @@ public class MediaDetailFragment extends Fragment {
}
}
};
Utils.executeAsyncTask(detailFetchTask);
detailFetchTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
//This should not usually happen, image along with associated details should always be loaded from Internet, but keeping this for now for backup.
//Even if image is loaded from device storage, it will display, albeit with empty desc and cat.

View file

@ -97,7 +97,7 @@ public class UploadController {
contribution.setLicense(license);
//FIXME: Add permission request here. Only executeAsyncTask if permission has been granted
Utils.executeAsyncTask(new AsyncTask<Void, Void, Contribution>() {
new AsyncTask<Void, Void, Contribution>() {
// Fills up missing information about Contributions
// Only does things that involve some form of IO
@ -162,6 +162,6 @@ public class UploadController {
uploadService.queue(UploadService.ACTION_UPLOAD_FILE, contribution);
onComplete.onUploadStarted(contribution);
}
});
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}