@@ -12,7 +12,6 @@ import androidx.recyclerview.widget.DividerItemDecoration
12
12
import androidx.recyclerview.widget.LinearLayoutManager
13
13
import com.mattskala.itemadapter.ItemAdapter
14
14
import kotlinx.coroutines.delay
15
- import kotlinx.coroutines.isActive
16
15
import kotlinx.coroutines.launch
17
16
import nl.tudelft.ipv8.android.IPv8Android
18
17
import nl.tudelft.trustchain.demo.DemoCommunity
@@ -44,53 +43,54 @@ class DemoActivity : AppCompatActivity() {
44
43
binding.recyclerView.layoutManager = LinearLayoutManager (this )
45
44
binding.recyclerView.addItemDecoration(DividerItemDecoration (this , LinearLayout .VERTICAL ))
46
45
47
- loadNetworkInfo()
48
- }
49
-
50
- private fun loadNetworkInfo () {
51
46
lifecycleScope.launch {
52
47
lifecycle.repeatOnLifecycle(Lifecycle .State .STARTED ) {
53
- while (isActive) {
54
- val demoCommunity = IPv8Android .getInstance().getOverlay<DemoCommunity >()!!
55
- val peers = demoCommunity.getPeers()
56
-
57
- val discoveredAddresses = demoCommunity.network.getWalkableAddresses(demoCommunity.serviceId)
58
-
59
- val discoveredBluetoothAddresses =
60
- demoCommunity.network.getNewBluetoothPeerCandidates().map { it.address }
61
-
62
- val peerItems = peers.map {
63
- PeerItem (
64
- it
65
- )
66
- }
67
-
68
- val addressItems = discoveredAddresses.map { address ->
69
- val contacted = demoCommunity.discoveredAddressesContacted[address]
70
- AddressItem (
71
- address, null , contacted
72
- )
73
- }
74
-
75
- val bluetoothAddressItems = discoveredBluetoothAddresses.map { address ->
76
- AddressItem (
77
- address, null , null
78
- )
79
- }
80
-
81
- val items = peerItems + bluetoothAddressItems + addressItems
82
-
83
- adapter.updateItems(items)
84
- binding.txtCommunityName.text = demoCommunity.javaClass.simpleName
85
- binding.txtPeerCount.text = " ${peers.size} peers"
86
- val textColorResId = if (peers.isNotEmpty()) R .color.green else R .color.red
87
- val textColor = ResourcesCompat .getColor(resources, textColorResId, null )
88
- binding.txtPeerCount.setTextColor(textColor)
89
- binding.imgEmpty.isVisible = items.isEmpty()
90
-
48
+ while (true ) {
49
+ loadNetworkInfo()
91
50
delay(1000 )
92
51
}
93
52
}
94
53
}
95
54
}
55
+
56
+ private fun loadNetworkInfo () {
57
+ val demoCommunity = IPv8Android .getInstance().getOverlay<DemoCommunity >()!!
58
+ val peers = demoCommunity.getPeers()
59
+
60
+ val discoveredAddresses = demoCommunity.network.getWalkableAddresses(demoCommunity.serviceId)
61
+
62
+ val discoveredBluetoothAddresses =
63
+ demoCommunity.network.getNewBluetoothPeerCandidates().map { it.address }
64
+
65
+ val peerItems = peers.map {
66
+ PeerItem (
67
+ it
68
+ )
69
+ }
70
+
71
+ val addressItems = discoveredAddresses.map { address ->
72
+ val contacted = demoCommunity.discoveredAddressesContacted[address]
73
+ AddressItem (
74
+ address, null , contacted
75
+ )
76
+ }
77
+
78
+ val bluetoothAddressItems = discoveredBluetoothAddresses.map { address ->
79
+ AddressItem (
80
+ address, null , null
81
+ )
82
+ }
83
+
84
+ val items = peerItems + bluetoothAddressItems + addressItems
85
+
86
+ adapter.updateItems(items)
87
+ binding.txtCommunityName.text = demoCommunity.javaClass.simpleName
88
+ binding.txtPeerCount.text = " ${peers.size} peers"
89
+ val textColorResId = if (peers.isNotEmpty()) R .color.green else R .color.red
90
+ val textColor = ResourcesCompat .getColor(resources, textColorResId, null )
91
+ binding.txtPeerCount.setTextColor(textColor)
92
+ binding.imgEmpty.isVisible = items.isEmpty()
93
+
94
+
95
+ }
96
96
}
0 commit comments