mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat(settings): Only show homoglyph setting for Cyrillic locales (#4559)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
d14ae9e7c3
commit
fb1bdb2044
4 changed files with 144 additions and 41 deletions
|
|
@ -25,6 +25,7 @@ import android.provider.Settings
|
|||
import android.provider.Settings.ACTION_APP_LOCALE_SETTINGS
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.appcompat.app.AppCompatActivity.RESULT_OK
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.compose.foundation.layout.Column
|
||||
|
|
@ -53,9 +54,11 @@ import androidx.compose.runtime.remember
|
|||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.os.ConfigurationCompat
|
||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||
|
|
@ -313,11 +316,10 @@ fun SettingsScreen(
|
|||
|
||||
val homoglyphEncodingEnabled by
|
||||
viewModel.homoglyphEncodingEnabledFlow.collectAsStateWithLifecycle(false)
|
||||
SwitchListItem(
|
||||
text = stringResource(Res.string.use_homoglyph_characters_encoding),
|
||||
checked = homoglyphEncodingEnabled,
|
||||
leadingIcon = Icons.Default.Abc,
|
||||
onClick = { viewModel.toggleHomoglyphCharactersEncodingEnabled() },
|
||||
|
||||
HomoglyphSetting(
|
||||
homoglyphEncodingEnabled = homoglyphEncodingEnabled,
|
||||
onToggle = { viewModel.toggleHomoglyphCharactersEncodingEnabled() },
|
||||
)
|
||||
|
||||
val settingsLauncher =
|
||||
|
|
@ -535,3 +537,18 @@ private fun ThemePickerDialog(onClickTheme: (Int) -> Unit, onDismiss: () -> Unit
|
|||
},
|
||||
)
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@Composable
|
||||
fun HomoglyphSetting(homoglyphEncodingEnabled: Boolean, onToggle: () -> Unit) {
|
||||
val currentLocale = ConfigurationCompat.getLocales(LocalConfiguration.current).get(0)
|
||||
val supportedLanguages = listOf("ru", "uk", "be", "bg", "sr", "mk", "kk", "ky", "tg", "mn")
|
||||
if (currentLocale?.language in supportedLanguages) {
|
||||
SwitchListItem(
|
||||
text = stringResource(Res.string.use_homoglyph_characters_encoding),
|
||||
checked = homoglyphEncodingEnabled,
|
||||
leadingIcon = Icons.Default.Abc,
|
||||
onClick = onToggle,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.feature.settings
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.junit4.v2.createComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import com.meshtastic.core.strings.getString
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.meshtastic.core.strings.Res
|
||||
import org.meshtastic.core.strings.use_homoglyph_characters_encoding
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import java.util.Locale
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34])
|
||||
class HomoglyphSettingTest {
|
||||
|
||||
@get:Rule val composeTestRule = createComposeRule()
|
||||
|
||||
@Test
|
||||
fun homoglyphSetting_isVisible_forRussianLocale() {
|
||||
val russianConfig = Configuration().apply { setLocale(Locale.forLanguageTag("ru")) }
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalConfiguration provides russianConfig) {
|
||||
HomoglyphSetting(homoglyphEncodingEnabled = false, onToggle = {})
|
||||
}
|
||||
}
|
||||
|
||||
val expectedText = getString(Res.string.use_homoglyph_characters_encoding)
|
||||
composeTestRule.onNodeWithText(expectedText).assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun homoglyphSetting_isNotVisible_forEnglishLocale() {
|
||||
val englishConfig = Configuration().apply { setLocale(Locale.forLanguageTag("en")) }
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalConfiguration provides englishConfig) {
|
||||
HomoglyphSetting(homoglyphEncodingEnabled = false, onToggle = {})
|
||||
}
|
||||
}
|
||||
|
||||
val expectedText = getString(Res.string.use_homoglyph_characters_encoding)
|
||||
composeTestRule.onNodeWithText(expectedText).assertDoesNotExist()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue