This commit is contained in:
commit
0a02620564
13 files changed
+27
-128
No files matched your search
@@ -241,11 +241,11 @@ class Drama {
|
||||
}
|
||||
|
||||
String localizedTitle(String languageCode) {
|
||||
return localizedRequiredText(languageCode, title, titleLocales);
|
||||
return localizedText(languageCode, title, titleLocales);
|
||||
}
|
||||
|
||||
String localizedSynopsis(String languageCode) {
|
||||
return localizedRequiredText(languageCode, synopsis, synopsisLocales);
|
||||
return localizedText(languageCode, synopsis, synopsisLocales);
|
||||
}
|
||||
|
||||
String localizedTag(String languageCode) {
|
||||
|
||||
@@ -18,16 +18,3 @@ String localizedText(
|
||||
if (chinese.isNotEmpty) return chinese;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/// 按当前语言取必须本地化的文案;印尼语缺失时不回退中文。
|
||||
String localizedRequiredText(
|
||||
String languageCode,
|
||||
String fallback,
|
||||
Map<String, String> locales,
|
||||
) {
|
||||
final primaryCode = languageCode.split(RegExp(r'[_-]')).first;
|
||||
final selected = locales[languageCode] ?? locales[primaryCode] ?? '';
|
||||
if (selected.trim().isNotEmpty) return selected;
|
||||
if (primaryCode == 'id') return '';
|
||||
return localizedText(primaryCode, fallback, locales);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import '../data/models/drama.dart';
|
||||
|
||||
const String _indonesianLanguageCode = 'id';
|
||||
|
||||
/// 判断短剧是否满足当前界面语言的基础文案完整度。
|
||||
bool isDramaCompleteForLocale(Drama drama, String languageCode) {
|
||||
final primaryCode = languageCode.split(RegExp(r'[_-]')).first;
|
||||
if (primaryCode != _indonesianLanguageCode) return true;
|
||||
return drama.localizedTitle(primaryCode).trim().isNotEmpty &&
|
||||
drama.localizedSynopsis(primaryCode).trim().isNotEmpty;
|
||||
}
|
||||
|
||||
/// 过滤不满足首发语言文案完整度的短剧,保持原顺序。
|
||||
List<Drama> visibleDramasForLocale(
|
||||
Iterable<Drama> dramas,
|
||||
String languageCode,
|
||||
) => dramas
|
||||
.where((drama) => isDramaCompleteForLocale(drama, languageCode))
|
||||
.toList(growable: false);
|
||||
@@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/data/models/drama.dart';
|
||||
import '../../../core/formatting/error_text.dart';
|
||||
import '../../../core/formatting/content_locale_guard.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/widgets/empty_state.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
@@ -34,18 +33,10 @@ class DiscoverSearchResults extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final visibleResults = visibleDramasForLocale(
|
||||
results,
|
||||
Localizations.localeOf(context).languageCode,
|
||||
);
|
||||
if (!loading && error == null && visibleResults.isNotEmpty) {
|
||||
if (!loading && error == null && results.isNotEmpty) {
|
||||
return SliverPadding(
|
||||
padding: _topPadding,
|
||||
sliver: SliverDramaGrid(
|
||||
l10n: l10n,
|
||||
dramas: visibleResults,
|
||||
onOpen: onOpen,
|
||||
),
|
||||
sliver: SliverDramaGrid(l10n: l10n, dramas: results, onOpen: onOpen),
|
||||
);
|
||||
}
|
||||
return SliverPadding(
|
||||
|
||||
@@ -7,7 +7,6 @@ import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../core/data/models/drama.dart';
|
||||
import '../../../core/data/services/category_controller.dart';
|
||||
import '../../../core/formatting/content_locale_guard.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/widgets/app_pull_to_refresh.dart';
|
||||
import '../../../core/widgets/drama_grid_skeleton.dart';
|
||||
@@ -78,10 +77,7 @@ class _HomeCategoryDramasState extends State<HomeCategoryDramas> {
|
||||
final controller = context.watch<CategoryController>();
|
||||
final categoryId = widget.lockedCategoryId ?? '';
|
||||
final slot = categoryId.isEmpty ? null : controller.slotOf(categoryId);
|
||||
final dramas = visibleDramasForLocale(
|
||||
slot?.dramas ?? const <Drama>[],
|
||||
Localizations.localeOf(context).languageCode,
|
||||
);
|
||||
final dramas = slot?.dramas ?? const <Drama>[];
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
|
||||
@@ -12,7 +12,6 @@ import '../../../core/data/services/catalog_controller.dart';
|
||||
import '../../../core/data/services/category_controller.dart';
|
||||
import '../../../core/data/services/home_feed_controller.dart';
|
||||
import '../../../core/data/services/wallet_controller.dart';
|
||||
import '../../../core/formatting/content_locale_guard.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/widgets/app_pull_to_refresh.dart';
|
||||
@@ -195,10 +194,7 @@ class _HomeFeedGridState extends State<HomeFeedGrid> {
|
||||
mainAxisSpacing: AppDimens.homeGridRowGap,
|
||||
);
|
||||
}
|
||||
final dramas = _dramasFor(
|
||||
category,
|
||||
Localizations.localeOf(context).languageCode,
|
||||
);
|
||||
final dramas = _dramasFor(category);
|
||||
if (widget.feedController.loadingFirstPage && dramas.isEmpty) {
|
||||
return const DramaGridSkeleton(
|
||||
key: Key('home-grid-skeleton'),
|
||||
@@ -328,14 +324,8 @@ class _HomeFeedGridState extends State<HomeFeedGrid> {
|
||||
];
|
||||
}
|
||||
|
||||
List<Drama> _dramasFor(
|
||||
HomeGridCategoryShortcut category,
|
||||
String languageCode,
|
||||
) {
|
||||
final dramas = visibleDramasForLocale(
|
||||
widget.feedController.dramas,
|
||||
languageCode,
|
||||
);
|
||||
List<Drama> _dramasFor(HomeGridCategoryShortcut category) {
|
||||
final dramas = widget.feedController.dramas;
|
||||
final categoryName = category.categoryName.toLowerCase();
|
||||
if (categoryName.isEmpty) return dramas;
|
||||
final matched = dramas
|
||||
|
||||
@@ -9,7 +9,6 @@ import '../../core/data/models/drama.dart';
|
||||
import '../../core/data/models/home_feed.dart';
|
||||
import '../../core/data/remote/catalog_api.dart';
|
||||
import '../../core/data/services/category_controller.dart';
|
||||
import '../../core/formatting/content_locale_guard.dart';
|
||||
import '../../core/theme/app_colors.dart';
|
||||
import '../../core/widgets/app_pull_to_refresh.dart';
|
||||
import '../../core/widgets/empty_state.dart';
|
||||
@@ -285,10 +284,7 @@ class _ChannelFeedState extends State<_ChannelFeed>
|
||||
super.build(context);
|
||||
final categories = context.watch<CategoryController>();
|
||||
final slot = categories.slotOf(widget.categoryId);
|
||||
final dramas = visibleDramasForLocale(
|
||||
slot.dramas,
|
||||
Localizations.localeOf(context).languageCode,
|
||||
);
|
||||
final dramas = slot.dramas;
|
||||
final showCarousel = widget.isFeatured && widget.banners.isNotEmpty;
|
||||
final bottomInset = MediaQuery.of(context).padding.bottom;
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import '../../core/data/services/download_controller.dart';
|
||||
import '../../core/data/services/home_feed_controller.dart';
|
||||
import '../../core/data/services/playlist_controller.dart';
|
||||
import '../../core/data/services/wallet_controller.dart';
|
||||
import '../../core/formatting/content_locale_guard.dart';
|
||||
import '../../core/theme/app_colors.dart';
|
||||
import '../../core/widgets/empty_state.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
@@ -299,10 +298,7 @@ class _RecommendPageState extends State<RecommendPage>
|
||||
|
||||
Widget _recommendFeed(BuildContext context) {
|
||||
final feed = widget.feedController;
|
||||
final dramas = visibleDramasForLocale(
|
||||
widget.feedController.dramas,
|
||||
Localizations.localeOf(context).languageCode,
|
||||
);
|
||||
final dramas = widget.feedController.dramas;
|
||||
if (dramas.isNotEmpty) {
|
||||
return PlayerPage(
|
||||
key: const Key('recommend-feed-player'),
|
||||
|
||||
@@ -10,7 +10,6 @@ import '../../../core/data/models/drama.dart';
|
||||
import '../../../core/data/remote/catalog_api.dart';
|
||||
import '../../../core/data/services/all_dramas_controller.dart';
|
||||
import '../../../core/data/services/home_feed_controller.dart';
|
||||
import '../../../core/formatting/content_locale_guard.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/widgets/app_pull_to_refresh.dart';
|
||||
@@ -108,10 +107,7 @@ class _AllDramasFilterGridState extends State<AllDramasFilterGrid> {
|
||||
}
|
||||
|
||||
Widget _dramaList(AppLocalizations l10n, double itemExtent) {
|
||||
final dramas = visibleDramasForLocale(
|
||||
_dramas,
|
||||
Localizations.localeOf(context).languageCode,
|
||||
);
|
||||
final dramas = _dramas;
|
||||
return NotificationListener<ScrollNotification>(
|
||||
onNotification: _onScroll,
|
||||
child: AppPullToRefresh(
|
||||
|
||||
@@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/data/models/drama.dart';
|
||||
import '../../../core/data/models/playlist_detail.dart';
|
||||
import '../../../core/formatting/content_locale_guard.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/widgets/app_pull_to_refresh.dart';
|
||||
@@ -158,10 +157,7 @@ class _PlaylistDetailPageState extends State<PlaylistDetailPage> {
|
||||
}
|
||||
|
||||
Widget _body(double itemExtent) {
|
||||
final visibleDramas = visibleDramasForLocale(
|
||||
_dramas,
|
||||
Localizations.localeOf(context).languageCode,
|
||||
);
|
||||
final visibleDramas = _dramas;
|
||||
return CustomScrollView(
|
||||
key: const Key('playlist-detail-scroll'),
|
||||
physics: AppPullToRefresh.physics,
|
||||
|
||||
@@ -8,7 +8,6 @@ import '../../../core/data/models/playlist_detail.dart';
|
||||
import '../../../core/data/services/category_controller.dart';
|
||||
import '../../../core/data/services/home_feed_controller.dart';
|
||||
import '../../../core/data/services/playlist_controller.dart';
|
||||
import '../../../core/formatting/content_locale_guard.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/widgets/app_pull_to_refresh.dart';
|
||||
@@ -44,8 +43,7 @@ class RecommendSectionsView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final languageCode = Localizations.localeOf(context).languageCode;
|
||||
final source = visibleDramasForLocale(feedController.dramas, languageCode);
|
||||
final source = feedController.dramas;
|
||||
final remote = playlists;
|
||||
return AppPullToRefresh(
|
||||
key: const Key('recommend-sections-refresh'),
|
||||
@@ -165,10 +163,7 @@ class RecommendSectionsView extends StatelessWidget {
|
||||
subtitle: playlist.localizedDescription(
|
||||
Localizations.localeOf(context).languageCode,
|
||||
),
|
||||
dramas: visibleDramasForLocale(
|
||||
playlist.dramas,
|
||||
Localizations.localeOf(context).languageCode,
|
||||
).take(_sectionPreviewCount).toList(),
|
||||
dramas: playlist.dramas.take(_sectionPreviewCount).toList(),
|
||||
onMore: () => onOpenPlaylist?.call(playlist),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -62,10 +62,12 @@ void main() {
|
||||
});
|
||||
|
||||
test('should_pick_address_by_environment_switch', () {
|
||||
// 仓库里的开关默认指向开发环境。
|
||||
expect(AppConfig.useDevConfig, isTrue);
|
||||
expect(AppConfig.baseUrl, DevConfig.baseUrl);
|
||||
expect(AppConfig.apiBaseUrl, DevConfig.baseUrl);
|
||||
// 跟随开关:开发分支为 true(开发地址),发版分支为 false(生产地址)。
|
||||
final expected = AppConfig.useDevConfig
|
||||
? DevConfig.baseUrl
|
||||
: ProdConfig.baseUrl;
|
||||
expect(AppConfig.baseUrl, expected);
|
||||
expect(AppConfig.apiBaseUrl, expected);
|
||||
expect(Uri.parse(AppConfig.baseUrl).port, 8081);
|
||||
});
|
||||
|
||||
@@ -87,7 +89,10 @@ void main() {
|
||||
AppConfig.applyRuntimeBaseUrl('http://runtime.test:8081');
|
||||
|
||||
expect(AppConfig.apiBaseUrl, 'http://runtime.test:8081');
|
||||
expect(AppConfig.baseUrl, DevConfig.baseUrl);
|
||||
expect(
|
||||
AppConfig.baseUrl,
|
||||
AppConfig.useDevConfig ? DevConfig.baseUrl : ProdConfig.baseUrl,
|
||||
);
|
||||
});
|
||||
|
||||
test('should_append_host_to_relative_media_paths', () {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/models/drama.dart';
|
||||
import 'package:fruitshorts/core/formatting/localized_content.dart';
|
||||
import 'package:fruitshorts/core/formatting/content_locale_guard.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations_en.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations_id.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations_zh.dart';
|
||||
@@ -77,7 +76,7 @@ void main() {
|
||||
expect(localizedDramaSynopsis(zh, custom), 'Custom synopsis');
|
||||
});
|
||||
|
||||
test('should_not_fall_back_to_chinese_when_indonesian_copy_is_missing', () {
|
||||
test('should_fall_back_to_chinese_when_indonesian_copy_is_missing', () {
|
||||
const drama = Drama(
|
||||
id: 'missing-id-copy',
|
||||
title: '古城',
|
||||
@@ -87,35 +86,8 @@ void main() {
|
||||
posterUrl: '/files/poster.png',
|
||||
);
|
||||
|
||||
expect(drama.localizedTitle('id'), isEmpty);
|
||||
expect(drama.localizedSynopsis('id'), isEmpty);
|
||||
});
|
||||
|
||||
test('should_filter_incomplete_indonesian_content_from_visible_list', () {
|
||||
const complete = Drama(
|
||||
id: 'complete-id-copy',
|
||||
title: 'Kota Lama',
|
||||
synopsis: 'Kisah dari kota lama.',
|
||||
titleLocales: {'id': 'Kota Lama'},
|
||||
synopsisLocales: {'id': 'Kisah dari kota lama.'},
|
||||
posterUrl: '/files/complete.png',
|
||||
);
|
||||
const incomplete = Drama(
|
||||
id: 'incomplete-id-copy',
|
||||
title: '古城',
|
||||
synopsis: '中文简介',
|
||||
titleLocales: {'zh': '古城'},
|
||||
synopsisLocales: {'zh': '中文简介'},
|
||||
posterUrl: '/files/incomplete.png',
|
||||
);
|
||||
|
||||
expect(isDramaCompleteForLocale(complete, 'id'), isTrue);
|
||||
expect(isDramaCompleteForLocale(incomplete, 'id'), isFalse);
|
||||
expect(visibleDramasForLocale([complete, incomplete], 'id'), [complete]);
|
||||
expect(visibleDramasForLocale([complete, incomplete], 'en'), [
|
||||
complete,
|
||||
incomplete,
|
||||
]);
|
||||
expect(drama.localizedTitle('id'), '古城');
|
||||
expect(drama.localizedSynopsis('id'), '中文简介');
|
||||
});
|
||||
|
||||
test('should_ignore_raw_catalog_text_when_drama_is_seeded', () {
|
||||
|
||||
Reference in new issue
Block a user