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<>();
|
||||
// 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 {
|
||||
Cursor cursor = context.getContentResolver().query(contentUri, projection, null, null, null);
|
||||
if (cursor != null) {
|
||||
|
@ -269,6 +272,7 @@ public abstract class ImageProvider {
|
|||
newFields.put("contentId", contentId);
|
||||
newFields.put("path", path);
|
||||
newFields.put("title", cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.TITLE)));
|
||||
newFields.put("dateModifiedSecs", cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATE_MODIFIED)));
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ class ImageEntry {
|
|||
int orientationDegrees;
|
||||
final int sizeBytes;
|
||||
String sourceTitle;
|
||||
final int dateModifiedSecs;
|
||||
int _dateModifiedSecs;
|
||||
final int sourceDateTakenMillis;
|
||||
final int durationMillis;
|
||||
int _catalogDateMillis;
|
||||
|
@ -44,18 +44,20 @@ class ImageEntry {
|
|||
this.orientationDegrees,
|
||||
this.sizeBytes,
|
||||
this.sourceTitle,
|
||||
this.dateModifiedSecs,
|
||||
int dateModifiedSecs,
|
||||
this.sourceDateTakenMillis,
|
||||
this.durationMillis,
|
||||
}) : assert(width != null),
|
||||
assert(height != null) {
|
||||
this.path = path;
|
||||
this.dateModifiedSecs = dateModifiedSecs;
|
||||
}
|
||||
|
||||
ImageEntry copyWith({
|
||||
@required String uri,
|
||||
@required String path,
|
||||
@required int contentId,
|
||||
@required int dateModifiedSecs,
|
||||
}) {
|
||||
final copyContentId = contentId ?? this.contentId;
|
||||
final copied = ImageEntry(
|
||||
|
@ -202,6 +204,13 @@ class ImageEntry {
|
|||
return _bestDate;
|
||||
}
|
||||
|
||||
int get dateModifiedSecs => _dateModifiedSecs;
|
||||
|
||||
set dateModifiedSecs(int dateModifiedSecs) {
|
||||
_dateModifiedSecs = dateModifiedSecs;
|
||||
_bestDate = null;
|
||||
}
|
||||
|
||||
DateTime get monthTaken {
|
||||
final d = bestDate;
|
||||
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');
|
||||
}
|
||||
|
||||
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) {
|
||||
if (entry == null) return;
|
||||
batch.insert(
|
||||
|
|
|
@ -136,6 +136,7 @@ class SelectionActionDelegate with FeedbackMixin, PermissionAwareMixin {
|
|||
uri: newFields['uri'] as String,
|
||||
path: newFields['path'] as String,
|
||||
contentId: newFields['contentId'] as int,
|
||||
dateModifiedSecs: newFields['dateModifiedSecs'] as int,
|
||||
));
|
||||
});
|
||||
await metadataDb.saveMetadata(movedEntries.map((entry) => entry.catalogMetadata));
|
||||
|
@ -151,9 +152,13 @@ class SelectionActionDelegate with FeedbackMixin, PermissionAwareMixin {
|
|||
final newContentId = newFields['contentId'] as int;
|
||||
entry.uri = newFields['uri'] as String;
|
||||
entry.path = newFields['path'] as String;
|
||||
entry.dateModifiedSecs = newFields['dateModifiedSecs'] as int;
|
||||
entry.contentId = newContentId;
|
||||
entry.catalogMetadata = entry.catalogMetadata?.copyWith(contentId: newContentId);
|
||||
entry.addressDetails = entry.addressDetails?.copyWith(contentId: newContentId);
|
||||
movedEntries.add(entry);
|
||||
|
||||
await metadataDb.updateEntryId(oldContentId, entry);
|
||||
await metadataDb.updateMetadataId(oldContentId, entry.catalogMetadata);
|
||||
await metadataDb.updateAddressId(oldContentId, entry.addressDetails);
|
||||
await favourites.move(oldContentId, entry);
|
||||
|
|
Loading…
Reference in a new issue