From ae402e8fd2b648efc95fb5423f57e0ba7f83c14f Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Tue, 2 Mar 2021 13:22:55 +0800 Subject: [PATCH] add warning text for downrev apps --- .../java/com/geeksville/mesh/MainActivity.kt | 42 +++++++++++++------ .../geeksville/mesh/service/MeshService.kt | 5 ++- .../mesh/service/RadioInterfaceService.kt | 1 + app/src/main/proto | 2 +- app/src/main/res/values/strings.xml | 4 +- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/MainActivity.kt b/app/src/main/java/com/geeksville/mesh/MainActivity.kt index b79a2615..8e5a7230 100644 --- a/app/src/main/java/com/geeksville/mesh/MainActivity.kt +++ b/app/src/main/java/com/geeksville/mesh/MainActivity.kt @@ -20,10 +20,14 @@ import android.os.Build import android.os.Bundle import android.os.Handler import android.os.RemoteException +import android.text.SpannableString +import android.text.method.LinkMovementMethod +import android.text.util.Linkify import android.view.Menu import android.view.MenuItem import android.view.MotionEvent import android.view.View +import android.widget.TextView import android.widget.Toast import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity @@ -64,6 +68,7 @@ import java.nio.charset.Charset import java.text.DateFormat import java.util.* + /* UI design @@ -619,26 +624,38 @@ class MainActivity : AppCompatActivity(), Logging, debug("Getting latest radioconfig from service") try { - model.radioConfig.value = - MeshProtos.RadioConfig.parseFrom(service.radioConfig) - val info = service.myNodeInfo model.myNodeInfo.value = info val isOld = info.minAppVersion > BuildConfig.VERSION_CODE - if (isOld) - MaterialAlertDialogBuilder(this) + if (isOld) { + // make links clickable per https://stackoverflow.com/a/62642807 + val messageStr = getText(R.string.must_update) + + val builder = MaterialAlertDialogBuilder(this) .setTitle(getString(R.string.app_too_old)) - .setMessage(getString(R.string.must_update)) + .setMessage(messageStr) .setPositiveButton("Okay") { _, _ -> info("User acknowledged app is old") } - .show() - updateNodesFromDevice() + val dialog = builder.show() - // we have a connection to our device now, do the channel change - perhapsChangeChannel() + // Make the textview clickable. Must be called after show() + val view = (dialog.findViewById(android.R.id.message) as TextView?)!! + // Linkify.addLinks(view, Linkify.ALL) // not needed with this method + view.movementMethod = LinkMovementMethod.getInstance() + } else { + // If our app is too old, we probably don't understand the new radioconfig messages + + model.radioConfig.value = + MeshProtos.RadioConfig.parseFrom(service.radioConfig) + + updateNodesFromDevice() + + // we have a connection to our device now, do the channel change + perhapsChangeChannel() + } } catch (ex: RemoteException) { warn("Abandoning connect $ex, because we probably just lost device connection") model.isConnected.value = oldConnection @@ -931,7 +948,8 @@ class MainActivity : AppCompatActivity(), Logging, } override fun onPrepareOptionsMenu(menu: Menu): Boolean { - menu.findItem(R.id.stress_test).isVisible = BuildConfig.DEBUG // only show stress test for debug builds (for now) + menu.findItem(R.id.stress_test).isVisible = + BuildConfig.DEBUG // only show stress test for debug builds (for now) return super.onPrepareOptionsMenu(menu) } @@ -972,7 +990,7 @@ class MainActivity : AppCompatActivity(), Logging, ) } item.isChecked = !item.isChecked // toggle ping test - if(item.isChecked) + if (item.isChecked) postPing() else handler.removeCallbacksAndMessages(null) diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index 6d62a08b..72907284 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -73,6 +73,9 @@ class MeshService : Service(), Logging { class NodeNumNotFoundException(id: Int) : NodeNotFoundException("NodeNum not found $id") class IdNotFoundException(id: String) : NodeNotFoundException("ID not found $id") + class NoRadioConfigException(message: String = "No radio settings received (is our app too old?)") : + RadioNotConnectedException(message) + /** We treat software update as similar to loss of comms to the regular bluetooth service (so things like sendPosition for background GPS ignores the problem */ class IsUpdatingException() : RadioNotConnectedException("Operation prohibited during firmware update") @@ -1589,7 +1592,7 @@ class MeshService : Service(), Logging { override fun getRadioConfig(): ByteArray = toRemoteExceptions { this@MeshService.radioConfig?.toByteArray() - ?: throw RadioNotConnectedException() + ?: throw NoRadioConfigException() } override fun setRadioConfig(payload: ByteArray) = toRemoteExceptions { diff --git a/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt b/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt index 78890c33..112f7010 100644 --- a/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt @@ -26,6 +26,7 @@ open class RadioNotConnectedException(message: String = "Not connected to radio" BLEException(message) + /** * Handles the bluetooth link with a mesh radio device. Does not cache any device state, * just does bluetooth comms etc... diff --git a/app/src/main/proto b/app/src/main/proto index b1aed064..512d1aca 160000 --- a/app/src/main/proto +++ b/app/src/main/proto @@ -1 +1 @@ -Subproject commit b1aed06442025624841b2288fac273d9bc41c438 +Subproject commit 512d1aca0a066107de749c0c47397c7f9bf9cb99 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0f56c52e..33c6f745 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -60,8 +60,8 @@ Not connected, select radio below Connected to radio, but it is sleeping Update to %s - Application too old - You must update this application on the Google Play store (or Github). It is too old to talk to this radio. + Application update required + You must update this application on the Google Play store (or Github). It is too old to talk to this radio firmware. Please read our wiki on this topic. None (disable) Short range (but fast) Medium range (but fast)