chore: add morphExampleInfo to activity model
This commit is contained in:
parent
10197ae209
commit
d1c6effb2a
3 changed files with 55 additions and 0 deletions
|
|
@ -12,6 +12,42 @@ class MorphExampleInfo {
|
|||
const MorphExampleInfo({
|
||||
required this.exampleMessage,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final segments = <Map<String, dynamic>>[];
|
||||
|
||||
for (final span in exampleMessage) {
|
||||
if (span is TextSpan) {
|
||||
segments.add({
|
||||
'text': span.text ?? '',
|
||||
'isBold': span.style?.fontWeight == FontWeight.bold,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
'segments': segments,
|
||||
};
|
||||
}
|
||||
|
||||
factory MorphExampleInfo.fromJson(Map<String, dynamic> json) {
|
||||
final segments = json['segments'] as List<dynamic>? ?? [];
|
||||
|
||||
final spans = <InlineSpan>[];
|
||||
for (final segment in segments) {
|
||||
final text = segment['text'] as String? ?? '';
|
||||
final isBold = segment['isBold'] as bool? ?? false;
|
||||
|
||||
spans.add(
|
||||
TextSpan(
|
||||
text: text,
|
||||
style: isBold ? const TextStyle(fontWeight: FontWeight.bold) : null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return MorphExampleInfo(exampleMessage: spans);
|
||||
}
|
||||
}
|
||||
|
||||
class AnalyticsActivityTarget {
|
||||
|
|
@ -28,6 +64,7 @@ class AnalyticsActivityTarget {
|
|||
Map<String, dynamic> toJson() => {
|
||||
'target': target.toJson(),
|
||||
'grammarErrorInfo': grammarErrorInfo?.toJson(),
|
||||
'morphExampleInfo': morphExampleInfo?.toJson(),
|
||||
};
|
||||
|
||||
factory AnalyticsActivityTarget.fromJson(Map<String, dynamic> json) =>
|
||||
|
|
@ -36,6 +73,9 @@ class AnalyticsActivityTarget {
|
|||
grammarErrorInfo: json['grammarErrorInfo'] != null
|
||||
? GrammarErrorRequestInfo.fromJson(json['grammarErrorInfo'])
|
||||
: null,
|
||||
morphExampleInfo: json['morphExampleInfo'] != null
|
||||
? MorphExampleInfo.fromJson(json['morphExampleInfo'])
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:fluffychat/pangea/analytics_practice/analytics_practice_session_model.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
|
||||
import 'package:fluffychat/pangea/morphs/default_morph_mapping.dart';
|
||||
import 'package:fluffychat/pangea/morphs/morph_models.dart';
|
||||
|
|
@ -58,6 +59,8 @@ class MorphCategoryActivityGenerator {
|
|||
choices: choices.toSet(),
|
||||
answers: {morphTag},
|
||||
),
|
||||
morphExampleInfo:
|
||||
req.morphExampleInfo ?? const MorphExampleInfo(exampleMessage: []),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import 'package:sentry_flutter/sentry_flutter.dart';
|
|||
import 'package:fluffychat/pangea/analytics_misc/construct_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/analytics_misc/construct_use_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/analytics_misc/constructs_model.dart';
|
||||
import 'package:fluffychat/pangea/analytics_practice/analytics_practice_session_model.dart';
|
||||
import 'package:fluffychat/pangea/events/models/pangea_token_model.dart';
|
||||
import 'package:fluffychat/pangea/morphs/morph_features_enum.dart';
|
||||
import 'package:fluffychat/pangea/practice_activities/activity_type_enum.dart';
|
||||
|
|
@ -111,6 +112,9 @@ sealed class PracticeActivityModel {
|
|||
tokens: tokens,
|
||||
morphFeature: morph!,
|
||||
multipleChoiceContent: multipleChoiceContent!,
|
||||
morphExampleInfo: json['morph_example_info'] != null
|
||||
? MorphExampleInfo.fromJson(json['morph_example_info'])
|
||||
: const MorphExampleInfo(exampleMessage: []),
|
||||
);
|
||||
case ActivityTypeEnum.lemmaAudio:
|
||||
assert(
|
||||
|
|
@ -307,6 +311,7 @@ class MorphCategoryPracticeActivityModel extends MorphPracticeActivityModel {
|
|||
required super.langCode,
|
||||
required super.morphFeature,
|
||||
required super.multipleChoiceContent,
|
||||
required this.morphExampleInfo,
|
||||
});
|
||||
|
||||
@override
|
||||
|
|
@ -330,6 +335,13 @@ class MorphCategoryPracticeActivityModel extends MorphPracticeActivityModel {
|
|||
xp: useType.pointValue,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
final json = super.toJson();
|
||||
json['morph_example_info'] = morphExampleInfo.toJson();
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
class MorphMatchPracticeActivityModel extends MorphPracticeActivityModel {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue