Skip to content

Commit

Permalink
Merge pull request #26 from bakicelebi/PAINTROID-549
Browse files Browse the repository at this point in the history
PAINTROID-549 Refactoring
  • Loading branch information
juliajulie95 authored Jul 2, 2023
2 parents 8d71189 + 40c75ef commit 84b50c4
Show file tree
Hide file tree
Showing 82 changed files with 1,191 additions and 983 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: arduino/setup-protoc@v1
- name: Install Protoc
uses: arduino/setup-protoc@v2
- uses: subosito/[email protected]
with:
flutter-version: '3.3.9'
flutter-version: '3.10.5'
channel: 'stable'
cache: true
- name: Setup
Expand Down
14 changes: 13 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
include: package:flutter_lints/flutter.yaml
linter:
rules:
- always_use_package_imports
always_use_package_imports: true
avoid_relative_lib_imports: true
prefer_relative_imports: false
prefer_single_quotes: true
avoid_void_async: true

analyzer:

errors:
missing_enum_constant_in_switch: error
exhaustive_cases: error
unused_element: error
type_annotate_public_apis: error
missing_required_param: error
invalid_use_of_protected_member: error
unused_import: error

exclude:
- lib/**.pb*.dart
- lib/data/*.g.dart
Expand Down
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.8.21'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
7 changes: 4 additions & 3 deletions lib/command/src/command_factory.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import 'dart:ui';

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:paintroid/core/path_with_action_history.dart';

import 'package:paintroid/command/src/implementation/command/graphic/draw_path_command.dart';
import 'package:paintroid/core/path_with_action_history.dart';

class CommandFactory {
const CommandFactory();

static final provider = Provider((ref) => const CommandFactory());

DrawPathCommand createDrawPathCommand(PathWithActionHistory path, Paint paint) => DrawPathCommand(path, paint);
DrawPathCommand createDrawPathCommand(
PathWithActionHistory path, Paint paint) =>
DrawPathCommand(path, paint);
}
1 change: 0 additions & 1 deletion lib/command/src/command_manager.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:ui';

import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'package:paintroid/command/src/command.dart';
import 'package:paintroid/command/src/graphic_command.dart';
import 'package:paintroid/command/src/implementation/manager/sync_command_manager.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:ui';

import 'package:flutter/widgets.dart';
import 'package:paintroid/core/path_with_action_history.dart';
import 'package:paintroid/command/src/graphic_command.dart';
import 'package:paintroid/core/path_with_action_history.dart';

class DrawPathCommand extends GraphicCommand {
const DrawPathCommand(this.path, super.paint);
Expand Down
4 changes: 2 additions & 2 deletions lib/core/image_with_pixel_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class ImageWithPixelInfo {
/// Range: (0,0) → (width-1, height-1)
Color pixelColorAt(int x, int y) {
if (x < 0 || x >= _width || y < 0 || y >= _height) {
throw "Failed to calculate color due to"
"invalid coordinates: ($x, $y) don't fit inside $_width x $_height";
throw 'Failed to calculate color due to'
'invalid coordinates: ($x, $y) don\'t fit inside $_width x $_height';
}
final byteOffset = 4 * (x + (y * _width));
return Color(_rgbaToArgb(_byteData.getUint32(byteOffset)));
Expand Down
2 changes: 1 addition & 1 deletion lib/core/loggable_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import 'package:logging/logging.dart';

mixin LoggableMixin {
late final logger = Logger(runtimeType.toString());
}
}
1 change: 0 additions & 1 deletion lib/data/project_dao.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:floor/floor.dart';

import 'package:paintroid/data/model/project.dart';

@dao
Expand Down
2 changes: 1 addition & 1 deletion lib/data/project_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ abstract class ProjectDatabase extends FloorDatabase {
ProjectDAO get projectDAO;

static final provider = FutureProvider((ref) =>
$FloorProjectDatabase.databaseBuilder("project_database.db").build());
$FloorProjectDatabase.databaseBuilder('project_database.db').build());
}
2 changes: 1 addition & 1 deletion lib/io/src/entity/catrobat_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:ui';
import 'package:paintroid/command/command.dart' show Command;

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

final int version;
Expand Down
6 changes: 3 additions & 3 deletions lib/io/src/entity/image_format.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
part of 'image_meta_data.dart';

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

const ImageFormat(this.extension);

Expand Down
4 changes: 2 additions & 2 deletions lib/io/src/entity/image_meta_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ abstract class ImageMetaData {
const ImageMetaData(this.name, this.format);

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

class JpgMetaData extends ImageMetaData {
Expand All @@ -17,7 +17,7 @@ class JpgMetaData extends ImageMetaData {
const JpgMetaData(String name, this.quality) : super(name, ImageFormat.jpg);

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

class PngMetaData extends ImageMetaData {
Expand Down
8 changes: 4 additions & 4 deletions lib/io/src/failure/load_image_failure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class LoadImageFailure extends Failure {
const LoadImageFailure._(super.message);

static const permissionDenied =
LoadImageFailure._("Permission to view photos is denied in settings");
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");
LoadImageFailure._('User did not choose an image');
static const invalidImage = LoadImageFailure._('Invalid image');
static const unidentified = LoadImageFailure._('Could not load image');
}
6 changes: 3 additions & 3 deletions lib/io/src/failure/save_image_failure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class SaveImageFailure extends Failure {
const SaveImageFailure._(super.message);

static const permissionDenied =
SaveImageFailure._("Permission to save photos is denied in settings");
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");
SaveImageFailure._('User did not choose a save location');
static const unidentified = SaveImageFailure._('Could not save image');
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ abstract class ProtoSerializerWithVersioning<T,
extends VersionSerializer<T, SERIALIZABLE> {
const ProtoSerializerWithVersioning(super.version);

static const urlPrefix = "org.catrobat.paintroid";
static const urlPrefix = 'org.catrobat.paintroid';

@protected
SERIALIZABLE Function(Uint8List binary) get fromBytesToSerializable;
Expand Down
22 changes: 11 additions & 11 deletions lib/io/src/serialization/serializer/catrobat_image_serializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ class CatrobatImageSerializer extends ProtoSerializerWithVersioning<
backgroundImageData =
result.unwrapOrElse((failure) => throw failure.message);
}
return SerializableCatrobatImage(
magicValue: CatrobatImage.magicValue,
version: CatrobatImage.latestVersion,
width: object.width,
height: object.height,
backgroundImage: backgroundImageData,
commands: await Future.wait(object.commands.map((command) async {
return SerializableCatrobatImage()
..magicValue = CatrobatImage.magicValue
..version = CatrobatImage.latestVersion
..width = object.width
..height = object.height
..backgroundImage =
(backgroundImageData != null) ? backgroundImageData : Uint8List(0)
..commands.addAll(await Future.wait(object.commands.map((command) async {
if (command is DrawPathCommand) {
return Any.pack(
await _drawPathCommandSerializer
.serializeWithLatestVersion(command),
typeUrlPrefix: ProtoSerializerWithVersioning.urlPrefix,
);
} else {
throw "Invalid command type";
throw 'Invalid command type';
}
})),
);
})));
}

@override
Expand All @@ -60,7 +60,7 @@ class CatrobatImageSerializer extends ProtoSerializerWithVersioning<
final unpacked = cmd.unpackInto(SerializableDrawPathCommand());
commands.add(await _drawPathCommandSerializer.deserialize(unpacked));
} else {
throw "Invalid command type";
throw 'Invalid command type';
}
}
Image? image;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ class DrawPathCommandSerializer extends ProtoSerializerWithVersioning<
@override
Future<SerializableDrawPathCommand> serializeWithLatestVersion(
DrawPathCommand object) async {
final sPaint = await _paintSerializer.serializeWithLatestVersion(object.paint);
final sPaint =
await _paintSerializer.serializeWithLatestVersion(object.paint);
final sPath = await _pathSerializer.serializeWithLatestVersion(object.path);
return SerializableDrawPathCommand(paint: sPaint, path: sPath);
return SerializableDrawPathCommand()
..paint = sPaint
..path = sPath;
}
}
18 changes: 11 additions & 7 deletions lib/io/src/serialization/serializer/graphic/path_serializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PathSerializer extends ProtoSerializerWithVersioning<
} else if (action.hasClose()) {
path.close();
} else {
logger.severe("No Path Action was set at index $i.");
logger.severe('No Path Action was set at index $i.');
}
}
return path;
Expand All @@ -61,16 +61,20 @@ class PathSerializer extends ProtoSerializerWithVersioning<
for (final action in object.actions) {
late final SerializablePath_Action serializableAction;
if (action is MoveToAction) {
final moveTo = SerializablePath_Action_MoveTo(x: action.x, y: action.y);
serializableAction = SerializablePath_Action(moveTo: moveTo);
final moveTo = SerializablePath_Action_MoveTo()
..x = action.x
..y = action.y;
serializableAction = SerializablePath_Action()..moveTo = moveTo;
} else if (action is LineToAction) {
final lineTo = SerializablePath_Action_LineTo(x: action.x, y: action.y);
serializableAction = SerializablePath_Action(lineTo: lineTo);
final lineTo = SerializablePath_Action_LineTo()
..x = action.x
..y = action.y;
serializableAction = SerializablePath_Action()..lineTo = lineTo;
} else if (action is CloseAction) {
final close = SerializablePath_Action_Close();
serializableAction = SerializablePath_Action(close: close);
serializableAction = SerializablePath_Action()..close = close;
} else {
logger.severe("Path Action serialization was not handled for $action");
logger.severe('Path Action serialization was not handled for $action');
}
serializablePath.actions.add(serializableAction);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/io/src/serialization/version_serializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class VersionSerializer<FROM, TO> {
case v1:
return deserializeV1(data);
default:
throw "Invalid version";
throw 'Invalid version';
}
}

Expand Down
26 changes: 13 additions & 13 deletions lib/io/src/service/file_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ class FileService with LoggableMixin implements IFileService {
final result =
await FilePicker.platform.pickFiles(allowCompression: false);
if (result == null) {
return Result.err(LoadImageFailure.userCancelled);
return const Result.err(LoadImageFailure.userCancelled);
}
if (result.files.single.path == null) {
throw "file path is null";
throw 'file path is null';
} else {
return Result.ok(File(result.files.single.path!));
}
} catch (err, stacktrace) {
logger.severe("Could not load file", err, stacktrace);
return Result.err(LoadImageFailure.unidentified);
logger.severe('Could not load file', err, stacktrace);
return const Result.err(LoadImageFailure.unidentified);
}
}

Expand All @@ -47,14 +47,14 @@ class FileService with LoggableMixin implements IFileService {
try {
final saveDirectory = await FilePicker.platform.getDirectoryPath();
if (saveDirectory == null) {
return Result.err(SaveImageFailure.userCancelled);
return const Result.err(SaveImageFailure.userCancelled);
}
final file =
await File("$saveDirectory/$filename").create(recursive: true);
await File('$saveDirectory/$filename').create(recursive: true);
return Result.ok(await file.writeAsBytes(data));
} catch (err, stacktrace) {
logger.severe("Could not save file", err, stacktrace);
return Result.err(SaveImageFailure.unidentified);
logger.severe('Could not save file', err, stacktrace);
return const Result.err(SaveImageFailure.unidentified);
}
}

Expand All @@ -67,12 +67,12 @@ class FileService with LoggableMixin implements IFileService {
Future<Result<File, Failure>> saveToApplicationDirectory(
String filename, Uint8List data) async {
try {
String saveDirectory = "${await _localPath}/$filename";
String saveDirectory = '${await _localPath}/$filename';
final file = await File(saveDirectory).create(recursive: true);
return Result.ok(await file.writeAsBytes(data));
} catch (err, stacktrace) {
logger.severe("Could not save file", err, stacktrace);
return Result.err(SaveImageFailure.unidentified);
logger.severe('Could not save file', err, stacktrace);
return const Result.err(SaveImageFailure.unidentified);
}
}

Expand All @@ -81,8 +81,8 @@ class FileService with LoggableMixin implements IFileService {
try {
return Result.ok(File(path));
} catch (err, stacktrace) {
logger.severe("Could not load file", err, stacktrace);
return Result.err(LoadImageFailure.unidentified);
logger.severe('Could not load file', err, stacktrace);
return const Result.err(LoadImageFailure.unidentified);
}
}
}
Loading

0 comments on commit 84b50c4

Please sign in to comment.