mirror of
https://github.com/immich-app/immich.git
synced 2025-02-11 01:18:24 -05:00
fix(mobile): Fix for incorrectly naming edited files and structure change (#11741)
* Fix null name * Fix null name and Fix button * Remove extension correctly * Refactoring the code and formatting * formatting * Fix for the extension name
This commit is contained in:
parent
00a7b80184
commit
843345df4f
4 changed files with 88 additions and 68 deletions
|
@ -3,6 +3,7 @@ import 'package:crop_image/crop_image.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:immich_mobile/routing/router.dart';
|
import 'package:immich_mobile/routing/router.dart';
|
||||||
import 'package:immich_mobile/utils/hooks/crop_controller_hook.dart';
|
import 'package:immich_mobile/utils/hooks/crop_controller_hook.dart';
|
||||||
|
import 'package:immich_mobile/entities/asset.entity.dart';
|
||||||
import 'edit.page.dart';
|
import 'edit.page.dart';
|
||||||
import 'package:auto_route/auto_route.dart';
|
import 'package:auto_route/auto_route.dart';
|
||||||
|
|
||||||
|
@ -14,7 +15,8 @@ import 'package:auto_route/auto_route.dart';
|
||||||
@RoutePage()
|
@RoutePage()
|
||||||
class CropImagePage extends HookWidget {
|
class CropImagePage extends HookWidget {
|
||||||
final Image image;
|
final Image image;
|
||||||
const CropImagePage({super.key, required this.image});
|
final Asset asset;
|
||||||
|
const CropImagePage({super.key, required this.image, required this.asset});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -34,7 +36,13 @@ class CropImagePage extends HookWidget {
|
||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final croppedImage = await cropController.croppedImage();
|
final croppedImage = await cropController.croppedImage();
|
||||||
context.pushRoute(EditImageRoute(image: croppedImage));
|
context.pushRoute(
|
||||||
|
EditImageRoute(
|
||||||
|
asset: asset,
|
||||||
|
image: croppedImage,
|
||||||
|
isEdited: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
@ -12,6 +12,7 @@ import 'package:immich_mobile/widgets/common/immich_toast.dart';
|
||||||
import 'package:auto_route/auto_route.dart';
|
import 'package:auto_route/auto_route.dart';
|
||||||
import 'package:immich_mobile/routing/router.dart';
|
import 'package:immich_mobile/routing/router.dart';
|
||||||
import 'package:photo_manager/photo_manager.dart';
|
import 'package:photo_manager/photo_manager.dart';
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
import 'package:immich_mobile/providers/album/album.provider.dart';
|
import 'package:immich_mobile/providers/album/album.provider.dart';
|
||||||
|
|
||||||
/// A stateless widget that provides functionality for editing an image.
|
/// A stateless widget that provides functionality for editing an image.
|
||||||
|
@ -24,18 +25,16 @@ import 'package:immich_mobile/providers/album/album.provider.dart';
|
||||||
@immutable
|
@immutable
|
||||||
@RoutePage()
|
@RoutePage()
|
||||||
class EditImagePage extends ConsumerWidget {
|
class EditImagePage extends ConsumerWidget {
|
||||||
final Asset? asset;
|
final Asset asset;
|
||||||
final Image? image;
|
final Image image;
|
||||||
|
final bool isEdited;
|
||||||
|
|
||||||
const EditImagePage({
|
const EditImagePage({
|
||||||
super.key,
|
super.key,
|
||||||
this.image,
|
required this.asset,
|
||||||
this.asset,
|
required this.image,
|
||||||
}) : assert(
|
required this.isEdited,
|
||||||
(image != null && asset == null) || (image == null && asset != null),
|
});
|
||||||
'Must supply one of asset or image',
|
|
||||||
);
|
|
||||||
|
|
||||||
Future<Uint8List> _imageToUint8List(Image image) async {
|
Future<Uint8List> _imageToUint8List(Image image) async {
|
||||||
final Completer<Uint8List> completer = Completer();
|
final Completer<Uint8List> completer = Completer();
|
||||||
image.image.resolve(const ImageConfiguration()).addListener(
|
image.image.resolve(const ImageConfiguration()).addListener(
|
||||||
|
@ -58,19 +57,34 @@ class EditImagePage extends ConsumerWidget {
|
||||||
return completer.future;
|
return completer.future;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _saveEditedImage(
|
||||||
|
BuildContext context,
|
||||||
|
Asset asset,
|
||||||
|
Image image,
|
||||||
|
WidgetRef ref,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
final Uint8List imageData = await _imageToUint8List(image);
|
||||||
|
await PhotoManager.editor.saveImage(
|
||||||
|
imageData,
|
||||||
|
title: "${p.withoutExtension(asset.fileName)}_edited.jpg",
|
||||||
|
);
|
||||||
|
await ref.read(albumProvider.notifier).getDeviceAlbums();
|
||||||
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||||
|
} catch (e) {
|
||||||
|
ImmichToast.show(
|
||||||
|
durationInSecond: 6,
|
||||||
|
context: context,
|
||||||
|
msg: 'Error: $e',
|
||||||
|
gravity: ToastGravity.CENTER,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final ImageProvider provider = (asset != null)
|
final Image imageWidget =
|
||||||
? ImmichImage.imageProvider(asset: asset!)
|
Image(image: ImmichImage.imageProvider(asset: asset));
|
||||||
: (image != null)
|
|
||||||
? image!.image
|
|
||||||
: throw Exception('Invalid image source type');
|
|
||||||
|
|
||||||
final Image imageWidget = (asset != null)
|
|
||||||
? Image(image: ImmichImage.imageProvider(asset: asset!))
|
|
||||||
: (image != null)
|
|
||||||
? image!
|
|
||||||
: throw Exception('Invalid image source type');
|
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
|
@ -85,36 +99,16 @@ class EditImagePage extends ConsumerWidget {
|
||||||
Navigator.of(context).popUntil((route) => route.isFirst),
|
Navigator.of(context).popUntil((route) => route.isFirst),
|
||||||
),
|
),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
if (image != null)
|
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: isEdited
|
||||||
try {
|
? () => _saveEditedImage(context, asset, image, ref)
|
||||||
final Uint8List imageData = await _imageToUint8List(image!);
|
: null,
|
||||||
ImmichToast.show(
|
|
||||||
durationInSecond: 3,
|
|
||||||
context: context,
|
|
||||||
msg: 'Image Saved!',
|
|
||||||
gravity: ToastGravity.CENTER,
|
|
||||||
);
|
|
||||||
|
|
||||||
await PhotoManager.editor.saveImage(
|
|
||||||
imageData,
|
|
||||||
title: '${asset!.fileName}_edited.jpg',
|
|
||||||
);
|
|
||||||
await ref.read(albumProvider.notifier).getDeviceAlbums();
|
|
||||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
|
||||||
} catch (e) {
|
|
||||||
ImmichToast.show(
|
|
||||||
durationInSecond: 6,
|
|
||||||
context: context,
|
|
||||||
msg: 'Error: ${e.toString()}',
|
|
||||||
gravity: ToastGravity.BOTTOM,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: Text(
|
child: Text(
|
||||||
'Save to gallery',
|
'Save to gallery',
|
||||||
style: Theme.of(context).textTheme.displayMedium,
|
style: TextStyle(
|
||||||
|
color:
|
||||||
|
isEdited ? Theme.of(context).iconTheme.color : Colors.grey,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -122,7 +116,7 @@ class EditImagePage extends ConsumerWidget {
|
||||||
body: Column(
|
body: Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Image(image: provider),
|
child: image,
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
height: 80,
|
height: 80,
|
||||||
|
@ -148,7 +142,9 @@ class EditImagePage extends ConsumerWidget {
|
||||||
color: Theme.of(context).iconTheme.color,
|
color: Theme.of(context).iconTheme.color,
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
context.pushRoute(CropImageRoute(image: imageWidget));
|
context.pushRoute(
|
||||||
|
CropImageRoute(asset: asset, image: imageWidget),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Text('Crop', style: Theme.of(context).textTheme.displayMedium),
|
Text('Crop', style: Theme.of(context).textTheme.displayMedium),
|
||||||
|
|
|
@ -613,12 +613,14 @@ class CropImageRoute extends PageRouteInfo<CropImageRouteArgs> {
|
||||||
CropImageRoute({
|
CropImageRoute({
|
||||||
Key? key,
|
Key? key,
|
||||||
required Image image,
|
required Image image,
|
||||||
|
required Asset asset,
|
||||||
List<PageRouteInfo>? children,
|
List<PageRouteInfo>? children,
|
||||||
}) : super(
|
}) : super(
|
||||||
CropImageRoute.name,
|
CropImageRoute.name,
|
||||||
args: CropImageRouteArgs(
|
args: CropImageRouteArgs(
|
||||||
key: key,
|
key: key,
|
||||||
image: image,
|
image: image,
|
||||||
|
asset: asset,
|
||||||
),
|
),
|
||||||
initialChildren: children,
|
initialChildren: children,
|
||||||
);
|
);
|
||||||
|
@ -632,6 +634,7 @@ class CropImageRoute extends PageRouteInfo<CropImageRouteArgs> {
|
||||||
return CropImagePage(
|
return CropImagePage(
|
||||||
key: args.key,
|
key: args.key,
|
||||||
image: args.image,
|
image: args.image,
|
||||||
|
asset: args.asset,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -641,15 +644,18 @@ class CropImageRouteArgs {
|
||||||
const CropImageRouteArgs({
|
const CropImageRouteArgs({
|
||||||
this.key,
|
this.key,
|
||||||
required this.image,
|
required this.image,
|
||||||
|
required this.asset,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Key? key;
|
final Key? key;
|
||||||
|
|
||||||
final Image image;
|
final Image image;
|
||||||
|
|
||||||
|
final Asset asset;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'CropImageRouteArgs{key: $key, image: $image}';
|
return 'CropImageRouteArgs{key: $key, image: $image, asset: $asset}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,15 +664,17 @@ class CropImageRouteArgs {
|
||||||
class EditImageRoute extends PageRouteInfo<EditImageRouteArgs> {
|
class EditImageRoute extends PageRouteInfo<EditImageRouteArgs> {
|
||||||
EditImageRoute({
|
EditImageRoute({
|
||||||
Key? key,
|
Key? key,
|
||||||
Image? image,
|
required Asset asset,
|
||||||
Asset? asset,
|
required Image image,
|
||||||
|
required bool isEdited,
|
||||||
List<PageRouteInfo>? children,
|
List<PageRouteInfo>? children,
|
||||||
}) : super(
|
}) : super(
|
||||||
EditImageRoute.name,
|
EditImageRoute.name,
|
||||||
args: EditImageRouteArgs(
|
args: EditImageRouteArgs(
|
||||||
key: key,
|
key: key,
|
||||||
image: image,
|
|
||||||
asset: asset,
|
asset: asset,
|
||||||
|
image: image,
|
||||||
|
isEdited: isEdited,
|
||||||
),
|
),
|
||||||
initialChildren: children,
|
initialChildren: children,
|
||||||
);
|
);
|
||||||
|
@ -676,12 +684,12 @@ class EditImageRoute extends PageRouteInfo<EditImageRouteArgs> {
|
||||||
static PageInfo page = PageInfo(
|
static PageInfo page = PageInfo(
|
||||||
name,
|
name,
|
||||||
builder: (data) {
|
builder: (data) {
|
||||||
final args = data.argsAs<EditImageRouteArgs>(
|
final args = data.argsAs<EditImageRouteArgs>();
|
||||||
orElse: () => const EditImageRouteArgs());
|
|
||||||
return EditImagePage(
|
return EditImagePage(
|
||||||
key: args.key,
|
key: args.key,
|
||||||
image: args.image,
|
|
||||||
asset: args.asset,
|
asset: args.asset,
|
||||||
|
image: args.image,
|
||||||
|
isEdited: args.isEdited,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -690,19 +698,22 @@ class EditImageRoute extends PageRouteInfo<EditImageRouteArgs> {
|
||||||
class EditImageRouteArgs {
|
class EditImageRouteArgs {
|
||||||
const EditImageRouteArgs({
|
const EditImageRouteArgs({
|
||||||
this.key,
|
this.key,
|
||||||
this.image,
|
required this.asset,
|
||||||
this.asset,
|
required this.image,
|
||||||
|
required this.isEdited,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Key? key;
|
final Key? key;
|
||||||
|
|
||||||
final Image? image;
|
final Asset asset;
|
||||||
|
|
||||||
final Asset? asset;
|
final Image image;
|
||||||
|
|
||||||
|
final bool isEdited;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'EditImageRouteArgs{key: $key, image: $image, asset: $asset}';
|
return 'EditImageRouteArgs{key: $key, asset: $asset, image: $image, isEdited: $isEdited}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ import 'package:immich_mobile/widgets/asset_grid/asset_grid_data_structure.dart'
|
||||||
import 'package:immich_mobile/widgets/asset_viewer/video_controls.dart';
|
import 'package:immich_mobile/widgets/asset_viewer/video_controls.dart';
|
||||||
import 'package:immich_mobile/widgets/asset_grid/delete_dialog.dart';
|
import 'package:immich_mobile/widgets/asset_grid/delete_dialog.dart';
|
||||||
import 'package:immich_mobile/routing/router.dart';
|
import 'package:immich_mobile/routing/router.dart';
|
||||||
|
import 'package:immich_mobile/widgets/common/immich_image.dart';
|
||||||
import 'package:immich_mobile/entities/asset.entity.dart';
|
import 'package:immich_mobile/entities/asset.entity.dart';
|
||||||
import 'package:immich_mobile/providers/asset.provider.dart';
|
import 'package:immich_mobile/providers/asset.provider.dart';
|
||||||
import 'package:immich_mobile/providers/server_info.provider.dart';
|
import 'package:immich_mobile/providers/server_info.provider.dart';
|
||||||
|
@ -184,6 +185,7 @@ class BottomGalleryBar extends ConsumerWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleEdit() async {
|
void handleEdit() async {
|
||||||
|
final image = Image(image: ImmichImage.imageProvider(asset: asset));
|
||||||
if (asset.isOffline) {
|
if (asset.isOffline) {
|
||||||
ImmichToast.show(
|
ImmichToast.show(
|
||||||
durationInSecond: 1,
|
durationInSecond: 1,
|
||||||
|
@ -195,8 +197,11 @@ class BottomGalleryBar extends ConsumerWidget {
|
||||||
}
|
}
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) =>
|
builder: (context) => EditImagePage(
|
||||||
EditImagePage(asset: asset), // Send the Asset object
|
asset: asset,
|
||||||
|
image: image,
|
||||||
|
isEdited: false,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue