ente/lib/ui/viewer/file/file_icons_widget.dart

295 lines
7.4 KiB
Dart
Raw Normal View History

2022-07-02 17:30:04 +00:00
import 'package:flutter/material.dart';
2022-07-03 05:37:04 +00:00
import 'package:photos/ente_theme_data.dart';
import 'package:photos/models/collection.dart';
2022-07-02 17:30:04 +00:00
import 'package:photos/models/trash_file.dart';
import 'package:photos/theme/colors.dart';
import 'package:photos/ui/sharing/user_avator_widget.dart';
2022-07-02 17:30:04 +00:00
import 'package:photos/utils/date_time_util.dart';
class ThumbnailPlaceHolder extends StatelessWidget {
2022-10-19 09:02:33 +00:00
const ThumbnailPlaceHolder({Key? key}) : super(key: key);
2022-07-02 17:30:04 +00:00
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.center,
2022-07-03 05:37:04 +00:00
color: Theme.of(context).colorScheme.galleryThumbBackgroundColor,
2022-07-02 17:30:04 +00:00
);
}
}
class UnSyncedIcon extends StatelessWidget {
2022-10-19 09:02:33 +00:00
const UnSyncedIcon({Key? key}) : super(key: key);
2022-07-02 17:30:04 +00:00
@override
Widget build(BuildContext context) {
2022-12-20 07:25:50 +00:00
return const _BottomLeftOverlayIcon(Icons.cloud_off_outlined);
2022-12-20 06:34:02 +00:00
}
}
class DeviceIcon extends StatelessWidget {
const DeviceIcon({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const _BottomLeftOverlayIcon(
Icons.mobile_friendly_rounded,
baseSize: 18,
color: Color.fromRGBO(1, 222, 77, 0.8),
);
}
}
class CloudOnlyIcon extends StatelessWidget {
const CloudOnlyIcon({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const _BottomLeftOverlayIcon(
Icons.cloud_done_outlined,
baseSize: 18,
color: Color.fromRGBO(1, 222, 77, 0.8),
);
}
}
2022-12-20 06:34:02 +00:00
class FavoriteOverlayIcon extends StatelessWidget {
const FavoriteOverlayIcon({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
2022-12-20 07:25:50 +00:00
return const _BottomLeftOverlayIcon(
2022-12-20 07:10:31 +00:00
Icons.favorite_rounded,
baseSize: 22,
);
2022-12-20 06:34:02 +00:00
}
}
class ArchiveOverlayIcon extends StatelessWidget {
const ArchiveOverlayIcon({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
2022-12-20 07:25:50 +00:00
return const _BottomLeftOverlayIcon(
2022-12-20 06:34:02 +00:00
Icons.archive_outlined,
color: fixedStrokeMutedWhite,
2022-07-02 17:30:04 +00:00
);
}
}
2022-12-20 07:22:09 +00:00
class LivePhotoOverlayIcon extends StatelessWidget {
const LivePhotoOverlayIcon({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
2022-12-20 07:25:50 +00:00
return const _BottomRightOverlayIcon(
2022-12-20 07:22:09 +00:00
Icons.album_outlined,
baseSize: 18,
);
}
}
2022-07-02 17:30:04 +00:00
class VideoOverlayIcon extends StatelessWidget {
2022-10-19 09:02:33 +00:00
const VideoOverlayIcon({Key? key}) : super(key: key);
2022-07-02 17:30:04 +00:00
@override
Widget build(BuildContext context) {
2022-07-04 06:02:17 +00:00
return const SizedBox(
2022-07-02 17:30:04 +00:00
height: 64,
child: Icon(
Icons.play_circle_outline,
size: 40,
color: Colors.white70,
),
);
}
}
class OwnerAvatarOverlayIcon extends StatelessWidget {
final User user;
2022-12-16 04:20:08 +00:00
const OwnerAvatarOverlayIcon(this.user, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.topRight,
child: Padding(
padding: const EdgeInsets.only(right: 4, top: 4),
child: UserAvatarWidget(
user,
type: AvatarType.tiny,
2022-12-16 13:09:14 +00:00
thumbnailView: true,
),
),
);
}
}
2022-07-02 17:30:04 +00:00
class TrashedFileOverlayText extends StatelessWidget {
final TrashFile file;
2022-10-19 09:02:33 +00:00
const TrashedFileOverlayText(this.file, {Key? key}) : super(key: key);
2022-07-02 17:30:04 +00:00
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: [Colors.black.withOpacity(0.33), Colors.transparent],
),
),
2022-07-03 09:45:00 +00:00
alignment: Alignment.bottomCenter,
2022-07-04 06:02:17 +00:00
padding: const EdgeInsets.only(bottom: 5),
2022-07-02 17:30:04 +00:00
child: Text(
daysLeft(file.deleteBy),
style: Theme.of(context)
.textTheme
2022-10-19 09:02:33 +00:00
.subtitle2!
2022-07-02 17:30:04 +00:00
.copyWith(color: Colors.white), //same for both themes
),
);
}
}
2022-12-20 06:26:52 +00:00
// Base variations
/// Icon overlay in the bottom left.
///
/// This usually indicates ente specific state of a file, e.g. if it is
/// favorited/archived.
2022-12-20 07:25:50 +00:00
class _BottomLeftOverlayIcon extends StatelessWidget {
2022-12-20 06:26:52 +00:00
final IconData icon;
/// Overriddable color. Default is a fixed white.
final Color color;
2022-12-20 07:10:31 +00:00
/// Overriddable default size. This is just the initial hint, the actual size
/// is dynamic based on the widget's width (so that we show smaller icons in
/// smaller thumbnails).
final double baseSize;
2022-12-20 07:25:50 +00:00
const _BottomLeftOverlayIcon(
2022-12-20 06:26:52 +00:00
this.icon, {
Key? key,
2022-12-20 07:10:31 +00:00
this.baseSize = 24,
2022-12-20 06:26:52 +00:00
this.color = Colors.white, // fixed
}) : super(key: key);
@override
Widget build(BuildContext context) {
2022-12-20 07:02:08 +00:00
return LayoutBuilder(
builder: (context, constraints) {
double inset = 4;
2022-12-20 07:10:31 +00:00
double size = baseSize;
2022-12-20 07:02:08 +00:00
if (constraints.hasBoundedWidth) {
final w = constraints.maxWidth;
2022-12-20 07:10:31 +00:00
if (w > 120) {
2022-12-20 07:02:08 +00:00
size = 24;
2022-12-20 07:10:31 +00:00
} else if (w < 75) {
2022-12-20 07:02:08 +00:00
inset = 3;
size = 16;
}
}
return Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomLeft,
end: Alignment.center,
colors: [
Color.fromRGBO(0, 0, 0, 0.14),
Color.fromRGBO(0, 0, 0, 0.05),
Color.fromRGBO(0, 0, 0, 0.0),
],
stops: [0, 0.6, 1],
),
2022-12-20 06:26:52 +00:00
),
2022-12-20 07:02:08 +00:00
child: Align(
alignment: Alignment.bottomLeft,
child: Padding(
padding: EdgeInsets.only(left: inset, bottom: inset),
child: Icon(
icon,
size: size,
color: color,
),
),
),
);
},
2022-12-20 06:26:52 +00:00
);
}
}
2022-12-20 07:22:09 +00:00
/// Icon overlay in the bottom right.
///
/// This usually indicates information about the file itself, e.g. whether it is
/// a live photo, or the duration of the video.
2022-12-20 07:25:50 +00:00
class _BottomRightOverlayIcon extends StatelessWidget {
2022-12-20 07:22:09 +00:00
final IconData icon;
/// Overriddable color. Default is a fixed white.
final Color color;
/// Overriddable default size. This is just the initial hint, the actual size
/// is dynamic based on the widget's width (so that we show smaller icons in
/// smaller thumbnails).
final double baseSize;
2022-12-20 07:25:50 +00:00
const _BottomRightOverlayIcon(
2022-12-20 07:22:09 +00:00
this.icon, {
Key? key,
this.baseSize = 24,
this.color = Colors.white, // fixed
}) : super(key: key);
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
double inset = 4;
double size = baseSize;
if (constraints.hasBoundedWidth) {
final w = constraints.maxWidth;
if (w > 120) {
size = 24;
} else if (w < 75) {
inset = 3;
size = 16;
}
}
return Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomRight,
end: Alignment.center,
colors: [
Color.fromRGBO(0, 0, 0, 0.14),
Color.fromRGBO(0, 0, 0, 0.05),
Color.fromRGBO(0, 0, 0, 0.0),
],
stops: [0, 0.6, 1],
),
),
child: Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: EdgeInsets.only(bottom: inset, right: inset),
child: Icon(
icon,
size: size,
color: color,
),
),
),
);
},
);
}
}