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
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
fun providesMeshServiceNotifications(application: Application): MeshServiceNotifications =
|
||||
MeshServiceNotifications(application)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,8 +33,7 @@ import dagger.multibindings.Multibinds
|
|||
@InstallIn(SingletonComponent::class)
|
||||
abstract class RadioRepositoryModule {
|
||||
|
||||
@Multibinds
|
||||
abstract fun interfaceMap(): Map<InterfaceId, @JvmSuppressWildcards InterfaceSpec<*>>
|
||||
@Multibinds abstract fun interfaceMap(): Map<InterfaceId, @JvmSuppressWildcards InterfaceSpec<*>>
|
||||
|
||||
@[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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = {})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String, Int> 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<List<String>> =
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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<String, String> {
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue