Browse Source

use thread pool executor on most async tasks

pull/61/merge
oogee 6 years ago
parent
commit
3bda253ec4
  1. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  2. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java
  3. 8
      app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java
  4. 5
      app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java
  5. 10
      app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java
  6. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java
  7. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java
  8. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java
  9. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java
  10. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java
  11. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
  12. 2
      app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java
  13. 16
      app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java

2
app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java

@ -149,7 +149,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
});
boardTask = new BoardTask();
boardTask.execute(boardUrl);
boardTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, boardUrl);
}
@Override

6
app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java

@ -118,7 +118,7 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.
// uploadFAB.hide();
parseDownloadPageTask = new ParseDownloadPageTask();
parseDownloadPageTask.execute(downloadsUrl);
parseDownloadPageTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, downloadsUrl);
}
// @Override
@ -154,9 +154,9 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.
//Load data
parseDownloadPageTask = new ParseDownloadPageTask();
if (downloadsUrl.contains("tpstart"))
parseDownloadPageTask.execute(downloadsUrl.substring(0
parseDownloadPageTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, downloadsUrl.substring(0
, downloadsUrl.lastIndexOf(";tpstart=")) + ";tpstart=" + pagesLoaded * 10);
else parseDownloadPageTask.execute(downloadsUrl + ";tpstart=" + pagesLoaded * 10);
else parseDownloadPageTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, downloadsUrl + ";tpstart=" + pagesLoaded * 10);
}
}

8
app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java

@ -90,7 +90,7 @@ public class ForumFragment extends BaseFragment {
super.onActivityCreated(savedInstanceState);
if (categories.isEmpty()) {
forumTask = new ForumTask(this::onForumTaskStarted, this::onForumTaskFinished);
forumTask.execute();
forumTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Timber.d("onActivityCreated");
@ -114,7 +114,7 @@ public class ForumFragment extends BaseFragment {
forumTask.cancel(true);
forumTask = new ForumTask(ForumFragment.this::onForumTaskStarted, ForumFragment.this::onForumTaskFinished);
forumTask.setUrl(categories.get(parentPosition).getCategoryURL());
forumTask.execute();
forumTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
@ -125,7 +125,7 @@ public class ForumFragment extends BaseFragment {
forumTask.cancel(true);
forumTask = new ForumTask(ForumFragment.this::onForumTaskStarted, ForumFragment.this::onForumTaskFinished);
forumTask.setUrl(categories.get(parentPosition).getCategoryURL());
forumTask.execute();
forumTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
});
@ -145,7 +145,7 @@ public class ForumFragment extends BaseFragment {
if (forumTask != null && forumTask.getStatus() != AsyncTask.Status.RUNNING) {
forumTask = new ForumTask(ForumFragment.this::onForumTaskStarted, ForumFragment.this::onForumTaskFinished);
//forumTask.execute(SessionManager.indexUrl.toString());
forumTask.execute();
forumTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
);

5
app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java

@ -1,5 +1,6 @@
package gr.thmmy.mthmmy.activities.main.recent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -81,7 +82,7 @@ public class RecentFragment extends BaseFragment {
super.onActivityCreated(savedInstanceState);
if (topicSummaries.isEmpty()) {
recentTask = new RecentTask(this::onRecentTaskStarted, this::onRecentTaskFinished);
recentTask.execute(SessionManager.indexUrl.toString());
recentTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.indexUrl.toString());
}
Timber.d("onActivityCreated");
@ -113,7 +114,7 @@ public class RecentFragment extends BaseFragment {
swipeRefreshLayout.setOnRefreshListener(() -> {
if (!recentTask.isRunning()) {
recentTask = new RecentTask(this::onRecentTaskStarted, this::onRecentTaskFinished);
recentTask.execute(SessionManager.indexUrl.toString());
recentTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.indexUrl.toString());
}
}
);

10
app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java

@ -88,7 +88,7 @@ public class UnreadFragment extends BaseFragment {
if (topicSummaries.isEmpty()) {
unreadTask = new UnreadTask(this::onUnreadTaskStarted, this::onUnreadTaskFinished);
assert SessionManager.unreadUrl != null;
unreadTask.execute(SessionManager.unreadUrl.toString());
unreadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.unreadUrl.toString());
}
markReadTask = new MarkReadTask();
Timber.d("onActivityCreated");
@ -108,7 +108,7 @@ public class UnreadFragment extends BaseFragment {
fragmentInteractionListener, markReadLinkUrl -> {
if (!markReadTask.isRunning() && !unreadTask.isRunning()) {
markReadTask = new MarkReadTask();
markReadTask.execute(markReadLinkUrl);
markReadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, markReadLinkUrl);
}
});
@ -130,7 +130,7 @@ public class UnreadFragment extends BaseFragment {
loadedPages = 0;
unreadTask = new UnreadTask(this::onUnreadTaskStarted, this::onUnreadTaskFinished);
assert SessionManager.unreadUrl != null;
unreadTask.execute(SessionManager.unreadUrl.toString());
unreadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.unreadUrl.toString());
}
}
);
@ -171,7 +171,7 @@ public class UnreadFragment extends BaseFragment {
if (loadedPages < numberOfPages) {
unreadTask = new UnreadTask(this::onUnreadTaskStarted, this::onUnreadTaskFinished);
assert SessionManager.unreadUrl != null;
unreadTask.execute(SessionManager.unreadUrl.toString() + ";start=" + loadedPages * 20);
unreadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.unreadUrl.toString() + ";start=" + loadedPages * 20);
}
else {
progressBar.setVisibility(ProgressBar.INVISIBLE);
@ -306,7 +306,7 @@ public class UnreadFragment extends BaseFragment {
loadedPages = 0;
unreadTask = new UnreadTask(UnreadFragment.this::onUnreadTaskStarted, UnreadFragment.this::onUnreadTaskFinished);
assert SessionManager.unreadUrl != null;
unreadTask.execute(SessionManager.unreadUrl.toString());
unreadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.unreadUrl.toString());
}
}
}

2
app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java

@ -187,7 +187,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
}
profileTask = new ProfileTask();
profileTask.execute(profileUrl + ";wap"); //Attempts data parsing
profileTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, profileUrl + ";wap"); //Attempts data parsing
}
@Override

4
app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java

@ -122,7 +122,7 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap
//Load data
profileLatestPostsTask = new LatestPostsTask();
profileLatestPostsTask.execute(profileUrl + ";sa=showPosts;start=" + pagesLoaded * 15);
profileLatestPostsTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, profileUrl + ";sa=showPosts;start=" + pagesLoaded * 15);
++pagesLoaded;
}
}
@ -132,7 +132,7 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap
super.onActivityCreated(savedInstanceState);
if (parsedTopicSummaries.isEmpty() && userHasPosts) {
profileLatestPostsTask = new LatestPostsTask();
profileLatestPostsTask.execute(profileUrl + ";sa=showPosts");
profileLatestPostsTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, profileUrl + ";sa=showPosts");
pagesLoaded = 1;
}
}

2
app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java

@ -105,7 +105,7 @@ public class StatsFragment extends Fragment {
super.onActivityCreated(savedInstanceState);
if (!haveParsed) {
profileStatsTask = new ProfileStatsTask();
profileStatsTask.execute(profileUrl + ";sa=statPanel");
profileStatsTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, profileUrl + ";sa=statPanel");
}
Timber.d("onActivityCreated");
}

2
app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java

@ -90,7 +90,7 @@ public class SummaryFragment extends Fragment {
super.onActivityCreated(savedInstanceState);
if (parsedProfileSummaryData.isEmpty()) {
summaryTask = new SummaryTask();
summaryTask.execute(profileSummaryDocument);
summaryTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, profileSummaryDocument);
}
Timber.d("onActivityCreated");
}

3
app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java

@ -1,6 +1,7 @@
package gr.thmmy.mthmmy.activities.shoutbox;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
@ -137,7 +138,7 @@ public class ShoutboxFragment extends Fragment {
Timber.i("Shout was sent successfully");
editorView.getEditText().getText().clear();
shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished);
shoutboxTask.execute(SessionManager.shoutboxUrl.toString());
shoutboxTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.shoutboxUrl.toString());
} else if (resultCode == NetworkResultCodes.NETWORK_ERROR) {
Timber.w("Failed to send shout");
Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show();

2
app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java

@ -332,7 +332,7 @@ public class UploadActivity extends BaseActivity {
if (uploadRootCategories.isEmpty()) {
//Parses the uploads page
parseUploadPageTask = new ParseUploadPageTask();
parseUploadPageTask.execute(uploadIndexUrl);
parseUploadPageTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, uploadIndexUrl);
} else {
//Renders the already parsed data
updateUIElements();

2
app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java

@ -21,7 +21,7 @@ public class ShoutboxViewModel extends ViewModel {
if (shoutboxTask != null && shoutboxTask.getStatus() == AsyncTask.Status.RUNNING)
shoutboxTask.cancel(true);
shoutboxTask = new ShoutboxTask(onShoutboxTaskStarted, onShoutboxTaskFinished);
shoutboxTask.execute(SessionManager.shoutboxUrl.toString());
shoutboxTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, SessionManager.shoutboxUrl.toString());
}
public void sendShout(String shout) {

16
app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java

@ -95,7 +95,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
stopLoading();
topicUrl = pageUrl;
currentTopicTask = new TopicTask(topicTaskObserver, this);
currentTopicTask.execute(pageUrl);
currentTopicTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, pageUrl);
}
public void reloadPage() {
@ -122,7 +122,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
TopicViewModel.this.onTopicTaskCompleted(result);
runnable.run();
});
currentTopicTask.execute(ParseHelpers.getBaseURL(topicUrl) + "." + String.valueOf(currentPageIndex * 15));
currentTopicTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ParseHelpers.getBaseURL(topicUrl) + "." + String.valueOf(currentPageIndex * 15));
}
public void loadPageIndicated() {
@ -158,7 +158,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
SubmitVoteTask submitVoteTask = new SubmitVoteTask(votesArray);
submitVoteTask.setOnTaskStartedListener(voteTaskStartedListener);
submitVoteTask.setOnNetworkTaskFinishedListener(voteTaskFinishedListener);
submitVoteTask.execute(poll.getPollFormUrl(), poll.getSc());
submitVoteTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, poll.getPollFormUrl(), poll.getSc());
return true;
}
@ -167,7 +167,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
RemoveVoteTask removeVoteTask = new RemoveVoteTask();
removeVoteTask.setOnTaskStartedListener(removeVoteTaskStartedListener);
removeVoteTask.setOnNetworkTaskFinishedListener(removeVoteTaskFinishedListener);
removeVoteTask.execute(((Poll) topicItems.getValue().get(0)).getRemoveVoteUrl());
removeVoteTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ((Poll) topicItems.getValue().get(0)).getRemoveVoteUrl());
}
public void prepareForReply() {
@ -194,13 +194,13 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
}
toQuoteList.clear();
Timber.i("Posting reply");
new ReplyTask(replyFinishListener, includeAppSignature).execute(subject, reply,
new ReplyTask(replyFinishListener, includeAppSignature).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, subject, reply,
replyForm.getNumReplies(), replyForm.getSeqnum(), replyForm.getSc(), replyForm.getTopic());
}
public void deletePost(String postDeleteUrl) {
Timber.i("Deleting post");
new DeleteTask(deleteTaskStartedListener, deleteTaskFinishedListener).execute(postDeleteUrl);
new DeleteTask(deleteTaskStartedListener, deleteTaskFinishedListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, postDeleteUrl);
}
public void prepareForEdit(int position, String postEditURL) {
@ -210,7 +210,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
Timber.i("Preparing for edit");
currentPrepareForEditTask = new PrepareForEditTask(prepareForEditCallbacks, this, position,
replyPageUrl.getValue());
currentPrepareForEditTask.execute(postEditURL);
currentPrepareForEditTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, postEditURL);
}
public void editPost(int position, String subject, String message) {
@ -218,7 +218,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
throw new NullPointerException("Edit preparation was not found!");
PrepareForEditResult editResult = prepareForEditResult.getValue();
Timber.i("Editing post");
new EditTask(editTaskCallbacks, position).execute(editResult.getCommitEditUrl(), message,
new EditTask(editTaskCallbacks, position).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, editResult.getCommitEditUrl(), message,
editResult.getNumReplies(), editResult.getSeqnum(), editResult.getSc(), subject, editResult.getTopic());
}

Loading…
Cancel
Save