From 83995877cf089a355be76ed5757838048c72b754 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 12 Aug 2019 13:07:14 +0200 Subject: [PATCH] Refactoring --- app/src/main/java/eu/faircode/email/ActivityBase.java | 5 +---- app/src/main/java/eu/faircode/email/Core.java | 8 +++----- app/src/main/java/eu/faircode/email/FragmentBase.java | 5 +---- app/src/main/java/eu/faircode/email/FragmentCompose.java | 6 ++---- app/src/main/java/eu/faircode/email/Log.java | 5 +++++ app/src/main/java/eu/faircode/email/MailService.java | 4 +--- app/src/main/java/eu/faircode/email/ServiceBase.java | 9 +++------ app/src/main/java/eu/faircode/email/ServiceSend.java | 5 +---- .../main/java/eu/faircode/email/ServiceSynchronize.java | 4 +--- 9 files changed, 18 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityBase.java b/app/src/main/java/eu/faircode/email/ActivityBase.java index f5e8e62092..d474792d3b 100644 --- a/app/src/main/java/eu/faircode/email/ActivityBase.java +++ b/app/src/main/java/eu/faircode/email/ActivityBase.java @@ -35,9 +35,6 @@ import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.PreferenceManager; -import com.bugsnag.android.BreadcrumbType; -import com.bugsnag.android.Bugsnag; - import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -102,7 +99,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc crumb.put("name", this.getClass().getName()); crumb.put("before", Integer.toString(before)); crumb.put("after", Integer.toString(after)); - Bugsnag.leaveBreadcrumb("onSaveInstanceState", BreadcrumbType.LOG, crumb); + Log.breadcrumb("onSaveInstanceState", crumb); for (String key : outState.keySet()) Log.i("Saved " + this + " " + key + "=" + outState.get(key)); diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index a6148984c3..0d800ceccd 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -37,8 +37,6 @@ import androidx.annotation.NonNull; import androidx.core.app.NotificationCompat; import androidx.preference.PreferenceManager; -import com.bugsnag.android.BreadcrumbType; -import com.bugsnag.android.Bugsnag; import com.sun.mail.iap.BadCommandException; import com.sun.mail.iap.CommandFailedException; import com.sun.mail.iap.ConnectionException; @@ -149,7 +147,7 @@ class Core { if (op.message != null) crumb.put("message", Long.toString(op.message)); crumb.put("free", Integer.toString(Log.getFreeMemMb())); - Bugsnag.leaveBreadcrumb("operation", BreadcrumbType.LOG, crumb); + Log.breadcrumb("operation", crumb); // Fetch most recent copy of message EntityMessage message = null; @@ -1238,7 +1236,7 @@ class Core { crumb.put("start", Integer.toString(from)); crumb.put("end", Integer.toString(i)); crumb.put("free", Integer.toString(free)); - Bugsnag.leaveBreadcrumb("sync", BreadcrumbType.LOG, crumb); + Log.breadcrumb("sync", crumb); Log.i("Sync " + from + ".." + i + " free=" + free); for (int j = isub.length - 1; j >= 0 && state.running() && state.recoverable(); j--) @@ -1317,7 +1315,7 @@ class Core { crumb.put("start", Integer.toString(from)); crumb.put("end", Integer.toString(i)); crumb.put("free", Integer.toString(free)); - Bugsnag.leaveBreadcrumb("download", BreadcrumbType.LOG, crumb); + Log.breadcrumb("download", crumb); Log.i("Download " + from + ".." + i + " free=" + free); for (int j = isub.length - 1; j >= 0 && state.running() && state.recoverable(); j--) diff --git a/app/src/main/java/eu/faircode/email/FragmentBase.java b/app/src/main/java/eu/faircode/email/FragmentBase.java index 7759a1356c..bcb3e91406 100644 --- a/app/src/main/java/eu/faircode/email/FragmentBase.java +++ b/app/src/main/java/eu/faircode/email/FragmentBase.java @@ -34,9 +34,6 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.lifecycle.Lifecycle; -import com.bugsnag.android.BreadcrumbType; -import com.bugsnag.android.Bugsnag; - import java.util.HashMap; import java.util.Map; @@ -91,7 +88,7 @@ public class FragmentBase extends Fragment { Object value = outState.get(key); crumb.put(key, value == null ? "" : value.getClass().getName()); } - Bugsnag.leaveBreadcrumb("onSaveInstanceState", BreadcrumbType.LOG, crumb); + Log.breadcrumb("onSaveInstanceState", crumb); for (String key : outState.keySet()) Log.i("Saved " + this + " " + key + "=" + outState.get(key)); diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index e7e157db32..49ae88f526 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -104,8 +104,6 @@ import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import com.bugsnag.android.BreadcrumbType; -import com.bugsnag.android.Bugsnag; import com.google.android.material.bottomnavigation.BottomNavigationView; import com.google.android.material.bottomnavigation.LabelVisibilityMode; import com.google.android.material.snackbar.Snackbar; @@ -1956,7 +1954,7 @@ public class FragmentCompose extends FragmentBase { crumb.put("draft", Long.toString(id)); crumb.put("reference", Long.toString(reference)); crumb.put("action", action); - Bugsnag.leaveBreadcrumb("compose", BreadcrumbType.LOG, crumb); + Log.breadcrumb("compose", crumb); EntityMessage draft; @@ -2528,7 +2526,7 @@ public class FragmentCompose extends FragmentBase { crumb.put("content", Boolean.toString(draft.content)); crumb.put("file", Boolean.toString(draft.getFile(context).exists())); crumb.put("action", getActionName(action)); - Bugsnag.leaveBreadcrumb("compose", BreadcrumbType.LOG, crumb); + Log.breadcrumb("compose", crumb); List attachments = db.attachment().getAttachments(draft.id); diff --git a/app/src/main/java/eu/faircode/email/Log.java b/app/src/main/java/eu/faircode/email/Log.java index b53df70849..2a0fe782bd 100644 --- a/app/src/main/java/eu/faircode/email/Log.java +++ b/app/src/main/java/eu/faircode/email/Log.java @@ -39,6 +39,7 @@ import android.view.WindowManager; import androidx.preference.PreferenceManager; +import com.bugsnag.android.BreadcrumbType; import com.bugsnag.android.Bugsnag; import com.bugsnag.android.Severity; @@ -117,6 +118,10 @@ public class Log { return android.util.Log.e(TAG, prefix + " " + ex + "\n" + android.util.Log.getStackTraceString(ex)); } + static void breadcrumb(String name, Map crumb) { + Bugsnag.leaveBreadcrumb("operation", BreadcrumbType.LOG, crumb); + } + static void logExtras(Intent intent) { if (intent != null) logBundle(intent.getExtras()); diff --git a/app/src/main/java/eu/faircode/email/MailService.java b/app/src/main/java/eu/faircode/email/MailService.java index 5af2245944..67930b86c2 100644 --- a/app/src/main/java/eu/faircode/email/MailService.java +++ b/app/src/main/java/eu/faircode/email/MailService.java @@ -2,8 +2,6 @@ package eu.faircode.email; import android.content.Context; -import com.bugsnag.android.BreadcrumbType; -import com.bugsnag.android.Bugsnag; import com.sun.mail.imap.IMAPStore; import com.sun.mail.smtp.SMTPTransport; import com.sun.mail.util.MailConnectException; @@ -185,7 +183,7 @@ public class MailService implements AutoCloseable { crumb.put(key, sid.get(key)); EntityLog.log(context, "Server " + key + "=" + sid.get(key)); } - Bugsnag.leaveBreadcrumb("server", BreadcrumbType.LOG, crumb); + Log.breadcrumb("server", crumb); } } catch (MessagingException ex) { Log.w(ex); diff --git a/app/src/main/java/eu/faircode/email/ServiceBase.java b/app/src/main/java/eu/faircode/email/ServiceBase.java index 577b830688..5ddaca69d4 100644 --- a/app/src/main/java/eu/faircode/email/ServiceBase.java +++ b/app/src/main/java/eu/faircode/email/ServiceBase.java @@ -24,9 +24,6 @@ import android.os.Bundle; import androidx.lifecycle.LifecycleService; -import com.bugsnag.android.BreadcrumbType; -import com.bugsnag.android.Bugsnag; - import java.util.HashMap; import java.util.Map; @@ -35,7 +32,7 @@ abstract class ServiceBase extends LifecycleService { public void onCreate() { Map crumb = new HashMap<>(); crumb.put("state", "create"); - Bugsnag.leaveBreadcrumb(this.getClass().getSimpleName(), BreadcrumbType.STATE, crumb); + Log.breadcrumb(this.getClass().getSimpleName(), crumb); super.onCreate(); } @@ -52,7 +49,7 @@ abstract class ServiceBase extends LifecycleService { crumb.put(key, value == null ? null : value.toString()); } } - Bugsnag.leaveBreadcrumb(this.getClass().getSimpleName(), BreadcrumbType.LOG, crumb); + Log.breadcrumb(this.getClass().getSimpleName(), crumb); return super.onStartCommand(intent, flags, startId); } @@ -61,7 +58,7 @@ abstract class ServiceBase extends LifecycleService { public void onDestroy() { Map crumb = new HashMap<>(); crumb.put("state", "destroy"); - Bugsnag.leaveBreadcrumb(this.getClass().getSimpleName(), BreadcrumbType.STATE, crumb); + Log.breadcrumb(this.getClass().getSimpleName(), crumb); super.onDestroy(); } diff --git a/app/src/main/java/eu/faircode/email/ServiceSend.java b/app/src/main/java/eu/faircode/email/ServiceSend.java index e9aa9a63ac..f6dbf074f3 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSend.java +++ b/app/src/main/java/eu/faircode/email/ServiceSend.java @@ -36,9 +36,6 @@ import androidx.core.content.ContextCompat; import androidx.lifecycle.Observer; import androidx.preference.PreferenceManager; -import com.bugsnag.android.BreadcrumbType; -import com.bugsnag.android.Bugsnag; - import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; @@ -144,7 +141,7 @@ public class ServiceSend extends ServiceBase { if (op.message != null) crumb.put("message", Long.toString(op.message)); crumb.put("free", Integer.toString(Log.getFreeMemMb())); - Bugsnag.leaveBreadcrumb("operation", BreadcrumbType.LOG, crumb); + Log.breadcrumb("operation", crumb); switch (op.name) { case EntityOperation.SYNC: diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index f4a6b860fc..e502354d78 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -42,8 +42,6 @@ import androidx.core.content.ContextCompat; import androidx.lifecycle.Observer; import androidx.preference.PreferenceManager; -import com.bugsnag.android.BreadcrumbType; -import com.bugsnag.android.Bugsnag; import com.sun.mail.imap.IMAPFolder; import com.sun.mail.imap.IMAPMessage; @@ -445,7 +443,7 @@ public class ServiceSynchronize extends ServiceBase { crumb.put("unmetered", Boolean.toString(networkState.isUnmetered())); crumb.put("roaming", Boolean.toString(networkState.isRoaming())); crumb.put("lastLost", new Date(lastLost).toString()); - Bugsnag.leaveBreadcrumb("reload", BreadcrumbType.LOG, crumb); + Log.breadcrumb("reload", crumb); if (doStop) stop();