Filter logging on background

This commit is contained in:
M66B 2021-09-29 09:07:34 +02:00
parent 47d757066d
commit 0e278dc566
1 changed files with 49 additions and 30 deletions

View File

@ -20,6 +20,7 @@ package eu.faircode.email;
*/
import android.content.Context;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
@ -41,6 +42,7 @@ import androidx.recyclerview.widget.RecyclerView;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
public class AdapterLog extends RecyclerView.Adapter<AdapterLog.ViewHolder> {
private Fragment parentFragment;
@ -67,6 +69,9 @@ public class AdapterLog extends RecyclerView.Adapter<AdapterLog.ViewHolder> {
private DateFormat TF;
private static final ExecutorService executor =
Helper.getBackgroundExecutor(1, "contacts");
public class ViewHolder extends RecyclerView.ViewHolder {
private TextView tvTime;
private TextView tvData;
@ -154,8 +159,11 @@ public class AdapterLog extends RecyclerView.Adapter<AdapterLog.ViewHolder> {
this.message = message;
this.types = types;
new SimpleTask<List<EntityLog>>() {
@Override
protected List<EntityLog> onExecute(Context context, Bundle args) throws Throwable {
List<EntityLog> items = new ArrayList<>();
for (EntityLog log : all)
for (EntityLog log : logs)
if (account == null && folder == null && message == null) {
if (types.contains(log.type))
items.add(log);
@ -165,10 +173,14 @@ public class AdapterLog extends RecyclerView.Adapter<AdapterLog.ViewHolder> {
(message == null || message.equals(log.message)))
items.add(log);
}
return items;
}
@Override
protected void onExecuted(Bundle args, List<EntityLog> items) {
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(selected, items), false);
this.selected = items;
selected = items;
diff.dispatchUpdatesTo(new ListUpdateCallback() {
@Override
@ -191,7 +203,14 @@ public class AdapterLog extends RecyclerView.Adapter<AdapterLog.ViewHolder> {
Log.d("Changed @" + position + " #" + count);
}
});
diff.dispatchUpdatesTo(this);
diff.dispatchUpdatesTo(AdapterLog.this);
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.setExecutor(executor).execute(context, owner, new Bundle(), "logs:filter");
}
public void setTypes(@NonNull List<EntityLog.Type> types) {