Skip to content

Commit

Permalink
tag_browse: add support for editing images in bulk
Browse files Browse the repository at this point in the history
  • Loading branch information
resucutie committed Sep 2, 2024
1 parent 1f1a46f commit 061e241
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
12 changes: 9 additions & 3 deletions lib/views/image_manager/shell.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:collection/collection.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
Expand Down Expand Up @@ -53,13 +54,18 @@ class _ImageManagerShellState extends State<ImageManagerShell> {

final booru = await getCurrentBooru();
final listLength = await booru.getListLength();
final futureImageIDs = preset.pages!.asMap().keys.map((index) => "${index + listLength}").toList();

final List<ImageID> imaginaryIDs = preset.pages!.mapIndexed((index, preset) {
if(preset.replaceID != null) return preset.replaceID!;
return "${index + listLength}";
}).toList();

for (final (index, imagePreset) in preset.pages!.indexed) {
if(isCorelated && preset.pages!.length > 1) {
imagePreset.relatedImages = futureImageIDs.where((e) => e != futureImageIDs[index]).toList();
final selfID = imaginaryIDs[index];
imagePreset.relatedImages = imaginaryIDs.where((id) => id != selfID).toList();
}
imagePreset.replaceID ??= futureImageIDs[index];
imagePreset.replaceID ??= imaginaryIDs[index];

await insertImage(imagePreset);
setState(() => savedImages++);
Expand Down
9 changes: 6 additions & 3 deletions lib/views/navigation/tag_browse.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,14 @@ class _GalleryViewerState extends State<GalleryViewer> {
backgroundColor: Theme.of(context).colorScheme.surfaceContainerHighest,
leading: CloseButton(onPressed: () => setState(() => _selectedImages = []),),
actions: [
if(_selectedImages.length == 1) IconButton(
IconButton(
icon: const Icon(Icons.edit),
onPressed: () async {
context.push("/manage_image", extra: PresetManageImageSendable(await PresetImage.fromExistingImage(snapshot.data!["images"].firstWhere((element) => element.id == _selectedImages[0]))));
setState(() => _selectedImages = []);
final sendable = PresetListManageImageSendable(await Future.wait(_selectedImages.map((e) => PresetImage.fromExistingImage((snapshot.data!["images"] as List<BooruImage>).firstWhere((image) => image.id == e)))));
if(context.mounted) {
context.push("/manage_image", extra: sendable);
setState(() => _selectedImages = []);
}
},
),
PopupMenuButton(itemBuilder: (context) {
Expand Down

0 comments on commit 061e241

Please sign in to comment.