diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/activities/common')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt b/app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt index 82ecc9d..2bdbcca 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt | |||
@@ -19,17 +19,20 @@ | |||
19 | package org.pacien.tincapp.activities.common | 19 | package org.pacien.tincapp.activities.common |
20 | 20 | ||
21 | import android.support.v7.app.AlertDialog | 21 | import android.support.v7.app.AlertDialog |
22 | import org.apache.commons.io.input.ReversedLinesFileReader | ||
22 | import org.pacien.tincapp.R | 23 | import org.pacien.tincapp.R |
23 | import org.pacien.tincapp.activities.BaseActivity | 24 | import org.pacien.tincapp.activities.BaseActivity |
24 | import org.pacien.tincapp.context.App | 25 | import org.pacien.tincapp.context.App |
25 | import org.pacien.tincapp.context.AppPaths | 26 | import org.pacien.tincapp.context.AppPaths |
26 | import org.pacien.tincapp.context.CrashRecorder | 27 | import org.pacien.tincapp.context.CrashRecorder |
28 | import java.io.File | ||
27 | 29 | ||
28 | /** | 30 | /** |
29 | * @author pacien | 31 | * @author pacien |
30 | */ | 32 | */ |
31 | class RecentCrashHandler(private val parentActivity: BaseActivity) { | 33 | class RecentCrashHandler(private val parentActivity: BaseActivity) { |
32 | private val resources by lazy { parentActivity.resources!! } | 34 | private val resources by lazy { parentActivity.resources!! } |
35 | private val maxLines = 1000 | ||
33 | 36 | ||
34 | fun handleRecentCrash() { | 37 | fun handleRecentCrash() { |
35 | if (!CrashRecorder.hasPreviouslyCrashed()) return | 38 | if (!CrashRecorder.hasPreviouslyCrashed()) return |
@@ -53,6 +56,17 @@ class RecentCrashHandler(private val parentActivity: BaseActivity) { | |||
53 | App.sendMail( | 56 | App.sendMail( |
54 | resources.getString(R.string.crash_modal_dev_email), | 57 | resources.getString(R.string.crash_modal_dev_email), |
55 | listOf(R.string.app_name, R.string.crash_modal_title).joinToString(" / ", transform = resources::getString), | 58 | listOf(R.string.app_name, R.string.crash_modal_title).joinToString(" / ", transform = resources::getString), |
56 | AppPaths.appLogFile().let { if (it.exists()) it.readText() else "" } | 59 | AppPaths.appLogFile().let { if (it.exists()) it.readLastLines(maxLines) else "" } |
57 | ) | 60 | ) |
61 | |||
62 | private fun File.readLastLines(n: Int): String { | ||
63 | val reader = ReversedLinesFileReader(this, Charsets.UTF_8) | ||
64 | val lastLines = generateSequence(reader::readLine) | ||
65 | .takeWhile { line: String? -> line != null } | ||
66 | .take(n) | ||
67 | .toList() | ||
68 | .asReversed() | ||
69 | |||
70 | return lastLines.joinToString("\n") | ||
71 | } | ||
58 | } | 72 | } |