feat: replace XP level emojis with svgs (#1508)
This commit is contained in:
parent
14f5aa38b1
commit
c0fb41d2f9
9 changed files with 55 additions and 41 deletions
|
|
@ -164,6 +164,8 @@ abstract class AppConfig {
|
|||
"https://support.microsoft.com/en-us/topic/download-languages-and-voices-for-immersive-reader-read-mode-and-read-aloud-4c83a8d8-7486-42f7-8e46-2b0fdf753130";
|
||||
static String androidTTSDownloadInstructions =
|
||||
"https://support.google.com/accessibility/android/answer/6006983?hl=en";
|
||||
static String svgAssetsBaseURL =
|
||||
"https://pangea-chat-client-assets.s3.us-east-1.amazonaws.com";
|
||||
// Pangea#
|
||||
|
||||
static void loadFromJson(Map<String, dynamic> json) {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ class AnalyticsConstants {
|
|||
static const int morphUseMaxXP = 500;
|
||||
static const int xpForGreens = 30;
|
||||
static const int xpForFlower = 100;
|
||||
static const String seedSvgFileName = "Seed.svg";
|
||||
static const String leafSvgFileName = "Leaf.svg";
|
||||
static const String flowerSvgFileName = "Flower.svg";
|
||||
static const String emojiForSeed = "🫛";
|
||||
static const String emojiForGreen = "🌱";
|
||||
static const String emojiForFlower = "🌸";
|
||||
|
|
|
|||
|
|
@ -36,6 +36,17 @@ extension LemmaCategoryExtension on LemmaCategoryEnum {
|
|||
}
|
||||
}
|
||||
|
||||
String get svgURL {
|
||||
switch (this) {
|
||||
case LemmaCategoryEnum.seeds:
|
||||
return "${AppConfig.svgAssetsBaseURL}/${AnalyticsConstants.seedSvgFileName}";
|
||||
case LemmaCategoryEnum.greens:
|
||||
return "${AppConfig.svgAssetsBaseURL}/${AnalyticsConstants.leafSvgFileName}";
|
||||
case LemmaCategoryEnum.flowers:
|
||||
return "${AppConfig.svgAssetsBaseURL}/${AnalyticsConstants.flowerSvgFileName}";
|
||||
}
|
||||
}
|
||||
|
||||
String get emoji {
|
||||
switch (this) {
|
||||
case LemmaCategoryEnum.flowers:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import 'package:fluffychat/pangea/analytics/constants/analytics_constants.dart';
|
||||
import 'package:fluffychat/pangea/analytics/enums/construct_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/analytics/enums/construct_use_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/analytics/models/constructs_model.dart';
|
||||
|
|
@ -65,19 +64,4 @@ class ConstructUses {
|
|||
};
|
||||
return json;
|
||||
}
|
||||
|
||||
String get xpEmoji {
|
||||
if (points < AnalyticsConstants.xpForGreens) {
|
||||
// bean emoji
|
||||
return AnalyticsConstants.emojiForSeed;
|
||||
}
|
||||
|
||||
if (points < AnalyticsConstants.xpForFlower) {
|
||||
// sprout emoji
|
||||
return AnalyticsConstants.emojiForGreen;
|
||||
}
|
||||
|
||||
// flower emoji
|
||||
return AnalyticsConstants.emojiForFlower;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
|
||||
|
||||
String? getMorphSvgLink({
|
||||
|
|
@ -7,9 +8,6 @@ String? getMorphSvgLink({
|
|||
String? morphTag,
|
||||
required BuildContext context,
|
||||
}) {
|
||||
const baseURL =
|
||||
"https://pangea-chat-client-assets.s3.us-east-1.amazonaws.com";
|
||||
|
||||
if (morphTag == null) {
|
||||
final key = morphFeature.toLowerCase();
|
||||
String? filename;
|
||||
|
|
@ -51,7 +49,7 @@ String? getMorphSvgLink({
|
|||
return null;
|
||||
}
|
||||
|
||||
return "$baseURL/$filename";
|
||||
return "${AppConfig.svgAssetsBaseURL}/$filename";
|
||||
}
|
||||
|
||||
final key = "${morphFeature.toLowerCase()}${morphTag.toLowerCase()}";
|
||||
|
|
@ -180,5 +178,5 @@ String? getMorphSvgLink({
|
|||
return null;
|
||||
}
|
||||
|
||||
return "$baseURL/$filename";
|
||||
return "${AppConfig.svgAssetsBaseURL}/$filename";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import 'package:fluffychat/pangea/analytics/models/construct_list_model.dart';
|
|||
import 'package:fluffychat/pangea/analytics/models/construct_use_model.dart';
|
||||
import 'package:fluffychat/pangea/analytics/utils/get_grammar_copy.dart';
|
||||
import 'package:fluffychat/pangea/analytics/widgets/analytics_summary/vocab_analytics_popup/vocab_definition_popup.dart';
|
||||
import 'package:fluffychat/pangea/common/widgets/customized_svg.dart';
|
||||
import 'package:fluffychat/pangea/common/widgets/full_width_dialog.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
|
|
@ -216,11 +217,10 @@ class VocabAnalyticsPopupState extends State<VocabAnalyticsPopup> {
|
|||
? Colors.white
|
||||
: Colors.black,
|
||||
radius: 16,
|
||||
child: Text(
|
||||
" ${type.emoji}",
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
),
|
||||
child: CustomizedSvg(
|
||||
svgUrl: type.svgURL,
|
||||
colorReplacements: const {},
|
||||
errorIcon: Text(type.emoji),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import 'package:fluffychat/pangea/analytics/repo/lemma_info_repo.dart';
|
|||
import 'package:fluffychat/pangea/analytics/repo/lemma_info_request.dart';
|
||||
import 'package:fluffychat/pangea/analytics/repo/lemma_info_response.dart';
|
||||
import 'package:fluffychat/pangea/analytics/utils/get_grammar_copy.dart';
|
||||
import 'package:fluffychat/pangea/common/widgets/customized_svg.dart';
|
||||
import 'package:fluffychat/pangea/events/models/pangea_token_model.dart';
|
||||
import 'package:fluffychat/pangea/events/models/pangea_token_text_model.dart';
|
||||
import 'package:fluffychat/pangea/learning_settings/constants/language_constants.dart';
|
||||
|
|
@ -469,12 +470,30 @@ class VocabDefinitionPopupState extends State<VocabDefinitionPopup> {
|
|||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
Text(
|
||||
"${widget.type.emoji} ${widget.points} XP",
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
fontSize: 20,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 10),
|
||||
child: CustomizedSvg(
|
||||
svgUrl: widget.type.svgURL,
|
||||
colorReplacements: const {},
|
||||
errorIcon: Text(
|
||||
widget.type.emoji,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
"${widget.points} XP",
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
|
|
|
|||
|
|
@ -6,22 +6,20 @@ import 'package:http/http.dart' as http;
|
|||
|
||||
class CustomizedSvg extends StatelessWidget {
|
||||
final String svgUrl;
|
||||
final String cacheKey;
|
||||
final Map<String, String> colorReplacements;
|
||||
final IconData? errorIcon;
|
||||
final Widget errorIcon;
|
||||
|
||||
const CustomizedSvg({
|
||||
super.key,
|
||||
required this.svgUrl,
|
||||
required this.cacheKey,
|
||||
required this.colorReplacements,
|
||||
this.errorIcon = Icons.error_outline,
|
||||
this.errorIcon = const Icon(Icons.error_outline),
|
||||
});
|
||||
|
||||
static final GetStorage _svgStorage = GetStorage('svg_cache');
|
||||
|
||||
Future<String> _fetchSvg() async {
|
||||
final cachedSvg = _svgStorage.read(cacheKey);
|
||||
final cachedSvg = _svgStorage.read(svgUrl);
|
||||
if (cachedSvg != null) {
|
||||
return cachedSvg;
|
||||
}
|
||||
|
|
@ -32,7 +30,7 @@ class CustomizedSvg extends StatelessWidget {
|
|||
}
|
||||
|
||||
final String svgContent = response.body;
|
||||
await _svgStorage.write(cacheKey, svgContent);
|
||||
await _svgStorage.write(svgUrl, svgContent);
|
||||
|
||||
return svgContent;
|
||||
}
|
||||
|
|
@ -55,7 +53,7 @@ class CustomizedSvg extends StatelessWidget {
|
|||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const CircularProgressIndicator();
|
||||
} else if (snapshot.hasError) {
|
||||
return Icon(errorIcon);
|
||||
return errorIcon;
|
||||
} else if (snapshot.hasData) {
|
||||
return SvgPicture.string(snapshot.data!);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -36,14 +36,13 @@ class MorphologicalListItem extends StatelessWidget {
|
|||
icon: svgLink != null
|
||||
? CustomizedSvg(
|
||||
svgUrl: svgLink!,
|
||||
cacheKey: svgLink!,
|
||||
colorReplacements: {
|
||||
"white": Theme.of(context).cardColor.hexValue.toString(),
|
||||
"black": Theme.of(context).brightness == Brightness.dark
|
||||
? "white"
|
||||
: "black",
|
||||
},
|
||||
errorIcon: icon,
|
||||
errorIcon: Icon(icon),
|
||||
)
|
||||
: Icon(icon),
|
||||
isSelected: isSelected,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue