kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
connection state now shown in gui
rodzic
984bc460d6
commit
63b9da4c12
|
@ -44,6 +44,7 @@ android {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// per protobuf-gradle-plugin docs, this is recommended for android
|
// per protobuf-gradle-plugin docs, this is recommended for android
|
||||||
protobuf {
|
protobuf {
|
||||||
protoc {
|
protoc {
|
||||||
|
|
|
@ -14,14 +14,12 @@ import android.view.MenuItem
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.compose.Composable
|
import androidx.compose.Composable
|
||||||
import androidx.compose.Model
|
import androidx.compose.mutableStateOf
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.ui.core.Text
|
import androidx.ui.core.Text
|
||||||
import androidx.ui.core.dp
|
|
||||||
import androidx.ui.core.setContent
|
import androidx.ui.core.setContent
|
||||||
import androidx.ui.layout.Column
|
import androidx.ui.layout.Column
|
||||||
import androidx.ui.layout.Spacing
|
|
||||||
import androidx.ui.material.Button
|
import androidx.ui.material.Button
|
||||||
import androidx.ui.material.MaterialTheme
|
import androidx.ui.material.MaterialTheme
|
||||||
import androidx.ui.tooling.preview.Preview
|
import androidx.ui.tooling.preview.Preview
|
||||||
|
@ -39,13 +37,18 @@ class MainActivity : AppCompatActivity(), Logging {
|
||||||
const val DID_REQUEST_PERM = 11
|
const val DID_REQUEST_PERM = 11
|
||||||
}
|
}
|
||||||
|
|
||||||
@Model
|
/// A map from nodeid to to nodeinfo
|
||||||
class MeshServiceState(
|
private val nodes = mutableStateOf(mapOf<String, NodeInfo>())
|
||||||
var connected: Boolean = false,
|
|
||||||
var onlineIds: Array<String> = arrayOf()
|
data class TextMessage(val date: Date, val from: String, val text: String)
|
||||||
)
|
|
||||||
|
private val messages = mutableStateOf(listOf<TextMessage>())
|
||||||
|
|
||||||
|
/// Are we connected to our radio device
|
||||||
|
private var isConnected = mutableStateOf(false)
|
||||||
|
|
||||||
|
private val utf8 = Charset.forName("UTF-8")
|
||||||
|
|
||||||
val meshServiceState = MeshServiceState()
|
|
||||||
|
|
||||||
private val bluetoothAdapter: BluetoothAdapter? by lazy(LazyThreadSafetyMode.NONE) {
|
private val bluetoothAdapter: BluetoothAdapter? by lazy(LazyThreadSafetyMode.NONE) {
|
||||||
val bluetoothManager = getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
val bluetoothManager = getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
||||||
|
@ -96,7 +99,7 @@ class MainActivity : AppCompatActivity(), Logging {
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
fun previewView() {
|
fun previewView() {
|
||||||
composeView(meshServiceState)
|
composeView()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendTestPackets() {
|
private fun sendTestPackets() {
|
||||||
|
@ -120,14 +123,20 @@ class MainActivity : AppCompatActivity(), Logging {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun composeView(meshServiceState: MeshServiceState) {
|
fun composeView() {
|
||||||
MaterialTheme {
|
MaterialTheme {
|
||||||
Column(modifier = Spacing(8.dp)) {
|
// modifier = Spacing(8.dp)
|
||||||
Text(text = "Meshtastic", modifier = Spacing(8.dp))
|
Column() {
|
||||||
|
Text(text = "Meshtastic")
|
||||||
|
|
||||||
Text("Radio connected: ${meshServiceState.connected}")
|
Text("Radio connected: ${isConnected.value}")
|
||||||
meshServiceState.onlineIds.forEach {
|
|
||||||
Text("User: $it")
|
nodes.value.values.forEach {
|
||||||
|
Text("Node: $it")
|
||||||
|
}
|
||||||
|
|
||||||
|
messages.value.forEach {
|
||||||
|
Text("Text: $it")
|
||||||
}
|
}
|
||||||
|
|
||||||
Button(text = "Start scan",
|
Button(text = "Start scan",
|
||||||
|
@ -157,7 +166,7 @@ class MainActivity : AppCompatActivity(), Logging {
|
||||||
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true)
|
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true)
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
composeView(meshServiceState)
|
composeView()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensures Bluetooth is available on the device and it is enabled. If not,
|
// Ensures Bluetooth is available on the device and it is enabled. If not,
|
||||||
|
@ -183,17 +192,6 @@ class MainActivity : AppCompatActivity(), Logging {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A map from nodeid to to nodeinfo
|
|
||||||
private val nodes = mutableMapOf<String, NodeInfo>()
|
|
||||||
|
|
||||||
data class TextMessage(val date: Date, val from: String, val text: String)
|
|
||||||
|
|
||||||
private val messages = mutableListOf<TextMessage>()
|
|
||||||
|
|
||||||
/// Are we connected to our radio device
|
|
||||||
private var isConnected = false
|
|
||||||
|
|
||||||
private val utf8 = Charset.forName("UTF-8")
|
|
||||||
|
|
||||||
private val meshServiceReceiver = object : BroadcastReceiver() {
|
private val meshServiceReceiver = object : BroadcastReceiver() {
|
||||||
|
|
||||||
|
@ -207,25 +205,30 @@ class MainActivity : AppCompatActivity(), Logging {
|
||||||
|
|
||||||
// We only care about nodes that have user info
|
// We only care about nodes that have user info
|
||||||
info.user?.id?.let {
|
info.user?.id?.let {
|
||||||
nodes[it] = info
|
val newnodes = nodes.value.toMutableMap()
|
||||||
|
newnodes[it] = info
|
||||||
|
nodes.value = newnodes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MeshService.ACTION_RECEIVED_DATA -> {
|
MeshService.ACTION_RECEIVED_DATA -> {
|
||||||
warn("TODO rxopaqe")
|
warn("TODO rxopaqe")
|
||||||
val sender = intent.getStringExtra(EXTRA_SENDER)!!
|
val sender = intent.getStringExtra(EXTRA_SENDER)!!
|
||||||
val payload = intent.getByteArrayExtra(EXTRA_PAYLOAD)!!
|
val payload = intent.getByteArrayExtra(EXTRA_PAYLOAD)!!
|
||||||
val typ = intent.getIntExtra(EXTRA_TYP, -1)!!
|
val typ = intent.getIntExtra(EXTRA_TYP, -1)
|
||||||
|
|
||||||
when (typ) {
|
when (typ) {
|
||||||
MeshProtos.Data.Type.CLEAR_TEXT_VALUE -> {
|
MeshProtos.Data.Type.CLEAR_TEXT_VALUE -> {
|
||||||
// FIXME - use the real time from the packet
|
// FIXME - use the real time from the packet
|
||||||
messages.add(TextMessage(Date(), sender, payload.toString(utf8)))
|
val modded = messages.value.toMutableList()
|
||||||
|
modded.add(TextMessage(Date(), sender, payload.toString(utf8)))
|
||||||
|
messages.value = modded
|
||||||
}
|
}
|
||||||
else -> TODO()
|
else -> TODO()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RadioInterfaceService.CONNECTCHANGED_ACTION -> {
|
RadioInterfaceService.CONNECTCHANGED_ACTION -> {
|
||||||
isConnected = intent.getBooleanExtra(EXTRA_CONNECTED, false)
|
isConnected.value = intent.getBooleanExtra(EXTRA_CONNECTED, false)
|
||||||
debug("connchange $isConnected")
|
debug("connchange $isConnected")
|
||||||
}
|
}
|
||||||
else -> TODO()
|
else -> TODO()
|
||||||
|
@ -245,16 +248,12 @@ class MainActivity : AppCompatActivity(), Logging {
|
||||||
// FIXME - do actions for when we connect to the service
|
// FIXME - do actions for when we connect to the service
|
||||||
debug("did connect")
|
debug("did connect")
|
||||||
|
|
||||||
// FIXME: this still can't work this early because the send to +6508675310
|
isConnected.value = m.isConnected
|
||||||
// requires a DB lookup which isn't yet populated (until the sim test packets
|
|
||||||
// from the radio arrive)
|
|
||||||
// sendTestPackets() // send some traffic ASAP
|
|
||||||
|
|
||||||
// FIXME this doesn't work because the model has already been copied into compose land?
|
// make some placeholder nodeinfos
|
||||||
// runOnUiThread { // FIXME - this can be removed?
|
val pairs = m.online.toList().map { it to NodeInfo(0, MeshUser(it, "unknown", "unk")) }
|
||||||
meshServiceState.connected = m.isConnected
|
.toTypedArray()
|
||||||
meshServiceState.onlineIds = m.online
|
nodes.value = mapOf(*pairs)
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onServiceDisconnected(name: ComponentName) {
|
override fun onServiceDisconnected(name: ComponentName) {
|
||||||
|
|
|
@ -283,7 +283,7 @@ class MeshService : Service(), Logging {
|
||||||
if (userId != null)
|
if (userId != null)
|
||||||
nodeDBbyID[userId] = info
|
nodeDBbyID[userId] = info
|
||||||
|
|
||||||
broadcastNodeChange(info)
|
// FIXME broadcastNodeChange(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate a new mesh packet builder with our node as the sender, and the specified node num
|
/// Generate a new mesh packet builder with our node as the sender, and the specified node num
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = '1.3.61'
|
ext.kotlin_version = '1.3.61'
|
||||||
ext.compose_version = '0.1.0-dev03'
|
ext.compose_version = '0.1.0-dev04'
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
|
|
Ładowanie…
Reference in New Issue