Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues after pull request upgrade #95

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading