aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt64
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt105
-rw-r--r--app/src/main/java/org/pacien/tincapp/utils/AndroidExtensions.kt23
-rw-r--r--app/src/main/java/org/pacien/tincapp/utils/FileObserver.kt16
-rw-r--r--app/src/main/res/layout/page_start.xml5
-rw-r--r--app/src/main/res/layout/page_status.xml5
6 files changed, 166 insertions, 52 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
index 19d01e6..cecd474 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
@@ -2,6 +2,7 @@ package org.pacien.tincapp.activities
2 2
3import android.content.Intent 3import android.content.Intent
4import android.os.Bundle 4import android.os.Bundle
5import android.support.v4.widget.SwipeRefreshLayout
5import android.view.Menu 6import android.view.Menu
6import android.view.MenuItem 7import android.view.MenuItem
7import android.view.View 8import android.view.View
@@ -13,16 +14,30 @@ import kotlinx.android.synthetic.main.page_start.*
13import org.pacien.tincapp.R 14import org.pacien.tincapp.R
14import org.pacien.tincapp.context.AppPaths 15import org.pacien.tincapp.context.AppPaths
15import org.pacien.tincapp.service.TincVpnService 16import org.pacien.tincapp.service.TincVpnService
17import org.pacien.tincapp.utils.FileObserver
18import org.pacien.tincapp.utils.setElements
16 19
17/** 20/**
18 * @author pacien 21 * @author pacien
19 */ 22 */
20class StartActivity : BaseActivity(), AdapterView.OnItemClickListener { 23class StartActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
24
25 private var networkListAdapter: ArrayAdapter<String>? = null
26 private var confChangeObserver: FileObserver? = null
21 27
22 override fun onCreate(savedInstanceState: Bundle?) { 28 override fun onCreate(savedInstanceState: Bundle?) {
23 super.onCreate(savedInstanceState) 29 super.onCreate(savedInstanceState)
30
31 networkListAdapter = ArrayAdapter<String>(this, R.layout.fragment_list_item)
32 confChangeObserver = FileObserver(AppPaths.confDir().absolutePath, FileObserver.CHANGE, { _, _ -> onRefresh() })
33
24 layoutInflater.inflate(R.layout.page_start, main_content) 34 layoutInflater.inflate(R.layout.page_start, main_content)
25 writeContent() 35 network_list_wrapper.setOnRefreshListener(this)
36 network_list.addHeaderView(layoutInflater.inflate(R.layout.fragment_network_list_header, network_list, false), null, false)
37 network_list.addFooterView(View(this), null, false)
38 network_list.emptyView = network_list_empty
39 network_list.adapter = networkListAdapter
40 network_list.onItemClickListener = this
26 } 41 }
27 42
28 override fun onCreateOptionsMenu(m: Menu): Boolean { 43 override fun onCreateOptionsMenu(m: Menu): Boolean {
@@ -30,27 +45,44 @@ class StartActivity : BaseActivity(), AdapterView.OnItemClickListener {
30 return super.onCreateOptionsMenu(m) 45 return super.onCreateOptionsMenu(m)
31 } 46 }
32 47
33 override fun onResume() { 48 override fun onDestroy() {
34 super.onResume() 49 confChangeObserver = null
50 networkListAdapter = null
51 super.onDestroy()
52 }
35 53
36 if (TincVpnService.isConnected()) startActivity(Intent(this, StatusActivity::class.java) 54 override fun onStart() {
37 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)) 55 super.onRestart()
56 onRefresh()
57 confChangeObserver?.startWatching()
38 } 58 }
39 59
40 override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { 60 override fun onStop() {
41 PromptActivity.requestVpnPermission((view as TextView).text.toString()) 61 super.onStop()
62 confChangeObserver?.stopWatching()
42 } 63 }
43 64
44 fun openConfigureActivity(@Suppress("UNUSED_PARAMETER") i: MenuItem) { 65 override fun onResume() {
45 startActivity(Intent(this, ConfigureActivity::class.java)) 66 super.onResume()
67 if (TincVpnService.isConnected()) openStatusActivity()
46 } 68 }
47 69
48 private fun writeContent() { 70 override fun onRefresh() {
49 network_list.addHeaderView(layoutInflater.inflate(R.layout.fragment_network_list_header, network_list, false), null, false) 71 val networks = AppPaths.confDir().list().toList()
50 network_list.addFooterView(View(this), null, false) 72 runOnUiThread {
51 network_list.emptyView = network_list_empty 73 networkListAdapter?.setElements(networks)
52 network_list.adapter = ArrayAdapter<String>(this, R.layout.fragment_list_item, AppPaths.confDir().list()) 74 network_list_wrapper.isRefreshing = false
53 network_list.onItemClickListener = this 75 }
54 } 76 }
55 77
78 override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) =
79 PromptActivity.requestVpnPermission((view as TextView).text.toString())
80
81 fun openConfigureActivity(@Suppress("UNUSED_PARAMETER") i: MenuItem) =
82 startActivity(Intent(this, ConfigureActivity::class.java))
83
84 fun openStatusActivity() =
85 startActivity(Intent(this, StatusActivity::class.java)
86 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK))
87
56} 88}
diff --git a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt
index ca572ea..b4ba7dd 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt
@@ -2,6 +2,7 @@ package org.pacien.tincapp.activities
2 2
3import android.content.Intent 3import android.content.Intent
4import android.os.Bundle 4import android.os.Bundle
5import android.support.v4.widget.SwipeRefreshLayout
5import android.support.v7.app.AlertDialog 6import android.support.v7.app.AlertDialog
6import android.view.Menu 7import android.view.Menu
7import android.view.MenuItem 8import android.view.MenuItem
@@ -17,16 +18,33 @@ import org.pacien.tincapp.R
17import org.pacien.tincapp.commands.Tinc 18import org.pacien.tincapp.commands.Tinc
18import org.pacien.tincapp.service.TincVpnService 19import org.pacien.tincapp.service.TincVpnService
19import org.pacien.tincapp.service.VpnInterfaceConfiguration 20import org.pacien.tincapp.service.VpnInterfaceConfiguration
21import org.pacien.tincapp.utils.setElements
22import org.pacien.tincapp.utils.setText
23import java.util.*
24import kotlin.concurrent.timerTask
20 25
21/** 26/**
22 * @author pacien 27 * @author pacien
23 */ 28 */
24class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener { 29class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
30
31 private var nodeListAdapter: ArrayAdapter<String>? = null
32 private var refreshTimer: Timer? = null
33 private var updateView: Boolean = false
25 34
26 override fun onCreate(savedInstanceState: Bundle?) { 35 override fun onCreate(savedInstanceState: Bundle?) {
27 super.onCreate(savedInstanceState) 36 super.onCreate(savedInstanceState)
37
38 nodeListAdapter = ArrayAdapter<String>(this, R.layout.fragment_list_item)
39 refreshTimer = Timer(true)
40
28 layoutInflater.inflate(R.layout.page_status, main_content) 41 layoutInflater.inflate(R.layout.page_status, main_content)
29 writeContent() 42 node_list_wrapper.setOnRefreshListener(this)
43 node_list.addHeaderView(layoutInflater.inflate(R.layout.fragment_network_status_header, node_list, false), null, false)
44 node_list.addFooterView(View(this), null, false)
45 node_list.emptyView = node_list_empty
46 node_list.onItemClickListener = this
47 node_list.adapter = nodeListAdapter
30 } 48 }
31 49
32 override fun onCreateOptionsMenu(m: Menu): Boolean { 50 override fun onCreateOptionsMenu(m: Menu): Boolean {
@@ -34,55 +52,78 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener {
34 return super.onCreateOptionsMenu(m) 52 return super.onCreateOptionsMenu(m)
35 } 53 }
36 54
37 override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { 55 override fun onDestroy() {
38 val nodeName = (view as TextView).text.toString() 56 super.onDestroy()
39 val v = layoutInflater.inflate(R.layout.dialog_text_monopsace, main_content, false) 57 refreshTimer?.cancel()
40 v.dialog_text_monospace.text = Tinc.info(TincVpnService.getCurrentNetName()!!, nodeName) 58 nodeListAdapter = null
41 59 refreshTimer = null
42 AlertDialog.Builder(this)
43 .setTitle(R.string.title_node_info)
44 .setView(v)
45 .setPositiveButton(R.string.action_close) { _, _ -> /* nop */ }
46 .show()
47 } 60 }
48 61
49 fun stopVpn(@Suppress("UNUSED_PARAMETER") i: MenuItem) { 62 override fun onStart() {
50 TincVpnService.stopVpn() 63 super.onStart()
51 startActivity(Intent(this, StartActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) 64 writeNetworkInfo(TincVpnService.getCurrentInterfaceCfg() ?: VpnInterfaceConfiguration())