aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/org/pacien')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt12
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/start/NetworkListFragment.kt23
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListFragment.kt22
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListFragment.kt15
4 files changed, 33 insertions, 39 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt
index dda783b..7306d4b 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt
@@ -18,19 +18,9 @@
18 18
19package org.pacien.tincapp.activities 19package org.pacien.tincapp.activities
20 20
21import androidx.annotation.LayoutRes
22import androidx.fragment.app.Fragment 21import androidx.fragment.app.Fragment
23import android.view.LayoutInflater
24import android.view.View
25import android.view.ViewGroup
26import kotlinx.android.synthetic.main.base_activity.*
27 22
28/** 23/**
29 * @author euxane 24 * @author euxane
30 */ 25 */
31abstract class BaseFragment : Fragment() { 26abstract class BaseFragment : Fragment()
32 private val rootView by lazy { base_activity_frame }
33
34 fun inflate(@LayoutRes layout: Int) = layoutInflater.inflate(layout, rootView, false)!!
35 fun inflate(inflateFunc: (LayoutInflater, ViewGroup?, Boolean) -> View) = inflateFunc(layoutInflater, rootView, false)
36}
diff --git a/app/src/main/java/org/pacien/tincapp/activities/start/NetworkListFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/start/NetworkListFragment.kt
index fe7d3ee..9a25a0c 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/start/NetworkListFragment.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/start/NetworkListFragment.kt
@@ -26,10 +26,9 @@ import android.view.ViewGroup
26import android.widget.AdapterView 26import android.widget.AdapterView
27import android.widget.ArrayAdapter 27import android.widget.ArrayAdapter
28import android.widget.TextView 28import android.widget.TextView
29import kotlinx.android.synthetic.main.start_network_list.*
30import org.pacien.tincapp.R 29import org.pacien.tincapp.R
31import org.pacien.tincapp.activities.BaseFragment 30import org.pacien.tincapp.activities.BaseFragment
32import org.pacien.tincapp.context.AppPaths 31import org.pacien.tincapp.databinding.StartNetworkListBinding
33import org.pacien.tincapp.extensions.hideBottomSeparator 32import org.pacien.tincapp.extensions.hideBottomSeparator
34import org.pacien.tincapp.extensions.setElements 33import org.pacien.tincapp.extensions.setElements
35 34
@@ -39,6 +38,7 @@ import org.pacien.tincapp.extensions.setElements
39class NetworkListFragment : BaseFragment() { 38class NetworkListFragment : BaseFragment() {
40 private val networkListViewModel by lazy { NetworkListViewModel() } 39 private val networkListViewModel by lazy { NetworkListViewModel() }
41 private val networkListAdapter by lazy { ArrayAdapter<String>(requireContext(), R.layout.start_network_list_item) } 40 private val networkListAdapter by lazy { ArrayAdapter<String>(requireContext(), R.layout.start_network_list_item) }
41 private lateinit var startNetworkListBinding: StartNetworkListBinding
42 var connectToNetworkAction = { _: String -> Unit } 42 var connectToNetworkAction = { _: String -> Unit }
43 43
44 override fun onCreate(savedInstanceState: Bundle?) { 44 override fun onCreate(savedInstanceState: Bundle?) {
@@ -47,16 +47,17 @@ class NetworkListFragment : BaseFragment() {
47 } 47 }
48 48
49 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { 49 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
50 return inflater.inflate(R.layout.start_network_list, container, false) 50 startNetworkListBinding = StartNetworkListBinding.inflate(inflater, container, false)
51 return startNetworkListBinding.root
51 } 52 }
52 53
53 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 54 override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
54 val listHeaderView = layoutInflater.inflate(R.layout.start_network_list_header, start_network_list, false) 55 val listHeaderView = layoutInflater.inflate(R.layout.start_network_list_header, startNetworkListBinding.root, false)
55 start_network_list.addHeaderView(listHeaderView, null, false) 56 startNetworkListBinding.startNetworkList.addHeaderView(listHeaderView, null, false)
56 start_network_list.hideBottomSeparator() 57 startNetworkListBinding.startNetworkList.hideBottomSeparator()
57 start_network_list.emptyView = start_network_list_placeholder 58 startNetworkListBinding.startNetworkList.emptyView = startNetworkListBinding.startNetworkListPlaceholder
58 start_network_list.onItemClickListener = AdapterView.OnItemClickListener(this::onItemClick) 59 startNetworkListBinding.startNetworkList.onItemClickListener = AdapterView.OnItemClickListener(this::onItemClick)
59 start_network_list.adapter = networkListAdapter 60 startNetworkListBinding.startNetworkList.adapter = networkListAdapter
60 } 61 }
61 62
62 @Suppress("UNUSED_PARAMETER") 63 @Suppress("UNUSED_PARAMETER")
@@ -71,8 +72,8 @@ class NetworkListFragment : BaseFragment() {
71 } 72 }
72 73
73 private fun updatePlaceholder() { 74 private fun updatePlaceholder() {
74 start_network_list_placeholder.post { 75 startNetworkListBinding.startNetworkListPlaceholder.post {
75 start_network_list_placeholder_text?.text = getString(R.string.start_network_list_empty_none_found) 76 startNetworkListBinding.startNetworkListPlaceholderText?.text = getString(R.string.start_network_list_empty_none_found)
76 } 77 }
77 } 78 }
78} 79}
diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListFragment.kt
index 993c770..05c65d7 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListFragment.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListFragment.kt
@@ -25,11 +25,11 @@ import androidx.appcompat.app.AlertDialog
25import android.view.LayoutInflater 25import android.view.LayoutInflater
26import android.view.View 26import android.view.View
27import android.view.ViewGroup 27import android.view.ViewGroup
28import kotlinx.android.synthetic.main.status_node_info_dialog.view.*
29import kotlinx.android.synthetic.main.status_node_list_fragment.*
30import org.pacien.tincapp.R 28import org.pacien.tincapp.R
31import org.pacien.tincapp.activities.BaseFragment 29import org.pacien.tincapp.activities.BaseFragment
32import org.pacien.tincapp.commands.Tinc 30import org.pacien.tincapp.commands.Tinc
31import org.pacien.tincapp.databinding.StatusNodeInfoDialogBinding
32import org.pacien.tincapp.databinding.StatusNodeListFragmentBinding
33import org.pacien.tincapp.extensions.hideBottomSeparator 33import org.pacien.tincapp.extensions.hideBottomSeparator
34import org.pacien.tincapp.extensions.hideTopSeparator 34import org.pacien.tincapp.extensions.hideTopSeparator
35import org.pacien.tincapp.extensions.setElements 35import org.pacien.tincapp.extensions.setElements
@@ -45,6 +45,7 @@ class NodeListFragment : BaseFragment() {
45 private val nodeListViewModel by lazy { ViewModelProviders.of(this).get(NodeListViewModel::class.java) } 45 private val nodeListViewModel by lazy { ViewModelProviders.of(this).get(NodeListViewModel::class.java) }
46 private val nodeListAdapter by lazy { NodeInfoArrayAdapter(requireContext(), this::onItemClick) } 46 private val nodeListAdapter by lazy { NodeInfoArrayAdapter(requireContext(), this::onItemClick) }
47 private val nodeListObserver by lazy { Observer<List<NodeInfo>> { nodeListAdapter.setElements(it) } } 47 private val nodeListObserver by lazy { Observer<List<NodeInfo>> { nodeListAdapter.setElements(it) } }
48 private lateinit var statusNodeListFragmentBinding: StatusNodeListFragmentBinding
48 49
49 override fun onCreate(savedInstanceState: Bundle?) { 50 override fun onCreate(savedInstanceState: Bundle?) {
50 super.onCreate(savedInstanceState) 51 super.onCreate(savedInstanceState)
@@ -52,30 +53,31 @@ class NodeListFragment : BaseFragment() {
52 } 53 }
53 54
54 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { 55 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
55 return inflater.inflate(R.layout.status_node_list_fragment, container, false) 56 statusNodeListFragmentBinding = StatusNodeListFragmentBinding.inflate(inflater, container, false)
57 return statusNodeListFragmentBinding.root
56 } 58 }
57 59
58 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 60 override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
59 status_node_list.hideTopSeparator() 61 statusNodeListFragmentBinding.statusNodeList.hideTopSeparator()
60 status_node_list.hideBottomSeparator() 62 statusNodeListFragmentBinding.statusNodeList.hideBottomSeparator()
61 status_node_list.emptyView = status_node_list_placeholder 63 statusNodeListFragmentBinding.statusNodeList.emptyView = statusNodeListFragmentBinding.statusNodeListPlaceholder
62 status_node_list.adapter = nodeListAdapter 64 statusNodeListFragmentBinding.statusNodeList.adapter = nodeListAdapter
63 } 65 }
64 66
65 private fun onItemClick(nodeInfo: NodeInfo) = 67 private fun onItemClick(nodeInfo: NodeInfo) =
66 showNodeInfo(nodeInfo.name) 68 showNodeInfo(nodeInfo.name)
67 69
68 private fun showNodeInfo(nodeName: String) { 70 private fun showNodeInfo(nodeName: String) {
69 val dialogTextView = inflate(R.layout.status_node_info_dialog) 71 val dialogTextViewBinding = StatusNodeInfoDialogBinding.inflate(layoutInflater)
70 72
71 AlertDialog.Builder(context!!) 73 AlertDialog.Builder(context!!)
72 .setTitle(R.string.status_node_info_dialog_title) 74 .setTitle(R.string.status_node_info_dialog_title)
73 .setView(dialogTextView) 75 .setView(dialogTextViewBinding.root)
74 .setPositiveButton(R.string.status_node_info_dialog_close_action) { _, _ -> Unit } 76 .setPositiveButton(R.string.status_node_info_dialog_close_action) { _, _ -> Unit }
75 .show() 77 .show()
76 78
77 tincCtl.info(netName, nodeName).thenAccept { nodeInfo -> 79 tincCtl.info(netName, nodeName).thenAccept { nodeInfo ->
78 view?.post { dialogTextView.dialog_node_details.text = nodeInfo } 80 view?.post { dialogTextViewBinding.dialogNodeDetails.text = nodeInfo }
79 } 81 }
80 } 82 }
81} 83}
diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListFragment.kt
index 9701e5e..c842323 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListFragment.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/status/subnets/SubnetListFragment.kt
@@ -24,9 +24,8 @@ import android.os.Bundle