mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-02-01 19:33:28 -05:00
fix autobug crash when primary channel is null
This commit is contained in:
@@ -24,7 +24,7 @@ The app is also distributed for Amazon Fire devices via the Amazon appstore: [![
|
||||
If you would like to develop this application we'd love your help! These build instructions are brief
|
||||
and should be improved, please send a PR if you can.
|
||||
|
||||
* Use Android Studio 4.0 RC 1 to build/debug (other versions might work but no promises)
|
||||
* Use Android Studio 4.1.2 to build/debug (other versions might work but no promises)
|
||||
* Use "git submodule update --init --recursive" to pull in the various submodules we depend on
|
||||
* There are a few config files which you'll need to copy from templates included in the project.
|
||||
Run the following commands to do so:
|
||||
|
||||
@@ -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}")
|
||||
}
|
||||
|
||||
@@ -47,9 +47,11 @@ data class ChannelSet(
|
||||
/**
|
||||
* Return the primary channel info
|
||||
*/
|
||||
val primaryChannel: Channel get() {
|
||||
return Channel(protobuf.getSettings(0))
|
||||
}
|
||||
val primaryChannel: Channel? get() =
|
||||
if(protobuf.settingsCount > 0)
|
||||
Channel(protobuf.getSettings(0))
|
||||
else
|
||||
null
|
||||
|
||||
/// Return an URL that represents the current channel values
|
||||
/// @param upperCasePrefix - portions of the URL can be upper case to make for more efficient QR codes
|
||||
|
||||
@@ -79,11 +79,10 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
|
||||
/// Pull the latest data from the model (discarding any user edits)
|
||||
private fun setGUIfromModel() {
|
||||
val channels = model.channels.value
|
||||
val channel = channels?.primaryChannel
|
||||
|
||||
binding.editableCheckbox.isChecked = false // start locked
|
||||
if (channels != null) {
|
||||
val channel = channels.primaryChannel
|
||||
|
||||
if (channel != null) {
|
||||
binding.qrView.visibility = View.VISIBLE
|
||||
binding.channelNameEdit.visibility = View.VISIBLE
|
||||
binding.channelNameEdit.setText(channel.humanName)
|
||||
@@ -156,8 +155,8 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
|
||||
val checked = binding.editableCheckbox.isChecked
|
||||
if (checked) {
|
||||
// User just unlocked for editing - remove the # goo around the channel name
|
||||
model.channels.value?.let { channels ->
|
||||
binding.channelNameEdit.setText(channels.primaryChannel.name)
|
||||
model.channels.value?.primaryChannel?.let { ch ->
|
||||
binding.channelNameEdit.setText(ch.name)
|
||||
}
|
||||
} else {
|
||||
// User just locked it, we should warn and then apply changes to radio
|
||||
@@ -169,8 +168,7 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
|
||||
}
|
||||
.setPositiveButton(getString(R.string.accept)) { _, _ ->
|
||||
// Generate a new channel with only the changes the user can change in the GUI
|
||||
model.channels.value?.let { old ->
|
||||
val oldPrimary = old.primaryChannel
|
||||
model.channels.value?.primaryChannel?.let { oldPrimary ->
|
||||
val newSettings = oldPrimary.settings.toBuilder()
|
||||
newSettings.name = binding.channelNameEdit.text.toString().trim()
|
||||
|
||||
|
||||
@@ -94,4 +94,5 @@
|
||||
<string name="okay">Okay</string>
|
||||
<string name="must_set_region">You must set a region!</string>
|
||||
<string name="region">Region</string>
|
||||
<string name="cant_change_no_radio">Couldn\'t change channel, because radio is not yet connected. Please try again.</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user