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