diff options
Diffstat (limited to 'app/src')
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 | ||
19 | package org.pacien.tincapp.activities | 19 | package org.pacien.tincapp.activities |
20 | 20 | ||
21 | import androidx.annotation.LayoutRes | ||
22 | import androidx.fragment.app.Fragment | 21 | import androidx.fragment.app.Fragment |
23 | import android.view.LayoutInflater | ||
24 | import android.view.View | ||
25 | import android.view.ViewGroup | ||
26 | import kotlinx.android.synthetic.main.base_activity.* | ||
27 | 22 | ||
28 | /** | 23 | /** |
29 | * @author euxane | 24 | * @author euxane |
30 | */ | 25 | */ |
31 | abstract class BaseFragment : Fragment() { | 26 | abstract 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 | |||
26 | import android.widget.AdapterView | 26 | import android.widget.AdapterView |
27 | import android.widget.ArrayAdapter | 27 | import android.widget.ArrayAdapter |
28 | import android.widget.TextView | 28 | import android.widget.TextView |
29 | import kotlinx.android.synthetic.main.start_network_list.* | ||
30 | import org.pacien.tincapp.R | 29 | import org.pacien.tincapp.R |
31 | import org.pacien.tincapp.activities.BaseFragment | 30 | import org.pacien.tincapp.activities.BaseFragment |
32 | import org.pacien.tincapp.context.AppPaths | 31 | import org.pacien.tincapp.databinding.StartNetworkListBinding |
33 | import org.pacien.tincapp.extensions.hideBottomSeparator | 32 | import org.pacien.tincapp.extensions.hideBottomSeparator |
34 | import org.pacien.tincapp.extensions.setElements | 33 | import org.pacien.tincapp.extensions.setElements |
35 | 34 | ||
@@ -39,6 +38,7 @@ import org.pacien.tincapp.extensions.setElements | |||
39 | class NetworkListFragment : BaseFragment() { | 38 | class 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 | |||
25 | import android.view.LayoutInflater | 25 | import android.view.LayoutInflater |
26 | import android.view.View | 26 | import android.view.View |
27 | import android.view.ViewGroup | 27 | import android.view.ViewGroup |
28 | import kotlinx.android.synthetic.main.status_node_info_dialog.view.* | ||
29 | import kotlinx.android.synthetic.main.status_node_list_fragment.* | ||
30 | import org.pacien.tincapp.R | 28 | import org.pacien.tincapp.R |
31 | import org.pacien.tincapp.activities.BaseFragment | 29 | import org.pacien.tincapp.activities.BaseFragment |
32 | import org.pacien.tincapp.commands.Tinc | 30 | import org.pacien.tincapp.commands.Tinc |
31 | import org.pacien.tincapp.databinding.StatusNodeInfoDialogBinding | ||
32 | import org.pacien.tincapp.databinding.StatusNodeListFragmentBinding | ||
33 | import org.pacien.tincapp.extensions.hideBottomSeparator | 33 | import org.pacien.tincapp.extensions.hideBottomSeparator |
34 | import org.pacien.tincapp.extensions.hideTopSeparator | 34 | import org.pacien.tincapp.extensions.hideTopSeparator |
35 | import org.pacien.tincapp.extensions.setElements | 35 | import 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/ |