aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/org')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/ViewLogActivity.kt46
1 files changed, 28 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()