mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Run Spotless (#2762)
This commit is contained in:
parent
1044f4b61c
commit
2173a53567
6 changed files with 81 additions and 138 deletions
|
|
@ -31,46 +31,27 @@ import androidx.emoji2.emojipicker.RecentEmojiProviderAdapter
|
|||
import com.geeksville.mesh.util.CustomRecentEmojiProvider
|
||||
|
||||
@Composable
|
||||
fun EmojiPicker(
|
||||
onDismiss: () -> Unit = {},
|
||||
onConfirm: (String) -> Unit
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Bottom
|
||||
) {
|
||||
BackHandler {
|
||||
onDismiss()
|
||||
}
|
||||
fun EmojiPicker(onDismiss: () -> Unit = {}, onConfirm: (String) -> Unit) {
|
||||
Column(verticalArrangement = Arrangement.Bottom) {
|
||||
BackHandler { onDismiss() }
|
||||
AndroidView(
|
||||
factory = { context ->
|
||||
androidx.emoji2.emojipicker.EmojiPickerView(context).apply {
|
||||
clipToOutline = true
|
||||
setRecentEmojiProvider(
|
||||
RecentEmojiProviderAdapter(CustomRecentEmojiProvider(context))
|
||||
)
|
||||
setRecentEmojiProvider(RecentEmojiProviderAdapter(CustomRecentEmojiProvider(context)))
|
||||
setOnEmojiPickedListener { emoji ->
|
||||
onDismiss()
|
||||
onConfirm(emoji.emoji)
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(MaterialTheme.colorScheme.background)
|
||||
modifier = Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.background),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun EmojiPickerDialog(
|
||||
onDismiss: () -> Unit = {},
|
||||
onConfirm: (String) -> Unit
|
||||
) = BottomSheetDialog(
|
||||
onDismiss = onDismiss,
|
||||
modifier = Modifier.fillMaxHeight(fraction = .4f),
|
||||
) {
|
||||
EmojiPicker(
|
||||
onConfirm = onConfirm,
|
||||
onDismiss = onDismiss,
|
||||
)
|
||||
}
|
||||
fun EmojiPickerDialog(onDismiss: () -> Unit = {}, onConfirm: (String) -> Unit) =
|
||||
BottomSheetDialog(onDismiss = onDismiss, modifier = Modifier.fillMaxHeight(fraction = .4f)) {
|
||||
EmojiPicker(onConfirm = onConfirm, onDismiss = onDismiss)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,21 +51,16 @@ import com.geeksville.mesh.ui.common.components.PreferenceFooter
|
|||
import com.geeksville.mesh.ui.common.components.SwitchPreference
|
||||
import com.geeksville.mesh.ui.radioconfig.RadioConfigViewModel
|
||||
|
||||
const val MapConsentPreferencesKey = "map_consent_preferences"
|
||||
const val MAP_CONSENT_PREFERENCES_KEY = "map_consent_preferences"
|
||||
|
||||
@Composable
|
||||
fun MQTTConfigScreen(
|
||||
viewModel: RadioConfigViewModel = hiltViewModel(),
|
||||
) {
|
||||
fun MQTTConfigScreen(viewModel: RadioConfigViewModel = hiltViewModel()) {
|
||||
val state by viewModel.radioConfigState.collectAsStateWithLifecycle()
|
||||
val destNode by viewModel.destNode.collectAsStateWithLifecycle()
|
||||
val destNum = destNode?.num
|
||||
|
||||
if (state.responseState.isWaiting()) {
|
||||
PacketResponseStateDialog(
|
||||
state = state.responseState,
|
||||
onDismiss = viewModel::clearPacketResponse,
|
||||
)
|
||||
PacketResponseStateDialog(state = state.responseState, onDismiss = viewModel::clearPacketResponse)
|
||||
}
|
||||
|
||||
MQTTConfigItemList(
|
||||
|
|
@ -75,7 +70,7 @@ fun MQTTConfigScreen(
|
|||
onSaveClicked = { mqttInput ->
|
||||
val config = moduleConfig { mqtt = mqttInput }
|
||||
viewModel.setModuleConfig(config)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -88,19 +83,16 @@ fun MQTTConfigItemList(
|
|||
) {
|
||||
val focusManager = LocalFocusManager.current
|
||||
var mqttInput by rememberSaveable { mutableStateOf(mqttConfig) }
|
||||
val sharedPrefs = LocalContext.current.getSharedPreferences(
|
||||
MapConsentPreferencesKey, Context.MODE_PRIVATE
|
||||
)
|
||||
val sharedPrefs = LocalContext.current.getSharedPreferences(MAP_CONSENT_PREFERENCES_KEY, Context.MODE_PRIVATE)
|
||||
if (!mqttInput.mapReportSettings.shouldReportLocation) {
|
||||
val settings = mqttInput.mapReportSettings.copy {
|
||||
this.shouldReportLocation = sharedPrefs.getBoolean(nodeNum.toString(), false)
|
||||
}
|
||||
val settings =
|
||||
mqttInput.mapReportSettings.copy {
|
||||
this.shouldReportLocation = sharedPrefs.getBoolean(nodeNum.toString(), false)
|
||||
}
|
||||
mqttInput = mqttInput.copy { mapReportSettings = settings }
|
||||
}
|
||||
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
LazyColumn(modifier = Modifier.fillMaxSize()) {
|
||||
item { PreferenceCategory(text = stringResource(R.string.mqtt_config)) }
|
||||
|
||||
item {
|
||||
|
|
@ -108,7 +100,7 @@ fun MQTTConfigItemList(
|
|||
title = stringResource(R.string.mqtt_enabled),
|
||||
checked = mqttInput.enabled,
|
||||
enabled = enabled,
|
||||
onCheckedChange = { mqttInput = mqttInput.copy { this.enabled = it } }
|
||||
onCheckedChange = { mqttInput = mqttInput.copy { this.enabled = it } },
|
||||
)
|
||||
}
|
||||
item { HorizontalDivider() }
|
||||
|
|
@ -120,11 +112,10 @@ fun MQTTConfigItemList(
|
|||
maxSize = 63, // address max_size:64
|
||||
enabled = enabled,
|
||||
isError = false,
|
||||
keyboardOptions = KeyboardOptions.Default.copy(
|
||||
keyboardType = KeyboardType.Text, imeAction = ImeAction.Done
|
||||
),
|
||||
keyboardOptions =
|
||||
KeyboardOptions.Default.copy(keyboardType = KeyboardType.Text, imeAction = ImeAction.Done),
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = { mqttInput = mqttInput.copy { address = it } }
|
||||
onValueChanged = { mqttInput = mqttInput.copy { address = it } },
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -135,11 +126,10 @@ fun MQTTConfigItemList(
|
|||
maxSize = 63, // username max_size:64
|
||||
enabled = enabled,
|
||||
isError = false,
|
||||
keyboardOptions = KeyboardOptions.Default.copy(
|
||||
keyboardType = KeyboardType.Text, imeAction = ImeAction.Done
|
||||
),
|
||||
keyboardOptions =
|
||||
KeyboardOptions.Default.copy(keyboardType = KeyboardType.Text, imeAction = ImeAction.Done),
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = { mqttInput = mqttInput.copy { username = it } }
|
||||
onValueChanged = { mqttInput = mqttInput.copy { username = it } },
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -150,7 +140,7 @@ fun MQTTConfigItemList(
|
|||
maxSize = 63, // password max_size:64
|
||||
enabled = enabled,
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = { mqttInput = mqttInput.copy { password = it } }
|
||||
onValueChanged = { mqttInput = mqttInput.copy { password = it } },
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -159,7 +149,7 @@ fun MQTTConfigItemList(
|
|||
title = stringResource(R.string.encryption_enabled),
|
||||
checked = mqttInput.encryptionEnabled,
|
||||
enabled = enabled,
|
||||
onCheckedChange = { mqttInput = mqttInput.copy { encryptionEnabled = it } }
|
||||
onCheckedChange = { mqttInput = mqttInput.copy { encryptionEnabled = it } },
|
||||
)
|
||||
}
|
||||
item { HorizontalDivider() }
|
||||
|
|
@ -169,7 +159,7 @@ fun MQTTConfigItemList(
|
|||
title = stringResource(R.string.json_output_enabled),
|
||||
checked = mqttInput.jsonEnabled,
|
||||
enabled = enabled,
|
||||
onCheckedChange = { mqttInput = mqttInput.copy { jsonEnabled = it } }
|
||||
onCheckedChange = { mqttInput = mqttInput.copy { jsonEnabled = it } },
|
||||
)
|
||||
}
|
||||
item { HorizontalDivider() }
|
||||
|
|
@ -179,7 +169,7 @@ fun MQTTConfigItemList(
|
|||
title = stringResource(R.string.tls_enabled),
|
||||
checked = mqttInput.tlsEnabled,
|
||||
enabled = enabled,
|
||||
onCheckedChange = { mqttInput = mqttInput.copy { tlsEnabled = it } }
|
||||
onCheckedChange = { mqttInput = mqttInput.copy { tlsEnabled = it } },
|
||||
)
|
||||
}
|
||||
item { HorizontalDivider() }
|
||||
|
|
@ -191,11 +181,10 @@ fun MQTTConfigItemList(
|
|||
maxSize = 31, // root max_size:32
|
||||
enabled = enabled,
|
||||
isError = false,
|
||||
keyboardOptions = KeyboardOptions.Default.copy(
|
||||
keyboardType = KeyboardType.Text, imeAction = ImeAction.Done
|
||||
),
|
||||
keyboardOptions =
|
||||
KeyboardOptions.Default.copy(keyboardType = KeyboardType.Text, imeAction = ImeAction.Done),
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = { mqttInput = mqttInput.copy { root = it } }
|
||||
onValueChanged = { mqttInput = mqttInput.copy { root = it } },
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -204,7 +193,7 @@ fun MQTTConfigItemList(
|
|||
title = stringResource(R.string.proxy_to_client_enabled),
|
||||
checked = mqttInput.proxyToClientEnabled,
|
||||
enabled = enabled,
|
||||
onCheckedChange = { mqttInput = mqttInput.copy { proxyToClientEnabled = it } }
|
||||
onCheckedChange = { mqttInput = mqttInput.copy { proxyToClientEnabled = it } },
|
||||
)
|
||||
}
|
||||
item { HorizontalDivider() }
|
||||
|
|
@ -214,45 +203,37 @@ fun MQTTConfigItemList(
|
|||
item {
|
||||
MapReportingPreference(
|
||||
mapReportingEnabled = mqttInput.mapReportingEnabled,
|
||||
onMapReportingEnabledChanged = {
|
||||
mqttInput = mqttInput.copy { mapReportingEnabled = it }
|
||||
},
|
||||
onMapReportingEnabledChanged = { mqttInput = mqttInput.copy { mapReportingEnabled = it } },
|
||||
shouldReportLocation = mqttInput.mapReportSettings.shouldReportLocation,
|
||||
onShouldReportLocationChanged = {
|
||||
sharedPrefs.edit { putBoolean(nodeNum.toString(), it) }
|
||||
val settings =
|
||||
mqttInput.mapReportSettings.copy { this.shouldReportLocation = it }
|
||||
mqttInput = mqttInput.copy {
|
||||
mapReportSettings = settings
|
||||
}
|
||||
val settings = mqttInput.mapReportSettings.copy { this.shouldReportLocation = it }
|
||||
mqttInput = mqttInput.copy { mapReportSettings = settings }
|
||||
},
|
||||
positionPrecision = mqttInput.mapReportSettings.positionPrecision,
|
||||
onPositionPrecisionChanged = {
|
||||
val settings = mqttInput.mapReportSettings.copy { positionPrecision = it }
|
||||
mqttInput = mqttInput.copy {
|
||||
mapReportSettings = settings
|
||||
}
|
||||
mqttInput = mqttInput.copy { mapReportSettings = settings }
|
||||
},
|
||||
publishIntervalSecs = mqttInput.mapReportSettings.publishIntervalSecs,
|
||||
onPublishIntervalSecsChanged = {
|
||||
val settings = mqttInput.mapReportSettings.copy { publishIntervalSecs = it }
|
||||
mqttInput = mqttInput.copy {
|
||||
mapReportSettings = settings
|
||||
}
|
||||
mqttInput = mqttInput.copy { mapReportSettings = settings }
|
||||
},
|
||||
enabled = enabled,
|
||||
focusManager = focusManager
|
||||
focusManager = focusManager,
|
||||
)
|
||||
}
|
||||
item { HorizontalDivider() }
|
||||
|
||||
item {
|
||||
val consentValid = if (mqttInput.mapReportingEnabled) {
|
||||
mqttInput.mapReportSettings.shouldReportLocation &&
|
||||
mqttConfig.mapReportSettings.publishIntervalSecs >= MinIntervalSecs
|
||||
} else {
|
||||
true
|
||||
}
|
||||
val consentValid =
|
||||
if (mqttInput.mapReportingEnabled) {
|
||||
mqttInput.mapReportSettings.shouldReportLocation &&
|
||||
mqttConfig.mapReportSettings.publishIntervalSecs >= MIN_INTERVAL_SECS
|
||||
} else {
|
||||
true
|
||||
}
|
||||
PreferenceFooter(
|
||||
enabled = enabled && mqttInput != mqttConfig && consentValid,
|
||||
onCancelClicked = {
|
||||
|
|
@ -262,20 +243,16 @@ fun MQTTConfigItemList(
|
|||
onSaveClicked = {
|
||||
focusManager.clearFocus()
|
||||
onSaveClicked(mqttInput)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const val MinIntervalSecs = 3600
|
||||
private const val MIN_INTERVAL_SECS = 3600
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
private fun MQTTConfigPreview() {
|
||||
MQTTConfigItemList(
|
||||
mqttConfig = MQTTConfig.getDefaultInstance(),
|
||||
enabled = true,
|
||||
onSaveClicked = { },
|
||||
)
|
||||
MQTTConfigItemList(mqttConfig = MQTTConfig.getDefaultInstance(), enabled = true, onSaveClicked = {})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue