aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/start/NetworkListFragment.kt13
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListFragment.kt14
-rw-r--r--app/src/main/java/org/pacien/tincapp/extensions/ListViewExtensions.kt23
3 files changed, 38 insertions, 12 deletions
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 9a25a0c..7b5006a 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
@@ -31,6 +31,7 @@ import org.pacien.tincapp.activities.BaseFragment
31import org.pacien.tincapp.databinding.StartNetworkListBinding 31import org.pacien.tincapp.databinding.StartNetworkListBinding
32import org.pacien.tincapp.extensions.hideBottomSeparator 32import org.pacien.tincapp.extensions.hideBottomSeparator
33import org.pacien.tincapp.extensions.setElements 33import org.pacien.tincapp.extensions.setElements
34import org.pacien.tincapp.extensions.updatePlaceholderVisibility
34 35
35/** 36/**
36 * @author euxane 37 * @author euxane
@@ -55,7 +56,6 @@ class NetworkListFragment : BaseFragment() {
55 val listHeaderView = layoutInflater.inflate(R.layout.start_network_list_header, startNetworkListBinding.root, false) 56 val listHeaderView = layoutInflater.inflate(R.layout.start_network_list_header, startNetworkListBinding.root, false)
56 startNetworkListBinding.startNetworkList.addHeaderView(listHeaderView, null, false) 57 startNetworkListBinding.startNetworkList.addHeaderView(listHeaderView, null, false)
57 startNetworkListBinding.startNetworkList.hideBottomSeparator() 58 startNetworkListBinding.startNetworkList.hideBottomSeparator()
58 startNetworkListBinding.startNetworkList.emptyView = startNetworkListBinding.startNetworkListPlaceholder
59 startNetworkListBinding.startNetworkList.onItemClickListener = AdapterView.OnItemClickListener(this::onItemClick) 59 startNetworkListBinding.startNetworkList.onItemClickListener = AdapterView.OnItemClickListener(this::onItemClick)
60 startNetworkListBinding.startNetworkList.adapter = networkListAdapter 60 startNetworkListBinding.startNetworkList.adapter = networkListAdapter
61 } 61 }
@@ -67,13 +67,10 @@ class NetworkListFragment : BaseFragment() {
67 } 67 }
68 68
69 private fun updateNetworkList(networks: List<String>) { 69 private fun updateNetworkList(networks: List<String>) {
70 startNetworkListBinding.startNetworkList.updatePlaceholderVisibility(
71 startNetworkListBinding.startNetworkListPlaceholder,
72 networks.isEmpty()
73 )
70 networkListAdapter.setElements(networks) 74 networkListAdapter.setElements(networks)
71 if (networks.isEmpty()) updatePlaceholder()
72 }
73
74 private fun updatePlaceholder() {
75 startNetworkListBinding.startNetworkListPlaceholder.post {
76 startNetworkListBinding.startNetworkListPlaceholderText?.text = getString(R.string.start_network_list_empty_none_found)
77 }
78 } 75 }
79} 76}
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 05c65d7..474ab6e 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
@@ -18,7 +18,6 @@
18 18
19package org.pacien.tincapp.activities.status.nodes 19package org.pacien.tincapp.activities.status.nodes
20 20
21import androidx.lifecycle.Observer
22import androidx.lifecycle.ViewModelProviders 21import androidx.lifecycle.ViewModelProviders
23import android.os.Bundle 22import android.os.Bundle
24import androidx.appcompat.app.AlertDialog 23import androidx.appcompat.app.AlertDialog
@@ -33,6 +32,7 @@ import org.pacien.tincapp.databinding.StatusNodeListFragmentBinding
33import org.pacien.tincapp.extensions.hideBottomSeparator 32import org.pacien.tincapp.extensions.hideBottomSeparator
34import org.pacien.tincapp.extensions.hideTopSeparator 33import org.pacien.tincapp.extensions.hideTopSeparator
35import org.pacien.tincapp.extensions.setElements 34import org.pacien.tincapp.extensions.setElements
35import org.pacien.tincapp.extensions.updatePlaceholderVisibility
36import org.pacien.tincapp.service.TincVpnService 36import org.pacien.tincapp.service.TincVpnService
37 37
38/** 38/**
@@ -44,12 +44,11 @@ class NodeListFragment : BaseFragment() {
44 private val netName by lazy { vpnService.getCurrentNetName()!! } 44 private val netName by lazy { vpnService.getCurrentNetName()!! }
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) } }
48 private lateinit var statusNodeListFragmentBinding: StatusNodeListFragmentBinding 47 private lateinit var statusNodeListFragmentBinding: StatusNodeListFragmentBinding
49 48
50 override fun onCreate(savedInstanceState: Bundle?) { 49 override fun onCreate(savedInstanceState: Bundle?) {
51 super.onCreate(savedInstanceState) 50 super.onCreate(savedInstanceState)
52 nodeListViewModel.nodeList.observe(this, nodeListObserver) 51 nodeListViewModel.nodeList.observe(this) { updateNodeList(it) }
53 } 52 }
54 53
55 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { 54 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
@@ -60,10 +59,17 @@ class NodeListFragment : BaseFragment() {
60 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 59 override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
61 statusNodeListFragmentBinding.statusNodeList.hideTopSeparator() 60 statusNodeListFragmentBinding.statusNodeList.hideTopSeparator()
62 statusNodeListFragmentBinding.statusNodeList.hideBottomSeparator() 61 statusNodeListFragmentBinding.statusNodeList.hideBottomSeparator()
63 statusNodeListFragmentBinding.statusNodeList.emptyView = statusNodeListFragmentBinding.statusNodeListPlaceholder
64 statusNodeListFragmentBinding.statusNodeList.adapter = nodeListAdapter 62 statusNodeListFragmentBinding.statusNodeList.adapter = nodeListAdapter
65 } 63 }
66 64
65 private fun updateNodeList(nodes: List<NodeInfo>) {
66 statusNodeListFragmentBinding.statusNodeList.updatePlaceholderVisibility(
67 statusNodeListFragmentBinding.statusNodeListPlaceholder,
68 nodes.isEmpty()
69 )
70 nodeListAdapter.setElements(nodes)
71 }
72
67 private fun onItemClick(nodeInfo: NodeInfo) = 73 private fun onItemClick(nodeInfo: NodeInfo) =
68 showNodeInfo(nodeInfo.name) 74 showNodeInfo(nodeInfo.name)
69 75
diff --git a/app/src/main/java/org/pacien/tincapp/extensions/ListViewExtensions.kt b/app/src/main/java/org/pacien/tincapp/extensions/ListViewExtensions.kt
index 9501a8d..8a52484 100644
--- a/app/src/main/java/org/pacien/tincapp/extensions/ListViewExtensions.kt
+++ b/app/src/main/java/org/pacien/tincapp/extensions/ListViewExtensions.kt
@@ -45,3 +45,26 @@ fun ListView.hideTopSeparator() {
45fun ListView.hideBottomSeparator() { 45fun ListView.hideBottomSeparator() {
46 addFooterView(View(context), null, false) 46 addFooterView(View(context), null, false)
47} 47}
48
49/**
50 * Workaround for mishandled list emptyView since Android SDK 34:
51
52java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
53 at android.widget.ListView.removeUnusedFixedViews(ListView.java:2001)
54 at android.widget.ListView.layoutChildren(ListView.java:1860)
55 at android.widget.AbsListView.onLayout(AbsListView.java:2271)
56 at android.widget.AdapterView.updateEmptyStatus(AdapterView.java:794)
57 at android.widget.AdapterView.checkFocus(AdapterView.java:767)
58 at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:859)
59 at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:6949)
60 at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:38)
61 at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:54)
62 at android.widget.ArrayAdapter.notifyDataSetChanged(ArrayAdapter.java:355)
63 at org.pacien.tincapp.extensions.ListViewExtensionsKt.setElements(ListViewExtensions.kt:36)
64 */
65fun ListView.updatePlaceholderVisibility(placeholderView: View, usePlaceholder: Boolean) {
66 post {
67 placeholderView.visibility = if (usePlaceholder) View.VISIBLE else View.GONE
68 visibility = if (usePlaceholder) View.GONE else View.VISIBLE
69 }
70} \ No newline at end of file