68 lines
2.3 KiB
Kotlin
68 lines
2.3 KiB
Kotlin
package pro.nnnteam.nnnet
|
|
|
|
import android.os.Bundle
|
|
import android.widget.ImageButton
|
|
import android.widget.TextView
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import androidx.lifecycle.lifecycleScope
|
|
import kotlinx.coroutines.launch
|
|
import pro.nnnteam.nnnet.data.MeshDatabase
|
|
import pro.nnnteam.nnnet.data.MeshRepository
|
|
import pro.nnnteam.nnnet.ui.MapNodeUi
|
|
import pro.nnnteam.nnnet.ui.NetworkMapView
|
|
|
|
class PacketMapActivity : AppCompatActivity() {
|
|
private lateinit var repository: MeshRepository
|
|
private lateinit var mapView: NetworkMapView
|
|
private lateinit var mapMetaText: TextView
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
setContentView(R.layout.activity_packet_map)
|
|
|
|
val database = MeshDatabase.getInstance(applicationContext)
|
|
repository = MeshRepository(
|
|
database.messageDao(),
|
|
database.outboundQueueDao(),
|
|
database.profileDao(),
|
|
database.packetTraceDao()
|
|
)
|
|
|
|
mapView = findViewById(R.id.mapView)
|
|
mapMetaText = findViewById(R.id.mapMetaText)
|
|
findViewById<ImageButton>(R.id.backButton).setOnClickListener { finish() }
|
|
|
|
renderMap()
|
|
}
|
|
|
|
private fun renderMap() {
|
|
lifecycleScope.launch {
|
|
val local = repository.localProfile()
|
|
val remoteNodes = repository.mapNodes()
|
|
val nodes = buildList {
|
|
add(
|
|
MapNodeUi(
|
|
label = local?.displayName() ?: getString(R.string.you_label),
|
|
peerId = local?.peerId.orEmpty(),
|
|
isSelf = true
|
|
)
|
|
)
|
|
remoteNodes
|
|
.filter { it.peerId != local?.peerId }
|
|
.take(16)
|
|
.forEach { profile ->
|
|
add(
|
|
MapNodeUi(
|
|
label = profile.displayName(),
|
|
peerId = profile.peerId,
|
|
isSelf = false
|
|
)
|
|
)
|
|
}
|
|
}
|
|
mapView.submitNodes(nodes)
|
|
mapMetaText.text = getString(R.string.map_mode_hint, nodes.size)
|
|
}
|
|
}
|
|
}
|