Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement catrobat-image save/load + refactor #2

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
include: package:flutter_lints/flutter.yaml
analyzer:
errors:
missing_enum_constant_in_switch: error
exhaustive_cases: error
exclude:
- lib/**.pb*.dart
53 changes: 53 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,67 @@
PODS:
- DKImagePickerController/Core (4.3.4):
- DKImagePickerController/ImageDataManager
- DKImagePickerController/Resource
- DKImagePickerController/ImageDataManager (4.3.4)
- DKImagePickerController/PhotoGallery (4.3.4):
- DKImagePickerController/Core
- DKPhotoGallery
- DKImagePickerController/Resource (4.3.4)
- DKPhotoGallery (0.0.17):
- DKPhotoGallery/Core (= 0.0.17)
- DKPhotoGallery/Model (= 0.0.17)
- DKPhotoGallery/Preview (= 0.0.17)
- DKPhotoGallery/Resource (= 0.0.17)
- SDWebImage
- SwiftyGif
- DKPhotoGallery/Core (0.0.17):
- DKPhotoGallery/Model
- DKPhotoGallery/Preview
- SDWebImage
- SwiftyGif
- DKPhotoGallery/Model (0.0.17):
- SDWebImage
- SwiftyGif
- DKPhotoGallery/Preview (0.0.17):
- DKPhotoGallery/Model
- DKPhotoGallery/Resource
- SDWebImage
- SwiftyGif
- DKPhotoGallery/Resource (0.0.17):
- SDWebImage
- SwiftyGif
- file_picker (0.0.1):
- DKImagePickerController/PhotoGallery
- Flutter
- Flutter (1.0.0)
- image_picker_ios (0.0.1):
- Flutter
- integration_test (0.0.1):
- Flutter
- path_provider_ios (0.0.1):
- Flutter
- SDWebImage (5.13.1):
- SDWebImage/Core (= 5.13.1)
- SDWebImage/Core (5.13.1)
- SwiftyGif (5.4.3)

DEPENDENCIES:
- file_picker (from `.symlinks/plugins/file_picker/ios`)
- Flutter (from `Flutter`)
- image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)

SPEC REPOS:
trunk:
- DKImagePickerController
- DKPhotoGallery
- SDWebImage
- SwiftyGif

EXTERNAL SOURCES:
file_picker:
:path: ".symlinks/plugins/file_picker/ios"
Flutter:
:path: Flutter
image_picker_ios:
Expand All @@ -24,10 +72,15 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/path_provider_ios/ios"

SPEC CHECKSUMS:
DKImagePickerController: b512c28220a2b8ac7419f21c491fc8534b7601ac
DKPhotoGallery: fdfad5125a9fdda9cc57df834d49df790dbb4179
file_picker: 817ab1d8cd2da9d2da412a417162deee3500fc95
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
image_picker_ios: b786a5dcf033a8336a657191401bfdf12017dabb
integration_test: a1e7d09bd98eca2fc37aefd79d4f41ad37bdbbe5
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
SDWebImage: fb26a455eeda4c7a55e4dcb6172dbb258af7a4ca
SwiftyGif: 6c3eafd0ce693cad58bb63d2b2fb9bacb8552780

PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c

Expand Down
5 changes: 5 additions & 0 deletions lib/command/src/command_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:ui';

import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'command.dart';
import 'graphic_command.dart';
import 'implementation/manager/sync_command_manager.dart';

Expand All @@ -10,9 +11,13 @@ abstract class CommandManager {
(ref) => SyncCommandManager(commands: []),
);

Iterable<Command> get commands;

void addGraphicCommand(GraphicCommand command);

void executeLastCommand(Canvas canvas);

void executeAllCommands(Canvas canvas);

void resetHistory({Iterable<Command>? newCommands});
}
14 changes: 12 additions & 2 deletions lib/command/src/implementation/manager/sync_command_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import '../../command_manager.dart';
import '../../graphic_command.dart';

class SyncCommandManager implements CommandManager {
SyncCommandManager({required List<Command> commands})
: _history = commands;
SyncCommandManager({required List<Command> commands}) : _history = commands;

final List<Command> _history;

@override
Iterable<Command> get commands => List.unmodifiable(_history);

@override
void addGraphicCommand(GraphicCommand command) {
_history.add(command);
Expand All @@ -32,4 +34,12 @@ class SyncCommandManager implements CommandManager {
}
}
}

@override
void resetHistory({Iterable<Command>? newCommands}) {
_history.clear();
if (newCommands != null) {
_history.addAll(newCommands);
}
}
}
2 changes: 1 addition & 1 deletion lib/core/loggable_mixin.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:logging/logging.dart';

mixin LoggableMixin {
late final log = Logger(runtimeType.toString());
late final logger = Logger(runtimeType.toString());
}
17 changes: 9 additions & 8 deletions lib/io/io.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
export 'src/entity/image_format.dart';
export 'src/entity/catrobat_image.dart';
export 'src/entity/image_meta_data.dart';
export 'src/failure/load_image_failure.dart';
export 'src/failure/save_image_failure.dart';
export 'src/serialization/proto/output/command/graphic/draw_path_command.pb.dart';
export 'src/serialization/proto/output/graphic/paint.pb.dart';
export 'src/serialization/proto/output/graphic/path.pb.dart';
export 'src/serialization/proto_serializer.dart';
export 'src/serialization/serializer.dart';
export 'src/serialization/serializer/catrobat_image_serializer.dart';
export 'src/service/file_service.dart';
export 'src/service/image_service.dart';
export 'src/service/photo_library_service.dart';
export 'src/ui/discard_changes_dialog.dart';
export 'src/ui/load_image_dialog.dart';
export 'src/ui/save_image_dialog.dart';
export 'src/usecase/load_image.dart';
export 'src/usecase/save_image.dart';
export 'src/usecase/load_image_from_photo_library.dart';
export 'src/usecase/save_as_catrobat_image.dart';
export 'src/usecase/save_as_raster_image.dart';
10 changes: 10 additions & 0 deletions lib/io/serialization.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export 'src/serialization/proto/output/catrobat_image.pb.dart';
export 'src/serialization/proto/output/command/graphic/draw_path_command.pb.dart';
export 'src/serialization/proto/output/google/protobuf/any.pb.dart';
export 'src/serialization/proto/output/graphic/paint.pb.dart';
export 'src/serialization/proto/output/graphic/path.pb.dart';
export 'src/serialization/proto_serializer_with_versioning.dart';
export 'src/serialization/serializer/command/graphic/draw_path_command_serializer.dart';
export 'src/serialization/serializer/graphic/paint_serializer.dart';
export 'src/serialization/serializer/graphic/path_serializer.dart';
export 'src/serialization/version_serializer.dart';
18 changes: 18 additions & 0 deletions lib/io/src/entity/catrobat_image.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'dart:typed_data';

import 'package:paintroid/command/command.dart' show Command;

class CatrobatImage {
static const magicValue = "CATROBAT";
static const latestVersion = 1;

final int version;
final Iterable<Command> commands;
final Uint8List? loadedImage;

const CatrobatImage(
this.commands,
this.loadedImage, {
this.version = latestVersion,
});
}
5 changes: 4 additions & 1 deletion lib/io/src/entity/image_format.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
part of 'image_meta_data.dart';

enum ImageFormat {
png("png"),
jpg("jpg");
jpg("jpg"),
catrobatImage("catrobat-image");

const ImageFormat(this.extension);

Expand Down
1 change: 1 addition & 0 deletions lib/io/src/entity/image_location.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enum ImageLocation { photos, files }
30 changes: 30 additions & 0 deletions lib/io/src/entity/image_meta_data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
part 'image_format.dart';

abstract class ImageMetaData {
final String name;
final ImageFormat format;

const ImageMetaData(this.name, this.format);

@override
String toString() => "$name.${format.extension}";
}

class JpgMetaData extends ImageMetaData {
/// Value between 1-100 (both inclusive)
final int quality;

const JpgMetaData(String name, this.quality) : super(name, ImageFormat.jpg);

@override
String toString() => "$name.${format.extension} - $quality%";
}

class PngMetaData extends ImageMetaData {
const PngMetaData(String name) : super(name, ImageFormat.png);
}

class CatrobatImageMetaData extends ImageMetaData {
const CatrobatImageMetaData(String name)
: super(name, ImageFormat.catrobatImage);
}
1 change: 1 addition & 0 deletions lib/io/src/failure/load_image_failure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ class LoadImageFailure extends Failure {
LoadImageFailure._("Permission to view photos is denied in settings");
static const userCancelled =
LoadImageFailure._("User did not choose an image");
static const invalidImage = LoadImageFailure._("Invalid image");
static const unidentified = LoadImageFailure._("Could not load image");
}
2 changes: 2 additions & 0 deletions lib/io/src/failure/save_image_failure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ class SaveImageFailure extends Failure {

static const permissionDenied =
SaveImageFailure._("Permission to save photos is denied in settings");
static const userCancelled =
SaveImageFailure._("User did not choose a save location");
static const unidentified = SaveImageFailure._("Could not save image");
}
2 changes: 1 addition & 1 deletion lib/io/src/serialization/proto/generate_protos.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
protoc --dart_out=output --proto_path=schema "$(find schema -iname "*.proto")"
protoc --dart_out=output --proto_path=schema $(find schema -iname "*.proto") google/protobuf/any.proto
90 changes: 90 additions & 0 deletions lib/io/src/serialization/proto/output/catrobat_image.pb.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
///
import 'dart:core' as $core;

import 'package:protobuf/protobuf.dart' as $pb;

import 'google/protobuf/any.pb.dart' as $2;

class SerializableCatrobatImage extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'SerializableCatrobatImage', createEmptyInstance: create)
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'magicValue', protoName: 'magicValue')
..a<$core.int>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'version', $pb.PbFieldType.O3)
..pc<$2.Any>(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'commands', $pb.PbFieldType.PM, subBuilder: $2.Any.create)
..a<$core.List<$core.int>>(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'loadedImage', $pb.PbFieldType.OY, protoName: 'loadedImage')
..hasRequiredFields = false
;

SerializableCatrobatImage._() : super();
factory SerializableCatrobatImage({
$core.String? magicValue,
$core.int? version,
$core.Iterable<$2.Any>? commands,
$core.List<$core.int>? loadedImage,
}) {
final _result = create();
if (magicValue != null) {
_result.magicValue = magicValue;
}
if (version != null) {
_result.version = version;
}
if (commands != null) {
_result.commands.addAll(commands);
}
if (loadedImage != null) {
_result.loadedImage = loadedImage;
}
return _result;
}
factory SerializableCatrobatImage.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory SerializableCatrobatImage.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
SerializableCatrobatImage clone() => SerializableCatrobatImage()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
SerializableCatrobatImage copyWith(void Function(SerializableCatrobatImage) updates) => super.copyWith((message) => updates(message as SerializableCatrobatImage)) as SerializableCatrobatImage; // ignore: deprecated_member_use
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static SerializableCatrobatImage create() => SerializableCatrobatImage._();
SerializableCatrobatImage createEmptyInstance() => create();
static $pb.PbList<SerializableCatrobatImage> createRepeated() => $pb.PbList<SerializableCatrobatImage>();
@$core.pragma('dart2js:noInline')
static SerializableCatrobatImage getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<SerializableCatrobatImage>(create);
static SerializableCatrobatImage? _defaultInstance;

@$pb.TagNumber(1)
$core.String get magicValue => $_getSZ(0);
@$pb.TagNumber(1)
set magicValue($core.String v) { $_setString(0, v); }
@$pb.TagNumber(1)
$core.bool hasMagicValue() => $_has(0);
@$pb.TagNumber(1)
void clearMagicValue() => clearField(1);

@$pb.TagNumber(2)
$core.int get version => $_getIZ(1);
@$pb.TagNumber(2)
set version($core.int v) { $_setSignedInt32(1, v); }
@$pb.TagNumber(2)
$core.bool hasVersion() => $_has(1);
@$pb.TagNumber(2)
void clearVersion() => clearField(2);

@$pb.TagNumber(3)
$core.List<$2.Any> get commands => $_getList(2);

@$pb.TagNumber(4)
$core.List<$core.int> get loadedImage => $_getN(3);
@$pb.TagNumber(4)
set loadedImage($core.List<$core.int> v) { $_setBytes(3, v); }
@$pb.TagNumber(4)
$core.bool hasLoadedImage() => $_has(3);
@$pb.TagNumber(4)
void clearLoadedImage() => clearField(4);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
///
// Generated code. Do not modify.
// source: catrobat_image.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides,camel_case_types,constant_identifier_names,directives_ordering,library_prefixes,non_constant_identifier_names,prefer_final_fields,return_of_invalid_type,unnecessary_const,unnecessary_import,unnecessary_this,unused_import,unused_shown_name

20 changes: 20 additions & 0 deletions lib/io/src/serialization/proto/output/catrobat_image.pbjson.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
///
import 'dart:convert' as $convert;
import 'dart:core' as $core;
import 'dart:typed_data' as $typed_data;
@$core.Deprecated('Use serializableCatrobatImageDescriptor instead')
const SerializableCatrobatImage$json = const {
'1': 'SerializableCatrobatImage',
'2': const [
const {'1': 'magicValue', '3': 1, '4': 1, '5': 9, '10': 'magicValue'},
const {'1': 'version', '3': 2, '4': 1, '5': 5, '10': 'version'},
const {'1': 'commands', '3': 3, '4': 3, '5': 11, '6': '.google.protobuf.Any', '10': 'commands'},
const {'1': 'loadedImage', '3': 4, '4': 1, '5': 12, '9': 0, '10': 'loadedImage', '17': true},
],
'8': const [
const {'1': '_loadedImage'},
],
};

/// Descriptor for `SerializableCatrobatImage`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List serializableCatrobatImageDescriptor = $convert.base64Decode('ChlTZXJpYWxpemFibGVDYXRyb2JhdEltYWdlEh4KCm1hZ2ljVmFsdWUYASABKAlSCm1hZ2ljVmFsdWUSGAoHdmVyc2lvbhgCIAEoBVIHdmVyc2lvbhIwCghjb21tYW5kcxgDIAMoCzIULmdvb2dsZS5wcm90b2J1Zi5BbnlSCGNvbW1hbmRzEiUKC2xvYWRlZEltYWdlGAQgASgMSABSC2xvYWRlZEltYWdliAEBQg4KDF9sb2FkZWRJbWFnZQ==');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
///
export 'catrobat_image.pb.dart';

Loading