diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/build.gradle | 1 | ||||
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt | 16 | ||||
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/context/App.kt | 7 |
3 files changed, 19 insertions, 5 deletions
diff --git a/app/build.gradle b/app/build.gradle index 778899d..36b78dd 100644 --- a/app/build.gradle +++ b/app/build.gradle | |||
@@ -86,6 +86,7 @@ dependencies { | |||
86 | implementation 'com.github.tony19:logback-android:1.1.1-12' | 86 | implementation 'com.github.tony19:logback-android:1.1.1-12' |
87 | implementation('org.apache.commons:commons-configuration2:2.2') { exclude group: 'commons-logging', module: 'commons-logging' } | 87 | implementation('org.apache.commons:commons-configuration2:2.2') { exclude group: 'commons-logging', module: 'commons-logging' } |
88 | implementation('commons-beanutils:commons-beanutils:1.9.3') { exclude group: 'commons-logging', module: 'commons-logging' } | 88 | implementation('commons-beanutils:commons-beanutils:1.9.3') { exclude group: 'commons-logging', module: 'commons-logging' } |
89 | implementation('commons-io:commons-io:2.6') { exclude group: 'commons-logging', module: 'commons-logging' } | ||
89 | } | 90 | } |
90 | 91 | ||
91 | repositories { | 92 | repositories { |
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 | } |
diff --git a/app/src/main/java/org/pacien/tincapp/context/App.kt b/app/src/main/java/org/pacien/tincapp/context/App.kt index 6f28bd0..cf12dda 100644 --- a/app/src/main/java/org/pacien/tincapp/context/App.kt +++ b/app/src/main/java/org/pacien/tincapp/context/App.kt | |||
@@ -28,7 +28,6 @@ import android.support.annotation.StringRes | |||
28 | import org.pacien.tincapp.BuildConfig | 28 | import org.pacien.tincapp.BuildConfig |
29 | import org.pacien.tincapp.R | 29 | import org.pacien.tincapp.R |
30 | import org.slf4j.LoggerFactory | 30 | import org.slf4j.LoggerFactory |
31 | import java.io.File | ||
32 | 31 | ||
33 | /** | 32 | /** |
34 | * @author pacien | 33 | * @author pacien |
@@ -71,12 +70,12 @@ class App : Application() { | |||
71 | appContext?.startActivity(chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) | 70 | appContext?.startActivity(chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) |
72 | } | 71 | } |
73 | 72 | ||
74 | fun sendMail(recipient: String, subject: String, body: String? = null, attachment: File? = null) { | 73 | // https://developer.android.com/guide/components/intents-common#Email |
74 | fun sendMail(recipient: String, subject: String, body: String) { | ||
75 | val intent = Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:")) | 75 | val intent = Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:")) |
76 | .putExtra(Intent.EXTRA_EMAIL, arrayOf(recipient)) | 76 | .putExtra(Intent.EXTRA_EMAIL, arrayOf(recipient)) |
77 | .putExtra(Intent.EXTRA_SUBJECT, subject) | 77 | .putExtra(Intent.EXTRA_SUBJECT, subject) |
78 | .apply { if (body != null) putExtra(Intent.EXTRA_TEXT, body) } | 78 | .putExtra(Intent.EXTRA_TEXT, body) |
79 | .apply { if (attachment != null) putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachment)) } | ||
80 | 79 | ||
81 | val chooser = Intent.createChooser(intent, getResources().getString(R.string.crash_modal_action_send_email)) | 80 | val chooser = Intent.createChooser(intent, getResources().getString(R.string.crash_modal_action_send_email)) |
82 | appContext?.startActivity(chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) | 81 | appContext?.startActivity(chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) |