aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/ViewLogActivity.kt46
-rw-r--r--app/src/main/res/menu/menu_viewlog.xml1
-rw-r--r--app/src/main/res/values/strings.xml1
3 files changed, 30 insertions, 18 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/ViewLogActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/ViewLogActivity.kt
index 2a56ceb..5dc1a36 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/ViewLogActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/ViewLogActivity.kt
@@ -31,16 +31,18 @@ class ViewLogActivity : BaseActivity() {
31 private val log = LinkedList<String>() 31 private val log = LinkedList<String>()
32 private var logUpdateTimer: Timer? = null 32 private var logUpdateTimer: Timer? = null
33 private var logger: Process? = null 33 private var logger: Process? = null
34 private var toggleButton: MenuItem? = null
34 35
35 override fun onCreate(savedInstanceState: Bundle?) { 36 override fun onCreate(savedInstanceState: Bundle?) {
36 super.onCreate(savedInstanceState) 37 super.onCreate(savedInstanceState)
37 supportActionBar!!.setDisplayHomeAsUpEnabled(true) 38 supportActionBar!!.setDisplayHomeAsUpEnabled(true)
38 layoutInflater.inflate(R.layout.page_viewlog, main_content) 39 layoutInflater.inflate(R.layout.page_viewlog, main_content)
39 startLogging() 40 toggleLogging(true)
40 } 41 }
41 42
42 override fun onCreateOptionsMenu(m: Menu): Boolean { 43 override fun onCreateOptionsMenu(m: Menu): Boolean {
43 menuInflater.inflate(R.menu.menu_viewlog, m) 44 menuInflater.inflate(R.menu.menu_viewlog, m)
45 toggleButton = m.findItem(R.id.log_viewer_action_toggle)
44 return super.onCreateOptionsMenu(m) 46 return super.onCreateOptionsMenu(m)
45 } 47 }
46 48
@@ -50,20 +52,10 @@ class ViewLogActivity : BaseActivity() {
50 } 52 }
51 53
52 override fun onDestroy() { 54 override fun onDestroy() {
53 stopLogging() 55 toggleLogging(false)
54 super.onDestroy() 56 super.onDestroy()
55 } 57 }
56 58
57 fun toggleLogging(menuItem: MenuItem) {
58 if (logger == null) {
59 startLogging()
60 menuItem.setIcon(R.drawable.ic_pause_circle_outline_primary_24dp)
61 } else {
62 stopLogging()
63 menuItem.setIcon(R.drawable.ic_pause_circle_filled_primary_24dp)
64 }
65 }
66
67 fun share(@Suppress("UNUSED_PARAMETER") menuItem: MenuItem) { 59 fun share(@Suppress("UNUSED_PARAMETER") menuItem: MenuItem) {
68 synchronized(this) { 60 synchronized(this) {
69 val logFragment = log.joinToString(NEW_LINE) 61 val logFragment = log.joinToString(NEW_LINE)
@@ -75,18 +67,36 @@ class ViewLogActivity : BaseActivity() {
75 } 67 }
76 } 68 }
77 69
70 fun toggleLogging(@Suppress("UNUSED_PARAMETER") menuItem: MenuItem) = toggleLogging(logger == null)
71
72 private fun toggleLogging(enable: Boolean) {
73 if (enable) {
74 disableUserScroll()
75 toggleButton?.setIcon(R.drawable.ic_pause_circle_outline_primary_24dp)
76 startLogging()
77 } else {
78 enableUserScroll()
79 toggleButton?.setIcon(R.drawable.ic_pause_circle_filled_primary_24dp)
80 stopLogging()
81 }
82 }
83
78 private fun startLogging(level: Int = LOG_LEVEL) { 84 private fun startLogging(level: Int = LOG_LEVEL) {
79 disableUserScroll()
80 appendLog(resources.getString(R.string.message_log_level_set, level)) 85 appendLog(resources.getString(R.string.message_log_level_set, level))
81 Tinc.log(TincVpnService.getCurrentNetName()!!, level).let { process -> 86
82 logger = process 87 TincVpnService.getCurrentNetName()?.let { netName ->
83 Executor.runAsyncTask { captureLog(process) } 88 Tinc.log(netName, level).let { process ->
89 logger = process
90 Executor.runAsyncTask { captureLog(process) }
91 }
92 logUpdateTimer = timer(period = UPDATE_INTERVAL, action = { printLog() })
93 } ?: run {
94 appendLog(resources.getString(R.string.message_no_daemon))
95 toggleLogging(false)
84 } 96 }
85 logUpdateTimer = timer(period = UPDATE_INTERVAL, action = { printLog() })
86 } 97 }
87 98
88 private fun stopLogging() { 99 private fun stopLogging() {
89 enableUserScroll()
90 logger?.destroy() 100 logger?.destroy()
91 logger = null 101 logger = null
92 logUpdateTimer?.cancel() 102 logUpdateTimer?.cancel()
diff --git a/app/src/main/res/menu/menu_viewlog.xml b/app/src/main/res/menu/menu_viewlog.xml
index 397055a..bcf49d2 100644
--- a/app/src/main/res/menu/menu_viewlog.xml
+++ b/app/src/main/res/menu/menu_viewlog.xml
@@ -4,6 +4,7 @@
4 tools:context="org.pacien.tincapp.activities.ViewLogActivity"> 4 tools:context="org.pacien.tincapp.activities.ViewLogActivity">
5 5
6 <item 6 <item
7 android:id="@+id/log_viewer_action_toggle"
7 android:icon="@drawable/ic_pause_circle_outline_primary_24dp" 8 android:icon="@drawable/ic_pause_circle_outline_primary_24dp"
8 android:onClick="toggleLogging" 9 android:onClick="toggleLogging"
9 android:tint="@color/colorAccent" 10 android:tint="@color/colorAccent"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index cab09ee..6ff9ab5 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -95,6 +95,7 @@
95 <string name="message_invalid_network_name">Invalid network name.</string> 95 <string name="message_invalid_network_name">Invalid network name.</string>
96 <string name="message_app_crash">The application has previously encountered a fatal error.</string> 96 <string name="message_app_crash">The application has previously encountered a fatal error.</string>
97 <string name="message_crash_logged">The crash details have been saved in \"%1$s\".</string> 97 <string name="message_crash_logged">The crash details have been saved in \"%1$s\".</string>
98 <string name="message_no_daemon">No running tinc daemon has been found.</string>
98 99
99 <string name="value_none">none</string> 100 <string name="value_none">none</string>
100 <string name="value_yes">yes</string> 101 <string name="value_yes">yes</string>