From ef75be5945de57c322f3b23b41f4e54400669150 Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Fri, 10 Jun 2022 11:28:02 -0400 Subject: [PATCH] Rename autocomplete setting (#143) --- .../channel/chat/widgets/chat_bottom_bar.dart | 88 +++++++++---------- .../settings/sections/chat_settings.dart | 15 ++-- .../settings/stores/settings_store.dart | 8 +- .../settings/stores/settings_store.g.dart | 22 ++--- 4 files changed, 65 insertions(+), 68 deletions(-) diff --git a/lib/screens/channel/chat/widgets/chat_bottom_bar.dart b/lib/screens/channel/chat/widgets/chat_bottom_bar.dart index 99aa6074..fe43cf6c 100644 --- a/lib/screens/channel/chat/widgets/chat_bottom_bar.dart +++ b/lib/screens/channel/chat/widgets/chat_bottom_bar.dart @@ -14,75 +14,71 @@ class ChatBottomBar extends StatelessWidget { Widget build(BuildContext context) { return Observer( builder: (context) { - final emotes = [ + final matchingEmotes = [ ...chatStore.assetsStore.userEmoteToObject.values, ...chatStore.assetsStore.bttvEmotes, ...chatStore.assetsStore.ffzEmotes, ...chatStore.assetsStore.sevenTVEmotes ].where((emote) => emote.name.toLowerCase().contains(chatStore.textController.text.split(' ').last.toLowerCase())).toList(); - final filteredMentionedChatters = chatStore.chatDetailsStore.allChatters + final matchingChatters = chatStore.chatDetailsStore.allChatters .where((chatter) => chatter.contains(chatStore.textController.text.split(' ').last.replaceFirst('@', '').toLowerCase())) .toList(); return Column( children: [ - if (chatStore.settings.emoteAutocomplete && chatStore.showEmoteAutocomplete && emotes.isNotEmpty) ...[ + if (chatStore.settings.autocomplete && (chatStore.showEmoteAutocomplete || chatStore.showMentionAutocomplete)) ...[ const Divider( height: 1.0, thickness: 1.0, ), - SizedBox( - height: 50, - child: ListView.builder( - padding: const EdgeInsets.symmetric(horizontal: 10.0), - itemCount: emotes.length, - scrollDirection: Axis.horizontal, - itemBuilder: (context, index) => InkWell( - onTap: () => chatStore.addEmote(emotes[index], autocompleteMode: true), - child: Tooltip( - message: emotes[index].name, - preferBelow: false, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 5.0), - child: Center( - child: CachedNetworkImage( - imageUrl: emotes[index].url, - fadeInDuration: const Duration(), - height: emotes[index].height?.toDouble() ?? defaultEmoteSize, - width: emotes[index].width?.toDouble(), + if (chatStore.showEmoteAutocomplete && matchingEmotes.isNotEmpty) + SizedBox( + height: 50, + child: ListView.builder( + padding: const EdgeInsets.symmetric(horizontal: 10.0), + itemCount: matchingEmotes.length, + scrollDirection: Axis.horizontal, + itemBuilder: (context, index) => InkWell( + onTap: () => chatStore.addEmote(matchingEmotes[index], autocompleteMode: true), + child: Tooltip( + message: matchingEmotes[index].name, + preferBelow: false, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 5.0), + child: Center( + child: CachedNetworkImage( + imageUrl: matchingEmotes[index].url, + fadeInDuration: const Duration(), + height: matchingEmotes[index].height?.toDouble() ?? defaultEmoteSize, + width: matchingEmotes[index].width?.toDouble(), + ), ), ), ), ), ), ), - ) - ], - if (chatStore.showMentionAutocomplete && filteredMentionedChatters.isNotEmpty) ...[ - const Divider( - height: 1.0, - thickness: 1.0, - ), - SizedBox( - height: 50, - child: ListView.builder( - padding: const EdgeInsets.symmetric(horizontal: 10.0), - itemCount: filteredMentionedChatters.length, - scrollDirection: Axis.horizontal, - itemBuilder: (context, index) => TextButton( - onPressed: () { - final split = chatStore.textController.text.split(' ') - ..removeLast() - ..add('@${filteredMentionedChatters[index]} '); + if (chatStore.showMentionAutocomplete && matchingChatters.isNotEmpty) + SizedBox( + height: 50, + child: ListView.builder( + padding: const EdgeInsets.symmetric(horizontal: 10.0), + itemCount: matchingChatters.length, + scrollDirection: Axis.horizontal, + itemBuilder: (context, index) => TextButton( + onPressed: () { + final split = chatStore.textController.text.split(' ') + ..removeLast() + ..add('@${matchingChatters[index]} '); - chatStore.textController.text = split.join(' '); - chatStore.textController.selection = TextSelection.fromPosition(TextPosition(offset: chatStore.textController.text.length)); - }, - child: Text(filteredMentionedChatters[index]), + chatStore.textController.text = split.join(' '); + chatStore.textController.selection = TextSelection.fromPosition(TextPosition(offset: chatStore.textController.text.length)); + }, + child: Text(matchingChatters[index]), + ), ), - ), - ) + ) ], Row( children: [ diff --git a/lib/screens/settings/sections/chat_settings.dart b/lib/screens/settings/sections/chat_settings.dart index 4c2a0c65..515a4449 100644 --- a/lib/screens/settings/sections/chat_settings.dart +++ b/lib/screens/settings/sections/chat_settings.dart @@ -38,6 +38,14 @@ class _ChatSettingsState extends State { ), ), children: [ + SwitchListTile.adaptive( + isThreeLine: true, + title: const Text('Autocomplete'), + subtitle: const Text('Shows a bar that suggests matching emotes and mentions when typing.'), + value: settingsStore.autocomplete, + onChanged: settingsStore.showBottomBar ? (newValue) => settingsStore.autocomplete = newValue : null, + ), + const SizedBox(height: 15.0), ListTile( title: Row( children: [ @@ -108,13 +116,6 @@ class _ChatSettingsState extends State { fontSize: 12.0, padding: sectionPadding, ), - SwitchListTile.adaptive( - isThreeLine: true, - title: const Text('Emote Autocomplete'), - subtitle: const Text('Shows a bar that suggests matching emotes when typing.'), - value: settingsStore.emoteAutocomplete, - onChanged: settingsStore.showBottomBar ? (newValue) => settingsStore.emoteAutocomplete = newValue : null, - ), SwitchListTile.adaptive( isThreeLine: true, title: const Text('Zero-Width Emotes'), diff --git a/lib/screens/settings/stores/settings_store.dart b/lib/screens/settings/stores/settings_store.dart index 5018045d..69f61d4b 100644 --- a/lib/screens/settings/stores/settings_store.dart +++ b/lib/screens/settings/stores/settings_store.dart @@ -91,7 +91,7 @@ abstract class _SettingsStoreBase with Store { static const defaultEmoteScale = 1.0; - static const defaultEmoteAutocomplete = true; + static const defaultAutocomplete = true; static const defaultChatWidth = 0.3; @@ -145,9 +145,9 @@ abstract class _SettingsStoreBase with Store { @observable var emoteScale = defaultEmoteScale; - @JsonKey(defaultValue: defaultEmoteAutocomplete) + @JsonKey(defaultValue: defaultAutocomplete) @observable - var emoteAutocomplete = defaultEmoteAutocomplete; + var autocomplete = defaultAutocomplete; @JsonKey(defaultValue: defaultChatWidth) @observable @@ -218,7 +218,7 @@ abstract class _SettingsStoreBase with Store { messageSpacing = defaultMessageSpacing; badgeScale = defaultBadgeScale; emoteScale = defaultEmoteScale; - emoteAutocomplete = defaultEmoteAutocomplete; + autocomplete = defaultAutocomplete; chatWidth = defaultChatWidth; landscapeChatLeftSide = false; chatDelay = defaultChatDelay; diff --git a/lib/screens/settings/stores/settings_store.g.dart b/lib/screens/settings/stores/settings_store.g.dart index 12cebbbb..7acdbab9 100644 --- a/lib/screens/settings/stores/settings_store.g.dart +++ b/lib/screens/settings/stores/settings_store.g.dart @@ -34,7 +34,7 @@ SettingsStore _$SettingsStoreFromJson(Map json) => ..messageScale = (json['messageScale'] as num?)?.toDouble() ?? 1.0 ..badgeScale = (json['badgeScale'] as num?)?.toDouble() ?? 1.0 ..emoteScale = (json['emoteScale'] as num?)?.toDouble() ?? 1.0 - ..emoteAutocomplete = json['emoteAutocomplete'] as bool? ?? true + ..autocomplete = json['autocomplete'] as bool? ?? true ..chatWidth = (json['chatWidth'] as num?)?.toDouble() ?? 0.3 ..landscapeChatLeftSide = json['landscapeChatLeftSide'] as bool? ?? false ..fullScreenChatOverlayOpacity = @@ -67,7 +67,7 @@ Map _$SettingsStoreToJson(SettingsStore instance) => 'messageScale': instance.messageScale, 'badgeScale': instance.badgeScale, 'emoteScale': instance.emoteScale, - 'emoteAutocomplete': instance.emoteAutocomplete, + 'autocomplete': instance.autocomplete, 'chatWidth': instance.chatWidth, 'landscapeChatLeftSide': instance.landscapeChatLeftSide, 'fullScreenChatOverlayOpacity': instance.fullScreenChatOverlayOpacity, @@ -419,19 +419,19 @@ mixin _$SettingsStore on _SettingsStoreBase, Store { }); } - late final _$emoteAutocompleteAtom = - Atom(name: '_SettingsStoreBase.emoteAutocomplete', context: context); + late final _$autocompleteAtom = + Atom(name: '_SettingsStoreBase.autocomplete', context: context); @override - bool get emoteAutocomplete { - _$emoteAutocompleteAtom.reportRead(); - return super.emoteAutocomplete; + bool get autocomplete { + _$autocompleteAtom.reportRead(); + return super.autocomplete; } @override - set emoteAutocomplete(bool value) { - _$emoteAutocompleteAtom.reportWrite(value, super.emoteAutocomplete, () { - super.emoteAutocomplete = value; + set autocomplete(bool value) { + _$autocompleteAtom.reportWrite(value, super.autocomplete, () { + super.autocomplete = value; }); } @@ -604,7 +604,7 @@ messageSpacing: ${messageSpacing}, messageScale: ${messageScale}, badgeScale: ${badgeScale}, emoteScale: ${emoteScale}, -emoteAutocomplete: ${emoteAutocomplete}, +autocomplete: ${autocomplete}, chatWidth: ${chatWidth}, landscapeChatLeftSide: ${landscapeChatLeftSide}, fullScreenChatOverlayOpacity: ${fullScreenChatOverlayOpacity},