feat(home): 首页改为三列探索网格
This commit is contained in:
1 parent
6dea9d479e
commit
dd96792e33
29 files changed
+1912
-256
No files matched your search
@@ -0,0 +1,49 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import '../../../core/data/models/drama.dart';
|
||||
|
||||
const int homeNewReleaseDays = 7;
|
||||
const int homeHotViewThreshold = 100000;
|
||||
const int _snowflakeEpochMillis = 1288834974657;
|
||||
const int _snowflakeTimestampShift = 22;
|
||||
|
||||
const Map<String, List<String>> _tagAliases = {
|
||||
'uplifting': ['爽剧', '逆袭', '复仇', 'revenge', 'balas'],
|
||||
'sweet': ['甜宠', '甜', 'sweet', 'romantis'],
|
||||
'faceSlap': ['打脸', '虐渣', 'comeuppance', 'comeback'],
|
||||
'angst': ['虐恋', '虐心', 'angst', 'heartbreak'],
|
||||
};
|
||||
|
||||
DateTime? publishedAtForDrama(Drama drama) {
|
||||
if (drama.createdAt != null) return drama.createdAt;
|
||||
final snowflake = BigInt.tryParse(drama.id);
|
||||
if (snowflake == null) return null;
|
||||
final timestamp =
|
||||
(snowflake >> _snowflakeTimestampShift).toInt() + _snowflakeEpochMillis;
|
||||
final publishedAt = DateTime.fromMillisecondsSinceEpoch(timestamp);
|
||||
return publishedAt.year >= 2015 ? publishedAt : null;
|
||||
}
|
||||
|
||||
bool isNewDrama(Drama drama, {DateTime? now}) {
|
||||
final publishedAt = publishedAtForDrama(drama);
|
||||
if (publishedAt == null) return false;
|
||||
final age = (now ?? DateTime.now()).difference(publishedAt);
|
||||
return !age.isNegative && age <= const Duration(days: homeNewReleaseDays);
|
||||
}
|
||||
|
||||
bool isHotDrama(Drama drama) {
|
||||
return drama.isHot || drama.viewCount >= homeHotViewThreshold;
|
||||
}
|
||||
|
||||
bool matchesHomeTag(Drama drama, String tagId) {
|
||||
if (tagId == 'hot') return isHotDrama(drama);
|
||||
return tagMatchesText(tagId, drama.genre) ||
|
||||
tagMatchesText(tagId, drama.category);
|
||||
}
|
||||
|
||||
bool tagMatchesText(String tagId, String text) {
|
||||
if (tagId == 'hot') return false;
|
||||
final normalized = text.toLowerCase();
|
||||
final aliases = _tagAliases[tagId] ?? const [];
|
||||
return aliases.any(normalized.contains);
|
||||
}
|
||||
Reference in new issue
Block a user