From 2173a53567610c7982dc970dac356e19599339b0 Mon Sep 17 00:00:00 2001 From: Phil Oliver <3497406+poliver@users.noreply.github.com> Date: Mon, 18 Aug 2025 07:51:06 -0400 Subject: [PATCH] Run Spotless (#2762) --- .../com/geeksville/mesh/ApplicationModule.kt | 23 ++-- .../repository/radio/RadioRepositoryModule.kt | 10 +- .../mesh/ui/common/components/EmojiPicker.kt | 37 ++---- .../components/MQTTConfigItemList.kt | 105 +++++++----------- .../mesh/util/CustomRecentEmojiProvider.kt | 25 ++--- .../com/geeksville/mesh/util/LanguageUtils.kt | 19 ++-- 6 files changed, 81 insertions(+), 138 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ApplicationModule.kt b/app/src/main/java/com/geeksville/mesh/ApplicationModule.kt index 8c9ebfb51..720d15b4d 100644 --- a/app/src/main/java/com/geeksville/mesh/ApplicationModule.kt +++ b/app/src/main/java/com/geeksville/mesh/ApplicationModule.kt @@ -33,22 +33,15 @@ import dagger.hilt.components.SingletonComponent @Module object ApplicationModule { @Provides - fun provideSharedPreferences(application: Application): SharedPreferences { - return application.getSharedPreferences("ui-prefs", Context.MODE_PRIVATE) - } + fun provideSharedPreferences(application: Application): SharedPreferences = + application.getSharedPreferences("ui-prefs", Context.MODE_PRIVATE) + + @Provides fun provideProcessLifecycleOwner(): LifecycleOwner = ProcessLifecycleOwner.get() @Provides - fun provideProcessLifecycleOwner(): LifecycleOwner { - return ProcessLifecycleOwner.get() - } + fun provideProcessLifecycle(processLifecycleOwner: LifecycleOwner): Lifecycle = processLifecycleOwner.lifecycle @Provides - fun provideProcessLifecycle(processLifecycleOwner: LifecycleOwner): Lifecycle { - return processLifecycleOwner.lifecycle - } - - @Provides - fun providesMeshServiceNotifications(application: Application): MeshServiceNotifications { - return MeshServiceNotifications(application) - } -} \ No newline at end of file + fun providesMeshServiceNotifications(application: Application): MeshServiceNotifications = + MeshServiceNotifications(application) +} diff --git a/app/src/main/java/com/geeksville/mesh/repository/radio/RadioRepositoryModule.kt b/app/src/main/java/com/geeksville/mesh/repository/radio/RadioRepositoryModule.kt index 1f51e94d6..ed22b7ab4 100644 --- a/app/src/main/java/com/geeksville/mesh/repository/radio/RadioRepositoryModule.kt +++ b/app/src/main/java/com/geeksville/mesh/repository/radio/RadioRepositoryModule.kt @@ -33,8 +33,7 @@ import dagger.multibindings.Multibinds @InstallIn(SingletonComponent::class) abstract class RadioRepositoryModule { - @Multibinds - abstract fun interfaceMap(): Map> + @Multibinds abstract fun interfaceMap(): Map> @[Binds IntoMap InterfaceMapKey(InterfaceId.BLUETOOTH)] abstract fun bindBluetoothInterfaceSpec(spec: BluetoothInterfaceSpec): @JvmSuppressWildcards InterfaceSpec<*> @@ -54,8 +53,7 @@ abstract class RadioRepositoryModule { companion object { @Provides @RadioRepositoryQualifier - fun provideSharedPreferences(application: Application): SharedPreferences { - return application.getSharedPreferences("radio-prefs", Context.MODE_PRIVATE) - } + fun provideSharedPreferences(application: Application): SharedPreferences = + application.getSharedPreferences("radio-prefs", Context.MODE_PRIVATE) } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/geeksville/mesh/ui/common/components/EmojiPicker.kt b/app/src/main/java/com/geeksville/mesh/ui/common/components/EmojiPicker.kt index e6c6dbe7c..09ee28d46 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/common/components/EmojiPicker.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/common/components/EmojiPicker.kt @@ -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) + } diff --git a/app/src/main/java/com/geeksville/mesh/ui/radioconfig/components/MQTTConfigItemList.kt b/app/src/main/java/com/geeksville/mesh/ui/radioconfig/components/MQTTConfigItemList.kt index 6c9576959..1fc391f05 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/radioconfig/components/MQTTConfigItemList.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/radioconfig/components/MQTTConfigItemList.kt @@ -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 = {}) } diff --git a/app/src/main/java/com/geeksville/mesh/util/CustomRecentEmojiProvider.kt b/app/src/main/java/com/geeksville/mesh/util/CustomRecentEmojiProvider.kt index 6797ba7bd..f6575638e 100644 --- a/app/src/main/java/com/geeksville/mesh/util/CustomRecentEmojiProvider.kt +++ b/app/src/main/java/com/geeksville/mesh/util/CustomRecentEmojiProvider.kt @@ -22,27 +22,24 @@ import androidx.emoji2.emojipicker.RecentEmojiAsyncProvider import com.google.common.util.concurrent.Futures import com.google.common.util.concurrent.ListenableFuture -/** - * Define a custom recent emoji provider which shows most frequently used emoji - */ -class CustomRecentEmojiProvider( - context: Context -) : RecentEmojiAsyncProvider { +/** Define a custom recent emoji provider which shows most frequently used emoji */ +class CustomRecentEmojiProvider(context: Context) : RecentEmojiAsyncProvider { - private val sharedPreferences = - context.getSharedPreferences(RECENT_EMOJI_LIST_FILE_NAME, Context.MODE_PRIVATE) + private val sharedPreferences = context.getSharedPreferences(RECENT_EMOJI_LIST_FILE_NAME, Context.MODE_PRIVATE) private val emoji2Frequency: MutableMap by lazy { - sharedPreferences.getString(PREF_KEY_CUSTOM_EMOJI_FREQ, null)?.split(SPLIT_CHAR) + sharedPreferences + .getString(PREF_KEY_CUSTOM_EMOJI_FREQ, null) + ?.split(SPLIT_CHAR) ?.associate { entry -> - entry.split(KEY_VALUE_DELIMITER, limit = 2).takeIf { it.size == 2 } - ?.let { it[0] to it[1].toInt() } ?: ("" to 0) - }?.toMutableMap() ?: mutableMapOf() + entry.split(KEY_VALUE_DELIMITER, limit = 2).takeIf { it.size == 2 }?.let { it[0] to it[1].toInt() } + ?: ("" to 0) + } + ?.toMutableMap() ?: mutableMapOf() } override fun getRecentEmojiListAsync(): ListenableFuture> = - Futures.immediateFuture(emoji2Frequency.toList().sortedByDescending { it.second } - .map { it.first }) + Futures.immediateFuture(emoji2Frequency.toList().sortedByDescending { it.second }.map { it.first }) override fun recordSelection(emoji: String) { emoji2Frequency[emoji] = (emoji2Frequency[emoji] ?: 0) + 1 diff --git a/app/src/main/java/com/geeksville/mesh/util/LanguageUtils.kt b/app/src/main/java/com/geeksville/mesh/util/LanguageUtils.kt index e78fc29cc..d2309d02a 100644 --- a/app/src/main/java/com/geeksville/mesh/util/LanguageUtils.kt +++ b/app/src/main/java/com/geeksville/mesh/util/LanguageUtils.kt @@ -22,8 +22,8 @@ import android.content.SharedPreferences import androidx.appcompat.app.AppCompatDelegate import androidx.core.content.edit import androidx.core.os.LocaleListCompat -import com.geeksville.mesh.android.Logging import com.geeksville.mesh.R +import com.geeksville.mesh.android.Logging import org.xmlpull.v1.XmlPullParser import java.util.Locale @@ -32,9 +32,7 @@ object LanguageUtils : Logging { const val SYSTEM_DEFAULT = "zz" const val SYSTEM_MANAGED = "appcompat" - fun getLocale(): String { - return AppCompatDelegate.getApplicationLocales().toLanguageTags().ifEmpty { SYSTEM_DEFAULT } - } + fun getLocale(): String = AppCompatDelegate.getApplicationLocales().toLanguageTags().ifEmpty { SYSTEM_DEFAULT } fun setLocale(lang: String) { AppCompatDelegate.setApplicationLocales( @@ -42,7 +40,7 @@ object LanguageUtils : Logging { LocaleListCompat.getEmptyLocaleList() } else { LocaleListCompat.forLanguageTags(lang) - } + }, ) } @@ -53,10 +51,7 @@ object LanguageUtils : Logging { setLocale(currentLang) } - /** - * Build a list from locales_config.xml - * of native language names paired to its Locale tag (ex: "English", "en") - */ + /** Build a list from locales_config.xml of native language names paired to its Locale tag (ex: "English", "en") */ fun getLanguageTags(context: Context): Map { val languageTags = mutableListOf(SYSTEM_DEFAULT) try { @@ -79,8 +74,10 @@ object LanguageUtils : Logging { "pt-BR" -> context.getString(R.string.pt_BR) "zh-CN" -> context.getString(R.string.zh_CN) "zh-TW" -> context.getString(R.string.zh_TW) - else -> loc.getDisplayLanguage(loc) - .replaceFirstChar { if (it.isLowerCase()) it.titlecase(loc) else it.toString() } + else -> + loc.getDisplayLanguage(loc).replaceFirstChar { + if (it.isLowerCase()) it.titlecase(loc) else it.toString() + } } } }