fixed id & date of moved entries
This commit is contained in:
parent
a44f16087a
commit
5029b19ebe
4 changed files with 29 additions and 3 deletions
|
@ -260,7 +260,10 @@ public abstract class ImageProvider {
|
||||||
|
|
||||||
Map<String, Object> newFields = new HashMap<>();
|
Map<String, Object> newFields = new HashMap<>();
|
||||||
// we retrieve updated fields as the renamed file became a new entry in the Media Store
|
// we retrieve updated fields as the renamed file became a new entry in the Media Store
|
||||||
String[] projection = {MediaStore.MediaColumns.TITLE};
|
String[] projection = {
|
||||||
|
MediaStore.MediaColumns.TITLE,
|
||||||
|
MediaStore.MediaColumns.DATE_MODIFIED,
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
Cursor cursor = context.getContentResolver().query(contentUri, projection, null, null, null);
|
Cursor cursor = context.getContentResolver().query(contentUri, projection, null, null, null);
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
|
@ -269,6 +272,7 @@ public abstract class ImageProvider {
|
||||||
newFields.put("contentId", contentId);
|
newFields.put("contentId", contentId);
|
||||||
newFields.put("path", path);
|
newFields.put("path", path);
|
||||||
newFields.put("title", cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.TITLE)));
|
newFields.put("title", cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.TITLE)));
|
||||||
|
newFields.put("dateModifiedSecs", cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATE_MODIFIED)));
|
||||||
}
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ class ImageEntry {
|
||||||
int orientationDegrees;
|
int orientationDegrees;
|
||||||
final int sizeBytes;
|
final int sizeBytes;
|
||||||
String sourceTitle;
|
String sourceTitle;
|
||||||
final int dateModifiedSecs;
|
int _dateModifiedSecs;
|
||||||
final int sourceDateTakenMillis;
|
final int sourceDateTakenMillis;
|
||||||
final int durationMillis;
|
final int durationMillis;
|
||||||
int _catalogDateMillis;
|
int _catalogDateMillis;
|
||||||
|
@ -44,18 +44,20 @@ class ImageEntry {
|
||||||
this.orientationDegrees,
|
this.orientationDegrees,
|
||||||
this.sizeBytes,
|
this.sizeBytes,
|
||||||
this.sourceTitle,
|
this.sourceTitle,
|
||||||
this.dateModifiedSecs,
|
int dateModifiedSecs,
|
||||||
this.sourceDateTakenMillis,
|
this.sourceDateTakenMillis,
|
||||||
this.durationMillis,
|
this.durationMillis,
|
||||||
}) : assert(width != null),
|
}) : assert(width != null),
|
||||||
assert(height != null) {
|
assert(height != null) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
this.dateModifiedSecs = dateModifiedSecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageEntry copyWith({
|
ImageEntry copyWith({
|
||||||
@required String uri,
|
@required String uri,
|
||||||
@required String path,
|
@required String path,
|
||||||
@required int contentId,
|
@required int contentId,
|
||||||
|
@required int dateModifiedSecs,
|
||||||
}) {
|
}) {
|
||||||
final copyContentId = contentId ?? this.contentId;
|
final copyContentId = contentId ?? this.contentId;
|
||||||
final copied = ImageEntry(
|
final copied = ImageEntry(
|
||||||
|
@ -202,6 +204,13 @@ class ImageEntry {
|
||||||
return _bestDate;
|
return _bestDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get dateModifiedSecs => _dateModifiedSecs;
|
||||||
|
|
||||||
|
set dateModifiedSecs(int dateModifiedSecs) {
|
||||||
|
_dateModifiedSecs = dateModifiedSecs;
|
||||||
|
_bestDate = null;
|
||||||
|
}
|
||||||
|
|
||||||
DateTime get monthTaken {
|
DateTime get monthTaken {
|
||||||
final d = bestDate;
|
final d = bestDate;
|
||||||
return d == null ? null : DateTime(d.year, d.month);
|
return d == null ? null : DateTime(d.year, d.month);
|
||||||
|
|
|
@ -131,6 +131,14 @@ class MetadataDb {
|
||||||
debugPrint('$runtimeType saveEntries complete in ${stopwatch.elapsed.inMilliseconds}ms for ${entries.length} entries');
|
debugPrint('$runtimeType saveEntries complete in ${stopwatch.elapsed.inMilliseconds}ms for ${entries.length} entries');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> updateEntryId(int oldId, ImageEntry entry) async {
|
||||||
|
final db = await _database;
|
||||||
|
final batch = db.batch();
|
||||||
|
batch.delete(entryTable, where: 'contentId = ?', whereArgs: [oldId]);
|
||||||
|
_batchInsertEntry(batch, entry);
|
||||||
|
await batch.commit(noResult: true);
|
||||||
|
}
|
||||||
|
|
||||||
void _batchInsertEntry(Batch batch, ImageEntry entry) {
|
void _batchInsertEntry(Batch batch, ImageEntry entry) {
|
||||||
if (entry == null) return;
|
if (entry == null) return;
|
||||||
batch.insert(
|
batch.insert(
|
||||||
|
|
|
@ -136,6 +136,7 @@ class SelectionActionDelegate with FeedbackMixin, PermissionAwareMixin {
|
||||||
uri: newFields['uri'] as String,
|
uri: newFields['uri'] as String,
|
||||||
path: newFields['path'] as String,
|
path: newFields['path'] as String,
|
||||||
contentId: newFields['contentId'] as int,
|
contentId: newFields['contentId'] as int,
|
||||||
|
dateModifiedSecs: newFields['dateModifiedSecs'] as int,
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
await metadataDb.saveMetadata(movedEntries.map((entry) => entry.catalogMetadata));
|
await metadataDb.saveMetadata(movedEntries.map((entry) => entry.catalogMetadata));
|
||||||
|
@ -151,9 +152,13 @@ class SelectionActionDelegate with FeedbackMixin, PermissionAwareMixin {
|
||||||
final newContentId = newFields['contentId'] as int;
|
final newContentId = newFields['contentId'] as int;
|
||||||
entry.uri = newFields['uri'] as String;
|
entry.uri = newFields['uri'] as String;
|
||||||
entry.path = newFields['path'] as String;
|
entry.path = newFields['path'] as String;
|
||||||
|
entry.dateModifiedSecs = newFields['dateModifiedSecs'] as int;
|
||||||
entry.contentId = newContentId;
|
entry.contentId = newContentId;
|
||||||
|
entry.catalogMetadata = entry.catalogMetadata?.copyWith(contentId: newContentId);
|
||||||
|
entry.addressDetails = entry.addressDetails?.copyWith(contentId: newContentId);
|
||||||
movedEntries.add(entry);
|
movedEntries.add(entry);
|
||||||
|
|
||||||
|
await metadataDb.updateEntryId(oldContentId, entry);
|
||||||
await metadataDb.updateMetadataId(oldContentId, entry.catalogMetadata);
|
await metadataDb.updateMetadataId(oldContentId, entry.catalogMetadata);
|
||||||
await metadataDb.updateAddressId(oldContentId, entry.addressDetails);
|
await metadataDb.updateAddressId(oldContentId, entry.addressDetails);
|
||||||
await favourites.move(oldContentId, entry);
|
await favourites.move(oldContentId, entry);
|
||||||
|
|
Loading…
Reference in a new issue