mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
remove compose completely and stub out temp broken things
This commit is contained in:
parent
8709d9db8c
commit
012139cb01
22 changed files with 161 additions and 728 deletions
|
|
@ -3,7 +3,6 @@ package com.geeksville.mesh.model
|
|||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import android.util.Base64
|
||||
import androidx.compose.Model
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
import com.google.zxing.BarcodeFormat
|
||||
import com.google.zxing.MultiFormatWriter
|
||||
|
|
@ -11,7 +10,6 @@ import com.journeyapps.barcodescanner.BarcodeEncoder
|
|||
import java.net.MalformedURLException
|
||||
|
||||
|
||||
@Model
|
||||
data class Channel(
|
||||
var name: String,
|
||||
var modemConfig: MeshProtos.ChannelSettings.ModemConfig,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.geeksville.mesh.model
|
||||
|
||||
import android.os.RemoteException
|
||||
import androidx.compose.frames.modelListOf
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.geeksville.android.BuildUtils.isEmulator
|
||||
import com.geeksville.android.Logging
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
|
|
@ -21,8 +21,8 @@ data class TextMessage(
|
|||
)
|
||||
|
||||
|
||||
object MessagesState : Logging {
|
||||
private val testTexts = arrayOf(
|
||||
class MessagesState(private val ui: UIViewModel) : Logging {
|
||||
private val testTexts = listOf(
|
||||
TextMessage(
|
||||
"+16508765310",
|
||||
"I found the cache"
|
||||
|
|
@ -35,17 +35,20 @@ object MessagesState : Logging {
|
|||
|
||||
// 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 = modelListOf(* if (isEmulator) testTexts else arrayOf())
|
||||
val messages =
|
||||
object : MutableLiveData<List<TextMessage>>(if (isEmulator) testTexts else listOf()) {
|
||||
|
||||
}
|
||||
|
||||
/// add a message our GUI list of past msgs
|
||||
fun addMessage(m: TextMessage) {
|
||||
messages.add(m)
|
||||
messages.value = messages.value!! + m
|
||||
}
|
||||
|
||||
/// Send a message and added it to our GUI log
|
||||
fun sendMessage(str: String, dest: String? = null) {
|
||||
var error: String? = null
|
||||
val service = UIState.meshService
|
||||
val service = ui.meshService
|
||||
if (service != null)
|
||||
try {
|
||||
service.sendData(
|
||||
|
|
@ -59,9 +62,9 @@ object MessagesState : Logging {
|
|||
else
|
||||
error = "Error: No Mesh service"
|
||||
|
||||
MessagesState.addMessage(
|
||||
addMessage(
|
||||
TextMessage(
|
||||
NodeDB.myId.value,
|
||||
ui.nodeDB.myId.value!!,
|
||||
str,
|
||||
errorMessage = error
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
package com.geeksville.mesh.model
|
||||
|
||||
import androidx.compose.frames.modelMapOf
|
||||
import androidx.compose.mutableStateOf
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.geeksville.android.BuildUtils.isEmulator
|
||||
import com.geeksville.mesh.MeshUser
|
||||
import com.geeksville.mesh.NodeInfo
|
||||
import com.geeksville.mesh.Position
|
||||
|
||||
object NodeDB {
|
||||
|
||||
/// NodeDB lives inside the UIViewModel, but it needs a backpointer to reach the service
|
||||
class NodeDB(private val ui: UIViewModel) {
|
||||
private val testPositions = arrayOf(
|
||||
Position(32.776665, -96.796989, 35), // dallas
|
||||
Position(32.960758, -96.733521, 35), // richardson
|
||||
|
|
@ -43,12 +44,14 @@ object NodeDB {
|
|||
private val seedWithTestNodes = isEmulator
|
||||
|
||||
/// The unique ID of our node
|
||||
val myId = mutableStateOf(if (isEmulator) "+16508765309" else "invalid")
|
||||
val myId = object : MutableLiveData<String>(if (isEmulator) "+16508765309" else "invalid") {}
|
||||
|
||||
/// A map from nodeid to to nodeinfo
|
||||
val nodes =
|
||||
modelMapOf(* (if (isEmulator) testNodes else listOf()).map { it.user!!.id to it }.toTypedArray())
|
||||
object :
|
||||
MutableLiveData<Map<String, NodeInfo>>(mapOf(*(if (isEmulator) testNodes else listOf()).map { it.user!!.id to it }
|
||||
.toTypedArray())) {}
|
||||
|
||||
/// Could be null if we haven't received our node DB yet
|
||||
val ourNodeInfo get() = nodes[myId.value]
|
||||
val ourNodeInfo get() = nodes.value!![myId.value]
|
||||
}
|
||||
|
|
@ -3,11 +3,8 @@ package com.geeksville.mesh.model
|
|||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.RemoteException
|
||||
import androidx.compose.mutableStateOf
|
||||
import androidx.core.content.edit
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.geeksville.android.BuildUtils.isEmulator
|
||||
|
|
@ -15,7 +12,15 @@ import com.geeksville.android.Logging
|
|||
import com.geeksville.mesh.IMeshService
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
import com.geeksville.mesh.service.MeshService
|
||||
import com.geeksville.mesh.ui.getInitials
|
||||
|
||||
/// Given a human name, strip out the first letter of the first three words and return that as the initials for
|
||||
/// that user.
|
||||
fun getInitials(name: String): String {
|
||||
val words = name.split(Regex("\\s+")).filter { it.isNotEmpty() }.take(3).map { it.first() }
|
||||
.joinToString("")
|
||||
|
||||
return words
|
||||
}
|
||||
|
||||
class UIViewModel : ViewModel(), Logging {
|
||||
init {
|
||||
|
|
@ -41,32 +46,15 @@ class UIViewModel : ViewModel(), Logging {
|
|||
context.getSharedPreferences("ui-prefs", Context.MODE_PRIVATE)
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
debug("ViewModel cleared")
|
||||
}
|
||||
|
||||
var meshService: IMeshService? = null
|
||||
|
||||
val nodeDB = NodeDB(this)
|
||||
val messagesState = MessagesState(this)
|
||||
|
||||
/// Are we connected to our radio device
|
||||
val isConnected =
|
||||
object : LiveData<MeshService.ConnectionState>(MeshService.ConnectionState.DISCONNECTED) {
|
||||
/**
|
||||
* Called when the number of active observers change to 1 from 0.
|
||||
*
|
||||
*
|
||||
* This callback can be used to know that this LiveData is being used thus should be kept
|
||||
* up to date.
|
||||
*/
|
||||
override fun onActive() {
|
||||
super.onActive()
|
||||
|
||||
// Get the current radio config from the service
|
||||
meshService?.let {
|
||||
debug("Getting connection state from service")
|
||||
value = MeshService.ConnectionState.valueOf(it.connectionState())
|
||||
}
|
||||
}
|
||||
object :
|
||||
MutableLiveData<MeshService.ConnectionState>(MeshService.ConnectionState.DISCONNECTED) {
|
||||
}
|
||||
|
||||
/// various radio settings (including the channel)
|
||||
|
|
@ -89,6 +77,11 @@ class UIViewModel : ViewModel(), Logging {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
debug("ViewModel cleared")
|
||||
}
|
||||
|
||||
/// Set the radio config (also updates our saved copy in preferences)
|
||||
fun setRadioConfig(context: Context, c: MeshProtos.RadioConfig) {
|
||||
debug("Setting new radio config!")
|
||||
|
|
@ -96,66 +89,28 @@ class UIViewModel : ViewModel(), Logging {
|
|||
radioConfig.value = c
|
||||
|
||||
getPreferences(context).edit(commit = true) {
|
||||
this.putString("channel-url", UIState.getChannel()!!.getChannelUrl().toString())
|
||||
this.putString("channel-url", getChannel(c)!!.getChannelUrl().toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// FIXME - figure out how to merge this staate with the AppStatus Model
|
||||
object UIState : Logging {
|
||||
|
||||
/// Kinda ugly - created in the activity but used from Compose - figure out if there is a cleaner way GIXME
|
||||
// lateinit var googleSignInClient: GoogleSignInClient
|
||||
|
||||
var meshService: IMeshService? = null
|
||||
|
||||
/// Are we connected to our radio device
|
||||
val isConnected = mutableStateOf(MeshService.ConnectionState.DISCONNECTED)
|
||||
|
||||
/// various radio settings (including the channel)
|
||||
private val radioConfig = mutableStateOf<MeshProtos.RadioConfig?>(null)
|
||||
|
||||
/// our name in hte radio
|
||||
/// Note, we generate owner initials automatically for now
|
||||
/// our activity will read this from prefs or set it to the empty string
|
||||
var ownerName: String = "MrInIDE Ownername"
|
||||
val ownerName = object : MutableLiveData<String>("MrIDE Test") {
|
||||
}
|
||||
|
||||
|
||||
/// If the app was launched because we received a new channel intent, the Url will be here
|
||||
var requestedChannelUrl: Uri? = null
|
||||
|
||||
var savedInstanceState: Bundle? = null
|
||||
|
||||
/**
|
||||
* Return the current channel info
|
||||
* FIXME, we should sim channels at the MeshService level if we are running on an emulator,
|
||||
* for now I just fake it by returning a canned channel.
|
||||
*/
|
||||
fun getChannel(): Channel? {
|
||||
val channel = radioConfig.value?.channelSettings?.let { Channel(it) }
|
||||
|
||||
return if (channel == null && isEmulator)
|
||||
Channel.emulated
|
||||
else
|
||||
channel
|
||||
}
|
||||
|
||||
fun getPreferences(context: Context): SharedPreferences =
|
||||
context.getSharedPreferences("ui-prefs", Context.MODE_PRIVATE)
|
||||
|
||||
/// Set the radio config (also updates our saved copy in preferences)
|
||||
fun setRadioConfig(context: Context, c: MeshProtos.RadioConfig) {
|
||||
radioConfig.value = c
|
||||
|
||||
getPreferences(context).edit(commit = true) {
|
||||
this.putString("channel-url", getChannel()!!.getChannelUrl().toString())
|
||||
}
|
||||
}
|
||||
|
||||
// clean up all this nasty owner state management FIXME
|
||||
fun setOwner(context: Context, s: String? = null) {
|
||||
|
||||
if (s != null) {
|
||||
ownerName = s
|
||||
ownerName.value = s
|
||||
|
||||
// note: we allow an empty userstring to be written to prefs
|
||||
getPreferences(context).edit(commit = true) {
|
||||
|
|
@ -164,15 +119,16 @@ object UIState : Logging {
|
|||
}
|
||||
|
||||
// Note: we are careful to not set a new unique ID
|
||||
if (ownerName.isNotEmpty())
|
||||
if (ownerName.value!!.isNotEmpty())
|
||||
try {
|
||||
meshService?.setOwner(
|
||||
null,
|
||||
ownerName,
|
||||
getInitials(ownerName)
|
||||
ownerName.value,
|
||||
getInitials(ownerName.value!!)
|
||||
) // Note: we use ?. here because we might be running in the emulator
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("Can't set username on device, is device offline? ${ex.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue