chore: add detekt formatting rule set

https://detekt.dev/docs/next/rules/formatting/
This commit is contained in:
andrekir 2024-10-13 23:02:05 -03:00 committed by Andre K
parent 056d4a5829
commit fe56d257f5
58 changed files with 725 additions and 432 deletions

View file

@ -37,8 +37,11 @@ fun BitwisePreference(
subtitle = value.toString(),
onClick = { dropDownExpanded = !dropDownExpanded },
enabled = enabled,
trailingIcon = if (dropDownExpanded) Icons.TwoTone.KeyboardArrowUp
else Icons.TwoTone.KeyboardArrowDown,
trailingIcon = if (dropDownExpanded) {
Icons.TwoTone.KeyboardArrowUp
} else {
Icons.TwoTone.KeyboardArrowDown
},
)
Box {

View file

@ -53,7 +53,6 @@ import com.geeksville.mesh.ui.components.CommonCharts.MS_PER_SEC
import com.geeksville.mesh.ui.components.CommonCharts.TIME_FORMAT
import com.geeksville.mesh.ui.theme.Orange
private val DEVICE_METRICS_COLORS = listOf(Color.Green, Color.Magenta, Color.Cyan)
private const val MAX_PERCENT_VALUE = 100f
@ -64,8 +63,9 @@ fun DeviceMetricsScreen(telemetries: List<Telemetry>) {
Column {
if (displayInfoDialog)
if (displayInfoDialog) {
DeviceInfoDialog { displayInfoDialog = false }
}
DeviceMetricsChart(
modifier = Modifier
@ -92,8 +92,7 @@ private fun DeviceMetricsChart(
) {
ChartHeader(amount = telemetries.size)
if (telemetries.isEmpty())
return
if (telemetries.isEmpty()) return
Spacer(modifier = Modifier.height(16.dp))
@ -153,8 +152,9 @@ private fun DeviceMetricsChart(
val x2 = spacing + (i + 1) * spacePerEntry
val y2 = height - spacing - (rightRatio * height)
if (i == 0)
if (i == 0) {
moveTo(x1, y1)
}
lastX = (x1 + x2) / 2f

View file

@ -56,8 +56,11 @@ fun <T> DropDownPreference(
dropDownExpanded = true
},
enabled = enabled,
trailingIcon = if (dropDownExpanded) Icons.TwoTone.KeyboardArrowUp
else Icons.TwoTone.KeyboardArrowDown,
trailingIcon = if (dropDownExpanded) {
Icons.TwoTone.KeyboardArrowUp
} else {
Icons.TwoTone.KeyboardArrowDown
},
summary = summary,
)
@ -74,15 +77,17 @@ fun <T> DropDownPreference(
},
modifier = modifier
.background(
color = if (selectedItem == item.first)
color = if (selectedItem == item.first) {
MaterialTheme.colors.primary.copy(alpha = 0.3f)
else
Color.Unspecified,
} else {
Color.Unspecified
},
),
content = {
Text(
text = item.second,
overflow = TextOverflow.Ellipsis,
maxLines = 1,
)
}
)

View file

@ -21,11 +21,13 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusState
import androidx.compose.ui.focus.onFocusEvent
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.geeksville.mesh.R
@Composable
fun EditTextPreference(
@ -167,8 +169,12 @@ fun EditTextPreference(
trailingIcon = {
if (trailingIcon != null) {
trailingIcon()
} else {
if (isError) Icon(Icons.TwoTone.Info, "Error", tint = MaterialTheme.colors.error)
} else if (isError) {
Icon(
imageVector = Icons.TwoTone.Info,
contentDescription = stringResource(id = R.string.error),
tint = MaterialTheme.colors.error
)
}
},
)

View file

@ -54,8 +54,6 @@ enum class Iaq(val color: Color, val description: String, val range: IntRange) {
DangerouslyPolluted(Color(0xFF663300), "Dangerously Polluted", 501..Int.MAX_VALUE)
}
fun getIaq(iaq: Int): Iaq {
return when {
iaq in Iaq.Excellent.range -> Iaq.Excellent
@ -70,7 +68,7 @@ fun getIaq(iaq: Int): Iaq {
}
private fun getIaqDescriptionWithRange(iaqEnum: Iaq): String {
return if (iaqEnum.range.last == Int.MAX_VALUE){
return if (iaqEnum.range.last == Int.MAX_VALUE) {
"${iaqEnum.description} (${iaqEnum.range.first}+)"
} else {
"${iaqEnum.description} (${iaqEnum.range.first}-${iaqEnum.range.last})"

View file

@ -31,7 +31,7 @@ fun SimpleAlertDialog(
onClick = onDismiss,
modifier = Modifier
.padding(horizontal = 16.dp),
colors = ButtonDefaults.textButtonColors(
colors = ButtonDefaults.textButtonColors(
contentColor = MaterialTheme.colors.onSurface,
),
) { Text(text = stringResource(id = R.string.close)) }

View file

@ -39,7 +39,11 @@ fun SwitchPreference(
Text(
text = title,
style = MaterialTheme.typography.body1,
color = if (!enabled) MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled) else Color.Unspecified,
color = if (enabled) {
Color.Unspecified
} else {
MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled)
},
)
Switch(
modifier = modifier

View file

@ -59,8 +59,9 @@ fun BluetoothConfigItemList(
enabled = enabled,
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
onValueChanged = {
if (it.toString().length == 6) // ensure 6 digits
if (it.toString().length == 6) { // ensure 6 digits
bluetoothInput = bluetoothInput.copy { fixedPin = it }
}
})
}

View file

@ -187,7 +187,7 @@ fun CannedMessageConfigItemList(
},
onSaveClicked = {
focusManager.clearFocus()
onSaveClicked(messagesInput,cannedMessageInput)
onSaveClicked(messagesInput, cannedMessageInput)
}
)
}

View file

@ -78,8 +78,11 @@ private fun ChannelItem(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(vertical = 4.dp, horizontal = 4.dp)
) {
val textColor = if (enabled) Color.Unspecified
else MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled)
val textColor = if (enabled) {
Color.Unspecified
} else {
MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled)
}
Chip(onClick = onClick) {
Text(
@ -165,8 +168,8 @@ fun ChannelSettingsItemList(
}
}
val isEditing: Boolean = settingsList.size != settingsListInput.size
|| settingsList.zip(settingsListInput).any { (item1, item2) -> item1 != item2 }
val isEditing: Boolean = settingsList.size != settingsListInput.size ||
settingsList.zip(settingsListInput).any { (item1, item2) -> item1 != item2 }
var showEditChannelDialog: Int? by rememberSaveable { mutableStateOf(null) }
@ -178,8 +181,11 @@ fun ChannelSettingsItemList(
},
modemPresetName = modemPresetName,
onAddClick = {
if (settingsListInput.size > index) settingsListInput[index] = it
else settingsListInput.add(it)
if (settingsListInput.size > index) {
settingsListInput[index] = it
} else {
settingsListInput.add(it)
}
showEditChannelDialog = null
},
onDismissRequest = { showEditChannelDialog = null }

View file

@ -25,7 +25,7 @@ import com.geeksville.mesh.ui.components.PreferenceCategory
import com.geeksville.mesh.ui.components.PreferenceFooter
import com.geeksville.mesh.ui.components.SwitchPreference
private val DeviceConfig.Role.stringRes: Int
private val DeviceConfig.Role.stringRes: Int
get() = when (this) {
DeviceConfig.Role.CLIENT -> R.string.role_client
DeviceConfig.Role.CLIENT_MUTE -> R.string.role_client_mute

View file

@ -153,7 +153,6 @@ fun DisplayConfigItemList(
)
}
}
}
@Preview(showBackground = true)

View file

@ -68,7 +68,7 @@ fun EditDeviceProfileDialog(
SwitchPreference(
title = field.name,
checked = state[field] == true,
enabled = deviceProfile.hasField(field),
enabled = deviceProfile.hasField(field),
onCheckedChange = { state[field] = it },
padding = PaddingValues(0.dp)
)

View file

@ -140,8 +140,9 @@ fun LoRaConfigItemList(
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
onFocusChanged = { isFocused = it.isFocused },
onValueChanged = {
if (it <= loraInput.numChannels) // total num of LoRa channels
if (it <= loraInput.numChannels) { // total num of LoRa channels
loraInput = loraInput.copy { channelNum = it }
}
})
}

View file

@ -97,8 +97,9 @@ fun PositionConfigItemList(
enabled = enabled,
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
onValueChanged = { value ->
if (value >= -90 && value <= 90.0)
if (value >= -90 && value <= 90.0) {
locationInput = locationInput.copy(latitude = value)
}
})
}
item {
@ -107,8 +108,9 @@ fun PositionConfigItemList(
enabled = enabled,
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
onValueChanged = { value ->
if (value >= -180 && value <= 180.0)
if (value >= -180 && value <= 180.0) {
locationInput = locationInput.copy(longitude = value)
}
})
}
item {

View file

@ -58,8 +58,9 @@ fun UserConfigItemList(
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
onValueChanged = {
userInput = userInput.copy { longName = it }
if (getInitials(it).toByteArray().size <= 4) // short_name max_size:5
if (getInitials(it).toByteArray().size <= 4) { // short_name max_size:5
userInput = userInput.copy { shortName = getInitials(it) }
}
})
}