album renaming performance review (WIP)
This commit is contained in:
parent
96422e3340
commit
3355779f16
3 changed files with 9 additions and 9 deletions
|
@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -190,6 +191,9 @@ public class ImageFileHandler implements MethodChannel.MethodCallHandler {
|
||||||
result.error("renameDirectory-args", "failed because of missing arguments", null);
|
result.error("renameDirectory-args", "failed because of missing arguments", null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!dirPath.endsWith(File.separator)) {
|
||||||
|
dirPath += File.separator;
|
||||||
|
}
|
||||||
|
|
||||||
ImageProvider provider = new MediaStoreImageProvider();
|
ImageProvider provider = new MediaStoreImageProvider();
|
||||||
provider.renameDirectory(activity, dirPath, newName, new ImageProvider.AlbumRenameOpCallback() {
|
provider.renameDirectory(activity, dirPath, newName, new ImageProvider.AlbumRenameOpCallback() {
|
||||||
|
|
|
@ -90,11 +90,7 @@ public abstract class ImageProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("UnstableApiUsage")
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
public void renameDirectory(Context context, String oldDirPath, String newDirName, final AlbumRenameOpCallback callback) {
|
public void renameDirectory(Context context, final String oldDirPath, String newDirName, final AlbumRenameOpCallback callback) {
|
||||||
if (!oldDirPath.endsWith(File.separator)) {
|
|
||||||
oldDirPath += File.separator;
|
|
||||||
}
|
|
||||||
|
|
||||||
DocumentFileCompat destinationDirDocFile = StorageUtils.createDirectoryIfAbsent(context, oldDirPath);
|
DocumentFileCompat destinationDirDocFile = StorageUtils.createDirectoryIfAbsent(context, oldDirPath);
|
||||||
if (destinationDirDocFile == null) {
|
if (destinationDirDocFile == null) {
|
||||||
callback.onFailure(new Exception("failed to find directory at path=" + oldDirPath));
|
callback.onFailure(new Exception("failed to find directory at path=" + oldDirPath));
|
||||||
|
@ -118,15 +114,16 @@ public abstract class ImageProvider {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String[] oldEntryPaths = entries.stream().map(entry -> oldDirPath + entry.get("displayName")).toArray(String[]::new);
|
||||||
|
String[] mimeTypes = entries.stream().map(entry -> (String) entry.get("mimeType")).toArray(String[]::new);
|
||||||
|
MediaScannerConnection.scanFile(context, oldEntryPaths, mimeTypes, null);
|
||||||
|
|
||||||
List<SettableFuture<Map<String, Object>>> scanFutures = new ArrayList<>();
|
List<SettableFuture<Map<String, Object>>> scanFutures = new ArrayList<>();
|
||||||
String newDirPath = new File(oldDirPath).getParent() + File.separator + newDirName + File.separator;
|
String newDirPath = new File(oldDirPath).getParent() + File.separator + newDirName + File.separator;
|
||||||
for (Map<String, Object> entry : entries) {
|
for (Map<String, Object> entry : entries) {
|
||||||
String displayName = (String) entry.get("displayName");
|
String displayName = (String) entry.get("displayName");
|
||||||
String mimeType = (String) entry.get("mimeType");
|
String mimeType = (String) entry.get("mimeType");
|
||||||
|
|
||||||
String oldEntryPath = oldDirPath + displayName;
|
|
||||||
MediaScannerConnection.scanFile(context, new String[]{oldEntryPath}, new String[]{mimeType}, null);
|
|
||||||
|
|
||||||
SettableFuture<Map<String, Object>> scanFuture = SettableFuture.create();
|
SettableFuture<Map<String, Object>> scanFuture = SettableFuture.create();
|
||||||
scanFutures.add(scanFuture);
|
scanFutures.add(scanFuture);
|
||||||
String newEntryPath = newDirPath + displayName;
|
String newEntryPath = newDirPath + displayName;
|
||||||
|
|
|
@ -219,7 +219,6 @@ class _CollectionScrollViewState extends State<CollectionScrollView> {
|
||||||
text: 'No favourites',
|
text: 'No favourites',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
debugPrint('collection.filters=${collection.filters}');
|
|
||||||
if (collection.filters.any((filter) => filter is MimeFilter && filter.mime == MimeTypes.anyVideo)) {
|
if (collection.filters.any((filter) => filter is MimeFilter && filter.mime == MimeTypes.anyVideo)) {
|
||||||
return EmptyContent(
|
return EmptyContent(
|
||||||
icon: AIcons.video,
|
icon: AIcons.video,
|
||||||
|
|
Loading…
Reference in a new issue