mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-18 21:28:54 +00:00
Skip counting body tasks
This commit is contained in:
parent
c4d6f7a89f
commit
28de9b2b27
2 changed files with 16 additions and 8 deletions
|
@ -1945,7 +1945,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||||
args.putBoolean("show_images", show_images);
|
args.putBoolean("show_images", show_images);
|
||||||
args.putBoolean("show_quotes", show_quotes);
|
args.putBoolean("show_quotes", show_quotes);
|
||||||
args.putInt("zoom", zoom);
|
args.putInt("zoom", zoom);
|
||||||
bodyTask.execute(context, owner, args, "message:body");
|
bodyTask.setCount(false).execute(context, owner, args, "message:body");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,9 @@ import java.util.concurrent.Executors;
|
||||||
// Results will not be delivered to destroyed fragments
|
// Results will not be delivered to destroyed fragments
|
||||||
|
|
||||||
public abstract class SimpleTask<T> implements LifecycleObserver {
|
public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
|
private boolean count = true;
|
||||||
|
private int executing = 0;
|
||||||
|
|
||||||
private static final List<SimpleTask> tasks = new ArrayList<>();
|
private static final List<SimpleTask> tasks = new ArrayList<>();
|
||||||
|
|
||||||
private static final ExecutorService executor = Executors.newFixedThreadPool(
|
private static final ExecutorService executor = Executors.newFixedThreadPool(
|
||||||
|
@ -51,6 +54,11 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
|
|
||||||
static final String ACTION_TASK_COUNT = BuildConfig.APPLICATION_ID + ".ACTION_TASK_COUNT";
|
static final String ACTION_TASK_COUNT = BuildConfig.APPLICATION_ID + ".ACTION_TASK_COUNT";
|
||||||
|
|
||||||
|
public SimpleTask<T> setCount(boolean count) {
|
||||||
|
this.count = count;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public void execute(Context context, LifecycleOwner owner, @NonNull Bundle args, @NonNull String name) {
|
public void execute(Context context, LifecycleOwner owner, @NonNull Bundle args, @NonNull String name) {
|
||||||
run(context, owner, args, name);
|
run(context, owner, args, name);
|
||||||
}
|
}
|
||||||
|
@ -75,14 +83,14 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
final Handler handler = new Handler();
|
final Handler handler = new Handler();
|
||||||
|
|
||||||
// prevent garbage collection
|
// prevent garbage collection
|
||||||
int count;
|
|
||||||
synchronized (tasks) {
|
synchronized (tasks) {
|
||||||
tasks.add(this);
|
tasks.add(this);
|
||||||
count = tasks.size();
|
if (count)
|
||||||
|
executing++;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
||||||
lbm.sendBroadcast(new Intent(ACTION_TASK_COUNT).putExtra("count", count));
|
lbm.sendBroadcast(new Intent(ACTION_TASK_COUNT).putExtra("count", executing));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
onPreExecute(args);
|
onPreExecute(args);
|
||||||
|
@ -164,15 +172,15 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanup(Context context) {
|
private void cleanup(Context context) {
|
||||||
int count;
|
|
||||||
synchronized (tasks) {
|
synchronized (tasks) {
|
||||||
tasks.remove(this);
|
tasks.remove(this);
|
||||||
count = tasks.size();
|
if (count)
|
||||||
|
executing--;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
||||||
lbm.sendBroadcast(new Intent(ACTION_TASK_COUNT).putExtra("count", count));
|
lbm.sendBroadcast(new Intent(ACTION_TASK_COUNT).putExtra("count", executing));
|
||||||
Log.i("Remaining tasks=" + count);
|
Log.i("Remaining tasks=" + tasks.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onPreExecute(Bundle args) {
|
protected void onPreExecute(Bundle args) {
|
||||||
|
|
Loading…
Reference in a new issue