start cleaning up models

This commit is contained in:
geeksville 2020-02-17 13:34:52 -08:00
parent 52deba7d4b
commit f18ac28dc0
9 changed files with 307 additions and 268 deletions

View file

@ -0,0 +1,36 @@
package com.geeksville.mesh.model
import androidx.compose.mutableStateOf
import com.geeksville.android.Logging
import java.util.*
/**
* the model object for a text message
*/
data class TextMessage(val from: String, val text: String, val date: Date = Date())
object MessagesState : Logging {
val testTexts = listOf(
TextMessage(
"+16508675310",
"I found the cache"
),
TextMessage(
"+16508675311",
"Help! I've fallen and I can't get up."
)
)
// If the following (unused otherwise) line is commented out, the IDE preview window works.
// if left in the preview always renders as empty.
val messages = mutableStateOf(testTexts, { a, b ->
a.size == b.size // If the # of messages changes, consider it important for rerender
})
fun addMessage(m: TextMessage) {
val l = messages.value.toMutableList()
l.add(m)
messages.value = l
}
}

View file

@ -0,0 +1,48 @@
package com.geeksville.mesh.model
import androidx.compose.mutableStateOf
import com.geeksville.mesh.MeshUser
import com.geeksville.mesh.NodeInfo
import com.geeksville.mesh.Position
object NodeDB {
private val testPositions = arrayOf(
Position(32.776665, -96.796989, 35), // dallas
Position(32.960758, -96.733521, 35), // richardson
Position(
32.912901,
-96.781776,
35
) // north dallas
)
val testNodeNoPosition = NodeInfo(
8,
MeshUser(
"+16508765308".format(8),
"Kevin MesterNoLoc",
"KLO"
),
null,
12345
)
val testNodes = testPositions.mapIndexed { index, it ->
NodeInfo(
9 + index,
MeshUser(
"+165087653%02d".format(9 + index),
"Kevin Mester$index",
"KM$index"
),
it,
12345
)
}
/// The unique ID of our node
val myId = mutableStateOf("+16508765309")
/// A map from nodeid to to nodeinfo
val nodes = mutableStateOf(testNodes.map { it.user!!.id to it }.toMap())
}

View file

@ -0,0 +1,32 @@
package com.geeksville.mesh.model
import android.util.Base64
import androidx.compose.mutableStateOf
import com.geeksville.mesh.MeshProtos
/// FIXME - figure out how to merge this staate with the AppStatus Model
object UIState {
/// Kinda ugly - created in the activity but used from Compose - figure out if there is a cleaner way GIXME
// lateinit var googleSignInClient: GoogleSignInClient
/// Are we connected to our radio device
val isConnected = mutableStateOf(false)
/// various radio settings (including the channel)
val radioConfig = mutableStateOf(MeshProtos.RadioConfig.getDefaultInstance())
/// our name in hte radio
/// Note, we generate owner initials automatically for now
val ownerName = mutableStateOf("fixme readfromprefs")
/// Return an URL that represents the current channel values
val channelUrl
get(): String {
val channelBytes = radioConfig.value.channelSettings.toByteArray()
val enc = Base64.encodeToString(channelBytes, Base64.URL_SAFE + Base64.NO_WRAP)
return "https://www.meshtastic.org/c/$enc"
}
}