Reflect backup status for device folder
This commit is contained in:
@@ -39,8 +39,8 @@ class LocalDBMappers {
|
||||
isFavorite: (row['is_fav'] as int) == 1,
|
||||
title: row['title'] as String?,
|
||||
relativePath: row['relative_path'] as String?,
|
||||
createDateSecond: (row['created_at'] as int),
|
||||
modifiedDateSecond: (row['modified_at'] as int),
|
||||
createDateSecond: (row['created_at'] as int) ~/ 1000000,
|
||||
modifiedDateSecond: (row['modified_at'] as int) ~/ 1000000,
|
||||
mimeType: row['mime_type'] as String?,
|
||||
latitude: row['latitude'] as double?,
|
||||
longitude: row['longitude'] as double?,
|
||||
|
||||
@@ -39,11 +39,13 @@ const String deviceCollectionWithOneAssetQuery = '''
|
||||
WITH latest_per_path AS (
|
||||
SELECT
|
||||
dpa.path_id,
|
||||
MAX(a.created_at) as max_created
|
||||
MAX(a.created_at) as max_created,
|
||||
count(*) as asset_count
|
||||
FROM
|
||||
device_path_assets dpa
|
||||
JOIN
|
||||
assets a ON dpa.asset_id = a.id
|
||||
|
||||
GROUP BY
|
||||
dpa.path_id
|
||||
),
|
||||
@@ -51,7 +53,8 @@ ranked_assets AS (
|
||||
SELECT
|
||||
dpa.path_id,
|
||||
a.*,
|
||||
ROW_NUMBER() OVER (PARTITION BY dpa.path_id ORDER BY a.id) as rn
|
||||
ROW_NUMBER() OVER (PARTITION BY dpa.path_id ORDER BY a.id) as rn,
|
||||
lpp.asset_count
|
||||
FROM
|
||||
device_path_assets dpa
|
||||
JOIN
|
||||
@@ -61,11 +64,14 @@ ranked_assets AS (
|
||||
)
|
||||
SELECT
|
||||
dp.*,
|
||||
ra.*
|
||||
ra.*,
|
||||
pc.*
|
||||
FROM
|
||||
device_path dp
|
||||
JOIN
|
||||
ranked_assets ra ON dp.path_id = ra.path_id AND ra.rn = 1
|
||||
LEFT JOIN path_backup_config pc
|
||||
on dp.path_id = pc.device_path_id
|
||||
''';
|
||||
|
||||
class LocalAssertsParam {
|
||||
|
||||
33
mobile/apps/photos/lib/db/local/table/device_albums.dart
Normal file
33
mobile/apps/photos/lib/db/local/table/device_albums.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import "package:photo_manager/photo_manager.dart";
|
||||
import "package:photos/db/local/db.dart";
|
||||
import "package:photos/db/local/mappers.dart";
|
||||
import "package:photos/db/local/schema.dart";
|
||||
import "package:photos/models/device_collection.dart";
|
||||
import "package:photos/models/file/file.dart";
|
||||
import "package:photos/models/upload_strategy.dart";
|
||||
|
||||
extension DeviceAlbums on LocalDB {
|
||||
Future<List<DeviceCollection>> getDeviceCollections() async {
|
||||
final List<DeviceCollection> collections = [];
|
||||
final rows = await sqliteDB.getAll(deviceCollectionWithOneAssetQuery);
|
||||
for (final row in rows) {
|
||||
final path = LocalDBMappers.assetPath(row);
|
||||
AssetEntity? asset;
|
||||
if (row['id'] != null) {
|
||||
asset = LocalDBMappers.asset(row);
|
||||
}
|
||||
|
||||
collections.add(
|
||||
DeviceCollection(
|
||||
path,
|
||||
count: row['asset_count'] as int,
|
||||
thumbnail: asset != null ? EnteFile.fromAssetSync(asset) : null,
|
||||
shouldBackup: (row['should_backup'] as int) == 1,
|
||||
uploadStrategy: UploadStrategy.values[row['upload_strategy'] as int],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return collections;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
import "package:photo_manager/photo_manager.dart";
|
||||
import 'package:photos/models/file/file.dart';
|
||||
import 'package:photos/models/upload_strategy.dart';
|
||||
|
||||
class DeviceCollection {
|
||||
final String id;
|
||||
final String name;
|
||||
AssetPathEntity assetPathEntity;
|
||||
final int count;
|
||||
final bool shouldBackup;
|
||||
UploadStrategy uploadStrategy;
|
||||
final String? coverId;
|
||||
int? collectionID;
|
||||
EnteFile? thumbnail;
|
||||
|
||||
@@ -15,10 +14,16 @@ class DeviceCollection {
|
||||
return collectionID != null && collectionID! != -1;
|
||||
}
|
||||
|
||||
String get name {
|
||||
return assetPathEntity.name;
|
||||
}
|
||||
|
||||
String get id {
|
||||
return assetPathEntity.id;
|
||||
}
|
||||
|
||||
DeviceCollection(
|
||||
this.id,
|
||||
this.name, {
|
||||
this.coverId,
|
||||
this.assetPathEntity, {
|
||||
this.count = 0,
|
||||
this.collectionID,
|
||||
this.thumbnail,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import "package:photos/db/local/table/device_albums.dart";
|
||||
import "package:photos/models/device_collection.dart";
|
||||
import "package:photos/models/file/file.dart";
|
||||
import "package:photos/service_locator.dart";
|
||||
@@ -5,23 +6,7 @@ import "package:photos/services/local/import/local_import.dart";
|
||||
|
||||
extension DeviceAlbums on LocalImportService {
|
||||
Future<List<DeviceCollection>> getDeviceCollections() async {
|
||||
final cache = await getLocalAssetsCache();
|
||||
final pathToLatestAsset = cache.getPathToLatestAsset();
|
||||
final List<DeviceCollection> collections = [];
|
||||
for (final path in cache.assetPaths.values) {
|
||||
final asset = pathToLatestAsset[path.id];
|
||||
if (asset != null) {
|
||||
collections.add(
|
||||
DeviceCollection(
|
||||
path.id,
|
||||
path.name,
|
||||
count: cache.pathToAssetIDs[path.id]?.length ?? 0,
|
||||
thumbnail: asset,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
return collections;
|
||||
return localDB.getDeviceCollections();
|
||||
}
|
||||
|
||||
Future<List<EnteFile>> getAlbumFiles(String pathID) async {
|
||||
|
||||
@@ -38,7 +38,7 @@ class DeviceFolderPage extends StatelessWidget {
|
||||
final gallery = Gallery(
|
||||
asyncLoader: (creationStartTime, creationEndTime, {limit, asc}) async {
|
||||
final files = await localDB.getPathAssets(
|
||||
deviceCollection.id,
|
||||
deviceCollection.assetPathEntity.id,
|
||||
params: LocalAssertsParam(
|
||||
limit: limit,
|
||||
isAsc: asc ?? false,
|
||||
@@ -56,7 +56,7 @@ class DeviceFolderPage extends StatelessWidget {
|
||||
EventType.deletedFromEverywhere,
|
||||
EventType.hide,
|
||||
},
|
||||
tagPrefix: "device_folder:" + deviceCollection.name,
|
||||
tagPrefix: "device_folder:" + deviceCollection.assetPathEntity.name,
|
||||
selectedFiles: _selectedFiles,
|
||||
header: Configuration.instance.hasConfiguredAccount()
|
||||
? BackupHeaderWidget(deviceCollection)
|
||||
@@ -69,7 +69,7 @@ class DeviceFolderPage extends StatelessWidget {
|
||||
preferredSize: const Size.fromHeight(50.0),
|
||||
child: GalleryAppBarWidget(
|
||||
GalleryType.localFolder,
|
||||
deviceCollection.name,
|
||||
deviceCollection.assetPathEntity.name,
|
||||
_selectedFiles,
|
||||
deviceCollection: deviceCollection,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user