mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
fix autobug crash when primary channel is null
This commit is contained in:
parent
fa17c4efe1
commit
98356b9205
5 changed files with 53 additions and 48 deletions
|
|
@ -20,9 +20,7 @@ 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
|
||||
|
|
@ -44,7 +42,6 @@ import com.geeksville.android.Logging
|
|||
import com.geeksville.android.ServiceClient
|
||||
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
|
||||
|
|
@ -307,11 +304,7 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
|
||||
if (deniedPermissions.isNotEmpty()) {
|
||||
errormsg("Denied permissions: ${deniedPermissions.joinToString(",")}")
|
||||
Toast.makeText(
|
||||
this,
|
||||
getString(R.string.permission_missing),
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
showToast(R.string.permission_missing)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -659,7 +652,7 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
|
||||
val curVer = DeviceVersion(info.firmwareVersion ?: "0.0.0")
|
||||
val minVer = DeviceVersion("1.2.0")
|
||||
if(curVer < minVer)
|
||||
if (curVer < minVer)
|
||||
showAlert(R.string.firmware_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
|
||||
|
|
@ -687,40 +680,52 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
}
|
||||
}
|
||||
|
||||
private fun showToast(msgId: Int) {
|
||||
Toast.makeText(
|
||||
this,
|
||||
msgId,
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
|
||||
private fun showToast(msg: String) {
|
||||
Toast.makeText(
|
||||
this,
|
||||
msg,
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
|
||||
private fun perhapsChangeChannel() {
|
||||
// If the is opening a channel URL, handle it now
|
||||
requestedChannelUrl?.let { url ->
|
||||
try {
|
||||
val channels = ChannelSet(url)
|
||||
val primary = channels.primaryChannel
|
||||
requestedChannelUrl = null
|
||||
if (primary == null)
|
||||
showToast(R.string.channel_invalid)
|
||||
else {
|
||||
requestedChannelUrl = null
|
||||
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.new_channel_rcvd)
|
||||
.setMessage(getString(R.string.do_you_want_switch).format(primary.name))
|
||||
.setNeutralButton(R.string.cancel) { _, _ ->
|
||||
// Do nothing
|
||||
}
|
||||
.setPositiveButton(R.string.accept) { _, _ ->
|
||||
debug("Setting channel from URL")
|
||||
try {
|
||||
model.setChannels(channels)
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("Couldn't change channel ${ex.message}")
|
||||
Toast.makeText(
|
||||
this,
|
||||
"Couldn't change channel, because radio is not yet connected. Please try again.",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.new_channel_rcvd)
|
||||
.setMessage(getString(R.string.do_you_want_switch).format(primary.name))
|
||||
.setNeutralButton(R.string.cancel) { _, _ ->
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
.show()
|
||||
.setPositiveButton(R.string.accept) { _, _ ->
|
||||
debug("Setting channel from URL")
|
||||
try {
|
||||
model.setChannels(channels)
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("Couldn't change channel ${ex.message}")
|
||||
showToast(R.string.cant_change_no_radio)
|
||||
}
|
||||
}
|
||||
.show()
|
||||
}
|
||||
} catch (ex: InvalidProtocolBufferException) {
|
||||
Toast.makeText(
|
||||
this,
|
||||
R.string.channel_invalid,
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
showToast(R.string.channel_invalid)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -869,8 +874,7 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
errormsg("Device error during init ${ex.message}")
|
||||
model.isConnected.value =
|
||||
MeshService.ConnectionState.valueOf(service.connectionState())
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
connectionJob = null
|
||||
}
|
||||
|
||||
|
|
@ -1037,7 +1041,7 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
try {
|
||||
val packageInfo: PackageInfo = packageManager.getPackageInfo(packageName, 0)
|
||||
val versionName = packageInfo.versionName
|
||||
Toast.makeText(applicationContext, versionName, Toast.LENGTH_LONG).show()
|
||||
showToast(versionName)
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
errormsg("Can not find the version: ${e.message}")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue