Add some color to the log view

This commit is contained in:
M66B 2021-08-15 20:46:28 +02:00
parent b8bddfedbf
commit e28a10120f
4 changed files with 36 additions and 3 deletions

View File

@ -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<AdapterLog.ViewHolder> {
private LifecycleOwner owner;
private LayoutInflater inflater;
private int textColorSecondary;
private int colorAccent;
private int colorWarning;
private List<EntityLog> items = new ArrayList<>();
private DateFormat TF;
@ -62,17 +68,40 @@ public class AdapterLog extends RecyclerView.Adapter<AdapterLog.ViewHolder> {
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);

View File

@ -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);

View File

@ -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");

View File

@ -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"