Use devicePathCollection entity to show device folder/album page
This commit is contained in:
parent
08bf7d478c
commit
b396d420b0
|
@ -4,6 +4,7 @@ import 'package:photo_manager/photo_manager.dart';
|
|||
import 'package:photos/db/files_db.dart';
|
||||
import 'package:photos/models/device_folder.dart';
|
||||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/models/file_load_result.dart';
|
||||
import 'package:sqflite/sqlite_api.dart';
|
||||
|
||||
extension DeviceFiles on FilesDB {
|
||||
|
@ -128,6 +129,30 @@ extension DeviceFiles on FilesDB {
|
|||
}
|
||||
}
|
||||
|
||||
Future<FileLoadResult> getFilesInDevicePathCollection(
|
||||
DevicePathCollection devicePathCollection,
|
||||
int startTime,
|
||||
int endTime, {
|
||||
int limit,
|
||||
bool asc,
|
||||
}) async {
|
||||
final db = await database;
|
||||
final order = (asc ?? false ? 'ASC' : 'DESC');
|
||||
String rawQuery = '''
|
||||
SELECT *
|
||||
FROM ${FilesDB.filesTable}
|
||||
WHERE ${FilesDB.columnLocalID} IS NOT NULL AND
|
||||
${FilesDB.columnCreationTime} >= $startTime AND
|
||||
${FilesDB.columnCreationTime} <= $endTime AND
|
||||
${FilesDB.columnLocalID} IN
|
||||
(SELECT id FROM device_files where path_id = '${devicePathCollection.id}' )
|
||||
ORDER BY ${FilesDB.columnCreationTime} $order , ${FilesDB.columnModificationTime} $order LIMIT $limit
|
||||
''';
|
||||
final results = await db.rawQuery(rawQuery);
|
||||
final files = convertToFiles(results);
|
||||
return FileLoadResult(files, files.length == limit);
|
||||
}
|
||||
|
||||
Future<List<DevicePathCollection>> getDevicePathCollections() async {
|
||||
debugPrint("Fetching DevicePathCollections From DB");
|
||||
try {
|
||||
|
|
|
@ -3,10 +3,10 @@ import 'package:photos/models/device_folder.dart';
|
|||
import 'package:photos/models/file.dart';
|
||||
|
||||
class CollectionItems {
|
||||
final List<DeviceFolder> folders;
|
||||
final List<DevicePathCollection> devicePathCollections;
|
||||
final List<CollectionWithThumbnail> collections;
|
||||
|
||||
CollectionItems(this.folders, this.collections);
|
||||
CollectionItems(this.devicePathCollections, this.collections);
|
||||
}
|
||||
|
||||
class CollectionWithThumbnail {
|
||||
|
|
|
@ -7,7 +7,7 @@ import 'package:photos/utils/navigation_util.dart';
|
|||
|
||||
class DeviceFolderIcon extends StatelessWidget {
|
||||
const DeviceFolderIcon(
|
||||
this.folder, {
|
||||
this.devicePathCollection, {
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
|
@ -36,12 +36,13 @@ class DeviceFolderIcon extends StatelessWidget {
|
|||
),
|
||||
);
|
||||
|
||||
final DeviceFolder folder;
|
||||
final DevicePathCollection devicePathCollection;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isBackedUp =
|
||||
Configuration.instance.getPathsToBackUp().contains(folder.path);
|
||||
final isBackedUp = Configuration.instance
|
||||
.getPathsToBackUp()
|
||||
.contains(devicePathCollection.name);
|
||||
return GestureDetector(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 2),
|
||||
|
@ -56,17 +57,18 @@ class DeviceFolderIcon extends StatelessWidget {
|
|||
height: 120,
|
||||
width: 120,
|
||||
child: Hero(
|
||||
tag:
|
||||
"device_folder:" + folder.path + folder.thumbnail.tag(),
|
||||
tag: "device_folder:" +
|
||||
devicePathCollection.name +
|
||||
devicePathCollection.thumbnail.tag(),
|
||||
child: Stack(
|
||||
children: [
|
||||
ThumbnailWidget(
|
||||
folder.thumbnail,
|
||||
devicePathCollection.thumbnail,
|
||||
shouldShowSyncStatus: false,
|
||||
key: Key(
|
||||
"device_folder:" +
|
||||
folder.path +
|
||||
folder.thumbnail.tag(),
|
||||
devicePathCollection.name +
|
||||
devicePathCollection.thumbnail.tag(),
|
||||
),
|
||||
),
|
||||
isBackedUp ? Container() : kUnsyncedIconOverlay,
|
||||
|
@ -78,7 +80,7 @@ class DeviceFolderIcon extends StatelessWidget {
|
|||
Padding(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
child: Text(
|
||||
folder.name,
|
||||
devicePathCollection.name,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.subtitle1
|
||||
|
@ -91,7 +93,7 @@ class DeviceFolderIcon extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
onTap: () {
|
||||
routeToPage(context, DeviceFolderPage(folder));
|
||||
routeToPage(context, DeviceFolderPage(devicePathCollection));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@ import 'package:photos/ui/collections/device_folder_icon_widget.dart';
|
|||
import 'package:photos/ui/viewer/gallery/empte_state.dart';
|
||||
|
||||
class DeviceFoldersGridViewWidget extends StatelessWidget {
|
||||
final List<DeviceFolder> folders;
|
||||
final List<DevicePathCollection> devicePathCollections;
|
||||
|
||||
const DeviceFoldersGridViewWidget(
|
||||
this.folders, {
|
||||
this.devicePathCollections, {
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
|
@ -19,7 +19,7 @@ class DeviceFoldersGridViewWidget extends StatelessWidget {
|
|||
height: 170,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: folders.isEmpty
|
||||
child: devicePathCollections.isEmpty
|
||||
? const EmptyState()
|
||||
: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
|
@ -28,9 +28,10 @@ class DeviceFoldersGridViewWidget extends StatelessWidget {
|
|||
physics: const ScrollPhysics(),
|
||||
// to disable GridView's scrolling
|
||||
itemBuilder: (context, index) {
|
||||
return DeviceFolderIcon(folders[index]);
|
||||
final devicePath = devicePathCollections[index];
|
||||
return DeviceFolderIcon(devicePath);
|
||||
},
|
||||
itemCount: folders.length,
|
||||
itemCount: devicePathCollections.length,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:logging/logging.dart';
|
||||
import 'package:photos/core/configuration.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/db/device_files_db.dart';
|
||||
import 'package:photos/db/files_db.dart';
|
||||
import 'package:photos/events/backup_folders_updated_event.dart';
|
||||
import 'package:photos/events/collection_updated_event.dart';
|
||||
|
@ -91,6 +92,8 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget>
|
|||
final collectionsService = CollectionsService.instance;
|
||||
final userID = Configuration.instance.getUserID();
|
||||
final List<DeviceFolder> folders = [];
|
||||
final List<DevicePathCollection> devicePathCollections =
|
||||
await filesDB.getDevicePathCollections();
|
||||
final latestLocalFiles = await filesDB.getLatestLocalFiles();
|
||||
for (final file in latestLocalFiles) {
|
||||
folders.add(DeviceFolder(file.deviceFolder, file.deviceFolder, file));
|
||||
|
@ -123,7 +126,7 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget>
|
|||
}
|
||||
},
|
||||
);
|
||||
return CollectionItems(folders, collectionsWithThumbnail);
|
||||
return CollectionItems(devicePathCollections, collectionsWithThumbnail);
|
||||
}
|
||||
|
||||
Widget _getCollectionsGalleryWidget(CollectionItems items) {
|
||||
|
@ -157,12 +160,12 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget>
|
|||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
items.folders.isEmpty
|
||||
items.devicePathCollections.isEmpty
|
||||
? const Padding(
|
||||
padding: EdgeInsets.all(22),
|
||||
child: EmptyState(),
|
||||
)
|
||||
: DeviceFoldersGridViewWidget(items.folders),
|
||||
: DeviceFoldersGridViewWidget(items.devicePathCollections),
|
||||
const Padding(padding: EdgeInsets.all(4)),
|
||||
const Divider(),
|
||||
Row(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:photos/core/configuration.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/db/device_files_db.dart';
|
||||
import 'package:photos/db/files_db.dart';
|
||||
import 'package:photos/ente_theme_data.dart';
|
||||
import 'package:photos/events/backup_folders_updated_event.dart';
|
||||
|
@ -14,17 +15,17 @@ import 'package:photos/ui/viewer/gallery/gallery_app_bar_widget.dart';
|
|||
import 'package:photos/ui/viewer/gallery/gallery_overlay_widget.dart';
|
||||
|
||||
class DeviceFolderPage extends StatelessWidget {
|
||||
final DeviceFolder folder;
|
||||
final DevicePathCollection devicePathCollection;
|
||||
final _selectedFiles = SelectedFiles();
|
||||
|
||||
DeviceFolderPage(this.folder, {Key key}) : super(key: key);
|
||||
DeviceFolderPage(this.devicePathCollection, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(Object context) {
|
||||
final gallery = Gallery(
|
||||
asyncLoader: (creationStartTime, creationEndTime, {limit, asc}) {
|
||||
return FilesDB.instance.getFilesInPath(
|
||||
folder.path,
|
||||
return FilesDB.instance.getFilesInDevicePathCollection(
|
||||
devicePathCollection,
|
||||
creationStartTime,
|
||||
creationEndTime,
|
||||
limit: limit,
|
||||
|
@ -36,21 +37,21 @@ class DeviceFolderPage extends StatelessWidget {
|
|||
EventType.deletedFromDevice,
|
||||
EventType.deletedFromEverywhere,
|
||||
},
|
||||
tagPrefix: "device_folder:" + folder.path,
|
||||
tagPrefix: "device_folder:" + devicePathCollection.name,
|
||||
selectedFiles: _selectedFiles,
|
||||
header: Configuration.instance.hasConfiguredAccount()
|
||||
? _getHeaderWidget()
|
||||
: Container(),
|
||||
initialFiles: [folder.thumbnail],
|
||||
initialFiles: [devicePathCollection.thumbnail],
|
||||
);
|
||||
return Scaffold(
|
||||
appBar: PreferredSize(
|
||||
preferredSize: const Size.fromHeight(50.0),
|
||||
child: GalleryAppBarWidget(
|
||||
GalleryType.localFolder,
|
||||
folder.name,
|
||||
devicePathCollection.name,
|
||||
_selectedFiles,
|
||||
path: folder.thumbnail.deviceFolder,
|
||||
path: devicePathCollection.thumbnail.deviceFolder,
|
||||
),
|
||||
),
|
||||
body: Stack(
|
||||
|
@ -67,7 +68,7 @@ class DeviceFolderPage extends StatelessWidget {
|
|||
}
|
||||
|
||||
Widget _getHeaderWidget() {
|
||||
return BackupConfigurationHeaderWidget(folder.path);
|
||||
return BackupConfigurationHeaderWidget(devicePathCollection.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue