sforkowany z mirror/meshtastic-android
feat: add managed mode
rodzic
a316495545
commit
0c78bc4e49
|
@ -727,6 +727,7 @@ 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.radio_config).isEnabled = !model.isManaged
|
||||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
|
|
|
@ -374,8 +374,8 @@ class UIViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
val isRouter: Boolean = config.device.role == Config.DeviceConfig.Role.ROUTER
|
||||
// managed mode disables all access to configuration
|
||||
val isManaged: Boolean get() = config.device.isManaged
|
||||
|
||||
/// hardware info about our local device (can be null)
|
||||
private val _myNodeInfo = MutableLiveData<MyNodeInfo?>()
|
||||
|
|
|
@ -118,6 +118,7 @@ fun ChannelScreen(viewModel: UIViewModel = viewModel()) {
|
|||
|
||||
val connectionState by viewModel.connectionState.observeAsState()
|
||||
val connected = connectionState == MeshService.ConnectionState.CONNECTED
|
||||
val enabled = connected && !viewModel.isManaged
|
||||
|
||||
val channels by viewModel.channels.collectAsStateWithLifecycle()
|
||||
var channelSet by remember(channels) { mutableStateOf(channels.protobuf) }
|
||||
|
@ -258,7 +259,7 @@ fun ChannelScreen(viewModel: UIViewModel = viewModel()) {
|
|||
var showChannelEditor by remember { mutableStateOf(false) }
|
||||
if (showChannelEditor) ChannelSettingsItemList(
|
||||
settingsList = channelSet.settingsList,
|
||||
enabled = connected,
|
||||
enabled = enabled,
|
||||
focusManager = focusManager,
|
||||
onNegativeClicked = {
|
||||
focusManager.clearFocus()
|
||||
|
@ -282,7 +283,7 @@ fun ChannelScreen(viewModel: UIViewModel = viewModel()) {
|
|||
title = stringResource(R.string.channel_name),
|
||||
subtitle = primaryChannel?.humanName.orEmpty(),
|
||||
onClick = { showChannelEditor = true },
|
||||
enabled = connected,
|
||||
enabled = enabled,
|
||||
trailingIcon = Icons.TwoTone.Edit
|
||||
)
|
||||
}
|
||||
|
@ -293,7 +294,7 @@ fun ChannelScreen(viewModel: UIViewModel = viewModel()) {
|
|||
?: painterResource(id = R.drawable.qrcode),
|
||||
contentDescription = stringResource(R.string.qr_code),
|
||||
contentScale = ContentScale.FillWidth,
|
||||
alpha = if (connected) 1f else 0.25f,
|
||||
alpha = if (enabled) 1f else 0.25f,
|
||||
// colorFilter = ColorFilter.colorMatrix(ColorMatrix().apply { setToSaturation(0f) }),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
|
@ -316,7 +317,7 @@ fun ChannelScreen(viewModel: UIViewModel = viewModel()) {
|
|||
}
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
enabled = connected,
|
||||
enabled = enabled,
|
||||
label = { Text("URL") },
|
||||
isError = isError,
|
||||
trailingIcon = {
|
||||
|
@ -362,7 +363,7 @@ fun ChannelScreen(viewModel: UIViewModel = viewModel()) {
|
|||
|
||||
item {
|
||||
DropDownPreference(title = stringResource(id = R.string.channel_options),
|
||||
enabled = connected,
|
||||
enabled = enabled,
|
||||
items = ChannelOption.values()
|
||||
.map { it.modemPreset to stringResource(it.configRes) },
|
||||
selectedItem = channelSet.loraConfig.modemPreset,
|
||||
|
@ -374,7 +375,7 @@ fun ChannelScreen(viewModel: UIViewModel = viewModel()) {
|
|||
|
||||
if (isEditing) item {
|
||||
PreferenceFooter(
|
||||
enabled = connected,
|
||||
enabled = enabled,
|
||||
onCancelClicked = {
|
||||
focusManager.clearFocus()
|
||||
channelSet = channels.protobuf
|
||||
|
@ -387,7 +388,7 @@ fun ChannelScreen(viewModel: UIViewModel = viewModel()) {
|
|||
} else {
|
||||
item {
|
||||
PreferenceFooter(
|
||||
enabled = connected,
|
||||
enabled = enabled,
|
||||
negativeText = R.string.reset,
|
||||
onNegativeClicked = {
|
||||
focusManager.clearFocus()
|
||||
|
|
|
@ -191,7 +191,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
// We don't want to be notified of our own changes, so turn off listener while making them
|
||||
spinner.setSelection(regionIndex, false)
|
||||
spinner.onItemSelectedListener = regionSpinnerListener
|
||||
spinner.isEnabled = true
|
||||
spinner.isEnabled = !model.isManaged
|
||||
|
||||
// If actively connected possibly let the user update firmware
|
||||
refreshUpdateButton(model.isConnected())
|
||||
|
@ -281,7 +281,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
spinner.adapter = regionAdapter
|
||||
|
||||
model.ownerName.observe(viewLifecycleOwner) { name ->
|
||||
binding.usernameEditText.isEnabled = !name.isNullOrEmpty()
|
||||
binding.usernameEditText.isEnabled = !name.isNullOrEmpty() && !model.isManaged
|
||||
binding.usernameEditText.setText(name)
|
||||
}
|
||||
|
||||
|
|
|
@ -113,6 +113,16 @@ fun DeviceConfigItemList(
|
|||
}
|
||||
item { Divider() }
|
||||
|
||||
item {
|
||||
SwitchPreference(title = "Managed mode",
|
||||
checked = deviceInput.isManaged,
|
||||
enabled = enabled,
|
||||
onCheckedChange = {
|
||||
deviceInput = deviceInput.copy { isManaged = it }
|
||||
})
|
||||
}
|
||||
item { Divider() }
|
||||
|
||||
item {
|
||||
PreferenceFooter(
|
||||
enabled = deviceInput != deviceConfig,
|
||||
|
|
Ładowanie…
Reference in New Issue