handle moving entries to source directory
This commit is contained in:
parent
4a61d64a4d
commit
d6b233ac2c
3 changed files with 63 additions and 50 deletions
|
@ -16,6 +16,7 @@ import deckers.thibault.aves.utils.MimeTypes
|
||||||
import deckers.thibault.aves.utils.MimeTypes.isImage
|
import deckers.thibault.aves.utils.MimeTypes.isImage
|
||||||
import deckers.thibault.aves.utils.MimeTypes.isVideo
|
import deckers.thibault.aves.utils.MimeTypes.isVideo
|
||||||
import deckers.thibault.aves.utils.StorageUtils.createDirectoryIfAbsent
|
import deckers.thibault.aves.utils.StorageUtils.createDirectoryIfAbsent
|
||||||
|
import deckers.thibault.aves.utils.StorageUtils.ensureTrailingSeparator
|
||||||
import deckers.thibault.aves.utils.StorageUtils.getDocumentFile
|
import deckers.thibault.aves.utils.StorageUtils.getDocumentFile
|
||||||
import deckers.thibault.aves.utils.StorageUtils.requireAccessPermission
|
import deckers.thibault.aves.utils.StorageUtils.requireAccessPermission
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -265,7 +266,16 @@ class MediaStoreImageProvider : ImageProvider() {
|
||||||
val future = SettableFuture.create<FieldMap>()
|
val future = SettableFuture.create<FieldMap>()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val sourceFileName = File(sourcePath).name
|
val sourceFile = File(sourcePath)
|
||||||
|
val sourceDir = sourceFile.parent?.let { ensureTrailingSeparator(it) }
|
||||||
|
if (sourceDir == destinationDir) {
|
||||||
|
if (copy) {
|
||||||
|
future.setException(Exception("file at path=$sourcePath is already in destination directory"))
|
||||||
|
} else {
|
||||||
|
future.set(HashMap<String, Any?>())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val sourceFileName = sourceFile.name
|
||||||
val desiredNameWithoutExtension = sourceFileName.replaceFirst("[.][^.]+$".toRegex(), "")
|
val desiredNameWithoutExtension = sourceFileName.replaceFirst("[.][^.]+$".toRegex(), "")
|
||||||
|
|
||||||
// the file created from a `TreeDocumentFile` is also a `TreeDocumentFile`
|
// the file created from a `TreeDocumentFile` is also a `TreeDocumentFile`
|
||||||
|
@ -310,6 +320,7 @@ class MediaStoreImageProvider : ImageProvider() {
|
||||||
future.setException(throwable)
|
future.setException(throwable)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(LOG_TAG, "failed to ${(if (copy) "copy" else "move")} entry", e)
|
Log.e(LOG_TAG, "failed to ${(if (copy) "copy" else "move")} entry", e)
|
||||||
future.setException(e)
|
future.setException(e)
|
||||||
|
|
|
@ -136,14 +136,16 @@ class CollectionSource with SourceBase, AlbumMixin, LocationMixin, TagMixin {
|
||||||
await metadataDb.saveAddresses(movedEntries.map((entry) => entry.addressDetails));
|
await metadataDb.saveAddresses(movedEntries.map((entry) => entry.addressDetails));
|
||||||
} else {
|
} else {
|
||||||
await Future.forEach<MoveOpEvent>(movedOps, (movedOp) async {
|
await Future.forEach<MoveOpEvent>(movedOps, (movedOp) async {
|
||||||
final sourceUri = movedOp.uri;
|
|
||||||
final newFields = movedOp.newFields;
|
final newFields = movedOp.newFields;
|
||||||
|
if (newFields.isNotEmpty) {
|
||||||
|
final sourceUri = movedOp.uri;
|
||||||
final entry = selection.firstWhere((entry) => entry.uri == sourceUri, orElse: () => null);
|
final entry = selection.firstWhere((entry) => entry.uri == sourceUri, orElse: () => null);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
fromAlbums.add(entry.directory);
|
fromAlbums.add(entry.directory);
|
||||||
movedEntries.add(entry);
|
movedEntries.add(entry);
|
||||||
await moveEntry(entry, newFields);
|
await moveEntry(entry, newFields);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ class SelectionActionDelegate with FeedbackMixin, PermissionAwareMixin {
|
||||||
final selectionCount = selection.length;
|
final selectionCount = selection.length;
|
||||||
if (movedCount < selectionCount) {
|
if (movedCount < selectionCount) {
|
||||||
final count = selectionCount - movedCount;
|
final count = selectionCount - movedCount;
|
||||||
showFeedback(context, 'Failed to move ${Intl.plural(count, one: '$count item', other: '$count items')}');
|
showFeedback(context, 'Failed to ${copy ? 'copy' : 'move'} ${Intl.plural(count, one: '$count item', other: '$count items')}');
|
||||||
} else {
|
} else {
|
||||||
final count = movedCount;
|
final count = movedCount;
|
||||||
showFeedback(context, '${copy ? 'Copied' : 'Moved'} ${Intl.plural(count, one: '$count item', other: '$count items')}');
|
showFeedback(context, '${copy ? 'Copied' : 'Moved'} ${Intl.plural(count, one: '$count item', other: '$count items')}');
|
||||||
|
|
Loading…
Reference in a new issue