diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt | 100 |
1 files changed, 50 insertions, 50 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 44d6e95..719bbc1 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt | |||
@@ -22,67 +22,67 @@ import org.pacien.tincapp.service.TincVpnService | |||
22 | */ | 22 | */ |
23 | class StartActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener { | 23 | class StartActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener { |
24 | 24 | ||
25 | private var networkListAdapter: ArrayAdapter<String>? = null | 25 | private var networkListAdapter: ArrayAdapter<String>? = null |
26 | 26 | ||
27 | override fun onCreate(savedInstanceState: Bundle?) { | 27 | override fun onCreate(savedInstanceState: Bundle?) { |
28 | super.onCreate(savedInstanceState) | 28 | super.onCreate(savedInstanceState) |
29 | networkListAdapter = ArrayAdapter(this, R.layout.fragment_list_item) | 29 | networkListAdapter = ArrayAdapter(this, R.layout.fragment_list_item) |
30 | layoutInflater.inflate(R.layout.fragment_list_view, main_content) | 30 | layoutInflater.inflate(R.layout.fragment_list_view, main_content) |
31 | list_wrapper.setOnRefreshListener(this) | 31 | list_wrapper.setOnRefreshListener(this) |
32 | list.addHeaderView(layoutInflater.inflate(R.layout.fragment_network_list_header, list, false), null, false) | 32 | list.addHeaderView(layoutInflater.inflate(R.layout.fragment_network_list_header, list, false), null, false) |
33 | list.addFooterView(View(this), null, false) | 33 | list.addFooterView(View(this), null, false) |
34 | list.adapter = networkListAdapter | 34 | list.adapter = networkListAdapter |
35 | list.onItemClickListener = this | 35 | list.onItemClickListener = this |
36 | } | 36 | } |
37 | 37 | ||
38 | override fun onCreateOptionsMenu(m: Menu): Boolean { | 38 | override fun onCreateOptionsMenu(m: Menu): Boolean { |
39 | menuInflater.inflate(R.menu.menu_start, m) | 39 | menuInflater.inflate(R.menu.menu_start, m) |
40 | return super.onCreateOptionsMenu(m) | 40 | return super.onCreateOptionsMenu(m) |
41 | } | 41 | } |
42 | 42 | ||
43 | override fun onDestroy() { | 43 | override fun onDestroy() { |
44 | networkListAdapter = null | 44 | networkListAdapter = null |
45 | super.onDestroy() | 45 | super.onDestroy() |
46 | } | 46 | } |
47 | 47 | ||
48 | override fun onStart() { | 48 | override fun onStart() { |
49 | super.onStart() | 49 | super.onStart() |
50 | onRefresh() | 50 | onRefresh() |
51 | } | 51 | } |
52 | 52 | ||
53 | override fun onResume() { | 53 | override fun onResume() { |
54 | super.onResume() | 54 | super.onResume() |
55 | if (TincVpnService.isConnected()) openStatusActivity() | 55 | if (TincVpnService.isConnected()) openStatusActivity() |
56 | } | 56 | } |
57 | 57 | ||
58 | override fun onRefresh() { | 58 | override fun onRefresh() { |
59 | val networks = AppPaths.confDir()?.list()?.toList() ?: emptyList() | 59 | val networks = AppPaths.confDir()?.list()?.toList() ?: emptyList() |
60 | runOnUiThread { | 60 | runOnUiThread { |
61 | networkListAdapter?.setElements(networks) | 61 | networkListAdapter?.setElements(networks) |
62 | setPlaceholderVisibility() | 62 | setPlaceholderVisibility() |
63 | list_wrapper.isRefreshing = false | 63 | list_wrapper.isRefreshing = false |
64 | } | ||
65 | } | 64 | } |
65 | } | ||
66 | 66 | ||
67 | override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) = | 67 | override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) = |
68 | LaunchActivity.connect((view as TextView).text.toString()) | 68 | LaunchActivity.connect((view as TextView).text.toString()) |
69 | 69 | ||
70 | fun openConfigureActivity(@Suppress("UNUSED_PARAMETER") i: MenuItem) = | 70 | fun openConfigureActivity(@Suppress("UNUSED_PARAMETER") i: MenuItem) = |
71 | startActivity(Intent(this, ConfigureActivity::class.java)) | 71 | startActivity(Intent(this, ConfigureActivity::class.java)) |
72 | 72 | ||
73 | fun openStatusActivity() = | 73 | fun openStatusActivity() = |
74 | startActivity(Intent(this, StatusActivity::class.java) | 74 | startActivity(Intent(this, StatusActivity::class.java) |
75 | .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)) | 75 | .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)) |
76 | 76 | ||
77 | private fun setPlaceholderVisibility() = if (networkListAdapter?.isEmpty != false) { | 77 | private fun setPlaceholderVisibility() = if (networkListAdapter?.isEmpty != false) { |
78 | network_list_placeholder.text = getListPlaceholderText() | 78 | network_list_placeholder.text = getListPlaceholderText() |
79 | network_list_placeholder.visibility = View.VISIBLE | 79 | network_list_placeholder.visibility = View.VISIBLE |
80 | } else { | 80 | } else { |
81 | network_list_placeholder.visibility = View.GONE | 81 | network_list_placeholder.visibility = View.GONE |
82 | } | 82 | } |
83 | 83 | ||
84 | private fun getListPlaceholderText() = | 84 | private fun getListPlaceholderText() = |
85 | if (!AppPaths.storageAvailable()) getText(R.string.message_storage_unavailable) | 85 | if (!AppPaths.storageAvailable()) getText(R.string.message_storage_unavailable) |
86 | else getText(R.string.message_no_network_configuration_found) | 86 | else getText(R.string.message_no_network_configuration_found) |
87 | 87 | ||
88 | } | 88 | } |