From e28a10120f9bc75b4ef160f688867c40b83fc43f Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 15 Aug 2021 20:46:28 +0200 Subject: [PATCH] Add some color to the log view --- .../java/eu/faircode/email/AdapterLog.java | 33 +++++++++++++++++-- .../java/eu/faircode/email/EmailService.java | 3 +- .../java/eu/faircode/email/EntityLog.java | 1 + app/src/main/res/layout/item_log.xml | 2 ++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterLog.java b/app/src/main/java/eu/faircode/email/AdapterLog.java index 9fa0523750..9cd1fecd58 100644 --- a/app/src/main/java/eu/faircode/email/AdapterLog.java +++ b/app/src/main/java/eu/faircode/email/AdapterLog.java @@ -20,6 +20,8 @@ package eu.faircode.email; */ import android.content.Context; +import android.text.SpannableStringBuilder; +import android.text.style.ForegroundColorSpan; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -45,6 +47,10 @@ public class AdapterLog extends RecyclerView.Adapter { private LifecycleOwner owner; private LayoutInflater inflater; + private int textColorSecondary; + private int colorAccent; + private int colorWarning; + private List items = new ArrayList<>(); private DateFormat TF; @@ -62,17 +68,40 @@ public class AdapterLog extends RecyclerView.Adapter { private void bindTo(EntityLog log) { tvTime.setText(TF.format(log.time)); - tvData.setText(log.data); + SpannableStringBuilder ssb = new SpannableStringBuilder(log.data); + switch (log.type) { + case EntityLog.LOG_GENERAL: + break; + case EntityLog.LOG_STATS: + ssb.setSpan(new ForegroundColorSpan(colorAccent), 0, ssb.length(), 0); + break; + case EntityLog.LOG_SCHEDULE: + ssb.setSpan(new ForegroundColorSpan(colorWarning), 0, ssb.length(), 0); + break; + case EntityLog.LOG_NETWORK: + ssb.setSpan(new ForegroundColorSpan(colorWarning), 0, ssb.length(), 0); + break; + case EntityLog.LOG_ACCOUNT: + ssb.setSpan(new ForegroundColorSpan(colorAccent), 0, ssb.length(), 0); + break; + case EntityLog.LOG_PROTOCOL: + ssb.setSpan(new ForegroundColorSpan(textColorSecondary), 0, ssb.length(), 0); + break; + } + tvData.setText(ssb); } } - AdapterLog(Fragment parentFragment) { this.parentFragment = parentFragment; this.context = parentFragment.getContext(); this.owner = parentFragment.getViewLifecycleOwner(); this.inflater = LayoutInflater.from(parentFragment.getContext()); + this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary); + this.colorAccent = Helper.resolveColor(context, R.attr.colorAccent); + this.colorWarning = Helper.resolveColor(context, R.attr.colorWarning); + this.TF = Helper.getTimeInstance(context); setHasStableIds(true); diff --git a/app/src/main/java/eu/faircode/email/EmailService.java b/app/src/main/java/eu/faircode/email/EmailService.java index e72f1e6a6c..a742315c0a 100644 --- a/app/src/main/java/eu/faircode/email/EmailService.java +++ b/app/src/main/java/eu/faircode/email/EmailService.java @@ -19,6 +19,7 @@ package eu.faircode.email; Copyright 2018-2021 by Marcel Bokhorst (M66B) */ +import static eu.faircode.email.EntityLog.LOG_PROTOCOL; import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_GMAIL; import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_OAUTH; @@ -576,7 +577,7 @@ public class EmailService implements AutoCloseable { String line = bos.toString(); if (!line.endsWith("ignoring socket timeout")) if (log) - EntityLog.log(context, user + " " + line); + EntityLog.log(context, LOG_PROTOCOL, user + " " + line); else { if (BuildConfig.DEBUG) Log.i("javamail", user + " " + line); diff --git a/app/src/main/java/eu/faircode/email/EntityLog.java b/app/src/main/java/eu/faircode/email/EntityLog.java index 6c3b97ce82..f792ebb0b2 100644 --- a/app/src/main/java/eu/faircode/email/EntityLog.java +++ b/app/src/main/java/eu/faircode/email/EntityLog.java @@ -64,6 +64,7 @@ public class EntityLog { static final int LOG_SCHEDULE = 2; static final int LOG_NETWORK = 3; static final int LOG_ACCOUNT = 4; + static final int LOG_PROTOCOL = 5; private static final ExecutorService executor = Helper.getBackgroundExecutor(1, "log"); diff --git a/app/src/main/res/layout/item_log.xml b/app/src/main/res/layout/item_log.xml index f7a8076783..818047d0b6 100644 --- a/app/src/main/res/layout/item_log.xml +++ b/app/src/main/res/layout/item_log.xml @@ -10,6 +10,7 @@ android:layout_height="wrap_content" android:text="12:34:56" android:textAppearance="@style/TextAppearance.AppCompat.Small" + android:textColor="?android:attr/textColorPrimary" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -20,6 +21,7 @@ android:layout_marginStart="6dp" android:text="log" android:textAppearance="@android:style/TextAppearance.Small" + android:textColor="?android:attr/textColorPrimary" android:textIsSelectable="true" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/tvTime"