-
Notifications
You must be signed in to change notification settings - Fork 77
PAINTROID-440, 441, 442 Created the landing page and implemented the basic functionality #8
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fd10a28
PAINTROID-442 implemented basic functionality of the landing page
CodeChamp-SS f12c09a
fix
CodeChamp-SS 819c4b9
refactoring the details dialog
CodeChamp-SS fb3c2ef
rafactoring and added unit tests
CodeChamp-SS 32cf767
added some unit tests and some minor bug fixes
CodeChamp-SS b0cd8bb
added widget test, refactored code
CodeChamp-SS 6cdfc42
added generated database file to gitignore
CodeChamp-SS 0b10157
excluding database generated file and test files from static analysis…
CodeChamp-SS 1bfc4d4
saving projects in applicationDocumentsDirectory
CodeChamp-SS 4d6e24f
refactoring
CodeChamp-SS e59a847
refactoring
CodeChamp-SS f47665c
refactoring
CodeChamp-SS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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,27 @@ | ||
import 'package:floor/floor.dart'; | ||
|
||
@entity | ||
class Project { | ||
String name; | ||
String path; | ||
DateTime lastModified; | ||
DateTime creationDate; | ||
String? resolution; | ||
String? format; | ||
int? size; | ||
String? imagePreviewPath; | ||
@PrimaryKey(autoGenerate: true) | ||
final int? id; | ||
|
||
Project({ | ||
required this.name, | ||
required this.path, | ||
required this.lastModified, | ||
required this.creationDate, | ||
this.resolution, | ||
this.format, | ||
this.size, | ||
this.imagePreviewPath, | ||
this.id, | ||
}); | ||
} |
This file contains hidden or 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,21 @@ | ||
import 'package:floor/floor.dart'; | ||
|
||
import 'model/project.dart'; | ||
|
||
@dao | ||
abstract class ProjectDAO { | ||
@Insert(onConflict: OnConflictStrategy.replace) | ||
Future<int> insertProject(Project project); | ||
|
||
@Insert(onConflict: OnConflictStrategy.replace) | ||
Future<List<int>> insertProjects(List<Project> projects); | ||
|
||
@Query('DELETE FROM Project WHERE id = :id') | ||
Future<void> deleteProject(int id); | ||
|
||
@delete | ||
Future<void> deleteProjects(List<Project> projects); | ||
|
||
@Query('SELECT * FROM Project order by lastModified desc') | ||
Future<List<Project>> getProjects(); | ||
} |
This file contains hidden or 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 'dart:async'; | ||
|
||
import 'package:floor/floor.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:paintroid/data/model/project.dart'; | ||
import 'package:paintroid/data/project_dao.dart'; | ||
import 'package:paintroid/data/typeconverters/date_time_converter.dart'; | ||
import 'package:sqflite/sqflite.dart' as sqflite; | ||
|
||
part 'project_database.g.dart'; | ||
|
||
@TypeConverters([DateTimeConverter]) | ||
@Database(version: 1, entities: [Project]) | ||
abstract class ProjectDatabase extends FloorDatabase { | ||
ProjectDAO get projectDAO; | ||
|
||
static final provider = FutureProvider((ref) => | ||
$FloorProjectDatabase.databaseBuilder("project_database.db").build()); | ||
} |
This file contains hidden or 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,13 @@ | ||
import 'package:floor/floor.dart'; | ||
|
||
class DateTimeConverter extends TypeConverter<DateTime, int> { | ||
@override | ||
DateTime decode(int databaseValue) { | ||
return DateTime.fromMillisecondsSinceEpoch(databaseValue); | ||
} | ||
|
||
@override | ||
int encode(DateTime value) { | ||
return value.millisecondsSinceEpoch; | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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,39 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
/// Returns [true] if user chose to delete the project or [null] if user | ||
/// dismiss the dialog by tapping outside | ||
Future<bool?> showDeleteDialog(BuildContext context, String name) => | ||
showGeneralDialog<bool>( | ||
context: context, | ||
pageBuilder: (_, __, ___) => DeleteProjectDialog(name: name), | ||
barrierDismissible: true, | ||
barrierLabel: "Show delete project dialog box"); | ||
|
||
class DeleteProjectDialog extends StatefulWidget { | ||
final String name; | ||
|
||
const DeleteProjectDialog({Key? key, required this.name}) : super(key: key); | ||
|
||
@override | ||
State<DeleteProjectDialog> createState() => _DeleteProjectDialogState(); | ||
} | ||
|
||
class _DeleteProjectDialogState extends State<DeleteProjectDialog> { | ||
@override | ||
Widget build(BuildContext context) => AlertDialog( | ||
title: Text("Delete ${widget.name}"), | ||
actions: [_discardButton, _deleteButton], | ||
content: const Text("Do you really want to delete your project?"), | ||
); | ||
|
||
TextButton get _deleteButton => TextButton( | ||
style: TextButton.styleFrom(primary: Colors.red), | ||
onPressed: () => Navigator.of(context).pop(true), | ||
child: const Text("Delete"), | ||
); | ||
|
||
ElevatedButton get _discardButton => ElevatedButton( | ||
juliajulie95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
juliajulie95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
onPressed: () => Navigator.of(context).pop(false), | ||
child: const Text("Cancel", style: TextStyle(color: Colors.white)), | ||
); | ||
} |
This file contains hidden or 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,110 @@ | ||
import 'package:filesize/filesize.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:flutter_styled_toast/flutter_styled_toast.dart'; | ||
import 'package:intl/intl.dart'; | ||
import 'package:oxidized/oxidized.dart'; | ||
import 'package:paintroid/io/io.dart'; | ||
|
||
import '../../../data/model/project.dart'; | ||
import '../../../ui/color_schemes.dart'; | ||
|
||
Future<bool?> showDetailsDialog(BuildContext context, Project project) => | ||
showGeneralDialog<bool>( | ||
context: context, | ||
pageBuilder: (_, __, ___) => ProjectDetailsDialog(project: project), | ||
barrierDismissible: true, | ||
barrierLabel: "Show project details dialog box"); | ||
|
||
class ProjectDetailsDialog extends ConsumerStatefulWidget { | ||
final Project project; | ||
|
||
const ProjectDetailsDialog({Key? key, required this.project}) | ||
: super(key: key); | ||
|
||
@override | ||
ConsumerState<ProjectDetailsDialog> createState() => | ||
_ProjectDetailsDialogState(); | ||
} | ||
|
||
class _ProjectDetailsDialogState extends ConsumerState<ProjectDetailsDialog> { | ||
late IImageService imageService; | ||
late IFileService fileService; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
imageService = ref.watch(IImageService.provider); | ||
fileService = ref.watch(IFileService.provider); | ||
|
||
final DateFormat formatter = DateFormat('dd-MM-yyyy HH:mm:ss'); | ||
|
||
return AlertDialog( | ||
title: Text(widget.project.name), | ||
actions: [_okButton], | ||
content: FutureBuilder( | ||
future: _getImageDimensions(widget.project.imagePreviewPath), | ||
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) { | ||
if (snapshot.hasData) { | ||
final dimensions = snapshot.data!; | ||
return Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Text("Resolution: ${dimensions[0]} X ${dimensions[1]}"), | ||
Text( | ||
"Last modified: ${formatter.format(widget.project.lastModified)}"), | ||
Text( | ||
"Creation date: ${formatter.format(widget.project.creationDate)}"), | ||
Text("Size: ${filesize(_getProjectSize())}"), | ||
], | ||
); | ||
} else { | ||
return Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
CircularProgressIndicator( | ||
backgroundColor: lightColorScheme.background, | ||
), | ||
], | ||
); | ||
} | ||
}, | ||
), | ||
); | ||
} | ||
|
||
ElevatedButton get _okButton => ElevatedButton( | ||
juliajulie95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
onPressed: () => Navigator.of(context).pop(false), | ||
child: const Text("OK", style: TextStyle(color: Colors.white)), | ||
); | ||
|
||
int _getProjectSize() => fileService.getFile(widget.project.path).when( | ||
ok: (file) => file.lengthSync(), | ||
err: (failure) { | ||
showToast(failure.message); | ||
return 0; | ||
}, | ||
); | ||
|
||
Future<List<int>> _getImageDimensions(String? path) async { | ||
List<int> dimensions = []; | ||
return imageService.getProjectPreview(path).when( | ||
ok: (img) => imageService.import(img).when( | ||
ok: (image) { | ||
dimensions.add(image.width); | ||
dimensions.add(image.height); | ||
return dimensions; | ||
}, | ||
err: (failure) { | ||
showToast(failure.message); | ||
return dimensions; | ||
}, | ||
), | ||
err: (failure) { | ||
showToast(failure.message); | ||
return dimensions; | ||
}, | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.