diff --git a/lib/pangea/controllers/message_analytics_controller.dart b/lib/pangea/controllers/message_analytics_controller.dart index e3e60e0e1..5d4a07360 100644 --- a/lib/pangea/controllers/message_analytics_controller.dart +++ b/lib/pangea/controllers/message_analytics_controller.dart @@ -27,19 +27,17 @@ class TargetTokensAndActivityType { return false; } - // check that the activity matches at least one construct in the target tokens - // TODO - this is complicated so we need to verify it works - // maybe we just verify that the target span of the activity is the same as the target span of the target - final allTokenConstructs = - tokens.map((t) => t.constructs).expand((e) => e).toList(); - for (final c in allTokenConstructs) { - if (activity.tgtConstructs.any((tc) => tc == c.id)) { - debugPrint('found existing activity'); - return true; - } - } + // This is kind of complicated + // if it's causing problems, + // maybe we just verify that the target span of the activity is the same as the target span of the target? + final List allTokenConstructs = tokens + .map((t) => t.constructs) + .expand((e) => e) + .map((c) => c.id) + .where(activityType.constructFilter) + .toList(); - return false; + return listEquals(activity.tgtConstructs, allTokenConstructs); } @override diff --git a/lib/pangea/enum/activity_type_enum.dart b/lib/pangea/enum/activity_type_enum.dart index 909ac9378..8da783867 100644 --- a/lib/pangea/enum/activity_type_enum.dart +++ b/lib/pangea/enum/activity_type_enum.dart @@ -1,4 +1,6 @@ +import 'package:fluffychat/pangea/enum/construct_type_enum.dart'; import 'package:fluffychat/pangea/enum/construct_use_type_enum.dart'; +import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_model.dart'; enum ActivityTypeEnum { wordMeaning, wordFocusListening, hiddenWordListening } @@ -68,4 +70,14 @@ extension ActivityTypeExtension on ActivityTypeEnum { ]; } } + + /// Filters out constructs that are not relevant to the activity type + bool Function(ConstructIdentifier) get constructFilter { + switch (this) { + case ActivityTypeEnum.wordMeaning: + case ActivityTypeEnum.wordFocusListening: + case ActivityTypeEnum.hiddenWordListening: + return (id) => id.type == ConstructTypeEnum.vocab; + } + } } diff --git a/lib/pangea/widgets/practice_activity/word_audio_button.dart b/lib/pangea/widgets/practice_activity/word_audio_button.dart index 03147ef0d..11a7a59d7 100644 --- a/lib/pangea/widgets/practice_activity/word_audio_button.dart +++ b/lib/pangea/widgets/practice_activity/word_audio_button.dart @@ -23,7 +23,6 @@ class WordAudioButtonState extends State { @override Widget build(BuildContext context) { - debugPrint('build WordAudioButton'); return IconButton( icon: const Icon(Icons.play_arrow_outlined), isSelected: _isPlaying,