From a737d23ba78496213fa9e234b91676c34b520800 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Fri, 31 Aug 2018 08:17:14 -0500 Subject: [PATCH] Report errors to ACRA instead of printing --- .gitignore | 1 + .../com/wbrawner/simplemarkdown/model/MarkdownFile.java | 9 +++++++-- .../presentation/MarkdownPresenterImpl.java | 6 ++++-- .../simplemarkdown/view/activity/ExplorerActivity.java | 3 +++ .../simplemarkdown/view/activity/MainActivity.java | 3 +++ build.gradle | 2 +- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 06c21f0..bf73d9d 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ IAP5Helper/build app/standard app/samsung *~ +*.log diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/model/MarkdownFile.java b/app/src/main/java/com/wbrawner/simplemarkdown/model/MarkdownFile.java index 39952fd..5f6c235 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/model/MarkdownFile.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/model/MarkdownFile.java @@ -2,6 +2,8 @@ package com.wbrawner.simplemarkdown.model; import com.wbrawner.simplemarkdown.utility.Utils; +import org.acra.ACRA; + import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -109,7 +111,7 @@ public class MarkdownFile { this.content = sb.toString(); return true; } catch (IOException e) { - e.printStackTrace(); + ACRA.getErrorReporter().handleException(e, false); return false; } finally { Utils.closeQuietly(reader); @@ -130,6 +132,7 @@ public class MarkdownFile { this.path = markdownFile.getParentFile().getAbsolutePath(); return load(new FileInputStream(markdownFile)); } catch (FileNotFoundException e) { + ACRA.getErrorReporter().handleException(e, false); return false; } } @@ -150,7 +153,7 @@ public class MarkdownFile { return false; } } catch (IOException e) { - e.printStackTrace(); + ACRA.getErrorReporter().handleException(e, false); return false; } } @@ -166,12 +169,14 @@ public class MarkdownFile { ); writer.write(this.content); } catch (IOException e) { + ACRA.getErrorReporter().handleException(e, false); return false; } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { + ACRA.getErrorReporter().handleException(e, false); // closing the reader failed } } diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenterImpl.java b/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenterImpl.java index 51281f7..6319739 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenterImpl.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenterImpl.java @@ -12,6 +12,8 @@ import com.wbrawner.simplemarkdown.utility.Utils; import com.wbrawner.simplemarkdown.view.MarkdownEditView; import com.wbrawner.simplemarkdown.view.MarkdownPreviewView; +import org.acra.ACRA; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -52,8 +54,7 @@ public class MarkdownPresenterImpl implements MarkdownPresenter { InputStream in = new FileInputStream(file); loadMarkdown(file.getName(), in); } catch (FileNotFoundException e) { - System.err.println(e.getLocalizedMessage()); - e.printStackTrace(); + ACRA.getErrorReporter().handleException(e, false); } } @@ -206,6 +207,7 @@ public class MarkdownPresenterImpl implements MarkdownPresenter { } loadMarkdown(fileName, in); } catch (Exception e) { + ACRA.getErrorReporter().handleException(e, false); if (editView != null) { editView.onFileLoaded(false); } diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/ExplorerActivity.java b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/ExplorerActivity.java index a979a25..c939206 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/ExplorerActivity.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/ExplorerActivity.java @@ -19,6 +19,8 @@ import com.wbrawner.simplemarkdown.R; import com.wbrawner.simplemarkdown.utility.Constants; import com.wbrawner.simplemarkdown.utility.Utils; +import org.acra.ACRA; + import java.io.File; import java.util.ArrayList; import java.util.HashMap; @@ -117,6 +119,7 @@ public class ExplorerActivity extends AppCompatActivity { try { sdcardSelected = filePath.get().contains(mounts[1].getAbsolutePath()); } catch (NullPointerException e) { + ACRA.getErrorReporter().handleException(e, false); updateListView(); menu.findItem(R.id.action_use_sdcard).setVisible(false); // TODO: Report this? diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.java b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.java index 83f68ac..9ac4b0f 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.java @@ -24,6 +24,8 @@ import com.wbrawner.simplemarkdown.utility.Utils; import com.wbrawner.simplemarkdown.view.DisableableViewPager; import com.wbrawner.simplemarkdown.view.adapter.EditPagerAdapter; +import org.acra.ACRA; + import java.io.File; import java.io.InputStream; @@ -164,6 +166,7 @@ public class MainActivity extends AppCompatActivity } }); } catch (Exception e) { + ACRA.getErrorReporter().handleException(e, false); Toast.makeText(MainActivity.this, R.string.file_load_error, Toast.LENGTH_SHORT).show(); } } diff --git a/build.gradle b/build.gradle index 19f6500..25063b7 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.android.tools.build:gradle:3.1.4' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }