update copy, add subtitle

This commit is contained in:
Adam Velebil 2023-01-10 11:44:43 +01:00
parent ad68c95f22
commit 3dde829cd2
No known key found for this signature in database
GPG Key ID: C9B1E4A3CBBD2E10
6 changed files with 27 additions and 23 deletions

View File

@ -26,7 +26,7 @@ class AppPreferences(context: Context) {
const val PREFS_FILE = "FlutterSharedPreferences"
const val PREF_NFC_OPEN_APP = "flutter.prefNfcOpenApp"
const val PREF_NFC_BYPASS_TOUCH = "flutter.prefNfcBypassTouch"
const val PREF_NFC_PLAY_DISCOVERY_SOUND = "flutter.prefNfcPlayDiscoverySound"
const val PREF_NFC_SILENCE_SOUNDS = "flutter.prefNfcSilenceSounds"
const val PREF_NFC_COPY_OTP = "flutter.prefNfcCopyOtp"
const val PREF_USB_OPEN_APP = "flutter.prefUsbOpenApp"
@ -50,8 +50,8 @@ class AppPreferences(context: Context) {
val bypassTouchOnNfcTap: Boolean
get() = prefs.getBoolean(PREF_NFC_BYPASS_TOUCH, false)
val playNfcDiscoverySound: Boolean
get() = prefs.getBoolean(PREF_NFC_PLAY_DISCOVERY_SOUND, true)
val silenceNfcSounds: Boolean
get() = prefs.getBoolean(PREF_NFC_SILENCE_SOUNDS, false)
val copyOtpOnNfcTap: Boolean
get() = prefs.getBoolean(PREF_NFC_COPY_OTP, false)

View File

@ -104,7 +104,7 @@ class MainActivity : FlutterFragmentActivity() {
try {
Log.d(TAG, "Starting nfc discovery")
yubikit.startNfcDiscovery(
nfcConfiguration.disableNfcDiscoverySound(!appPreferences.playNfcDiscoverySound),
nfcConfiguration.disableNfcDiscoverySound(appPreferences.silenceNfcSounds),
this,
::processYubiKey
)
@ -315,7 +315,7 @@ class MainActivity : FlutterFragmentActivity() {
}
private val sharedPreferencesListener = OnSharedPreferenceChangeListener { _, key ->
if ( AppPreferences.PREF_NFC_PLAY_DISCOVERY_SOUND == key) {
if ( AppPreferences.PREF_NFC_SILENCE_SOUNDS == key) {
stopNfcDiscovery()
startNfcDiscovery()
}

View File

@ -23,7 +23,7 @@ const betaDialogView = Key('$_prefix.beta_dialog');
const nfcTapSetting = Key('$_prefix.nfc_tap');
const nfcKeyboardLayoutSetting = Key('$_prefix.nfc_keyboard_layout');
const nfcBypassTouchSetting = Key('$_prefix.nfc_bypass_touch');
const nfcPlayDiscoverySoundSetting = Key('$_prefix.nfc_play_discovery_sound');
const nfcSilenceSoundsSettings = Key('$_prefix.nfc_silence_sounds');
const usbOpenApp = Key('$_prefix.usb_open_app');
const themeModeSetting = Key('$_prefix.theme_mode');

View File

@ -18,7 +18,7 @@
const betaDialogPrefName = 'prefBetaDialogShouldBeShown';
const prefNfcOpenApp = 'prefNfcOpenApp';
const prefNfcBypassTouch = 'prefNfcBypassTouch';
const prefNfcPlayDiscoverySound = 'prefNfcPlayDiscoverySound';
const prefNfcSilenceSounds = 'prefNfcSilenceSounds';
const prefNfcCopyOtp = 'prefNfcCopyOtp';
const prefClipKbdLayout = 'prefClipKbdLayout';
const prefUsbOpenApp = 'prefUsbOpenApp';

View File

@ -105,7 +105,7 @@ class _AndroidSettingsPageState extends ConsumerState<AndroidSettingsPage> {
final clipKbdLayout =
prefs.getString(prefClipKbdLayout) ?? _defaultClipKbdLayout;
final nfcBypassTouch = prefs.getBool(prefNfcBypassTouch) ?? false;
final nfcPlayDiscoverySound = prefs.getBool(prefNfcPlayDiscoverySound) ?? true;
final nfcSilenceSounds = prefs.getBool(prefNfcSilenceSounds) ?? false;
final usbOpenApp = prefs.getBool(prefUsbOpenApp) ?? false;
final themeMode = ref.watch(themeModeProvider);
@ -166,12 +166,16 @@ class _AndroidSettingsPageState extends ConsumerState<AndroidSettingsPage> {
});
}),
SwitchListTile(
title: const Text('Play sound on tap'),
value: nfcPlayDiscoverySound,
key: keys.nfcPlayDiscoverySoundSetting,
title: const Text('Silence NFC sounds'),
subtitle: nfcSilenceSounds
? const Text(
'No sounds will be played on NFC tap')
: const Text('Sound will play on NFC tap'),
value: nfcSilenceSounds,
key: keys.nfcSilenceSoundsSettings,
onChanged: (value) {
setState(() {
prefs.setBool(prefNfcPlayDiscoverySound, value);
prefs.setBool(prefNfcSilenceSounds, value);
});
}),
const ListTitle('USB options'),
@ -180,7 +184,7 @@ class _AndroidSettingsPageState extends ConsumerState<AndroidSettingsPage> {
subtitle: usbOpenApp
? const Text(
'This prevents other apps from using the YubiKey over USB')
: const Text('Other apps can use the YubiKey over USB.'),
: const Text('Other apps can use the YubiKey over USB'),
value: usbOpenApp,
key: keys.usbOpenApp,
onChanged: (value) {

View File

@ -108,8 +108,8 @@ extension _WidgetTesterHelper on WidgetTester {
await pumpAndSettle();
}
Future<void> tapPlayNfcDiscoverySounds() async {
await tap(find.byKey(keys.nfcPlayDiscoverySoundSetting));
Future<void> tapSilenceNfcSounds() async {
await tap(find.byKey(keys.nfcSilenceSoundsSettings));
await pumpAndSettle();
}
@ -320,8 +320,8 @@ void main() {
expect(sharedPrefs.getBool(prefUsbOpenApp), equals(false));
});
testWidgets('Play NFC Discovery sound', (WidgetTester tester) async {
SharedPreferences.setMockInitialValues({prefNfcPlayDiscoverySound: true});
testWidgets('Silence NFC sound', (WidgetTester tester) async {
SharedPreferences.setMockInitialValues({prefNfcSilenceSounds: false});
SharedPreferences sharedPrefs = await SharedPreferences.getInstance();
await tester.pumpWidget(androidWidget(
@ -329,12 +329,12 @@ void main() {
child: widget,
));
// change to false
await tester.tapPlayNfcDiscoverySounds();
expect(sharedPrefs.getBool(prefNfcPlayDiscoverySound), equals(false));
// change to true
await tester.tapPlayNfcDiscoverySounds();
expect(sharedPrefs.getBool(prefNfcPlayDiscoverySound), equals(true));
await tester.tapSilenceNfcSounds();
expect(sharedPrefs.getBool(prefNfcSilenceSounds), equals(true));
// change to false
await tester.tapSilenceNfcSounds();
expect(sharedPrefs.getBool(prefNfcSilenceSounds), equals(false));
});
}