Skip to content

Commit 6d19d5b

Browse files
committed
Remove unnecessary isActive
1 parent 0004697 commit 6d19d5b

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

demo-android/src/main/java/nl/tudelft/trustchain/demo/ui/DemoActivity.kt

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import androidx.recyclerview.widget.DividerItemDecoration
1212
import androidx.recyclerview.widget.LinearLayoutManager
1313
import com.mattskala.itemadapter.ItemAdapter
1414
import kotlinx.coroutines.delay
15-
import kotlinx.coroutines.isActive
1615
import kotlinx.coroutines.launch
1716
import nl.tudelft.ipv8.android.IPv8Android
1817
import nl.tudelft.trustchain.demo.DemoCommunity
@@ -44,53 +43,54 @@ class DemoActivity : AppCompatActivity() {
4443
binding.recyclerView.layoutManager = LinearLayoutManager(this)
4544
binding.recyclerView.addItemDecoration(DividerItemDecoration(this, LinearLayout.VERTICAL))
4645

47-
loadNetworkInfo()
48-
}
49-
50-
private fun loadNetworkInfo() {
5146
lifecycleScope.launch {
5247
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()
9150
delay(1000)
9251
}
9352
}
9453
}
9554
}
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+
}
9696
}

0 commit comments

Comments
 (0)