show alert for old firmware

pull/257/head
Kevin Hester 2021-03-02 15:12:57 +08:00
rodzic 2fc4099bfc
commit e27a3d937d
6 zmienionych plików z 57 dodań i 32 usunięć

Wyświetl plik

@ -46,6 +46,7 @@ import com.geeksville.concurrent.handledLaunch
import com.geeksville.mesh.databinding.ActivityMainBinding
import com.geeksville.mesh.model.Channel
import com.geeksville.mesh.model.ChannelSet
import com.geeksville.mesh.model.DeviceVersion
import com.geeksville.mesh.model.UIViewModel
import com.geeksville.mesh.service.*
import com.geeksville.mesh.ui.*
@ -613,6 +614,29 @@ class MainActivity : AppCompatActivity(), Logging,
}
}
/** Show an alert that may contain HTML */
private fun showAlert(titleText: Int, messageText: Int) {
// make links clickable per https://stackoverflow.com/a/62642807
// val messageStr = getText(messageText)
val builder = MaterialAlertDialogBuilder(this)
.setTitle(titleText)
.setMessage(messageText)
.setPositiveButton("Okay") { _, _ ->
info("User acknowledged")
}
val dialog = builder.show()
// 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()
showSettingsPage() // Default to the settings page in this case
}
/// Called when we gain/lose a connection to our mesh radio
private fun onMeshConnectionChanged(connected: MeshService.ConnectionState) {
debug("connchange ${model.isConnected.value} -> $connected")
@ -629,33 +653,25 @@ class MainActivity : AppCompatActivity(), Logging,
model.myNodeInfo.value = info
val isOld = info.minAppVersion > BuildConfig.VERSION_CODE
if (isOld) {
// make links clickable per https://stackoverflow.com/a/62642807
val messageStr = getText(R.string.must_update)
if (isOld)
showAlert(R.string.app_too_old, R.string.must_update)
else {
val builder = MaterialAlertDialogBuilder(this)
.setTitle(getString(R.string.app_too_old))
.setMessage(messageStr)
.setPositiveButton("Okay") { _, _ ->
info("User acknowledged app is old")
}
val curVer = DeviceVersion(info.firmwareVersion ?: "0.0.0")
val minVer = DeviceVersion("1.2.0")
if(curVer < minVer)
showAlert(R.string.app_too_old, R.string.firmware_old)
else {
// If our app is too old/new, we probably don't understand the new radioconfig messages, so we don't read them until here
val dialog = builder.show()
model.radioConfig.value =
RadioConfigProtos.RadioConfig.parseFrom(service.radioConfig)
// 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
updateNodesFromDevice()
model.radioConfig.value =
RadioConfigProtos.RadioConfig.parseFrom(service.radioConfig)
updateNodesFromDevice()
// we have a connection to our device now, do the channel change
perhapsChangeChannel()
// 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")

Wyświetl plik

@ -1,4 +1,4 @@
package com.geeksville.mesh.service
package com.geeksville.mesh.model
import com.geeksville.android.Logging

Wyświetl plik

@ -23,6 +23,7 @@ import com.geeksville.mesh.MeshProtos.ToRadio
import com.geeksville.mesh.database.MeshtasticDatabase
import com.geeksville.mesh.database.PacketRepository
import com.geeksville.mesh.database.entity.Packet
import com.geeksville.mesh.model.DeviceVersion
import com.geeksville.mesh.service.SoftwareUpdateService.Companion.ProgressNotStarted
import com.geeksville.util.*
import com.google.android.gms.common.api.ApiException

Wyświetl plik

@ -9,6 +9,7 @@ import androidx.core.app.JobIntentService
import com.geeksville.android.Logging
import com.geeksville.mesh.MainActivity
import com.geeksville.mesh.R
import com.geeksville.mesh.model.DeviceVersion
import com.geeksville.util.exceptionReporter
import java.util.*
import java.util.zip.CRC32

Wyświetl plik

@ -237,17 +237,22 @@ class MessagesFragment : ScreenFragment("Messages"), Logging {
})
// If connection state _OR_ myID changes we have to fix our ability to edit outgoing messages
model.isConnected.observe(viewLifecycleOwner, Observer { connected ->
// If we don't know our node ID and we are offline don't let user try to send
fun updateTextEnabled() {
binding.textInputLayout.isEnabled =
connected != MeshService.ConnectionState.DISCONNECTED && model.nodeDB.myId.value != null
})
model.isConnected.value != MeshService.ConnectionState.DISCONNECTED && model.nodeDB.myId.value != null && model.radioConfig.value != null
}
model.nodeDB.myId.observe(viewLifecycleOwner, Observer { myId ->
model.isConnected.observe(viewLifecycleOwner, Observer { _ ->
// If we don't know our node ID and we are offline don't let user try to send
binding.textInputLayout.isEnabled =
model.isConnected.value != MeshService.ConnectionState.DISCONNECTED && myId != null
})
updateTextEnabled() })
model.nodeDB.myId.observe(viewLifecycleOwner, Observer { _ ->
// If we don't know our node ID and we are offline don't let user try to send
updateTextEnabled() })
model.radioConfig.observe(viewLifecycleOwner, Observer { _ ->
// If we don't know our node ID and we are offline don't let user try to send
updateTextEnabled() })
}
}

Wyświetl plik

@ -89,4 +89,6 @@
<string name="broadcast_period_too_small">Minimum broadcast period for this channel is %d</string>
<string name="protocol_stress_test">Protocol stress test</string>
<string name="advanced_settings">Advanced settings</string>
<string name="firmware_too_old">Firmware update required</string>
<string name="firmware_old">The radio firmware is too old to talk to this application, please go to the settings pane and choose "Update Firmware". For more information on this see <a href="https://www.meshtastic.org/software/firmware-too-old.html">our wiki</a>.</string>
</resources>