Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ android/build/reports/problems/
**/macos/Pods/
**/ios/Podfile.lock
**/macos/Podfile.lock

# Local documentation
changelog.md
Binary file added android/app/build/v1.2.6/BIT2137.tmp
Binary file not shown.
6 changes: 6 additions & 0 deletions lib/bean/card/bangumi_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ class BangumiCardV extends StatelessWidget {
required this.bangumiItem,
this.canTap = true,
this.enableHero = true,
this.onLongPress,
this.onSecondaryTap,
});

final BangumiItem bangumiItem;
final bool canTap;
final bool enableHero;
final VoidCallback? onLongPress;
final VoidCallback? onSecondaryTap;

@override
Widget build(BuildContext context) {
Expand All @@ -25,6 +29,8 @@ class BangumiCardV extends StatelessWidget {
clipBehavior: Clip.antiAlias,
margin: EdgeInsets.zero,
child: GestureDetector(
onLongPress: onLongPress,
onSecondaryTap: onSecondaryTap,
child: InkWell(
onTap: () {
if (!canTap) {
Expand Down
35 changes: 27 additions & 8 deletions lib/bean/card/bangumi_timeline_card.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:kazumi/modules/bangumi/bangumi_item.dart';
import 'package:kazumi/bean/card/network_img_layer.dart';
import 'package:kazumi/utils/device.dart';
import 'package:kazumi/bean/card/network_img_layer.dart';

/// 时间线番剧卡片
class BangumiTimelineCard extends StatelessWidget {
Expand All @@ -11,22 +11,28 @@ class BangumiTimelineCard extends StatelessWidget {
required this.bangumiItem,
required this.showRating,
this.onTap,
this.onLongPress,
this.onSecondaryTap,
this.cardHeight = 120,
this.cardWidth,
this.enableHero = true,
this.episodeCount,
});

final BangumiItem bangumiItem;
final bool showRating;
final VoidCallback? onTap;
final VoidCallback? onLongPress;
final VoidCallback? onSecondaryTap;
final bool enableHero;
final double cardHeight;
final double? cardWidth;
final int? episodeCount;

@override
Widget build(BuildContext context) {
final desktopLayout = isDesktop();
final tabletLayout = isTablet();
final desktop = isDesktop();
final tablet = isTablet();
final theme = Theme.of(context);
final textScaler = MediaQuery.textScalerOf(context);
final colorScheme = theme.colorScheme;
Expand All @@ -46,9 +52,12 @@ class BangumiTimelineCard extends StatelessWidget {
),
clipBehavior: Clip.antiAlias,
color: colorScheme.surfaceContainerLow,
child: InkWell(
borderRadius: BorderRadius.circular(borderRadius),
onTap: onTap ??
child: GestureDetector(
onLongPress: onLongPress,
onSecondaryTap: onSecondaryTap,
child: InkWell(
borderRadius: BorderRadius.circular(borderRadius),
onTap: onTap ??
() {
Modular.to.pushNamed('/info/', arguments: bangumiItem);
},
Expand All @@ -71,14 +80,14 @@ class BangumiTimelineCard extends StatelessWidget {
),
const SizedBox(width: 12),
Expanded(
child: buildInfo(
context, textScaler, desktopLayout, tabletLayout),
child: buildInfo(context, textScaler, desktop, tablet),
),
],
),
),
),
),
),
);
}

Expand Down Expand Up @@ -172,10 +181,20 @@ class BangumiTimelineCard extends StatelessWidget {
final rankText = showRating ? '#${bangumiItem.rank}' : '#***';
final votesText = showRating ? bangumiItem.votes.toString() : '***';

final hasEpisodeCount = episodeCount != null && episodeCount! > 0;

return Wrap(
spacing: 8,
runSpacing: 4,
children: [
if (hasEpisodeCount)
buildMetric(
context,
icon: Icons.play_circle_outline_rounded,
iconColor: colorScheme.tertiary,
label: '更新至第$episodeCount话',
textStyle: metricStyle,
),
if (showScore)
buildMetric(
context,
Expand Down
58 changes: 28 additions & 30 deletions lib/bean/widget/collect_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class CollectButton extends StatefulWidget {
this.color = Colors.white,
this.onOpen,
this.onClose,
this.menuController,
}) {
isExtended = false;
}
Expand All @@ -20,6 +21,7 @@ class CollectButton extends StatefulWidget {
this.color = Colors.white,
this.onOpen,
this.onClose,
this.menuController,
}) {
isExtended = true;
}
Expand All @@ -29,6 +31,7 @@ class CollectButton extends StatefulWidget {
late final bool isExtended;
final void Function()? onOpen;
final void Function()? onClose;
final MenuController? menuController;

@override
State<CollectButton> createState() => _CollectButtonState();
Expand All @@ -43,49 +46,42 @@ class _CollectButtonState extends State<CollectButton> {
late int collectType;
final CollectController collectController = Modular.get<CollectController>();

static const Map<int, String> _typeLabels = {
0: '未追',
1: '在看',
2: '想看',
3: '搁置',
4: '看过',
5: '抛弃',
};

static const Map<int, IconData> _typeIcons = {
0: Icons.favorite_border,
1: Icons.favorite,
2: Icons.star_rounded,
3: Icons.pending_actions,
4: Icons.done,
5: Icons.heart_broken,
};

@override
void initState() {
super.initState();
}

String getTypeStringByInt(int collectType) {
switch (collectType) {
case 1:
return "在看";
case 2:
return "想看";
case 3:
return "搁置";
case 4:
return "看过";
case 5:
return "抛弃";
default:
return "未追";
}
return _typeLabels[collectType] ?? '未追';
}

IconData getIconByInt(int collectType) {
switch (collectType) {
case 1:
return Icons.favorite;
case 2:
return Icons.star_rounded;
case 3:
return Icons.pending_actions;
case 4:
return Icons.done;
case 5:
return Icons.heart_broken;
default:
return Icons.favorite_border;
}
return _typeIcons[collectType] ?? Icons.favorite_border;
}

@override
Widget build(BuildContext context) {
collectType = collectController.getCollectType(widget.bangumiItem);
return MenuAnchor(
controller: widget.menuController,
consumeOutsideTap: true,
onClose: widget.onClose,
onOpen: widget.onOpen,
Expand Down Expand Up @@ -117,6 +113,9 @@ class _CollectButtonState extends State<CollectButton> {
getIconByInt(collectType),
color: widget.color,
),
constraints: const BoxConstraints(minWidth: 32, minHeight: 32),
iconSize: 18,
padding: EdgeInsets.zero,
);
}
},
Expand All @@ -125,8 +124,7 @@ class _CollectButtonState extends State<CollectButton> {
(int index) => MenuItemButton(
onPressed: () async {
if (index != collectType && mounted) {
await collectController.addCollect(widget.bangumiItem,
type: index);
await collectController.addCollect(widget.bangumiItem, type: index);
// 防止状态错误刷新
if (!mounted) {
return;
Expand Down
58 changes: 58 additions & 0 deletions lib/bean/widget/collectable_card_wrapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'package:flutter/material.dart';
import 'package:kazumi/modules/bangumi/bangumi_item.dart';
import 'package:kazumi/bean/widget/collect_button.dart';

class CollectableCardWrapper extends StatefulWidget {
const CollectableCardWrapper({
super.key,
required this.bangumiItem,
required this.child,
});

final BangumiItem bangumiItem;
final Widget child;

@override
State<CollectableCardWrapper> createState() => _CollectableCardWrapperState();
}

class _CollectableCardWrapperState extends State<CollectableCardWrapper> {
final MenuController menuController = MenuController();

void _openMenu() {
if (!menuController.isOpen) {
menuController.open();
}
}

@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
return Stack(
children: [
GestureDetector(
onLongPress: _openMenu,
onSecondaryTap: _openMenu,
child: widget.child,
),
Positioned(
right: 4,
bottom: 8,
child: Container(
width: 32,
height: 32,
decoration: BoxDecoration(
color: colorScheme.surfaceContainerHigh.withAlpha(180),
shape: BoxShape.circle,
),
child: CollectButton(
bangumiItem: widget.bangumiItem,
color: colorScheme.onSurface.withAlpha(180),
menuController: menuController,
),
),
),
],
);
}
}
14 changes: 14 additions & 0 deletions lib/modules/bangumi/bangumi_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class BangumiItem {
List<int> votesCount;
@HiveField(14, defaultValue: '')
String info;
@HiveField(15, defaultValue: '')
String airTime;
BangumiInterest? interest;

BangumiItem({
Expand All @@ -55,6 +57,7 @@ class BangumiItem {
required this.votes,
required this.votesCount,
required this.info,
this.airTime = '',
this.interest,
});

Expand Down Expand Up @@ -122,7 +125,17 @@ class BangumiItem {
return '';
}

String resolveAirTimeString(Map<String, dynamic> jsonData) {
final airtime = jsonData['airtime'];
if (airtime is Map && airtime['time'] != null) {
final s = airtime['time'].toString().trim();
return s.isNotEmpty ? s : '';
}
return '';
}

final String airDateStr = resolveAirDateString(json);
final String airTimeStr = resolveAirTimeString(json);

List list = json['tags'] ?? [];
List<String> bangumiAlias = parseBangumiAliases(json);
Expand Down Expand Up @@ -163,6 +176,7 @@ class BangumiItem {
votes: json['rating']['total'] ?? 0,
votesCount: voteList,
info: json['info'] ?? '',
airTime: airTimeStr,
interest: interest,
);
}
Expand Down
7 changes: 5 additions & 2 deletions lib/modules/bangumi/bangumi_item.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading