diff --git a/app/src/main/java/com/geeksville/mesh/MainActivity.kt b/app/src/main/java/com/geeksville/mesh/MainActivity.kt
index 1d82ab494..f49994221 100644
--- a/app/src/main/java/com/geeksville/mesh/MainActivity.kt
+++ b/app/src/main/java/com/geeksville/mesh/MainActivity.kt
@@ -16,6 +16,7 @@ import android.view.Menu
import android.view.MenuItem
import android.view.MotionEvent
import android.widget.Toast
+import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
@@ -24,10 +25,7 @@ import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.geeksville.android.Logging
import com.geeksville.android.ServiceClient
-import com.geeksville.mesh.model.MessagesState
-import com.geeksville.mesh.model.NodeDB
-import com.geeksville.mesh.model.TextMessage
-import com.geeksville.mesh.model.UIState
+import com.geeksville.mesh.model.*
import com.geeksville.mesh.service.*
import com.geeksville.mesh.ui.*
import com.geeksville.util.Exceptions
@@ -106,26 +104,8 @@ class MainActivity : AppCompatActivity(), Logging,
bluetoothManager.adapter
}
- /*
-
+ private val model: UIViewModel by viewModels()
- /--
-
-
- -->
- */
data class TabInfo(val text: String, val icon: Int, val content: Fragment)
// private val tabIndexes = generateSequence(0) { it + 1 } FIXME, instead do withIndex or zip? to get the ids below, also stop duplicating strings
@@ -503,6 +483,7 @@ class MainActivity : AppCompatActivity(), Logging,
}) {
override fun onConnected(service: com.geeksville.mesh.IMeshService) {
UIState.meshService = service
+ model.meshService = service
// We don't start listening for packets until after we are connected to the service
registerMeshReceiver()
diff --git a/app/src/main/java/com/geeksville/mesh/model/UIState.kt b/app/src/main/java/com/geeksville/mesh/model/UIState.kt
index 5b613921b..61797d539 100644
--- a/app/src/main/java/com/geeksville/mesh/model/UIState.kt
+++ b/app/src/main/java/com/geeksville/mesh/model/UIState.kt
@@ -7,6 +7,7 @@ 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
@@ -48,10 +49,45 @@ class UIViewModel : ViewModel(), Logging {
var meshService: IMeshService? = null
/// Are we connected to our radio device
- val isConnected = MutableLiveData(MeshService.ConnectionState.DISCONNECTED)
+ val isConnected =
+ object : LiveData(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())
+ }
+ }
+ }
/// various radio settings (including the channel)
- val radioConfig = MutableLiveData(null)
+ val radioConfig = object : MutableLiveData(null) {
+ /**
+ * 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 latest radioconfig from service")
+ value = MeshProtos.RadioConfig.parseFrom(it.radioConfig)
+ }
+ }
+ }
/// Set the radio config (also updates our saved copy in preferences)
fun setRadioConfig(context: Context, c: MeshProtos.RadioConfig) {
diff --git a/app/src/main/res/layout/channel_fragment.xml b/app/src/main/res/layout/channel_fragment.xml
index 18fd4768b..ab14f82dd 100644
--- a/app/src/main/res/layout/channel_fragment.xml
+++ b/app/src/main/res/layout/channel_fragment.xml
@@ -69,7 +69,7 @@
android:layout_marginTop="8dp"
android:layout_marginEnd="64dp"
android:hint="Channel options"
- style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
+ style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/qrView">
diff --git a/geeksville-androidlib b/geeksville-androidlib
index 65f39f90c..953a65718 160000
--- a/geeksville-androidlib
+++ b/geeksville-androidlib
@@ -1 +1 @@
-Subproject commit 65f39f90ce365263620d5f9cbddca0c8abebcf9a
+Subproject commit 953a657184b2d4cde8a0867d1b520e1f7190cfd6