Skip to content

Commit

Permalink
Fix deprecated routines
Browse files Browse the repository at this point in the history
  • Loading branch information
Eragoneq committed Feb 7, 2025
1 parent 2c5fab9 commit 78e1013
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ file needs to define these variables and dependencies, too. A working template w
folder's `build.gradle` file.
- Don't forget to `include ':ipv8'` into your own `settings.gradle`,
as well as the module that you're going to use, presumably `ipv8-android` or `ipv8-jvm`.
- This repository currently uses Gradle version `8.8.0`. Ensure that your `gradle-wrapper.properties` uses the same version.
- This repository currently uses Gradle version `8.10.2`. Ensure that your `gradle-wrapper.properties` uses the same version.
- This repository currently uses Java version `17`. Ensure that your Gradle builds with this, too.
- By default, Gradle looks at the `JAVA_HOME` variable, which might not point to `17`.
- This repository currently uses Kotlin version `2.1.10`. Ensure that your Gradle builds with this Kotlin version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.mattskala.itemadapter.ItemAdapter
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import nl.tudelft.ipv8.android.IPv8Android
import nl.tudelft.trustchain.demo.DemoCommunity
import nl.tudelft.trustchain.demo.R
Expand Down Expand Up @@ -45,46 +48,48 @@ class DemoActivity : AppCompatActivity() {
}

private fun loadNetworkInfo() {
lifecycleScope.launchWhenStarted {
while (isActive) {
val demoCommunity = IPv8Android.getInstance().getOverlay<DemoCommunity>()!!
val peers = demoCommunity.getPeers()

val discoveredAddresses = demoCommunity.network.getWalkableAddresses(demoCommunity.serviceId)

val discoveredBluetoothAddresses =
demoCommunity.network.getNewBluetoothPeerCandidates().map { it.address }

val peerItems = peers.map {
PeerItem(
it
)
}

val addressItems = discoveredAddresses.map { address ->
val contacted = demoCommunity.discoveredAddressesContacted[address]
AddressItem(
address, null, contacted
)
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
while (isActive) {
val demoCommunity = IPv8Android.getInstance().getOverlay<DemoCommunity>()!!
val peers = demoCommunity.getPeers()

val discoveredAddresses = demoCommunity.network.getWalkableAddresses(demoCommunity.serviceId)

val discoveredBluetoothAddresses =
demoCommunity.network.getNewBluetoothPeerCandidates().map { it.address }

val peerItems = peers.map {
PeerItem(
it
)
}

val addressItems = discoveredAddresses.map { address ->
val contacted = demoCommunity.discoveredAddressesContacted[address]
AddressItem(
address, null, contacted
)
}

val bluetoothAddressItems = discoveredBluetoothAddresses.map { address ->
AddressItem(
address, null, null
)
}

val items = peerItems + bluetoothAddressItems + addressItems

adapter.updateItems(items)
binding.txtCommunityName.text = demoCommunity.javaClass.simpleName
binding.txtPeerCount.text = "${peers.size} peers"
val textColorResId = if (peers.isNotEmpty()) R.color.green else R.color.red
val textColor = ResourcesCompat.getColor(resources, textColorResId, null)
binding.txtPeerCount.setTextColor(textColor)
binding.imgEmpty.isVisible = items.isEmpty()

delay(1000)
}

val bluetoothAddressItems = discoveredBluetoothAddresses.map { address ->
AddressItem(
address, null, null
)
}

val items = peerItems + bluetoothAddressItems + addressItems

adapter.updateItems(items)
binding.txtCommunityName.text = demoCommunity.javaClass.simpleName
binding.txtPeerCount.text = "${peers.size} peers"
val textColorResId = if (peers.isNotEmpty()) R.color.green else R.color.red
val textColor = ResourcesCompat.getColor(resources, textColorResId, null)
binding.txtPeerCount.setTextColor(textColor)
binding.imgEmpty.isVisible = items.isEmpty()

delay(1000)
}
}
}
Expand Down

0 comments on commit 78e1013

Please sign in to comment.