-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PAINTROID-679 Implement JSON Serialization via Code Generation
- Loading branch information
1 parent
d18319e
commit d7fb50f
Showing
94 changed files
with
991 additions
and
2,349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,6 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install Protoc | ||
uses: arduino/setup-protoc@v2 | ||
with: | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: subosito/[email protected] | ||
with: | ||
flutter-version: "3.10.5" | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
library command; | ||
|
||
export 'src/graphic/draw_path_command.dart'; | ||
export 'src/manager/sync_command_manager.dart'; | ||
|
||
export 'src/command_factory.dart'; | ||
export 'src/command_manager.dart'; | ||
export 'src/command.dart'; | ||
export 'src/graphic_command.dart'; | ||
export 'graphic_factory/graphic_factory.dart'; | ||
export 'src/command_factory/command_factory.dart'; | ||
export 'src/command_implementation/command.dart'; | ||
export 'src/command_implementation/graphic/draw_path_command.dart'; | ||
export 'src/command_implementation/graphic/graphic_command.dart'; | ||
export 'src/command_manager/command_manager.dart'; | ||
export 'src/command_manager/sync_command_manager.dart'; | ||
export 'utils/path_with_action_history.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
library command; | ||
|
||
export 'src/command_factory_provider.dart'; | ||
export 'src/command_manager_provider.dart'; | ||
export 'graphic_factory/graphic_factory_provider.dart'; | ||
export 'src/command_factory/command_factory_provider.dart'; | ||
export 'src/command_manager/command_manager_provider.dart'; |
2 changes: 1 addition & 1 deletion
2
...brary/lib/src/models/graphic_factory.dart → .../lib/graphic_factory/graphic_factory.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ary/lib/src/graphic_factory_provider.dart → ...hic_factory/graphic_factory_provider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...ages/command/lib/src/command_factory.dart → .../src/command_factory/command_factory.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions
19
packages/command/lib/src/command_implementation/command.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'package:command/command.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:io_library/io_library.dart'; | ||
|
||
abstract class Command with EquatableMixin { | ||
const Command(); | ||
|
||
Map<String, dynamic> toJson(); | ||
|
||
factory Command.fromJson(Map<String, dynamic> json) { | ||
String type = json['type'] as String; | ||
switch (type) { | ||
case SerializerType.DRAW_PATH_COMMAND: | ||
return DrawPathCommand.fromJson(json); | ||
default: | ||
return DrawPathCommand.fromJson(json); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
packages/command/lib/src/command_implementation/graphic/draw_path_command.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:command/command.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:io_library/io_library.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'draw_path_command.g.dart'; | ||
|
||
@JsonSerializable() | ||
class DrawPathCommand extends GraphicCommand { | ||
final String type; | ||
final int version; | ||
|
||
DrawPathCommand( | ||
this.path, | ||
super.paint, { | ||
this.type = SerializerType.DRAW_PATH_COMMAND, | ||
int? version, | ||
}) : version = version ?? | ||
VersionStrategyManager.strategy.getDrawPathCommandVersion(); | ||
|
||
@PathWithActionHistoryConverter() | ||
final PathWithActionHistory path; | ||
|
||
@override | ||
void call(Canvas canvas) { | ||
canvas.drawPath(path, paint); | ||
} | ||
|
||
@override | ||
List<Object?> get props => [paint, path, type]; | ||
|
||
@override | ||
Map<String, dynamic> toJson() => _$DrawPathCommandToJson(this); | ||
|
||
factory DrawPathCommand.fromJson(Map<String, dynamic> json) { | ||
int version = json['version'] as int; | ||
|
||
switch (version) { | ||
case Version.v1: | ||
return _$DrawPathCommandFromJson(json); | ||
case Version.v2: | ||
// For different versions of DrawPathCommand the deserialization | ||
// has to be implemented manually. | ||
// Autogenerated code can only be used for one version | ||
default: | ||
return _$DrawPathCommandFromJson(json); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/command/lib/src/command_implementation/graphic/draw_path_command.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
...ages/command/lib/src/graphic_command.dart → ...plementation/graphic/graphic_command.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:collection/collection.dart'; | ||
import 'package:io_library/io_library.dart'; | ||
|
||
class PathWithActionHistory extends Path { | ||
PathWithActionHistory(); | ||
|
||
@PathActionConverter() | ||
final actions = <PathAction>[]; | ||
|
||
@override | ||
void moveTo(double x, double y) { | ||
actions.add(MoveToAction(x, y)); | ||
super.moveTo(x, y); | ||
} | ||
|
||
@override | ||
void lineTo(double x, double y) { | ||
actions.add(LineToAction(x, y)); | ||
super.lineTo(x, y); | ||
} | ||
|
||
@override | ||
void close() { | ||
actions.add(const CloseAction()); | ||
super.close(); | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
return const PathWithActionHistoryConverter().toJson(this); | ||
} | ||
|
||
factory PathWithActionHistory.fromJson(Map<String, dynamic> json) { | ||
return const PathWithActionHistoryConverter().fromJson(json); | ||
} | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
if (other is PathWithActionHistory) { | ||
return const ListEquality<PathAction>().equals(actions, other.actions); | ||
} | ||
return false; | ||
} | ||
|
||
@override | ||
int get hashCode => const ListEquality<PathAction>().hash(actions); | ||
} | ||
|
||
abstract class PathAction { | ||
const PathAction(); | ||
} | ||
|
||
class MoveToAction extends PathAction { | ||
final double x; | ||
final double y; | ||
|
||
const MoveToAction(this.x, this.y); | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
if (other is MoveToAction) { | ||
return x == other.x && y == other.y; | ||
} | ||
return false; | ||
} | ||
|
||
@override | ||
int get hashCode => Object.hash(x, y); | ||
} | ||
|
||
class LineToAction extends PathAction { | ||
final double x; | ||
final double y; | ||
|
||
const LineToAction(this.x, this.y); | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
if (other is LineToAction) { | ||
return x == other.x && y == other.y; | ||
} | ||
return false; | ||
} | ||
|
||
@override | ||
int get hashCode => Object.hash(x, y); | ||
} | ||
|
||
class CloseAction extends PathAction { | ||
const CloseAction(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,13 @@ | ||
library component_library; | ||
|
||
export 'src/components/imgs.dart'; | ||
export 'src/components/icon_svg.dart'; | ||
export 'src/components/bottom_nav_bar_icon.dart'; | ||
export 'src/components/custom_action_chip.dart'; | ||
export 'src/components/icon_button_with_label.dart'; | ||
export 'src/components/icon_svg.dart'; | ||
export 'src/components/imgs.dart'; | ||
export 'src/components/loading_overlay.dart'; | ||
export 'src/components/pop_menu_button.dart'; | ||
|
||
export 'src/models/graphic_factory.dart'; | ||
export 'src/models/path_with_action_history.dart'; | ||
|
||
export 'src/theme/color_schemes.dart'; | ||
export 'src/theme/styles.dart'; | ||
|
||
export 'src/utils/open_url.dart'; | ||
export 'src/utils/toast_utils.dart'; | ||
|
||
export 'src/graphic_factory_provider.dart'; |
Oops, something went wrong.