mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
chore: add detekt formatting rule set
https://detekt.dev/docs/next/rules/formatting/
This commit is contained in:
parent
056d4a5829
commit
fe56d257f5
58 changed files with 725 additions and 432 deletions
|
|
@ -47,7 +47,7 @@ data class Channel(
|
|||
}
|
||||
}
|
||||
|
||||
/// Return the name of our channel as a human readable string. If empty string, assume "Default" per mesh.proto spec
|
||||
// Return the name of our channel as a human readable string. If empty string, assume "Default" per mesh.proto spec
|
||||
val name: String
|
||||
get() = settings.name.ifEmpty {
|
||||
// We have a new style 'empty' channel name. Use the same logic from the device to convert that to a human readable name
|
||||
|
|
@ -66,15 +66,15 @@ data class Channel(
|
|||
}
|
||||
|
||||
val psk: ByteString
|
||||
get() = if (settings.psk.size() != 1)
|
||||
get() = if (settings.psk.size() != 1) {
|
||||
settings.psk // A standard PSK
|
||||
else {
|
||||
} else {
|
||||
// One of our special 1 byte PSKs, see mesh.proto for docs.
|
||||
val pskIndex = settings.psk.byteAt(0).toInt()
|
||||
|
||||
if (pskIndex == 0)
|
||||
if (pskIndex == 0) {
|
||||
cleartextPSK
|
||||
else {
|
||||
} else {
|
||||
// Treat an index of 1 as the old channelDefaultKey and work up from there
|
||||
val bytes = channelDefaultKey.clone()
|
||||
bytes[bytes.size - 1] = (0xff and (bytes[bytes.size - 1] + pskIndex - 1)).toByte()
|
||||
|
|
|
|||
|
|
@ -40,8 +40,9 @@ private fun LoRaConfig.bandwidth() = if (usePreset) {
|
|||
|
||||
val LoRaConfig.numChannels: Int get() {
|
||||
for (option in RegionInfo.entries) {
|
||||
if (option.regionCode == region)
|
||||
if (option.regionCode == region) {
|
||||
return ((option.freqEnd - option.freqStart) / bandwidth()).toInt()
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
|
@ -55,8 +56,9 @@ internal fun LoRaConfig.channelNum(primaryName: String): Int = when {
|
|||
internal fun LoRaConfig.radioFreq(channelNum: Int): Float {
|
||||
if (overrideFrequency != 0f) return overrideFrequency + frequencyOffset
|
||||
for (option in RegionInfo.entries) {
|
||||
if (option.regionCode == region)
|
||||
if (option.regionCode == region) {
|
||||
return (option.freqStart + bandwidth() / 2) + (channelNum - 1) * bandwidth()
|
||||
}
|
||||
}
|
||||
return 0f
|
||||
}
|
||||
|
|
@ -103,5 +105,4 @@ enum class ChannelOption(
|
|||
LONG_MODERATE(ModemPreset.LONG_MODERATE, R.string.modem_config_mod_long, .125f),
|
||||
LONG_SLOW(ModemPreset.LONG_SLOW, R.string.modem_config_slow_long, .125f),
|
||||
VERY_LONG_SLOW(ModemPreset.VERY_LONG_SLOW, R.string.modem_config_very_long, .0625f),
|
||||
;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -469,8 +469,11 @@ class RadioConfigViewModel @Inject constructor(
|
|||
setResponseStateError(app.getString(parsed.errorReason.stringRes))
|
||||
} else if (packet.from == destNum && route.isEmpty()) {
|
||||
requestIds.update { it.apply { remove(data.requestId) } }
|
||||
if (requestIds.value.isEmpty()) setResponseStateSuccess()
|
||||
else incrementCompleted()
|
||||
if (requestIds.value.isEmpty()) {
|
||||
setResponseStateSuccess()
|
||||
} else {
|
||||
incrementCompleted()
|
||||
}
|
||||
}
|
||||
}
|
||||
if (data?.portnumValue == Portnums.PortNum.ADMIN_APP_VALUE) {
|
||||
|
|
|
|||
|
|
@ -58,10 +58,10 @@ import java.util.concurrent.TimeUnit
|
|||
import javax.inject.Inject
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
// / Given a human name, strip out the first letter of the first three words and return that as the initials for
|
||||
// / that user. If the original name is only one word, strip vowels from the original name and if the result is
|
||||
// / 3 or more characters, use the first three characters. If not, just take the first 3 characters of the
|
||||
// / original name.
|
||||
// Given a human name, strip out the first letter of the first three words and return that as the initials for
|
||||
// that user. If the original name is only one word, strip vowels from the original name and if the result is
|
||||
// 3 or more characters, use the first three characters. If not, just take the first 3 characters of the
|
||||
// original name.
|
||||
fun getInitials(nameIn: String): String {
|
||||
val nchars = 4
|
||||
val minchars = 2
|
||||
|
|
@ -70,10 +70,11 @@ fun getInitials(nameIn: String): String {
|
|||
|
||||
val initials = when (words.size) {
|
||||
in 0 until minchars -> {
|
||||
val nm = if (name.isNotEmpty())
|
||||
val nm = if (name.isNotEmpty()) {
|
||||
name.first() + name.drop(1).filterNot { c -> c.lowercase() in "aeiou" }
|
||||
else
|
||||
} else {
|
||||
""
|
||||
}
|
||||
if (nm.length >= nchars) nm else name
|
||||
}
|
||||
else -> words.map { it.first() }.joinToString("")
|
||||
|
|
@ -414,7 +415,7 @@ class UIViewModel @Inject constructor(
|
|||
fun requestUserInfo(destNum: Int) {
|
||||
info("Requesting UserInfo for '$destNum'")
|
||||
try {
|
||||
meshService?.requestUserInfo( destNum )
|
||||
meshService?.requestUserInfo(destNum)
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("Request NodeInfo error: ${ex.message}")
|
||||
}
|
||||
|
|
@ -545,7 +546,7 @@ class UIViewModel @Inject constructor(
|
|||
fun setChannels(channelSet: AppOnlyProtos.ChannelSet, overwrite: Boolean = true) = viewModelScope.launch {
|
||||
val newRadioSettings: List<ChannelSettings> = if (overwrite) {
|
||||
channelSet.settingsList
|
||||
} else {
|
||||
} else {
|
||||
// To guarantee consistent ordering, using a LinkedHashSet which iterates through it's
|
||||
// entries according to the order an item was *first* inserted.
|
||||
// https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-linked-hash-set/
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ class MarkerWithLabel(mapView: MapView?, label: String, emoji: String? = null) :
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private var onLongClickListener: (() -> Boolean)? = null
|
||||
|
||||
fun setOnLongClickListener(listener: () -> Boolean) {
|
||||
|
|
@ -93,7 +92,7 @@ class MarkerWithLabel(mapView: MapView?, label: String, emoji: String? = null) :
|
|||
val bgRect = getTextBackgroundSize(mLabel, (p.x - 0F), (p.y - LABEL_Y_OFFSET))
|
||||
bgRect.inset(-8F, -2F)
|
||||
|
||||
if(mLabel.isNotEmpty()) {
|
||||
if (mLabel.isNotEmpty()) {
|
||||
c.drawRoundRect(bgRect, LABEL_CORNER_RADIUS, LABEL_CORNER_RADIUS, bgPaint)
|
||||
c.drawText(mLabel, (p.x - 0F), (p.y - LABEL_Y_OFFSET), textPaint)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue