Skip to content

Commit

Permalink
Merge pull request #7 from akinov/feature/v0.3.0
Browse files Browse the repository at this point in the history
Feature/v0.3.0
  • Loading branch information
akinov authored May 20, 2020
2 parents fb45521 + ad703d8 commit 966b309
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 12 deletions.
18 changes: 17 additions & 1 deletion lib/models/process.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,35 @@ class Process {
int step = 1;
String note = '';
int inSeconds;
int totalWater;

String get typeText {
return ProcessType.values[type].toString().split('.')[1];
}

String get title {
String get titleForList {
List<String> result = ['Duration ' + duration.toString() + 's'];
if (type != 1) {
result.add('Water ' + water.toString() + 'ml');
}
return result.join(', ');
}

String get textForTimer {
switch (ProcessType.values[type]) {
case ProcessType.Bloom:
return 'Pour ${water.toString()}g of water ${duration.toString()} seconds and wait to bloom';
case ProcessType.Wait:
return 'Wait for ${duration.toString()} seconds';
case ProcessType.Pour:
return 'Pour ${water.toString()}g of water ${duration.toString()} seconds';
case ProcessType.Stir:
return 'Stir for ${duration.toString()} seconds';
case ProcessType.Other:
return '${duration.toString()} seconds $note';
}
}

Map<String, dynamic> toMap() {
var map = <String, dynamic>{
columnRecipeId: recipeId,
Expand Down
1 change: 0 additions & 1 deletion lib/pages/process/new.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class _ProcessNewState extends State<ProcessNew> {
}
},
child: Text('Save', style: TextStyle(color: Colors.white)),
shape: CircleBorder(side: BorderSide(color: Colors.transparent)),
),
],
),
Expand Down
3 changes: 1 addition & 2 deletions lib/pages/recipe/new.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class _RecipeNewState extends State<RecipeNew> {
}
},
child: Text('Save', style: TextStyle(color: Colors.white)),
shape: CircleBorder(side: BorderSide(color: Colors.transparent)),
),
],
),
Expand Down Expand Up @@ -138,7 +137,7 @@ class _RecipeNewState extends State<RecipeNew> {
// subtitle: Text('hoghoge'),
leading: Text(process.step.toString()),
trailing: Icon(Icons.more_vert),
subtitle: Text(process.title),
subtitle: Text(process.titleForList),
),
);
}).toList();
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/recipe/show.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _RecipeShowState extends State<RecipeShow> {
fontWeight: FontWeight.bold,
),
)),
Text(widget.recipe.water.toString() + 'ml'),
Text(widget.recipe.water.toString() + 'g'),
Padding(
padding: EdgeInsets.only(top: 16.0, bottom: 8.0),
child: Text(
Expand Down Expand Up @@ -97,7 +97,7 @@ class _RecipeShowState extends State<RecipeShow> {
),
// subtitle: Text('hoghoge'),
leading: Text(process.step.toString()),
subtitle: Text(process.title),
subtitle: Text(process.titleForList),
),
);
}).toList();
Expand Down
44 changes: 39 additions & 5 deletions lib/pages/recipe/timer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class _RecipeTimerState extends State<RecipeTimer> {
Duration _tmpDuration = Duration();
bool _doing = true;
List<Process> _processes;
double _currentWater = 0;

@override
void initState() {
Expand All @@ -30,27 +31,43 @@ class _RecipeTimerState extends State<RecipeTimer> {
void _setupProcsses() {
List<Process> result = [];
int time = 0;
int water = 0;
widget.processes.forEach((process) {
time += process.duration;
process.inSeconds = time;
if (process.water != null) {
water += process.water;
}
process.totalWater = water;
result.add(process);
});
setState(() => _processes = result);
}

void _onTimer(Timer timer) {
Process process = _currentProcess();
int seconds = _duration().inSeconds;
if (_processes.length > 0) {
if (process.inSeconds <= _duration().inSeconds) {
if (process.inSeconds <= seconds) {
_processes.removeAt(0);
}
} else {
_stopTimer();
}

if (process.water != null || process.water != 0) {
double a = (process.inSeconds -
process.duration -
(_duration().inMilliseconds / 1000)) *
-1;
double b = a.toDouble() / process.duration.toDouble();
_currentWater = b * process.water;
}

setState(() {
_now = DateTime.now();
_processes = _processes;
_currentWater = _currentWater;
});
}

Expand Down Expand Up @@ -123,13 +140,24 @@ class _RecipeTimerState extends State<RecipeTimer> {

String _text() {
if (_currentProcess() != null) {
return _currentProcess().title;
}
{
return _currentProcess().textForTimer;
} else {
return ' ';
}
}

String _waterText() {
Process process = _currentProcess();
if (process == null) {
return '';
}
int prevWater = process.totalWater - process.water;
return (prevWater + _currentWater).toStringAsFixed(1) +
'/' +
process.totalWater.toStringAsFixed(1) +
' g';
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -138,8 +166,14 @@ class _RecipeTimerState extends State<RecipeTimer> {
),
body: Center(
child: Column(mainAxisSize: MainAxisSize.min, children: [
Padding(
padding: EdgeInsets.all(32.0),
child: Text(
_title(),
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 40),
)),
Text(
_title(),
_waterText(),
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 40),
),
Padding(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: Coffee drip timer
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.2.2+5
version: 0.3.0+6

environment:
sdk: '>=2.2.0 <3.0.0'
Expand Down

0 comments on commit 966b309

Please sign in to comment.