2019-08-24 21:22:32 +03:00
|
|
|
part of '../../main.dart';
|
2019-03-13 21:33:58 +02:00
|
|
|
|
|
|
|
class TimerEntity extends Entity {
|
2019-03-19 23:07:40 +02:00
|
|
|
TimerEntity(Map rawData, String webHost) : super(rawData, webHost);
|
2019-03-13 21:33:58 +02:00
|
|
|
|
|
|
|
Duration duration;
|
|
|
|
|
|
|
|
@override
|
2019-03-19 23:07:40 +02:00
|
|
|
void update(Map rawData, String webHost) {
|
|
|
|
super.update(rawData, webHost);
|
2019-03-13 21:33:58 +02:00
|
|
|
String durationSource = "${attributes["duration"]}";
|
2019-03-14 16:39:37 +02:00
|
|
|
if (durationSource != null && durationSource.isNotEmpty) {
|
|
|
|
try {
|
|
|
|
List<String> durationList = durationSource.split(":");
|
|
|
|
if (durationList.length == 1) {
|
|
|
|
duration = Duration(seconds: int.tryParse(durationList[0] ?? 0));
|
|
|
|
} else if (durationList.length == 2) {
|
|
|
|
duration = Duration(
|
|
|
|
hours: int.tryParse(durationList[0]) ?? 0,
|
|
|
|
minutes: int.tryParse(durationList[1]) ?? 0
|
|
|
|
);
|
|
|
|
} else if (durationList.length == 3) {
|
|
|
|
duration = Duration(
|
|
|
|
hours: int.tryParse(durationList[0]) ?? 0,
|
|
|
|
minutes: int.tryParse(durationList[1]) ?? 0,
|
|
|
|
seconds: int.tryParse(durationList[2]) ?? 0
|
|
|
|
);
|
|
|
|
} else {
|
2020-05-08 15:47:43 +03:00
|
|
|
Logger.e("Strange timer duration format: $durationSource");
|
2019-03-14 16:39:37 +02:00
|
|
|
duration = Duration(seconds: 0);
|
|
|
|
}
|
2020-05-01 19:24:13 +03:00
|
|
|
} catch (e, stacktrace) {
|
2020-05-08 15:47:43 +03:00
|
|
|
Logger.e("Error parsing timer duration \'$durationSource\': $e", stacktrace: stacktrace);
|
2019-03-14 16:39:37 +02:00
|
|
|
duration = Duration(seconds: 0);
|
|
|
|
}
|
2019-03-13 21:33:58 +02:00
|
|
|
} else {
|
|
|
|
duration = Duration(seconds: 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget _buildStatePart(BuildContext context) {
|
|
|
|
return TimerState();
|
|
|
|
}
|
|
|
|
}
|