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/db/files_db.dart';
|
||||||
import 'package:photos/models/device_folder.dart';
|
import 'package:photos/models/device_folder.dart';
|
||||||
import 'package:photos/models/file.dart';
|
import 'package:photos/models/file.dart';
|
||||||
|
import 'package:photos/models/file_load_result.dart';
|
||||||
import 'package:sqflite/sqlite_api.dart';
|
import 'package:sqflite/sqlite_api.dart';
|
||||||
|
|
||||||
extension DeviceFiles on FilesDB {
|
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 {
|
Future<List<DevicePathCollection>> getDevicePathCollections() async {
|
||||||
debugPrint("Fetching DevicePathCollections From DB");
|
debugPrint("Fetching DevicePathCollections From DB");
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -3,10 +3,10 @@ import 'package:photos/models/device_folder.dart';
|
||||||
import 'package:photos/models/file.dart';
|
import 'package:photos/models/file.dart';
|
||||||
|
|
||||||
class CollectionItems {
|
class CollectionItems {
|
||||||
final List<DeviceFolder> folders;
|
final List<DevicePathCollection> devicePathCollections;
|
||||||
final List<CollectionWithThumbnail> collections;
|
final List<CollectionWithThumbnail> collections;
|
||||||
|
|
||||||
CollectionItems(this.folders, this.collections);
|
CollectionItems(this.devicePathCollections, this.collections);
|
||||||
}
|
}
|
||||||
|
|
||||||
class CollectionWithThumbnail {
|
class CollectionWithThumbnail {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import 'package:photos/utils/navigation_util.dart';
|
||||||
|
|
||||||
class DeviceFolderIcon extends StatelessWidget {
|
class DeviceFolderIcon extends StatelessWidget {
|
||||||
const DeviceFolderIcon(
|
const DeviceFolderIcon(
|
||||||
this.folder, {
|
this.devicePathCollection, {
|
||||||
Key key,
|
Key key,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@ -36,12 +36,13 @@ class DeviceFolderIcon extends StatelessWidget {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final DeviceFolder folder;
|
final DevicePathCollection devicePathCollection;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final isBackedUp =
|
final isBackedUp = Configuration.instance
|
||||||
Configuration.instance.getPathsToBackUp().contains(folder.path);
|
.getPathsToBackUp()
|
||||||
|
.contains(devicePathCollection.name);
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 2),
|
padding: const EdgeInsets.symmetric(horizontal: 2),
|
||||||
|
@ -56,17 +57,18 @@ class DeviceFolderIcon extends StatelessWidget {
|
||||||
height: 120,
|
height: 120,
|
||||||
width: 120,
|
width: 120,
|
||||||
child: Hero(
|
child: Hero(
|
||||||
tag:
|
tag: "device_folder:" +
|
||||||
"device_folder:" + folder.path + folder.thumbnail.tag(),
|
devicePathCollection.name +
|
||||||
|
devicePathCollection.thumbnail.tag(),
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
ThumbnailWidget(
|
ThumbnailWidget(
|
||||||
folder.thumbnail,
|
devicePathCollection.thumbnail,
|
||||||
shouldShowSyncStatus: false,
|
shouldShowSyncStatus: false,
|
||||||
key: Key(
|
key: Key(
|
||||||
"device_folder:" +
|
"device_folder:" +
|
||||||
folder.path +
|
devicePathCollection.name +
|
||||||
folder.thumbnail.tag(),
|
devicePathCollection.thumbnail.tag(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
isBackedUp ? Container() : kUnsyncedIconOverlay,
|
isBackedUp ? Container() : kUnsyncedIconOverlay,
|
||||||
|
@ -78,7 +80,7 @@ class DeviceFolderIcon extends StatelessWidget {
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(top: 10),
|
padding: const EdgeInsets.only(top: 10),
|
||||||
child: Text(
|
child: Text(
|
||||||
folder.name,
|
devicePathCollection.name,
|
||||||
style: Theme.of(context)
|
style: Theme.of(context)
|
||||||
.textTheme
|
.textTheme
|
||||||
.subtitle1
|
.subtitle1
|
||||||
|
@ -91,7 +93,7 @@ class DeviceFolderIcon extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onTap: () {
|
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';
|
import 'package:photos/ui/viewer/gallery/empte_state.dart';
|
||||||
|
|
||||||
class DeviceFoldersGridViewWidget extends StatelessWidget {
|
class DeviceFoldersGridViewWidget extends StatelessWidget {
|
||||||
final List<DeviceFolder> folders;
|
final List<DevicePathCollection> devicePathCollections;
|
||||||
|
|
||||||
const DeviceFoldersGridViewWidget(
|
const DeviceFoldersGridViewWidget(
|
||||||
this.folders, {
|
this.devicePathCollections, {
|
||||||
Key key,
|
Key key,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class DeviceFoldersGridViewWidget extends StatelessWidget {
|
||||||
height: 170,
|
height: 170,
|
||||||
child: Align(
|
child: Align(
|
||||||
alignment: Alignment.centerLeft,
|
alignment: Alignment.centerLeft,
|
||||||
child: folders.isEmpty
|
child: devicePathCollections.isEmpty
|
||||||
? const EmptyState()
|
? const EmptyState()
|
||||||
: ListView.builder(
|
: ListView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
|
@ -28,9 +28,10 @@ class DeviceFoldersGridViewWidget extends StatelessWidget {
|
||||||
physics: const ScrollPhysics(),
|
physics: const ScrollPhysics(),
|
||||||
// to disable GridView's scrolling
|
// to disable GridView's scrolling
|
||||||
itemBuilder: (context, index) {
|
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:logging/logging.dart';
|
||||||
import 'package:photos/core/configuration.dart';
|
import 'package:photos/core/configuration.dart';
|
||||||
import 'package:photos/core/event_bus.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/db/files_db.dart';
|
||||||
import 'package:photos/events/backup_folders_updated_event.dart';
|
import 'package:photos/events/backup_folders_updated_event.dart';
|
||||||
import 'package:photos/events/collection_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 collectionsService = CollectionsService.instance;
|
||||||
final userID = Configuration.instance.getUserID();
|
final userID = Configuration.instance.getUserID();
|
||||||
final List<DeviceFolder> folders = [];
|
final List<DeviceFolder> folders = [];
|
||||||
|
final List<DevicePathCollection> devicePathCollections =
|
||||||
|
await filesDB.getDevicePathCollections();
|
||||||
final latestLocalFiles = await filesDB.getLatestLocalFiles();
|
final latestLocalFiles = await filesDB.getLatestLocalFiles();
|
||||||
for (final file in latestLocalFiles) {
|
for (final file in latestLocalFiles) {
|
||||||
folders.add(DeviceFolder(file.deviceFolder, file.deviceFolder, file));
|
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) {
|
Widget _getCollectionsGalleryWidget(CollectionItems items) {
|
||||||
|
@ -157,12 +160,12 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget>
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
items.folders.isEmpty
|
items.devicePathCollections.isEmpty
|
||||||
? const Padding(
|
? const Padding(
|
||||||
padding: EdgeInsets.all(22),
|
padding: EdgeInsets.all(22),
|
||||||
child: EmptyState(),
|
child: EmptyState(),
|
||||||
)
|
)
|
||||||
: DeviceFoldersGridViewWidget(items.folders),
|
: DeviceFoldersGridViewWidget(items.devicePathCollections),
|
||||||
const Padding(padding: EdgeInsets.all(4)),
|
const Padding(padding: EdgeInsets.all(4)),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
Row(
|
Row(
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:photos/core/configuration.dart';
|
import 'package:photos/core/configuration.dart';
|
||||||
import 'package:photos/core/event_bus.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/db/files_db.dart';
|
||||||
import 'package:photos/ente_theme_data.dart';
|
import 'package:photos/ente_theme_data.dart';
|
||||||
import 'package:photos/events/backup_folders_updated_event.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';
|
import 'package:photos/ui/viewer/gallery/gallery_overlay_widget.dart';
|
||||||
|
|
||||||
class DeviceFolderPage extends StatelessWidget {
|
class DeviceFolderPage extends StatelessWidget {
|
||||||
final DeviceFolder folder;
|
final DevicePathCollection devicePathCollection;
|
||||||
final _selectedFiles = SelectedFiles();
|
final _selectedFiles = SelectedFiles();
|
||||||
|
|
||||||
DeviceFolderPage(this.folder, {Key key}) : super(key: key);
|
DeviceFolderPage(this.devicePathCollection, {Key key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(Object context) {
|
Widget build(Object context) {
|
||||||
final gallery = Gallery(
|
final gallery = Gallery(
|
||||||
asyncLoader: (creationStartTime, creationEndTime, {limit, asc}) {
|
asyncLoader: (creationStartTime, creationEndTime, {limit, asc}) {
|
||||||
return FilesDB.instance.getFilesInPath(
|
return FilesDB.instance.getFilesInDevicePathCollection(
|
||||||
folder.path,
|
devicePathCollection,
|
||||||
creationStartTime,
|
creationStartTime,
|
||||||
creationEndTime,
|
creationEndTime,
|
||||||
limit: limit,
|
limit: limit,
|
||||||
|
@ -36,21 +37,21 @@ class DeviceFolderPage extends StatelessWidget {
|
||||||
EventType.deletedFromDevice,
|
EventType.deletedFromDevice,
|
||||||
EventType.deletedFromEverywhere,
|
EventType.deletedFromEverywhere,
|
||||||
},
|
},
|
||||||
tagPrefix: "device_folder:" + folder.path,
|
tagPrefix: "device_folder:" + devicePathCollection.name,
|
||||||
selectedFiles: _selectedFiles,
|
selectedFiles: _selectedFiles,
|
||||||
header: Configuration.instance.hasConfiguredAccount()
|
header: Configuration.instance.hasConfiguredAccount()
|
||||||
? _getHeaderWidget()
|
? _getHeaderWidget()
|
||||||
: Container(),
|
: Container(),
|
||||||
initialFiles: [folder.thumbnail],
|
initialFiles: [devicePathCollection.thumbnail],
|
||||||
);
|
);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: PreferredSize(
|
appBar: PreferredSize(
|
||||||
preferredSize: const Size.fromHeight(50.0),
|
preferredSize: const Size.fromHeight(50.0),
|
||||||
child: GalleryAppBarWidget(
|
child: GalleryAppBarWidget(
|
||||||
GalleryType.localFolder,
|
GalleryType.localFolder,
|
||||||
folder.name,
|
devicePathCollection.name,
|
||||||
_selectedFiles,
|
_selectedFiles,
|
||||||
path: folder.thumbnail.deviceFolder,
|
path: devicePathCollection.thumbnail.deviceFolder,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
body: Stack(
|
body: Stack(
|
||||||
|
@ -67,7 +68,7 @@ class DeviceFolderPage extends StatelessWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _getHeaderWidget() {
|
Widget _getHeaderWidget() {
|
||||||
return BackupConfigurationHeaderWidget(folder.path);
|
return BackupConfigurationHeaderWidget(devicePathCollection.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue