aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/org/pacien')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt16
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/App.kt7
2 files changed, 18 insertions, 5 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 @@
19package org.pacien.tincapp.activities.common 19package org.pacien.tincapp.activities.common
20 20
21import android.support.v7.app.AlertDialog 21import android.support.v7.app.AlertDialog
22import org.apache.commons.io.input.ReversedLinesFileReader
22import org.pacien.tincapp.R 23import org.pacien.tincapp.R
23import org.pacien.tincapp.activities.BaseActivity 24import org.pacien.tincapp.activities.BaseActivity
24import org.pacien.tincapp.context.App 25import org.pacien.tincapp.context.App
25import org.pacien.tincapp.context.AppPaths 26import org.pacien.tincapp.context.AppPaths
26import org.pacien.tincapp.context.CrashRecorder 27import org.pacien.tincapp.context.CrashRecorder
28import java.io.File
27 29
28/** 30/**
29 * @author pacien 31 * @author pacien
30 */ 32 */
31class RecentCrashHandler(private val parentActivity: BaseActivity) { 33class 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
28import org.pacien.tincapp.BuildConfig 28import org.pacien.tincapp.BuildConfig
29import org.pacien.tincapp.R 29import org.pacien.tincapp.R
30import org.slf4j.LoggerFactory 30import org.slf4j.LoggerFactory
31import 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))