diff options
Diffstat (limited to 'app/src/main/java')
4 files changed, 64 insertions, 24 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt index 975d4cf..196ccd3 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt | |||
@@ -30,8 +30,6 @@ import kotlinx.android.synthetic.main.base_activity.* | |||
30 | import org.pacien.tincapp.R | 30 | import org.pacien.tincapp.R |
31 | import org.pacien.tincapp.context.App | 31 | import org.pacien.tincapp.context.App |
32 | import org.pacien.tincapp.context.AppInfo | 32 | import org.pacien.tincapp.context.AppInfo |
33 | import org.pacien.tincapp.context.AppPaths | ||
34 | import org.pacien.tincapp.context.CrashRecorder | ||
35 | 33 | ||
36 | /** | 34 | /** |
37 | * @author pacien | 35 | * @author pacien |
@@ -98,26 +96,6 @@ abstract class BaseActivity : AppCompatActivity() { | |||
98 | if (active) super.runOnUiThread(action) | 96 | if (active) super.runOnUiThread(action) |
99 | } | 97 | } |
100 | 98 | ||
101 | fun handleRecentCrash() { | ||
102 | if (!CrashRecorder.hasPreviouslyCrashed()) return | ||
103 | CrashRecorder.dismissPreviousCrash() | ||
104 | |||
105 | AlertDialog.Builder(this) | ||
106 | .setTitle(R.string.crash_modal_title) | ||
107 | .setMessage(listOf( | ||
108 | resources.getString(R.string.crash_modal_message), | ||
109 | resources.getString(R.string.crash_modal_crash_logged, AppPaths.appLogFile().absolutePath) | ||
110 | ).joinToString("\n\n")) | ||
111 | .setNeutralButton(R.string.crash_modal_action_send_report) { _, _ -> | ||
112 | App.sendMail( | ||
113 | resources.getString(R.string.crash_modal_dev_email), | ||
114 | listOf(R.string.app_name, R.string.crash_modal_title).joinToString(" / ", transform = resources::getString), | ||
115 | AppPaths.appLogFile().let { if (it.exists()) it.readText() else "" }) | ||
116 | } | ||
117 | .setPositiveButton(R.string.generic_action_close) { _, _ -> Unit } | ||
118 | .show() | ||
119 | } | ||
120 | |||
121 | fun inflate(@LayoutRes layout: Int) = layoutInflater.inflate(layout, rootView, false)!! | 99 | fun inflate(@LayoutRes layout: Int) = layoutInflater.inflate(layout, rootView, false)!! |
122 | fun inflate(inflateFunc: (LayoutInflater, ViewGroup?, Boolean) -> View) = inflateFunc(layoutInflater, rootView, false) | 100 | fun inflate(inflateFunc: (LayoutInflater, ViewGroup?, Boolean) -> View) = inflateFunc(layoutInflater, rootView, false) |
123 | 101 | ||
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 new file mode 100644 index 0000000..82ecc9d --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon | ||
3 | * Copyright (C) 2017-2018 Pacien TRAN-GIRARD | ||
4 | * | ||
5 | * This program is free software: you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation, either version 3 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | package org.pacien.tincapp.activities.common | ||
20 | |||
21 | import android.support.v7.app.AlertDialog | ||
22 | import org.pacien.tincapp.R | ||
23 | import org.pacien.tincapp.activities.BaseActivity | ||
24 | import org.pacien.tincapp.context.App | ||
25 | import org.pacien.tincapp.context.AppPaths | ||
26 | import org.pacien.tincapp.context.CrashRecorder | ||
27 | |||
28 | /** | ||
29 | * @author pacien | ||
30 | */ | ||
31 | class RecentCrashHandler(private val parentActivity: BaseActivity) { | ||
32 | private val resources by lazy { parentActivity.resources!! } | ||
33 | |||
34 | fun handleRecentCrash() { | ||
35 | if (!CrashRecorder.hasPreviouslyCrashed()) return | ||
36 | CrashRecorder.dismissPreviousCrash() | ||
37 | |||
38 | AlertDialog.Builder(parentActivity) | ||
39 | .setTitle(R.string.crash_modal_title) | ||
40 | .setMessage(makeMessage()) | ||
41 | .setNeutralButton(R.string.crash_modal_action_send_report) { _, _ -> sendReportMail() } | ||
42 | .setPositiveButton(R.string.generic_action_close) { _, _ -> Unit } | ||
43 | .show() | ||
44 | } | ||
45 | |||
46 | private fun makeMessage() = | ||
47 | listOf( | ||
48 | resources.getString(R.string.crash_modal_message), | ||
49 | resources.getString(R.string.crash_modal_crash_logged, AppPaths.appLogFile().absolutePath) | ||
50 | ).joinToString("\n\n") | ||
51 | |||
52 | private fun sendReportMail() = | ||
53 | App.sendMail( | ||
54 | resources.getString(R.string.crash_modal_dev_email), | ||
55 | listOf(R.string.app_name, R.string.crash_modal_title).joinToString(" / ", transform = resources::getString), | ||
56 | AppPaths.appLogFile().let { if (it.exists()) it.readText() else "" } | ||
57 | ) | ||
58 | } | ||
diff --git a/app/src/main/java/org/pacien/tincapp/activities/start/StartActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/start/StartActivity.kt index 802115f..0e50060 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/start/StartActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/start/StartActivity.kt | |||
@@ -28,6 +28,7 @@ import kotlinx.android.synthetic.main.start_activity.* | |||
28 | import org.pacien.tincapp.R | 28 | import org.pacien.tincapp.R |
29 | import org.pacien.tincapp.activities.BaseActivity | 29 | import org.pacien.tincapp.activities.BaseActivity |
30 | import org.pacien.tincapp.activities.common.ProgressModal | 30 | import org.pacien.tincapp.activities.common.ProgressModal |
31 | import org.pacien.tincapp.activities.common.RecentCrashHandler | ||
31 | import org.pacien.tincapp.activities.configure.ConfigureActivity | 32 | import org.pacien.tincapp.activities.configure.ConfigureActivity |
32 | import org.pacien.tincapp.activities.status.StatusActivity | 33 | import org.pacien.tincapp.activities.status.StatusActivity |
33 | import org.pacien.tincapp.intent.Actions | 34 | import org.pacien.tincapp.intent.Actions |
@@ -40,6 +41,7 @@ import org.pacien.tincapp.service.TincVpnService | |||
40 | class StartActivity : BaseActivity() { | 41 | class StartActivity : BaseActivity() { |
41 | val permissionRequestCode = 0 | 42 | val permissionRequestCode = 0 |
42 | private val connectionStarter by lazy { ConnectionStarter(this) } | 43 | private val connectionStarter by lazy { ConnectionStarter(this) } |
44 | private val recentCrashHandler by lazy { RecentCrashHandler(this) } | ||
43 | private val broadcastMapper = BroadcastMapper(mapOf( | 45 | private val broadcastMapper = BroadcastMapper(mapOf( |
44 | Actions.EVENT_CONNECTED to this::onVpnStart, | 46 | Actions.EVENT_CONNECTED to this::onVpnStart, |
45 | Actions.EVENT_ABORTED to this::onVpnStartError | 47 | Actions.EVENT_ABORTED to this::onVpnStartError |
@@ -75,7 +77,7 @@ class StartActivity : BaseActivity() { | |||
75 | super.onResume() | 77 | super.onResume() |
76 | if (TincVpnService.isConnected()) openStatusActivity(false) | 78 | if (TincVpnService.isConnected()) openStatusActivity(false) |
77 | broadcastMapper.register() | 79 | broadcastMapper.register() |
78 | handleRecentCrash() | 80 | recentCrashHandler.handleRecentCrash() |
79 | } | 81 | } |
80 | 82 | ||
81 | override fun onPause() { | 83 | override fun onPause() { |
diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt index 152ed83..cebbc16 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt | |||
@@ -28,6 +28,7 @@ import org.pacien.tincapp.R | |||
28 | import org.pacien.tincapp.activities.BaseActivity | 28 | import org.pacien.tincapp.activities.BaseActivity |
29 | import org.pacien.tincapp.activities.common.FragmentListPagerAdapter | 29 | import org.pacien.tincapp.activities.common.FragmentListPagerAdapter |
30 | import org.pacien.tincapp.activities.common.ProgressModal | 30 | import org.pacien.tincapp.activities.common.ProgressModal |
31 | import org.pacien.tincapp.activities.common.RecentCrashHandler | ||
31 | import org.pacien.tincapp.activities.start.StartActivity | 32 | import org.pacien.tincapp.activities.start.StartActivity |
32 | import org.pacien.tincapp.activities.status.networkinfo.NetworkInfoFragment | 33 | import org.pacien.tincapp.activities.status.networkinfo.NetworkInfoFragment |
33 | import org.pacien.tincapp.activities.status.nodes.NodeListFragment | 34 | import org.pacien.tincapp.activities.status.nodes.NodeListFragment |
@@ -41,6 +42,7 @@ import org.pacien.tincapp.service.TincVpnService | |||
41 | * @author pacien | 42 | * @author pacien |
42 | */ | 43 | */ |
43 | class StatusActivity : BaseActivity() { | 44 | class StatusActivity : BaseActivity() { |
45 | private val recentCrashHandler by lazy { RecentCrashHandler(this) } | ||
44 | private val vpnService by lazy { TincVpnService } | 46 | private val vpnService by lazy { TincVpnService } |
45 | private val netName by lazy { vpnService.getCurrentNetName() } | 47 | private val netName by lazy { vpnService.getCurrentNetName() } |
46 | private val pagerAdapter by lazy { FragmentListPagerAdapter(pages, supportFragmentManager) } | 48 | private val pagerAdapter by lazy { FragmentListPagerAdapter(pages, supportFragmentManager) } |
@@ -72,7 +74,7 @@ class StatusActivity : BaseActivity() { | |||
72 | if (!TincVpnService.isConnected()) openStartActivity() | 74 | if (!TincVpnService.isConnected()) openStartActivity() |
73 | 75 | ||
74 | broadcastMapper.register() | 76 | broadcastMapper.register() |
75 | handleRecentCrash() | 77 | recentCrashHandler.handleRecentCrash() |
76 | } | 78 | } |
77 | 79 | ||
78 | override fun onPause() { | 80 | override fun onPause() { |