Gitea CI / Check code and tests (pull_request) Failing after 8s
Gitea CI / Build Android APK (pull_request) Skipped
Gitea CI / Build Windows x64 app (pull_request) Skipped
Gitea CI / Audit and package Windows x64 (pull_request) Skipped
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
Gitea CI / Gitea CI passed (pull_request) Failing after 1s
134 lines
4.1 KiB
Dart
134 lines
4.1 KiB
Dart
import 'dart:math' as math;
|
|
|
|
import 'package:cutdex_core/project.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../integrations/runtime/media_presentations.dart';
|
|
|
|
import 'package:cutdex_ui/icons.dart';
|
|
import 'package:cutdex_ui/theme.dart';
|
|
|
|
import 'audio_asset_tile.dart';
|
|
import 'media_asset_cover.dart';
|
|
|
|
/// Compact full-width preview used by the media library's list layout.
|
|
class MediaAssetStrip extends StatelessWidget {
|
|
const MediaAssetStrip({super.key, required this.asset});
|
|
static const height = 46.0;
|
|
final AssetDocument asset;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => SizedBox(
|
|
height: height,
|
|
child: LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
if (asset.metadata['kind'] == 'audio') {
|
|
return AudioAssetTile(
|
|
asset: asset,
|
|
showName: false,
|
|
aspectRatio: constraints.maxWidth / height,
|
|
);
|
|
}
|
|
|
|
return _VisualAssetStrip(asset: asset, width: constraints.maxWidth);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
class _VisualAssetStrip extends ConsumerWidget {
|
|
const _VisualAssetStrip({required this.asset, required this.width});
|
|
final AssetDocument asset;
|
|
final double width;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final video = asset.metadata['kind'] == 'video';
|
|
final duration = video
|
|
? ref.watch(mediaDurationProvider(asset)).value
|
|
: null;
|
|
final count = (width / (MediaAssetStrip.height * 16 / 9)).ceil().clamp(
|
|
1,
|
|
16,
|
|
);
|
|
return ColoredBox(
|
|
color: AppSurfaces.of(context).previewBackground,
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
for (var index = 0; index < count; index++)
|
|
Expanded(
|
|
child: MediaAssetCover(
|
|
asset: asset,
|
|
fit: BoxFit.cover,
|
|
timeMilliseconds: video && duration != null
|
|
? (duration * 1000 * index / count).floor()
|
|
: 0,
|
|
fallback: const Center(child: Icon(AppIcons.video)),
|
|
errorFallback: const Center(
|
|
child: Icon(AppIcons.imageUnavailable),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class MediaAssetDuration extends ConsumerWidget {
|
|
const MediaAssetDuration({super.key, required this.asset, this.badge = true});
|
|
final AssetDocument asset;
|
|
final bool badge;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
if (!const {'audio', 'video'}.contains(asset.metadata['kind'])) {
|
|
return const SizedBox.shrink();
|
|
}
|
|
final duration = ref.watch(mediaDurationProvider(asset)).value;
|
|
if (duration == null) return const SizedBox.shrink();
|
|
final seconds = math.max(0, duration.floor());
|
|
final hours = seconds ~/ 3600;
|
|
final minutes = hours > 0 ? (seconds ~/ 60) % 60 : seconds ~/ 60;
|
|
final text =
|
|
'${hours > 0 ? '$hours:' : ''}'
|
|
'${minutes.toString().padLeft(2, '0')}:'
|
|
'${(seconds % 60).toString().padLeft(2, '0')}';
|
|
if (!badge) {
|
|
return Text(
|
|
text,
|
|
key: ValueKey('media-duration-${asset.id}'),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
fontSize: 12,
|
|
height: 16 / 12,
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
fontFeatures: const [FontFeature.tabularFigures()],
|
|
),
|
|
);
|
|
}
|
|
return DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
color: Colors.black.withValues(alpha: .55),
|
|
borderRadius: BorderRadius.circular(4),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 1),
|
|
child: Text(
|
|
text,
|
|
key: ValueKey('media-duration-${asset.id}'),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: Colors.white,
|
|
fontFeatures: const [FontFeature.tabularFigures()],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|