mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-01 12:44:42 +00:00
Filter logging on background
This commit is contained in:
parent
47d757066d
commit
0e278dc566
1 changed files with 49 additions and 30 deletions
|
@ -20,6 +20,7 @@ package eu.faircode.email;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.style.ForegroundColorSpan;
|
import android.text.style.ForegroundColorSpan;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -41,6 +42,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
public class AdapterLog extends RecyclerView.Adapter<AdapterLog.ViewHolder> {
|
public class AdapterLog extends RecyclerView.Adapter<AdapterLog.ViewHolder> {
|
||||||
private Fragment parentFragment;
|
private Fragment parentFragment;
|
||||||
|
@ -67,6 +69,9 @@ public class AdapterLog extends RecyclerView.Adapter<AdapterLog.ViewHolder> {
|
||||||
|
|
||||||
private DateFormat TF;
|
private DateFormat TF;
|
||||||
|
|
||||||
|
private static final ExecutorService executor =
|
||||||
|
Helper.getBackgroundExecutor(1, "contacts");
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
private TextView tvTime;
|
private TextView tvTime;
|
||||||
private TextView tvData;
|
private TextView tvData;
|
||||||
|
@ -154,44 +159,58 @@ public class AdapterLog extends RecyclerView.Adapter<AdapterLog.ViewHolder> {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.types = types;
|
this.types = types;
|
||||||
|
|
||||||
List<EntityLog> items = new ArrayList<>();
|
new SimpleTask<List<EntityLog>>() {
|
||||||
for (EntityLog log : all)
|
|
||||||
if (account == null && folder == null && message == null) {
|
|
||||||
if (types.contains(log.type))
|
|
||||||
items.add(log);
|
|
||||||
} else {
|
|
||||||
if ((account == null || account.equals(log.account)) &&
|
|
||||||
(folder == null || folder.equals(log.folder)) &&
|
|
||||||
(message == null || message.equals(log.message)))
|
|
||||||
items.add(log);
|
|
||||||
}
|
|
||||||
|
|
||||||
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(selected, items), false);
|
|
||||||
|
|
||||||
this.selected = items;
|
|
||||||
|
|
||||||
diff.dispatchUpdatesTo(new ListUpdateCallback() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onInserted(int position, int count) {
|
protected List<EntityLog> onExecute(Context context, Bundle args) throws Throwable {
|
||||||
Log.d("Inserted @" + position + " #" + count);
|
List<EntityLog> items = new ArrayList<>();
|
||||||
|
for (EntityLog log : logs)
|
||||||
|
if (account == null && folder == null && message == null) {
|
||||||
|
if (types.contains(log.type))
|
||||||
|
items.add(log);
|
||||||
|
} else {
|
||||||
|
if ((account == null || account.equals(log.account)) &&
|
||||||
|
(folder == null || folder.equals(log.folder)) &&
|
||||||
|
(message == null || message.equals(log.message)))
|
||||||
|
items.add(log);
|
||||||
|
}
|
||||||
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRemoved(int position, int count) {
|
protected void onExecuted(Bundle args, List<EntityLog> items) {
|
||||||
Log.d("Removed @" + position + " #" + count);
|
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(selected, items), false);
|
||||||
|
|
||||||
|
selected = items;
|
||||||
|
|
||||||
|
diff.dispatchUpdatesTo(new ListUpdateCallback() {
|
||||||
|
@Override
|
||||||
|
public void onInserted(int position, int count) {
|
||||||
|
Log.d("Inserted @" + position + " #" + count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRemoved(int position, int count) {
|
||||||
|
Log.d("Removed @" + position + " #" + count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMoved(int fromPosition, int toPosition) {
|
||||||
|
Log.d("Moved " + fromPosition + ">" + toPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChanged(int position, int count, Object payload) {
|
||||||
|
Log.d("Changed @" + position + " #" + count);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
diff.dispatchUpdatesTo(AdapterLog.this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMoved(int fromPosition, int toPosition) {
|
protected void onException(Bundle args, Throwable ex) {
|
||||||
Log.d("Moved " + fromPosition + ">" + toPosition);
|
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
||||||
}
|
}
|
||||||
|
}.setExecutor(executor).execute(context, owner, new Bundle(), "logs:filter");
|
||||||
@Override
|
|
||||||
public void onChanged(int position, int count, Object payload) {
|
|
||||||
Log.d("Changed @" + position + " #" + count);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
diff.dispatchUpdatesTo(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTypes(@NonNull List<EntityLog.Type> types) {
|
public void setTypes(@NonNull List<EntityLog.Type> types) {
|
||||||
|
|
Loading…
Reference in a new issue