ente/lib/ui/collections_gallery_widget.dart

810 lines
28 KiB
Dart
Raw Normal View History

import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'package:flutter/material.dart';
2020-10-26 11:18:00 +00:00
import 'package:fluttertoast/fluttertoast.dart';
2020-10-28 15:25:32 +00:00
import 'package:logging/logging.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/core/event_bus.dart';
import 'package:photos/db/files_db.dart';
2022-05-05 06:46:31 +00:00
import 'package:photos/db/trash_db.dart';
2022-04-28 13:08:27 +00:00
import 'package:photos/ente_theme_data.dart';
import 'package:photos/events/backup_folders_updated_event.dart';
2020-10-28 12:03:28 +00:00
import 'package:photos/events/collection_updated_event.dart';
import 'package:photos/events/local_photos_updated_event.dart';
2020-10-26 11:18:00 +00:00
import 'package:photos/events/tab_changed_event.dart';
2021-03-17 21:07:17 +00:00
import 'package:photos/events/user_logged_out_event.dart';
import 'package:photos/models/collection_items.dart';
import 'package:photos/models/device_folder.dart';
2022-05-05 06:46:31 +00:00
import 'package:photos/models/magic_metadata.dart';
import 'package:photos/services/collections_service.dart';
import 'package:photos/ui/common/loading_widget.dart';
import 'package:photos/ui/viewer/file/thumbnail_widget.dart';
import 'package:photos/ui/viewer/gallery/archive_page.dart';
import 'package:photos/ui/viewer/gallery/collection_page.dart';
import 'package:photos/ui/viewer/gallery/device_all_page.dart';
import 'package:photos/ui/viewer/gallery/device_folder_page.dart';
import 'package:photos/ui/viewer/gallery/empte_state.dart';
import 'package:photos/ui/viewer/gallery/trash_page.dart';
import 'package:photos/utils/local_settings.dart';
import 'package:photos/utils/navigation_util.dart';
2020-10-26 11:18:00 +00:00
import 'package:photos/utils/toast_util.dart';
2021-09-17 04:44:10 +00:00
class CollectionsGalleryWidget extends StatefulWidget {
const CollectionsGalleryWidget({Key key}) : super(key: key);
@override
2022-07-03 09:49:33 +00:00
State<CollectionsGalleryWidget> createState() =>
_CollectionsGalleryWidgetState();
}
2020-11-10 11:36:51 +00:00
class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget>
with AutomaticKeepAliveClientMixin {
2020-10-28 15:25:32 +00:00
final _logger = Logger("CollectionsGallery");
2020-10-28 12:03:28 +00:00
StreamSubscription<LocalPhotosUpdatedEvent> _localFilesSubscription;
StreamSubscription<CollectionUpdatedEvent> _collectionUpdatesSubscription;
StreamSubscription<BackupFoldersUpdatedEvent> _backupFoldersUpdatedEvent;
2021-03-17 21:07:17 +00:00
StreamSubscription<UserLoggedOutEvent> _loggedOutEvent;
AlbumSortKey sortKey;
2022-05-05 06:46:31 +00:00
String _loadReason = "init";
@override
void initState() {
2022-07-03 09:49:33 +00:00
_localFilesSubscription =
Bus.instance.on<LocalPhotosUpdatedEvent>().listen((event) {
2022-05-05 06:46:31 +00:00
_loadReason = (LocalPhotosUpdatedEvent).toString();
2020-10-28 12:03:28 +00:00
setState(() {});
});
2022-07-03 09:49:33 +00:00
_collectionUpdatesSubscription =
Bus.instance.on<CollectionUpdatedEvent>().listen((event) {
2022-05-05 06:46:31 +00:00
_loadReason = (CollectionUpdatedEvent).toString();
setState(() {});
});
2021-03-17 21:07:17 +00:00
_loggedOutEvent = Bus.instance.on<UserLoggedOutEvent>().listen((event) {
2022-05-05 06:46:31 +00:00
_loadReason = (UserLoggedOutEvent).toString();
2021-03-17 21:07:17 +00:00
setState(() {});
});
2022-07-03 09:49:33 +00:00
_backupFoldersUpdatedEvent =
Bus.instance.on<BackupFoldersUpdatedEvent>().listen((event) {
2022-05-05 06:46:31 +00:00
_loadReason = (BackupFoldersUpdatedEvent).toString();
setState(() {});
});
sortKey = LocalSettings.instance.albumSortKey();
super.initState();
}
@override
Widget build(BuildContext context) {
2020-11-16 08:00:31 +00:00
super.build(context);
2022-05-05 06:46:31 +00:00
_logger.info("Building, trigger: $_loadReason");
return FutureBuilder<CollectionItems>(
future: _getCollections(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return _getCollectionsGalleryWidget(snapshot.data);
} else if (snapshot.hasError) {
return Text(snapshot.error.toString());
} else {
return const EnteLoadingWidget();
}
},
);
}
Future<CollectionItems> _getCollections() async {
2020-10-30 22:30:54 +00:00
final filesDB = FilesDB.instance;
final collectionsService = CollectionsService.instance;
final userID = Configuration.instance.getUserID();
2021-04-19 17:08:12 +00:00
final List<DeviceFolder> folders = [];
final latestLocalFiles = await filesDB.getLatestLocalFiles();
for (final file in latestLocalFiles) {
folders.add(DeviceFolder(file.deviceFolder, file.deviceFolder, file));
}
2022-06-11 08:23:52 +00:00
folders.sort(
2022-07-03 09:49:33 +00:00
(first, second) =>
second.thumbnail.creationTime.compareTo(first.thumbnail.creationTime),
2022-06-11 08:23:52 +00:00
);
final List<CollectionWithThumbnail> collectionsWithThumbnail = [];
2022-07-03 09:49:33 +00:00
final latestCollectionFiles =
await collectionsService.getLatestCollectionFiles();
for (final file in latestCollectionFiles) {
final c = collectionsService.getCollectionByID(file.collectionID);
if (c.owner.id == userID) {
collectionsWithThumbnail.add(CollectionWithThumbnail(c, file));
2020-10-28 15:25:32 +00:00
}
2020-10-30 22:30:54 +00:00
}
2022-04-28 13:08:27 +00:00
collectionsWithThumbnail.sort(
(first, second) {
if (sortKey == AlbumSortKey.albumName) {
// alphabetical ASC order
return first.collection.name.compareTo(second.collection.name);
} else if (sortKey == AlbumSortKey.newestPhoto) {
2022-07-03 09:49:33 +00:00
return second.thumbnail.creationTime
.compareTo(first.thumbnail.creationTime);
2022-04-28 13:08:27 +00:00
} else {
2022-07-03 09:49:33 +00:00
return second.collection.updationTime
.compareTo(first.collection.updationTime);
2022-04-28 13:08:27 +00:00
}
},
);
2020-10-28 15:25:32 +00:00
return CollectionItems(folders, collectionsWithThumbnail);
}
2020-12-12 01:11:12 +00:00
Widget _getCollectionsGalleryWidget(CollectionItems items) {
const double horizontalPaddingOfGridRow = 16;
const double crossAxisSpacingOfGrid = 9;
2022-07-03 09:49:33 +00:00
final TextStyle trashAndHiddenTextStyle = Theme.of(context)
.textTheme
.subtitle1
.copyWith(
2022-06-11 08:23:52 +00:00
color: Theme.of(context).textTheme.subtitle1.color.withOpacity(0.5),
);
Size size = MediaQuery.of(context).size;
2022-04-28 14:47:05 +00:00
int albumsCountInOneRow = max(size.width ~/ 220.0, 2);
2022-06-12 12:44:05 +00:00
final double sideOfThumbnail = (size.width / albumsCountInOneRow) -
horizontalPaddingOfGridRow -
((crossAxisSpacingOfGrid / 2) * (albumsCountInOneRow - 1));
2020-12-12 01:11:12 +00:00
return SingleChildScrollView(
child: Container(
margin: const EdgeInsets.only(bottom: 50),
child: Column(
children: [
2022-06-11 09:21:39 +00:00
const SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
const SectionTitle("On device"),
Platform.isAndroid
? const SizedBox.shrink()
: GestureDetector(
child: const Padding(
padding: EdgeInsets.only(right: 12.0),
child: Text("View all"),
),
onTap: () => routeToPage(context, DeviceAllPage()),
),
],
),
const SizedBox(height: 12),
2021-03-12 08:47:57 +00:00
items.folders.isEmpty
? const Padding(
padding: EdgeInsets.all(22),
child: EmptyState(),
2021-03-12 08:47:57 +00:00
)
2022-04-28 13:08:27 +00:00
: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: SizedBox(
height: 170,
child: Align(
alignment: Alignment.centerLeft,
child: items.folders.isEmpty
? const EmptyState()
2022-04-28 13:08:27 +00:00
: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
2022-07-04 06:02:17 +00:00
padding: const EdgeInsets.fromLTRB(6, 0, 6, 0),
physics: const ScrollPhysics(),
2022-05-05 06:46:31 +00:00
// to disable GridView's scrolling
2022-04-28 13:08:27 +00:00
itemBuilder: (context, index) {
return DeviceFolderIcon(items.folders[index]);
},
itemCount: items.folders.length,
),
),
2021-03-12 08:47:57 +00:00
),
),
2022-04-30 12:18:26 +00:00
const Padding(padding: EdgeInsets.all(4)),
const Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
2022-07-04 06:02:17 +00:00
const EnteSectionTitle(),
_sortMenu(),
],
),
const SizedBox(height: 12),
Configuration.instance.hasConfiguredAccount()
2022-04-28 13:08:27 +00:00
? Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: GridView.builder(
shrinkWrap: true,
2022-07-04 06:02:17 +00:00
physics: const ScrollPhysics(),
2022-05-05 06:46:31 +00:00
// to disable GridView's scrolling
2022-04-28 13:08:27 +00:00
itemBuilder: (context, index) {
return _buildCollection(
2022-06-11 08:23:52 +00:00
context,
items.collections,
index,
);
2022-04-28 13:08:27 +00:00
},
2022-05-05 06:46:31 +00:00
itemCount: items.collections.length + 1,
// To include the + button
2022-04-28 13:08:27 +00:00
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
2022-06-11 08:23:52 +00:00
crossAxisCount: albumsCountInOneRow,
mainAxisSpacing: 12,
crossAxisSpacing: crossAxisSpacingOfGrid,
2022-07-03 09:49:33 +00:00
childAspectRatio:
sideOfThumbnail / (sideOfThumbnail + 24),
2022-06-11 08:23:52 +00:00
), //24 is height of album title
),
)
: const EmptyState(),
const SizedBox(height: 10),
2022-04-30 12:18:26 +00:00
const Divider(),
const SizedBox(height: 16),
2022-04-28 13:08:27 +00:00
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
children: [
OutlinedButton(
style: OutlinedButton.styleFrom(
backgroundColor: Theme.of(context).backgroundColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
2022-07-04 06:02:17 +00:00
padding: const EdgeInsets.all(0),
2022-04-28 13:08:27 +00:00
side: BorderSide(
width: 0.5,
2022-07-03 09:49:33 +00:00
color:
Theme.of(context).iconTheme.color.withOpacity(0.24),
2022-04-28 13:08:27 +00:00
),
),
2022-05-05 06:46:31 +00:00
child: SizedBox(
2022-04-28 13:08:27 +00:00
height: 48,
width: double.infinity,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(
Icons.delete,
color: Theme.of(context).iconTheme.color,
),
2022-07-04 06:02:17 +00:00
const Padding(padding: EdgeInsets.all(6)),
2022-05-05 06:46:31 +00:00
FutureBuilder<int>(
future: TrashDB.instance.count(),
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data > 0) {
return RichText(
2022-06-11 08:23:52 +00:00
text: TextSpan(
style: trashAndHiddenTextStyle,
children: [
2022-05-05 06:46:31 +00:00
TextSpan(
2022-06-11 08:23:52 +00:00
text: "Trash",
2022-07-03 09:49:33 +00:00
style: Theme.of(context)
.textTheme
.subtitle1,
2022-06-11 08:23:52 +00:00
),
2022-07-04 06:02:17 +00:00
const TextSpan(text: " \u2022 "),
2022-05-05 06:46:31 +00:00
TextSpan(
2022-06-11 08:23:52 +00:00
text: snapshot.data.toString(),
),
2022-05-05 06:46:31 +00:00
//need to query in db and bring this value
2022-06-11 08:23:52 +00:00
],
),
);
2022-05-05 06:46:31 +00:00
} else {
return RichText(
2022-06-11 08:23:52 +00:00
text: TextSpan(
style: trashAndHiddenTextStyle,
children: [
2022-05-05 06:46:31 +00:00
TextSpan(
2022-06-11 08:23:52 +00:00
text: "Trash",
2022-07-03 09:49:33 +00:00
style: Theme.of(context)
.textTheme
.subtitle1,
2022-06-11 08:23:52 +00:00
),
2022-05-05 06:46:31 +00:00
//need to query in db and bring this value
2022-06-11 08:23:52 +00:00
],
),
);
2022-05-05 06:46:31 +00:00
}
},
),
2022-04-28 13:08:27 +00:00
],
),
Icon(
Icons.chevron_right,
color: Theme.of(context).iconTheme.color,
),
],
),
2022-04-28 13:08:27 +00:00
),
2021-10-12 20:01:51 +00:00
),
2022-04-28 13:08:27 +00:00
onPressed: () async {
routeToPage(
context,
TrashPage(),
);
},
),
2022-07-04 06:02:17 +00:00
const SizedBox(height: 12),
HiddenCollectionsButtonWidget(trashAndHiddenTextStyle),
2022-04-28 13:08:27 +00:00
],
),
),
2022-07-04 06:02:17 +00:00
const Padding(padding: EdgeInsets.fromLTRB(12, 12, 12, 36)),
],
),
2020-12-12 01:11:12 +00:00
),
);
}
Widget _sortMenu() {
Text sortOptionText(AlbumSortKey key) {
String text = key.toString();
2021-09-08 20:19:25 +00:00
switch (key) {
case AlbumSortKey.albumName:
2022-04-28 13:08:27 +00:00
text = "Name";
break;
2022-04-28 13:08:27 +00:00
case AlbumSortKey.newestPhoto:
text = "Newest";
break;
2022-04-28 13:08:27 +00:00
case AlbumSortKey.lastUpdated:
text = "Last updated";
2021-09-08 20:19:25 +00:00
}
2022-06-11 08:23:52 +00:00
return Text(
text,
style: Theme.of(context).textTheme.subtitle1.copyWith(
2022-04-28 13:08:27 +00:00
fontSize: 14,
2022-06-11 08:23:52 +00:00
color: Theme.of(context).iconTheme.color.withOpacity(0.7),
),
);
2021-09-08 20:19:25 +00:00
}
return Padding(
padding: const EdgeInsets.only(right: 24),
child: PopupMenuButton(
2022-07-04 06:02:17 +00:00
offset: const Offset(10, 50),
initialValue: sortKey?.index ?? 0,
child: Align(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
2022-07-04 06:02:17 +00:00
const Padding(
2022-04-28 13:08:27 +00:00
padding: EdgeInsets.only(left: 5.0),
),
Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: Theme.of(context).hintColor.withOpacity(0.2),
borderRadius: BorderRadius.circular(18),
),
child: Icon(
Icons.sort,
color: Theme.of(context).iconTheme.color,
size: 20,
),
),
],
),
),
2021-09-11 07:01:47 +00:00
onSelected: (int index) async {
2021-09-11 07:12:53 +00:00
sortKey = AlbumSortKey.values[index];
2021-09-11 07:01:47 +00:00
await LocalSettings.instance.setAlbumSortKey(sortKey);
2021-09-11 07:12:53 +00:00
setState(() {});
},
itemBuilder: (context) {
return List.generate(AlbumSortKey.values.length, (index) {
return PopupMenuItem(
value: index,
child: sortOptionText(AlbumSortKey.values[index]),
);
});
},
),
);
2021-09-08 20:19:25 +00:00
}
2022-06-11 08:23:52 +00:00
Widget _buildCollection(
BuildContext context,
List<CollectionWithThumbnail> collections,
int index,
) {
2021-04-27 15:29:34 +00:00
if (index < collections.length) {
final c = collections[index];
2021-04-27 15:35:42 +00:00
return CollectionItem(c);
2021-04-27 15:29:34 +00:00
} else {
2022-04-28 13:08:27 +00:00
return InkWell(
child: Container(
2022-07-04 06:02:17 +00:00
margin: const EdgeInsets.fromLTRB(30, 30, 30, 54),
2022-04-28 13:08:27 +00:00
decoration: BoxDecoration(
color: Theme.of(context).backgroundColor,
boxShadow: [
BoxShadow(
2022-06-11 08:23:52 +00:00
blurRadius: 2,
spreadRadius: 0,
2022-07-04 06:02:17 +00:00
offset: const Offset(0, 0),
2022-06-11 08:23:52 +00:00
color: Theme.of(context).iconTheme.color.withOpacity(0.3),
)
2022-04-28 13:08:27 +00:00
],
borderRadius: BorderRadius.circular(4),
2021-04-27 15:29:34 +00:00
),
child: Icon(
Icons.add,
2022-04-28 13:08:27 +00:00
color: Theme.of(context).iconTheme.color.withOpacity(0.25),
2021-04-27 15:29:34 +00:00
),
),
2022-04-28 13:08:27 +00:00
onTap: () async {
2022-06-11 08:23:52 +00:00
await showToast(
context,
"long press to select photos and click + to create an album",
toastLength: Toast.LENGTH_LONG,
);
2022-07-03 09:49:33 +00:00
Bus.instance
.fire(TabChangedEvent(0, TabChangedEventSource.collectionsPage));
2022-04-28 13:08:27 +00:00
},
2021-04-27 15:29:34 +00:00
);
}
}
@override
void dispose() {
_localFilesSubscription.cancel();
_collectionUpdatesSubscription.cancel();
_loggedOutEvent.cancel();
_backupFoldersUpdatedEvent.cancel();
super.dispose();
}
@override
bool get wantKeepAlive => true;
}
class HiddenCollectionsButtonWidget extends StatelessWidget {
final TextStyle textStyle;
const HiddenCollectionsButtonWidget(
this.textStyle, {
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return OutlinedButton(
style: OutlinedButton.styleFrom(
backgroundColor: Theme.of(context).backgroundColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
padding: const EdgeInsets.all(0),
side: BorderSide(
width: 0.5,
color: Theme.of(context).iconTheme.color.withOpacity(0.24),
),
),
child: SizedBox(
height: 48,
width: double.infinity,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(
Icons.visibility_off,
color: Theme.of(context).iconTheme.color,
),
const Padding(padding: EdgeInsets.all(6)),
FutureBuilder<int>(
future: FilesDB.instance.fileCountWithVisibility(
kVisibilityArchive,
Configuration.instance.getUserID(),
),
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data > 0) {
return RichText(
text: TextSpan(
style: textStyle,
children: [
TextSpan(
text: "Hidden",
style: Theme.of(context).textTheme.subtitle1,
),
const TextSpan(text: " \u2022 "),
TextSpan(
text: snapshot.data.toString(),
),
//need to query in db and bring this value
],
),
);
} else {
return RichText(
text: TextSpan(
style: textStyle,
children: [
TextSpan(
text: "Hidden",
style: Theme.of(context).textTheme.subtitle1,
),
//need to query in db and bring this value
],
),
);
}
},
),
],
),
Icon(
Icons.chevron_right,
color: Theme.of(context).iconTheme.color,
),
],
),
),
),
onPressed: () async {
routeToPage(
context,
ArchivePage(),
);
},
);
}
}
2021-04-27 15:29:34 +00:00
class DeviceFolderIcon extends StatelessWidget {
const DeviceFolderIcon(
this.folder, {
Key key,
}) : super(key: key);
static final kUnsyncedIconOverlay = Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black.withOpacity(0.6),
],
2021-08-05 19:35:09 +00:00
stops: const [0.7, 1],
),
),
child: Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.only(right: 8, bottom: 8),
child: Icon(
Icons.cloud_off_outlined,
size: 18,
color: Colors.white.withOpacity(0.9),
),
),
),
);
2021-04-27 15:29:34 +00:00
final DeviceFolder folder;
@override
Widget build(BuildContext context) {
2022-07-03 09:49:33 +00:00
final isBackedUp =
Configuration.instance.getPathsToBackUp().contains(folder.path);
return GestureDetector(
2022-04-28 13:08:27 +00:00
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 2),
2022-07-03 06:49:00 +00:00
child: SizedBox(
2022-04-28 13:08:27 +00:00
height: 140,
width: 120,
child: Column(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.circular(4),
child: SizedBox(
2022-07-03 09:45:00 +00:00
height: 120,
width: 120,
2022-04-28 13:08:27 +00:00
child: Hero(
2022-07-03 09:49:33 +00:00
tag:
"device_folder:" + folder.path + folder.thumbnail.tag(),
2022-04-28 13:08:27 +00:00
child: Stack(
children: [
ThumbnailWidget(
folder.thumbnail,
shouldShowSyncStatus: false,
2022-06-11 08:23:52 +00:00
key: Key(
2022-07-03 09:49:33 +00:00
"device_folder:" +
folder.path +
folder.thumbnail.tag(),
2022-06-11 08:23:52 +00:00
),
2022-04-28 13:08:27 +00:00
),
isBackedUp ? Container() : kUnsyncedIconOverlay,
],
),
),
),
),
2022-04-28 13:08:27 +00:00
Padding(
padding: const EdgeInsets.only(top: 10),
child: Text(
folder.name,
2022-07-03 09:49:33 +00:00
style: Theme.of(context)
.textTheme
.subtitle1
.copyWith(fontSize: 12),
2022-04-28 13:08:27 +00:00
overflow: TextOverflow.ellipsis,
),
),
2022-04-28 13:08:27 +00:00
],
),
),
),
onTap: () {
routeToPage(context, DeviceFolderPage(folder));
},
);
}
2021-04-27 15:29:34 +00:00
}
2021-04-27 15:35:42 +00:00
class CollectionItem extends StatelessWidget {
CollectionItem(
this.c, {
2021-04-27 15:29:34 +00:00
Key key,
}) : super(key: Key(c.collection.id.toString()));
final CollectionWithThumbnail c;
@override
Widget build(BuildContext context) {
2022-06-12 12:44:05 +00:00
const double horizontalPaddingOfGridRow = 16;
const double crossAxisSpacingOfGrid = 9;
2022-06-12 12:44:05 +00:00
Size size = MediaQuery.of(context).size;
int albumsCountInOneRow = max(size.width ~/ 220.0, 2);
2022-07-03 09:49:33 +00:00
double totalWhiteSpaceOfRow = (horizontalPaddingOfGridRow * 2) +
(albumsCountInOneRow - 1) * crossAxisSpacingOfGrid;
TextStyle albumTitleTextStyle =
Theme.of(context).textTheme.subtitle1.copyWith(fontSize: 14);
final double sideOfThumbnail = (size.width / albumsCountInOneRow) -
(totalWhiteSpaceOfRow / albumsCountInOneRow);
2021-04-27 15:29:34 +00:00
return GestureDetector(
child: Column(
2022-04-28 13:08:27 +00:00
crossAxisAlignment: CrossAxisAlignment.start,
2021-04-27 15:29:34 +00:00
children: <Widget>[
ClipRRect(
2022-04-28 13:08:27 +00:00
borderRadius: BorderRadius.circular(4),
2021-08-05 19:35:09 +00:00
child: SizedBox(
2022-07-03 09:45:00 +00:00
height: sideOfThumbnail,
width: sideOfThumbnail,
2022-06-11 08:23:52 +00:00
child: Hero(
tag: "collection" + c.thumbnail.tag(),
child: ThumbnailWidget(
c.thumbnail,
shouldShowArchiveStatus: c.collection.isArchived(),
key: Key(
"collection" + c.thumbnail.tag(),
),
),
),
),
2021-04-27 15:29:34 +00:00
),
2022-07-04 06:02:17 +00:00
const SizedBox(height: 4),
2022-04-28 13:08:27 +00:00
Row(
children: [
Container(
constraints: BoxConstraints(maxWidth: sideOfThumbnail - 40),
child: Text(
c.collection.name,
style: albumTitleTextStyle,
overflow: TextOverflow.ellipsis,
),
2020-12-12 01:11:12 +00:00
),
2022-05-05 06:46:31 +00:00
FutureBuilder<int>(
future: FilesDB.instance.collectionFileCount(c.collection.id),
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data > 0) {
return RichText(
2022-06-11 08:23:52 +00:00
text: TextSpan(
style: albumTitleTextStyle.copyWith(
color: albumTitleTextStyle.color.withOpacity(0.5),
),
children: [
2022-07-04 06:02:17 +00:00
const TextSpan(text: " \u2022 "),
2022-05-05 06:46:31 +00:00
TextSpan(text: snapshot.data.toString()),
2022-06-11 08:23:52 +00:00
],
),
);
2022-05-05 06:46:31 +00:00
} else {
return const SizedBox.shrink();
2022-05-05 06:46:31 +00:00
}
},
2022-04-28 13:08:27 +00:00
),
],
2020-12-12 00:31:06 +00:00
),
2021-04-27 15:29:34 +00:00
],
),
onTap: () {
2021-05-13 18:05:32 +00:00
routeToPage(context, CollectionPage(c));
2021-04-27 15:29:34 +00:00
},
);
}
}
class SectionTitle extends StatelessWidget {
final String title;
final Alignment alignment;
2021-06-16 15:11:30 +00:00
final double opacity;
const SectionTitle(
this.title, {
2021-08-05 19:35:09 +00:00
this.opacity = 0.8,
Key key,
this.alignment = Alignment.centerLeft,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
2022-07-04 06:02:17 +00:00
margin: const EdgeInsets.fromLTRB(16, 12, 0, 0),
2021-08-05 19:35:09 +00:00
child: Column(
children: [
Align(
alignment: alignment,
child: Text(
title,
2022-07-03 09:49:33 +00:00
style:
Theme.of(context).textTheme.headline6.copyWith(fontSize: 22),
),
),
2021-08-05 19:35:09 +00:00
],
),
);
}
}
2022-06-12 16:37:05 +00:00
class EnteSectionTitle extends StatelessWidget {
final double opacity;
const EnteSectionTitle({
this.opacity = 0.8,
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
2022-07-04 06:02:17 +00:00
margin: const EdgeInsets.fromLTRB(16, 12, 0, 0),
2022-06-12 16:37:05 +00:00
child: Column(
children: [
Align(
alignment: Alignment.centerLeft,
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: "On ",
2022-07-03 09:49:33 +00:00
style: Theme.of(context)
.textTheme
.headline6
.copyWith(fontSize: 22),
2022-06-12 16:37:05 +00:00
),
TextSpan(
text: "ente",
style: TextStyle(
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat',
fontSize: 22,
2022-06-12 16:40:46 +00:00
color: Theme.of(context).colorScheme.defaultTextColor,
2022-06-12 16:37:05 +00:00
),
),
],
),
),
),
],
),
);
}
}