forked from krille-chan/fluffychat
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmorph_analytics_view.dart
263 lines (244 loc) · 8.66 KB
/
morph_analytics_view.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
import 'package:flutter/material.dart';
import 'package:collection/collection.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pangea/analytics_misc/construct_identifier.dart';
import 'package:fluffychat/pangea/analytics_misc/construct_level_enum.dart';
import 'package:fluffychat/pangea/analytics_misc/construct_type_enum.dart';
import 'package:fluffychat/pangea/analytics_misc/construct_use_model.dart';
import 'package:fluffychat/pangea/morphs/default_morph_mapping.dart';
import 'package:fluffychat/pangea/morphs/get_grammar_copy.dart';
import 'package:fluffychat/pangea/morphs/morph_icon.dart';
import 'package:fluffychat/pangea/user/client_extension.dart';
import 'package:fluffychat/widgets/matrix.dart';
import '../morphs/morph_repo.dart';
class MorphAnalyticsView extends StatelessWidget {
final void Function(ConstructIdentifier) onConstructZoom;
const MorphAnalyticsView({
required this.onConstructZoom,
super.key,
});
@override
Widget build(BuildContext context) => Padding(
padding: const EdgeInsets.symmetric(vertical: 20),
child: FutureBuilder(
future: MorphsRepo.get(),
builder: (context, snapshot) {
final morphs = snapshot.data ?? defaultMorphMapping;
morphs.displayFeatures.sort(
(a, b) => morphFeatureSortOrder
.indexOf(a.feature)
.compareTo(morphFeatureSortOrder.indexOf(b.feature)),
);
return snapshot.connectionState == ConnectionState.done
? ListView.builder(
key: const PageStorageKey<String>('morph-analytics'),
itemCount: morphs.displayFeatures.length,
itemBuilder: (context, index) => morphs
.displayFeatures[index].displayTags.isNotEmpty
? MorphFeatureBox(
morphFeature: morphs.displayFeatures[index].feature,
allTags: snapshot.data
?.getDisplayTags(
morphs.displayFeatures[index].feature,
)
.map((tag) => tag.toLowerCase())
.toSet() ??
{},
onConstructZoom: onConstructZoom,
)
: const SizedBox.shrink(),
)
: const Center(
child: CircularProgressIndicator(),
);
},
),
);
}
class MorphFeatureBox extends StatelessWidget {
final String morphFeature;
final Set<String> allTags;
final void Function(ConstructIdentifier) onConstructZoom;
const MorphFeatureBox({
super.key,
required this.morphFeature,
required this.allTags,
required this.onConstructZoom,
});
String _categoryCopy(
String category,
BuildContext context,
) {
if (category.toLowerCase() == "other") {
return L10n.of(context).other;
}
return ConstructTypeEnum.morph.getDisplayCopy(
category,
context,
) ??
category;
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Container(
padding: const EdgeInsets.all(16.0),
margin: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16.0),
border: Border.all(
color: Theme.of(context).brightness == Brightness.dark
? AppConfig.primaryColorLight
: AppConfig.primaryColor,
width: 2,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 16.0,
children: [
SizedBox(
height: 30.0,
width: 30.0,
child: MorphIcon(morphFeature: morphFeature, morphTag: null),
),
Text(
_categoryCopy(morphFeature, context),
style: theme.textTheme.bodyLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
],
),
const SizedBox(height: 16.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
child: Wrap(
alignment: WrapAlignment.center,
spacing: 16.0,
runSpacing: 16.0,
children: allTags
.map(
(morphTag) {
final id = ConstructIdentifier(
lemma: morphTag,
type: ConstructTypeEnum.morph,
category: morphFeature,
);
final analytics = MatrixState.pangeaController
.getAnalytics.constructListModel
.getConstructUses(id) ??
ConstructUses(
lemma: morphTag,
constructType: ConstructTypeEnum.morph,
category: morphFeature,
uses: [],
);
return MorphTagChip(
morphFeature: morphFeature,
morphTag: morphTag,
constructAnalytics: analytics,
onTap: analytics.points > 0
? () => onConstructZoom(id)
: null,
);
},
)
.sortedBy<num>(
(chip) => chip.constructAnalytics.points,
)
.reversed
.toList(),
),
),
],
),
],
),
);
}
}
class MorphTagChip extends StatelessWidget {
final String morphFeature;
final String morphTag;
final ConstructUses constructAnalytics;
final VoidCallback? onTap;
const MorphTagChip({
super.key,
required this.morphFeature,
required this.morphTag,
required this.constructAnalytics,
this.onTap,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return InkWell(
borderRadius: BorderRadius.circular(32.0),
onTap: onTap,
child: Opacity(
opacity: constructAnalytics.points > 0 ? 1.0 : 0.3,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(32.0),
gradient: constructAnalytics.points > 0
? LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: <Color>[
Colors.transparent,
constructAnalytics.lemmaCategory.color,
],
)
: null,
color: constructAnalytics.points > 0 ? null : theme.disabledColor,
),
padding: const EdgeInsets.symmetric(
vertical: 4.0,
horizontal: 8.0,
),
child: Row(
mainAxisSize: MainAxisSize.min,
spacing: 8.0,
children: [
SizedBox(
width: 28.0,
height: 28.0,
child: constructAnalytics.points > 0 ||
Matrix.of(context).client.isSupportAccount
? MorphIcon(
morphFeature: morphFeature,
morphTag: morphTag,
)
: const Icon(
Icons.lock,
color: Colors.white,
),
),
Text(
getGrammarCopy(
category: morphFeature,
lemma: morphTag,
context: context,
) ??
morphTag,
style: TextStyle(
fontWeight: FontWeight.bold,
color: theme.brightness == Brightness.dark
? Colors.white
: Colors.black,
),
),
],
),
),
),
);
}
}