2020-10-24 23:10:37 +00:00
|
|
|
import 'dart:async';
|
2022-04-23 06:29:46 +00:00
|
|
|
import 'dart:math';
|
2020-10-24 23:10:37 +00:00
|
|
|
|
|
|
|
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';
|
2020-10-24 23:10:37 +00:00
|
|
|
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';
|
2021-03-25 19:54:05 +00:00
|
|
|
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';
|
2020-10-24 23:10:37 +00:00
|
|
|
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';
|
2020-10-29 00:30:02 +00:00
|
|
|
import 'package:photos/models/collection_items.dart';
|
2020-10-24 23:10:37 +00:00
|
|
|
import 'package:photos/models/device_folder.dart';
|
2022-05-05 06:46:31 +00:00
|
|
|
import 'package:photos/models/magic_metadata.dart';
|
2021-07-23 12:28:02 +00:00
|
|
|
import 'package:photos/services/collections_service.dart';
|
2022-07-01 14:18:05 +00:00
|
|
|
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_folder_page.dart';
|
2022-07-03 05:57:27 +00:00
|
|
|
import 'package:photos/ui/viewer/gallery/empte_state.dart';
|
2022-07-01 14:18:05 +00:00
|
|
|
import 'package:photos/ui/viewer/gallery/trash_page.dart';
|
2021-09-08 20:06:37 +00:00
|
|
|
import 'package:photos/utils/local_settings.dart';
|
2021-05-08 18:14:18 +00:00
|
|
|
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
|
|
|
|
2020-10-24 23:10:37 +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-10-24 23:10:37 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2021-03-25 19:54:05 +00:00
|
|
|
StreamSubscription<BackupFoldersUpdatedEvent> _backupFoldersUpdatedEvent;
|
2021-03-17 21:07:17 +00:00
|
|
|
StreamSubscription<UserLoggedOutEvent> _loggedOutEvent;
|
2021-09-08 20:06:37 +00:00
|
|
|
AlbumSortKey sortKey;
|
2022-05-05 06:46:31 +00:00
|
|
|
String _loadReason = "init";
|
2020-10-24 23:10:37 +00:00
|
|
|
|
|
|
|
@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();
|
2020-10-24 23:10:37 +00:00
|
|
|
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();
|
2021-03-25 19:54:05 +00:00
|
|
|
setState(() {});
|
|
|
|
});
|
2021-09-08 20:06:37 +00:00
|
|
|
sortKey = LocalSettings.instance.albumSortKey();
|
2020-10-24 23:10:37 +00:00
|
|
|
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");
|
2020-10-24 23:10:37 +00:00
|
|
|
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 {
|
2022-07-03 06:04:42 +00:00
|
|
|
return const EnteLoadingWidget();
|
2020-10-24 23:10:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<CollectionItems> _getCollections() async {
|
2020-10-30 22:30:54 +00:00
|
|
|
final filesDB = FilesDB.instance;
|
|
|
|
final collectionsService = CollectionsService.instance;
|
2020-10-29 16:21:51 +00:00
|
|
|
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));
|
2020-10-24 23:10:37 +00:00
|
|
|
}
|
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
|
|
|
);
|
2021-04-19 17:46:52 +00:00
|
|
|
|
|
|
|
final List<CollectionWithThumbnail> collectionsWithThumbnail = [];
|
2022-07-03 09:49:33 +00:00
|
|
|
final latestCollectionFiles =
|
|
|
|
await collectionsService.getLatestCollectionFiles();
|
2021-04-19 17:46:52 +00:00
|
|
|
for (final file in latestCollectionFiles) {
|
|
|
|
final c = collectionsService.getCollectionByID(file.collectionID);
|
|
|
|
if (c.owner.id == userID) {
|
2021-05-04 15:26:17 +00:00
|
|
|
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-10-24 23:10:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 01:11:12 +00:00
|
|
|
Widget _getCollectionsGalleryWidget(CollectionItems items) {
|
2022-04-30 07:18:02 +00:00
|
|
|
const double horizontalPaddingOfGridRow = 16;
|
2022-06-12 14:22:05 +00:00
|
|
|
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),
|
|
|
|
);
|
2022-04-23 06:29:46 +00:00
|
|
|
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) -
|
2022-04-30 07:18:02 +00:00
|
|
|
horizontalPaddingOfGridRow -
|
|
|
|
((crossAxisSpacingOfGrid / 2) * (albumsCountInOneRow - 1));
|
2020-12-12 01:11:12 +00:00
|
|
|
return SingleChildScrollView(
|
2021-02-08 09:26:49 +00:00
|
|
|
child: Container(
|
|
|
|
margin: const EdgeInsets.only(bottom: 50),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2022-06-11 09:21:39 +00:00
|
|
|
const SizedBox(height: 12),
|
2022-04-28 13:08:27 +00:00
|
|
|
SectionTitle("On device"),
|
2022-06-12 16:39:28 +00:00
|
|
|
const SizedBox(height: 12),
|
2021-03-12 08:47:57 +00:00
|
|
|
items.folders.isEmpty
|
2022-07-03 05:57:27 +00:00
|
|
|
? 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
|
2022-07-03 05:57:27 +00:00
|
|
|
? const EmptyState()
|
2022-04-28 13:08:27 +00:00
|
|
|
: ListView.builder(
|
|
|
|
shrinkWrap: true,
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
padding: EdgeInsets.fromLTRB(6, 0, 6, 0),
|
2022-05-05 06:46:31 +00:00
|
|
|
physics: ScrollPhysics(),
|
|
|
|
// 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(),
|
2021-09-09 06:14:07 +00:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
children: [
|
2022-06-12 16:37:05 +00:00
|
|
|
EnteSectionTitle(),
|
2021-09-09 06:14:07 +00:00
|
|
|
_sortMenu(),
|
|
|
|
],
|
|
|
|
),
|
2022-06-12 16:39:28 +00:00
|
|
|
const SizedBox(height: 12),
|
2021-05-19 15:51:38 +00:00
|
|
|
Configuration.instance.hasConfiguredAccount()
|
2022-04-28 13:08:27 +00:00
|
|
|
? Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
child: GridView.builder(
|
|
|
|
shrinkWrap: true,
|
2022-05-05 06:46:31 +00:00
|
|
|
physics: ScrollPhysics(),
|
|
|
|
// 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
|
2021-03-02 19:02:03 +00:00
|
|
|
),
|
|
|
|
)
|
2022-07-03 05:57:27 +00:00
|
|
|
: const EmptyState(),
|
2022-06-10 05:59:25 +00:00
|
|
|
const SizedBox(height: 10),
|
2022-04-30 12:18:26 +00:00
|
|
|
const Divider(),
|
2022-06-10 09:05:35 +00:00
|
|
|
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),
|
|
|
|
),
|
|
|
|
padding: EdgeInsets.all(0),
|
|
|
|
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
|
|
|
),
|
2021-10-30 00:49:59 +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,
|
|
|
|
),
|
|
|
|
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-05-05 06:46:31 +00:00
|
|
|
TextSpan(text: " \u2022 "),
|
|
|
|
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,
|
|
|
|
),
|
|
|
|
],
|
2021-10-13 12:05:20 +00:00
|
|
|
),
|
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(),
|
|
|
|
);
|
|
|
|
},
|
2021-10-30 00:49:59 +00:00
|
|
|
),
|
2022-04-28 13:08:27 +00:00
|
|
|
SizedBox(height: 12),
|
|
|
|
OutlinedButton(
|
|
|
|
style: OutlinedButton.styleFrom(
|
|
|
|
backgroundColor: Theme.of(context).backgroundColor,
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
),
|
|
|
|
padding: EdgeInsets.all(0),
|
|
|
|
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
|
|
|
),
|
2021-10-30 00:49:59 +00:00
|
|
|
),
|
2022-07-03 07:47:15 +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.visibility_off,
|
|
|
|
color: Theme.of(context).iconTheme.color,
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.all(6)),
|
2022-05-05 06:46:31 +00:00
|
|
|
FutureBuilder<int>(
|
2022-07-03 09:49:33 +00:00
|
|
|
future:
|
|
|
|
FilesDB.instance.fileCountWithVisibility(
|
2022-06-11 08:23:52 +00:00
|
|
|
kVisibilityArchive,
|
|
|
|
Configuration.instance.getUserID(),
|
|
|
|
),
|
2022-05-05 06:46:31 +00:00
|
|
|
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: "Hidden",
|
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
|
|
|
TextSpan(text: " \u2022 "),
|
|
|
|
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: "Hidden",
|
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,
|
|
|
|
),
|
|
|
|
],
|
2021-10-13 12:05:20 +00:00
|
|
|
),
|
2022-04-28 13:08:27 +00:00
|
|
|
),
|
2021-10-13 12:05:20 +00:00
|
|
|
),
|
2022-04-28 13:08:27 +00:00
|
|
|
onPressed: () async {
|
|
|
|
routeToPage(
|
|
|
|
context,
|
|
|
|
ArchivePage(),
|
|
|
|
);
|
|
|
|
},
|
2021-10-30 00:49:59 +00:00
|
|
|
),
|
2022-04-28 13:08:27 +00:00
|
|
|
],
|
|
|
|
),
|
2021-10-13 12:05:20 +00:00
|
|
|
),
|
2022-04-28 13:08:27 +00:00
|
|
|
Padding(padding: EdgeInsets.fromLTRB(12, 12, 12, 36)),
|
2021-02-08 09:26:49 +00:00
|
|
|
],
|
|
|
|
),
|
2020-12-12 01:11:12 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-09 06:14:07 +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";
|
2021-09-09 06:14:07 +00:00
|
|
|
break;
|
2022-04-28 13:08:27 +00:00
|
|
|
case AlbumSortKey.newestPhoto:
|
|
|
|
text = "Newest";
|
2021-09-09 06:14:07 +00:00
|
|
|
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
|
|
|
}
|
2021-09-09 06:14:07 +00:00
|
|
|
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 24),
|
|
|
|
child: PopupMenuButton(
|
2022-04-28 13:08:27 +00:00
|
|
|
offset: Offset(10, 50),
|
2021-09-09 06:14:07 +00:00
|
|
|
initialValue: sortKey?.index ?? 0,
|
|
|
|
child: Align(
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
2022-04-28 13:08:27 +00:00
|
|
|
Padding(
|
|
|
|
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-09 06:14:07 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
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(() {});
|
2021-09-09 06:14:07 +00:00
|
|
|
},
|
|
|
|
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(
|
|
|
|
margin: EdgeInsets.fromLTRB(30, 30, 30, 54),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context).backgroundColor,
|
|
|
|
boxShadow: [
|
|
|
|
BoxShadow(
|
2022-06-11 08:23:52 +00:00
|
|
|
blurRadius: 2,
|
|
|
|
spreadRadius: 0,
|
|
|
|
offset: Offset(0, 0),
|
|
|
|
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 DeviceFolderIcon extends StatelessWidget {
|
|
|
|
const DeviceFolderIcon(
|
|
|
|
this.folder, {
|
|
|
|
Key key,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
2021-07-05 08:56:30 +00:00
|
|
|
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],
|
2021-07-05 08:56:30 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
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);
|
2020-10-24 23:10:37 +00:00
|
|
|
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,
|
|
|
|
// padding: const EdgeInsets.all(8.0),
|
|
|
|
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,
|
|
|
|
],
|
|
|
|
),
|
2021-03-25 19:26:06 +00:00
|
|
|
),
|
|
|
|
),
|
2020-10-26 10:25:23 +00:00
|
|
|
),
|
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,
|
2020-10-24 23:10:37 +00:00
|
|
|
),
|
|
|
|
),
|
2022-04-28 13:08:27 +00:00
|
|
|
],
|
|
|
|
),
|
2020-10-24 23:10:37 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
onTap: () {
|
2021-05-08 18:14:18 +00:00
|
|
|
routeToPage(context, DeviceFolderPage(folder));
|
2020-10-24 23:10:37 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2021-04-27 15:29:34 +00:00
|
|
|
}
|
2020-10-24 23:10:37 +00:00
|
|
|
|
2021-04-27 15:35:42 +00:00
|
|
|
class CollectionItem extends StatelessWidget {
|
2021-05-04 15:26:17 +00:00
|
|
|
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;
|
2022-06-12 14:22:05 +00:00
|
|
|
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-04-28 13:08:27 +00:00
|
|
|
SizedBox(height: 4),
|
|
|
|
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-05-05 06:46:31 +00:00
|
|
|
TextSpan(text: " \u2022 "),
|
|
|
|
TextSpan(text: snapshot.data.toString()),
|
2022-06-11 08:23:52 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
2022-05-05 06:46:31 +00:00
|
|
|
} else {
|
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
);
|
2020-10-24 23:10:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SectionTitle extends StatelessWidget {
|
|
|
|
final String title;
|
2021-05-11 16:52:35 +00:00
|
|
|
final Alignment alignment;
|
2021-06-16 15:11:30 +00:00
|
|
|
final double opacity;
|
|
|
|
|
2021-05-11 16:52:35 +00:00
|
|
|
const SectionTitle(
|
|
|
|
this.title, {
|
2021-08-05 19:35:09 +00:00
|
|
|
this.opacity = 0.8,
|
2021-05-11 16:52:35 +00:00
|
|
|
Key key,
|
|
|
|
this.alignment = Alignment.centerLeft,
|
|
|
|
}) : super(key: key);
|
2020-10-24 23:10:37 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
2022-06-11 09:04:39 +00:00
|
|
|
margin: EdgeInsets.fromLTRB(16, 12, 0, 0),
|
2021-08-05 19:35:09 +00:00
|
|
|
child: Column(
|
|
|
|
children: [
|
2020-10-24 23:10:37 +00:00
|
|
|
Align(
|
2021-05-11 16:52:35 +00:00
|
|
|
alignment: alignment,
|
2020-10-24 23:10:37 +00:00
|
|
|
child: Text(
|
|
|
|
title,
|
2022-07-03 09:49:33 +00:00
|
|
|
style:
|
|
|
|
Theme.of(context).textTheme.headline6.copyWith(fontSize: 22),
|
2020-10-24 23:10:37 +00:00
|
|
|
),
|
|
|
|
),
|
2021-08-05 19:35:09 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
2020-10-24 23:10:37 +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(
|
|
|
|
margin: EdgeInsets.fromLTRB(16, 12, 0, 0),
|
|
|
|
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
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|