Brion VIBBER has submitted this change and it was merged. Change subject: Simplify SaneAsyncTask constructor boilerplate. ......................................................................
Simplify SaneAsyncTask constructor boilerplate. Added a constructor that just takes the number of threads to allocate for this type of task. Change-Id: If83e1453c658caa207ebf6e3b6e5631115abee14 --- M wikipedia/src/main/java/org/wikipedia/ApiTask.java M wikipedia/src/main/java/org/wikipedia/PageQueryTask.java M wikipedia/src/main/java/org/wikipedia/concurrency/SaneAsyncTask.java M wikipedia/src/main/java/org/wikipedia/createaccount/CreateAccountTask.java M wikipedia/src/main/java/org/wikipedia/editing/DoEditTask.java M wikipedia/src/main/java/org/wikipedia/editing/EditPreviewTask.java M wikipedia/src/main/java/org/wikipedia/editing/FetchEditTokenTask.java M wikipedia/src/main/java/org/wikipedia/editing/FetchSectionWikitextTask.java M wikipedia/src/main/java/org/wikipedia/editing/RefreshCaptchaTask.java M wikipedia/src/main/java/org/wikipedia/interlanguage/LangLinksFetchTask.java M wikipedia/src/main/java/org/wikipedia/login/LoginTask.java M wikipedia/src/main/java/org/wikipedia/login/LogoutTask.java M wikipedia/src/main/java/org/wikipedia/page/SectionsFetchTask.java M wikipedia/src/main/java/org/wikipedia/pageimages/PageImageSaveTask.java M wikipedia/src/main/java/org/wikipedia/pageimages/PageImagesTask.java M wikipedia/src/main/java/org/wikipedia/random/RandomArticleIdTask.java M wikipedia/src/main/java/org/wikipedia/savedpages/DeleteSavedPageTask.java M wikipedia/src/main/java/org/wikipedia/savedpages/DownloadImageTask.java M wikipedia/src/main/java/org/wikipedia/savedpages/LoadSavedPageTask.java M wikipedia/src/main/java/org/wikipedia/savedpages/SavePageTask.java M wikipedia/src/main/java/org/wikipedia/search/SearchArticlesTask.java M wikipedia/src/main/java/org/wikipedia/zero/WikipediaZeroTask.java 22 files changed, 38 insertions(+), 51 deletions(-) Approvals: Brion VIBBER: Verified; Looks good to me, approved diff --git a/wikipedia/src/main/java/org/wikipedia/ApiTask.java b/wikipedia/src/main/java/org/wikipedia/ApiTask.java index d21eeec..b8e1a93 100644 --- a/wikipedia/src/main/java/org/wikipedia/ApiTask.java +++ b/wikipedia/src/main/java/org/wikipedia/ApiTask.java @@ -3,13 +3,11 @@ import org.mediawiki.api.json.*; import org.wikipedia.concurrency.*; -import java.util.concurrent.*; - abstract public class ApiTask<T> extends SaneAsyncTask<T> { private final Api api; - public ApiTask(Executor executor, Api api) { - super(executor); + public ApiTask(int threadCount, Api api) { + super(threadCount); this.api = api; } diff --git a/wikipedia/src/main/java/org/wikipedia/PageQueryTask.java b/wikipedia/src/main/java/org/wikipedia/PageQueryTask.java index cd81ef0..ba72a55 100644 --- a/wikipedia/src/main/java/org/wikipedia/PageQueryTask.java +++ b/wikipedia/src/main/java/org/wikipedia/PageQueryTask.java @@ -5,14 +5,13 @@ import org.mediawiki.api.json.*; import java.util.*; -import java.util.concurrent.*; public abstract class PageQueryTask<T> extends ApiTask<Map<PageTitle,T>> { private final List<PageTitle> titles; private final Site site; - public PageQueryTask(Executor executor, Api api, Site site, List<PageTitle> titles) { - super(executor, api); + public PageQueryTask(int threadCount, Api api, Site site, List<PageTitle> titles) { + super(threadCount, api); this.titles = titles; this.site = site; } diff --git a/wikipedia/src/main/java/org/wikipedia/concurrency/SaneAsyncTask.java b/wikipedia/src/main/java/org/wikipedia/concurrency/SaneAsyncTask.java index 93167b7..18f62e7 100644 --- a/wikipedia/src/main/java/org/wikipedia/concurrency/SaneAsyncTask.java +++ b/wikipedia/src/main/java/org/wikipedia/concurrency/SaneAsyncTask.java @@ -18,6 +18,16 @@ } /** + * Creates an executor using the default ExecutorService. + * + * @param threadCount Number of threads to use at max for this thread pool. + */ + public SaneAsyncTask(int threadCount) { + this.executor = ExecutorService.getSingleton().getExecutor(getClass(), threadCount); + this.underlyingTask = new BackingAsyncTask(); + } + + /** * Called before the background task is executed. * <p/> * Called on the UI Thread. diff --git a/wikipedia/src/main/java/org/wikipedia/createaccount/CreateAccountTask.java b/wikipedia/src/main/java/org/wikipedia/createaccount/CreateAccountTask.java index 0023d4c..944ad8e 100644 --- a/wikipedia/src/main/java/org/wikipedia/createaccount/CreateAccountTask.java +++ b/wikipedia/src/main/java/org/wikipedia/createaccount/CreateAccountTask.java @@ -5,9 +5,7 @@ import org.json.*; import org.mediawiki.api.json.*; import org.wikipedia.*; -import org.wikipedia.concurrency.*; import org.wikipedia.editing.*; -import org.wikipedia.interlanguage.*; public class CreateAccountTask extends ApiTask<CreateAccountResult> { @@ -18,7 +16,7 @@ private final String token; public CreateAccountTask(Context context, String username, String password, String email, String token) { super( - ExecutorService.getSingleton().getExecutor(LangLinksFetchTask.class, 1), + 1, ((WikipediaApp)context.getApplicationContext()).getAPIForSite( ((WikipediaApp)context.getApplicationContext()).getPrimarySite() ) diff --git a/wikipedia/src/main/java/org/wikipedia/editing/DoEditTask.java b/wikipedia/src/main/java/org/wikipedia/editing/DoEditTask.java index 6e43425..3bf3016 100644 --- a/wikipedia/src/main/java/org/wikipedia/editing/DoEditTask.java +++ b/wikipedia/src/main/java/org/wikipedia/editing/DoEditTask.java @@ -5,7 +5,6 @@ import org.json.*; import org.mediawiki.api.json.*; import org.wikipedia.*; -import org.wikipedia.concurrency.*; public class DoEditTask extends ApiTask<EditingResult> { private final PageTitle title; @@ -17,7 +16,7 @@ public DoEditTask(Context context, PageTitle title, String sectionWikitext, int sectionID, String editToken, String summary) { super( - ExecutorService.getSingleton().getExecutor(DoEditTask.class, 1), + 1, ((WikipediaApp)context.getApplicationContext()).getAPIForSite(title.getSite()) ); this.title = title; diff --git a/wikipedia/src/main/java/org/wikipedia/editing/EditPreviewTask.java b/wikipedia/src/main/java/org/wikipedia/editing/EditPreviewTask.java index dfb7a4f..187fe67 100644 --- a/wikipedia/src/main/java/org/wikipedia/editing/EditPreviewTask.java +++ b/wikipedia/src/main/java/org/wikipedia/editing/EditPreviewTask.java @@ -3,7 +3,6 @@ import android.content.*; import org.mediawiki.api.json.*; import org.wikipedia.*; -import org.wikipedia.concurrency.*; public class EditPreviewTask extends ApiTask<String> { @@ -12,7 +11,7 @@ public EditPreviewTask(Context context, String wikiText, PageTitle title) { super( - ExecutorService.getSingleton().getExecutor(EditPreviewTask.class, 1), + 1, ((WikipediaApp)context.getApplicationContext()).getAPIForSite(title.getSite()) ); this.wikiText = wikiText; diff --git a/wikipedia/src/main/java/org/wikipedia/editing/FetchEditTokenTask.java b/wikipedia/src/main/java/org/wikipedia/editing/FetchEditTokenTask.java index 5c8c433..091b6bb 100644 --- a/wikipedia/src/main/java/org/wikipedia/editing/FetchEditTokenTask.java +++ b/wikipedia/src/main/java/org/wikipedia/editing/FetchEditTokenTask.java @@ -3,12 +3,11 @@ import android.content.*; import org.mediawiki.api.json.*; import org.wikipedia.*; -import org.wikipedia.concurrency.*; public class FetchEditTokenTask extends ApiTask<String> { public FetchEditTokenTask(Context context, Site site) { super( - ExecutorService.getSingleton().getExecutor(FetchEditTokenTask.class, 1), + 1, ((WikipediaApp)context.getApplicationContext()).getAPIForSite(site) ); } diff --git a/wikipedia/src/main/java/org/wikipedia/editing/FetchSectionWikitextTask.java b/wikipedia/src/main/java/org/wikipedia/editing/FetchSectionWikitextTask.java index dbccd12..231cbd1 100644 --- a/wikipedia/src/main/java/org/wikipedia/editing/FetchSectionWikitextTask.java +++ b/wikipedia/src/main/java/org/wikipedia/editing/FetchSectionWikitextTask.java @@ -4,7 +4,6 @@ import org.json.*; import org.mediawiki.api.json.*; import org.wikipedia.*; -import org.wikipedia.concurrency.*; public class FetchSectionWikitextTask extends ApiTask<String> { private final PageTitle title; @@ -13,7 +12,7 @@ public FetchSectionWikitextTask(Context context, PageTitle title, int sectionID) { super( - ExecutorService.getSingleton().getExecutor(FetchSectionWikitextTask.class, 1), + 1, ((WikipediaApp)context.getApplicationContext()).getAPIForSite(title.getSite()) ); this.title = title; diff --git a/wikipedia/src/main/java/org/wikipedia/editing/RefreshCaptchaTask.java b/wikipedia/src/main/java/org/wikipedia/editing/RefreshCaptchaTask.java index 8cc9b85..1e43ff5 100644 --- a/wikipedia/src/main/java/org/wikipedia/editing/RefreshCaptchaTask.java +++ b/wikipedia/src/main/java/org/wikipedia/editing/RefreshCaptchaTask.java @@ -4,12 +4,11 @@ import android.util.*; import org.mediawiki.api.json.*; import org.wikipedia.*; -import org.wikipedia.concurrency.*; public class RefreshCaptchaTask extends ApiTask<CaptchaResult> { public RefreshCaptchaTask(Context context, Site site) { super( - ExecutorService.getSingleton().getExecutor(DoEditTask.class, 1), + 1, ((WikipediaApp)context.getApplicationContext()).getAPIForSite(site) ); } diff --git a/wikipedia/src/main/java/org/wikipedia/interlanguage/LangLinksFetchTask.java b/wikipedia/src/main/java/org/wikipedia/interlanguage/LangLinksFetchTask.java index ce7f4d4..45a5d67 100644 --- a/wikipedia/src/main/java/org/wikipedia/interlanguage/LangLinksFetchTask.java +++ b/wikipedia/src/main/java/org/wikipedia/interlanguage/LangLinksFetchTask.java @@ -4,18 +4,15 @@ import org.json.*; import org.mediawiki.api.json.*; import org.wikipedia.*; -import org.wikipedia.concurrency.*; import java.util.*; - -import org.wikipedia.Utils; public class LangLinksFetchTask extends ApiTask<ArrayList<PageTitle>> { private final PageTitle title; private final WikipediaApp app; public LangLinksFetchTask(Context context, PageTitle title) { super( - ExecutorService.getSingleton().getExecutor(LangLinksFetchTask.class, 1), + 1, ((WikipediaApp)context.getApplicationContext()).getAPIForSite(title.getSite()) ); this.title = title; diff --git a/wikipedia/src/main/java/org/wikipedia/login/LoginTask.java b/wikipedia/src/main/java/org/wikipedia/login/LoginTask.java index 308e183..5fb4573 100644 --- a/wikipedia/src/main/java/org/wikipedia/login/LoginTask.java +++ b/wikipedia/src/main/java/org/wikipedia/login/LoginTask.java @@ -13,7 +13,7 @@ private final WikipediaApp app; public LoginTask(Context context, Site site, String username, String password) { - super(ExecutorService.getSingleton().getExecutor(LoginTask.class, 1)); + super(1); app = (WikipediaApp)context.getApplicationContext(); api = app.getAPIForSite(site); this.username = username; diff --git a/wikipedia/src/main/java/org/wikipedia/login/LogoutTask.java b/wikipedia/src/main/java/org/wikipedia/login/LogoutTask.java index f21046b..e56d705 100644 --- a/wikipedia/src/main/java/org/wikipedia/login/LogoutTask.java +++ b/wikipedia/src/main/java/org/wikipedia/login/LogoutTask.java @@ -3,14 +3,13 @@ import android.content.*; import org.mediawiki.api.json.*; import org.wikipedia.*; -import org.wikipedia.concurrency.*; public class LogoutTask extends ApiTask<Boolean> { private final WikipediaApp app; public LogoutTask(Context context, Site site) { super( - ExecutorService.getSingleton().getExecutor(LogoutTask.class, 1), + 1, ((WikipediaApp)context.getApplicationContext()).getAPIForSite(site) ); app = (WikipediaApp)context.getApplicationContext(); diff --git a/wikipedia/src/main/java/org/wikipedia/page/SectionsFetchTask.java b/wikipedia/src/main/java/org/wikipedia/page/SectionsFetchTask.java index 3b9b45c..4853138 100644 --- a/wikipedia/src/main/java/org/wikipedia/page/SectionsFetchTask.java +++ b/wikipedia/src/main/java/org/wikipedia/page/SectionsFetchTask.java @@ -4,7 +4,6 @@ import org.json.*; import org.mediawiki.api.json.*; import org.wikipedia.*; -import org.wikipedia.concurrency.*; import java.util.*; @@ -15,7 +14,7 @@ public SectionsFetchTask(Context context, PageTitle title, String sections) { super( - ExecutorService.getSingleton().getExecutor(SectionsFetchTask.class, 1), + 1, ((WikipediaApp)context.getApplicationContext()).getAPIForSite(title.getSite()) ); this.title = title; diff --git a/wikipedia/src/main/java/org/wikipedia/pageimages/PageImageSaveTask.java b/wikipedia/src/main/java/org/wikipedia/pageimages/PageImageSaveTask.java index c008ac7..44a574e 100644 --- a/wikipedia/src/main/java/org/wikipedia/pageimages/PageImageSaveTask.java +++ b/wikipedia/src/main/java/org/wikipedia/pageimages/PageImageSaveTask.java @@ -2,14 +2,13 @@ import org.mediawiki.api.json.*; import org.wikipedia.*; -import org.wikipedia.concurrency.*; import java.util.*; public class PageImageSaveTask extends PageImagesTask { private final WikipediaApp app; public PageImageSaveTask(WikipediaApp app, Api api, PageTitle title) { - super(ExecutorService.getSingleton().getExecutor(PageImageSaveTask.class, 2), api, title.getSite(), Arrays.asList(new PageTitle[] {title}), 96); + super(2, api, title.getSite(), Arrays.asList(new PageTitle[] {title}), 96); this.app = app; } diff --git a/wikipedia/src/main/java/org/wikipedia/pageimages/PageImagesTask.java b/wikipedia/src/main/java/org/wikipedia/pageimages/PageImagesTask.java index 2513240..1c2672d 100644 --- a/wikipedia/src/main/java/org/wikipedia/pageimages/PageImagesTask.java +++ b/wikipedia/src/main/java/org/wikipedia/pageimages/PageImagesTask.java @@ -3,23 +3,21 @@ import org.json.*; import org.mediawiki.api.json.*; import org.wikipedia.*; -import org.wikipedia.concurrency.ExecutorService; import java.util.*; -import java.util.concurrent.*; public class PageImagesTask extends PageQueryTask<String> { private final int thumbSize; private final int thumbsCount; - protected PageImagesTask(Executor executor, Api api, Site site, List<PageTitle> titles, int thumbSize) { - super(executor, api, site, titles); + protected PageImagesTask(int threadCount, Api api, Site site, List<PageTitle> titles, int thumbSize) { + super(threadCount, api, site, titles); this.thumbSize = thumbSize; this.thumbsCount = titles.size(); } public PageImagesTask(Api api, Site site, List<PageTitle> titles, int thumbSize) { - super(ExecutorService.getSingleton().getExecutor(PageImagesTask.class, 2), api, site, titles); + super(2, api, site, titles); this.thumbSize = thumbSize; this.thumbsCount = titles.size(); } diff --git a/wikipedia/src/main/java/org/wikipedia/random/RandomArticleIdTask.java b/wikipedia/src/main/java/org/wikipedia/random/RandomArticleIdTask.java index 956e8c1..25decc1 100644 --- a/wikipedia/src/main/java/org/wikipedia/random/RandomArticleIdTask.java +++ b/wikipedia/src/main/java/org/wikipedia/random/RandomArticleIdTask.java @@ -1,10 +1,9 @@ package org.wikipedia.random; +import android.content.*; import org.json.*; import org.mediawiki.api.json.*; import org.wikipedia.*; -import org.wikipedia.concurrency.*; -import android.content.Context; public class RandomArticleIdTask extends ApiTask<PageTitle> { @@ -12,7 +11,7 @@ private Site site; public RandomArticleIdTask(Api api, Site site, Context context) { - super(ExecutorService.getSingleton().getExecutor(RandomArticleIdTask.class, 1), api); + super(1, api); this.site = site; this.ctx = context; } diff --git a/wikipedia/src/main/java/org/wikipedia/savedpages/DeleteSavedPageTask.java b/wikipedia/src/main/java/org/wikipedia/savedpages/DeleteSavedPageTask.java index 4e3dae1..5fafa9b 100644 --- a/wikipedia/src/main/java/org/wikipedia/savedpages/DeleteSavedPageTask.java +++ b/wikipedia/src/main/java/org/wikipedia/savedpages/DeleteSavedPageTask.java @@ -8,7 +8,7 @@ private final WikipediaApp app; private final SavedPage savedPage; public DeleteSavedPageTask(Context context, SavedPage savedPage) { - super(ExecutorService.getSingleton().getExecutor(DeleteSavedPageTask.class, 1)); + super(1); app = (WikipediaApp) context.getApplicationContext(); this.savedPage = savedPage; } diff --git a/wikipedia/src/main/java/org/wikipedia/savedpages/DownloadImageTask.java b/wikipedia/src/main/java/org/wikipedia/savedpages/DownloadImageTask.java index 35ce88a..4717150 100644 --- a/wikipedia/src/main/java/org/wikipedia/savedpages/DownloadImageTask.java +++ b/wikipedia/src/main/java/org/wikipedia/savedpages/DownloadImageTask.java @@ -13,7 +13,7 @@ private final URL imageUrl; public DownloadImageTask(Context context, String imageUrl) { - super(ExecutorService.getSingleton().getExecutor(DownloadImageTask.class, 4)); + super(4); this.context = context; try { this.imageUrl = new URL(imageUrl); diff --git a/wikipedia/src/main/java/org/wikipedia/savedpages/LoadSavedPageTask.java b/wikipedia/src/main/java/org/wikipedia/savedpages/LoadSavedPageTask.java index 3133555..7919e8a 100644 --- a/wikipedia/src/main/java/org/wikipedia/savedpages/LoadSavedPageTask.java +++ b/wikipedia/src/main/java/org/wikipedia/savedpages/LoadSavedPageTask.java @@ -10,7 +10,7 @@ private final PageTitle title; public LoadSavedPageTask(Context context, PageTitle title) { - super(ExecutorService.getSingleton().getExecutor(LoadSavedPageTask.class, 1)); + super(1); app = (WikipediaApp) context.getApplicationContext(); this.title = title; } diff --git a/wikipedia/src/main/java/org/wikipedia/savedpages/SavePageTask.java b/wikipedia/src/main/java/org/wikipedia/savedpages/SavePageTask.java index ba6ea0e..8a8f5d6 100644 --- a/wikipedia/src/main/java/org/wikipedia/savedpages/SavePageTask.java +++ b/wikipedia/src/main/java/org/wikipedia/savedpages/SavePageTask.java @@ -5,7 +5,6 @@ import android.util.*; import org.json.*; import org.wikipedia.*; -import org.wikipedia.concurrency.ExecutorService; import org.wikipedia.concurrency.*; import org.wikipedia.page.*; @@ -30,7 +29,7 @@ private CountDownLatch imagesDownloadedLatch; public SavePageTask(Context context, CommunicationBridge bridge, Page page) { - super(ExecutorService.getSingleton().getExecutor(SavePageTask.class, 1)); + super(1); app = (WikipediaApp) context.getApplicationContext(); this.page = page; this.bridge = bridge; diff --git a/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesTask.java b/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesTask.java index e2745a4..1825698 100644 --- a/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesTask.java +++ b/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesTask.java @@ -1,13 +1,11 @@ package org.wikipedia.search; +import android.content.*; import org.json.*; import org.mediawiki.api.json.*; import org.wikipedia.*; -import org.wikipedia.concurrency.*; import java.util.*; - -import android.content.Context; public class SearchArticlesTask extends ApiTask<List<PageTitle>> { private final String prefix; @@ -15,7 +13,7 @@ private final WikipediaApp app; public SearchArticlesTask(Context context, Api api, Site site, String prefix) { - super(ExecutorService.getSingleton().getExecutor(SearchArticlesTask.class, 4), api); + super(4, api); this.prefix = prefix; this.site = site; this.app = (WikipediaApp)context.getApplicationContext(); diff --git a/wikipedia/src/main/java/org/wikipedia/zero/WikipediaZeroTask.java b/wikipedia/src/main/java/org/wikipedia/zero/WikipediaZeroTask.java index 6204908..bc4f43d 100644 --- a/wikipedia/src/main/java/org/wikipedia/zero/WikipediaZeroTask.java +++ b/wikipedia/src/main/java/org/wikipedia/zero/WikipediaZeroTask.java @@ -1,17 +1,16 @@ package org.wikipedia.zero; +import android.content.*; import org.json.*; import org.mediawiki.api.json.*; import org.wikipedia.*; -import org.wikipedia.concurrency.*; -import android.content.Context; public class WikipediaZeroTask extends ApiTask<String> { private Context ctx; public WikipediaZeroTask(Api api, Context context) { - super(ExecutorService.getSingleton().getExecutor(WikipediaZeroTask.class, 1), api); + super(1, api); this.ctx = context; } -- To view, visit https://gerrit.wikimedia.org/r/119642 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: If83e1453c658caa207ebf6e3b6e5631115abee14 Gerrit-PatchSet: 4 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Yuvipanda <yuvipa...@gmail.com> Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits