Skip to content

Commit

Permalink
Fixed tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanSarwar45 committed Apr 26, 2024
1 parent da78f27 commit 3387db9
Show file tree
Hide file tree
Showing 15 changed files with 324 additions and 203 deletions.
6 changes: 5 additions & 1 deletion fastlane/metadata/android/en-US/changelogs/191.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@

✨ Enhancements

* Added count setting to math tasks
* Added count setting to math and retype tasks
* Added option to select default UI for selecting time
* Added credits to about page
* Improved timer fullscreen button UI on smaller devices
* Improved timer fullscreen layout in landscape mode

🐛 Fixes

* Fixed numbers appearing after melody name
* Fixed alarm screen not updating after adding alarm through external app
* Fixed snackbar text clipping
* Fixed alarm tasks not getting deleted properly
* Fixed alarm tasks not working properly when same task is added multiple times
9 changes: 7 additions & 2 deletions fastlane/metadata/android/en-US/changelogs/192.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@

✨ Enhancements

* Added count setting to math tasks
* Added count setting to math and retype tasks
* Added option to select default UI for selecting time

* Added credits to about page
* Improved timer fullscreen button UI on smaller devices
* Improved timer fullscreen layout in landscape mode

🐛 Fixes

* Fixed numbers appearing after melody name
* Fixed alarm screen not updating after adding alarm through external app
* Fixed snackbar text clipping
* Fixed alarm tasks not getting deleted properly
* Fixed alarm tasks not working properly when same task is added multiple times
9 changes: 7 additions & 2 deletions fastlane/metadata/android/en-US/changelogs/193.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@

✨ Enhancements

* Added count setting to math tasks
* Added count setting to math and retype tasks
* Added option to select default UI for selecting time

* Added credits to about page
* Improved timer fullscreen button UI on smaller devices
* Improved timer fullscreen layout in landscape mode

🐛 Fixes

* Fixed numbers appearing after melody name
* Fixed alarm screen not updating after adding alarm through external app
* Fixed snackbar text clipping
* Fixed alarm tasks not getting deleted properly
* Fixed alarm tasks not working properly when same task is added multiple times
2 changes: 2 additions & 0 deletions lib/alarm/data/alarm_task_schemas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Map<AlarmTaskType, AlarmTaskSchema> alarmTaskSchemasMap = {
SliderSetting("Number of characters", 5, 20, 5, snapLength: 1),
SwitchSetting("Include numbers", false),
SwitchSetting("Include lowercase", false),
SliderSetting("Number of problems", 1, 10, 1, snapLength: 1),

]),
(onSolve, settings) {
return RetypeTask(onSolve: onSolve, settings: settings);
Expand Down
1 change: 1 addition & 0 deletions lib/alarm/screens/alarm_notification_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class _AlarmNotificationScreenState extends State<AlarmNotificationScreen> {
_currentWidget = alarm.tasks[_currentIndex].builder(_setNextWidget);
}
_currentIndex++;
print("######################## $_currentIndex");
});
}

Expand Down
21 changes: 14 additions & 7 deletions lib/alarm/types/alarm_task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,27 @@ class AlarmTaskSchema extends JsonSerializable {
}

class AlarmTask extends CustomizableListItem {
late AlarmTaskType type;
late AlarmTaskSchema _schema;
late int _id;
late AlarmTaskType type;
late AlarmTaskSchema _schema;

AlarmTask(this.type) : _schema = alarmTaskSchemasMap[type]!.copy();
AlarmTask(this.type)
: _schema = alarmTaskSchemasMap[type]!.copy(),
_id = UniqueKey().hashCode;

AlarmTask.from(AlarmTask task)
: type = task.type,
_id = UniqueKey().hashCode,
_schema = task._schema.copy();

AlarmTask.fromJson(Json json) {
if (json == null) {
_id = UniqueKey().hashCode;
type = AlarmTaskType.math;
_schema = alarmTaskSchemasMap[type]!.copy();
return;
}
_id = json['id'] ?? UniqueKey().hashCode;
type = AlarmTaskType.values.byName(json['type']);
_schema = alarmTaskSchemasMap[type]!.copy();
_schema.loadFromJson(json['schema']);
Expand All @@ -74,14 +80,14 @@ class AlarmTask extends CustomizableListItem {
return AlarmTask.from(this);
}

@override
@override
void copyFrom(dynamic other) {
type = other.type;
_schema = other._schema.copy();
type = other.type;
_schema = other._schema.copy();
}

@override
int get id => _schema.name.hashCode;
int get id => _id;
@override
bool get isDeletable => true;
AlarmTaskSchema get schema => _schema;
Expand All @@ -93,6 +99,7 @@ class AlarmTask extends CustomizableListItem {
@override
Json toJson() {
return {
'id': _id,
'schema': _schema.toJson(),
'type': type.name,
};
Expand Down
38 changes: 26 additions & 12 deletions lib/alarm/widgets/tasks/math_task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,43 @@ class MathTask extends StatefulWidget {

class _MathTaskState extends State<MathTask> {
final TextEditingController _textController = TextEditingController();
late final MathTaskDifficultyLevel _difficultyLevel =
widget.settings.getSetting("Difficulty").value;
late final _problemCount =
widget.settings.getSetting("Number of problems").value;
late MathTaskDifficultyLevel _difficultyLevel;
late double _problemCount;
int _problemsSolved = 0;

void initialize() {
_difficultyLevel = widget.settings.getSetting("Difficulty").value;
_problemCount = widget.settings.getSetting("Number of problems").value;
_problemsSolved = 0;
_difficultyLevel.generateProblem();
_textController.clear();

}

@override
void didUpdateWidget(covariant MathTask oldWidget) {
super.didUpdateWidget(oldWidget);
initialize();
}

@override
void initState() {
super.initState();
_textController.addListener(() {
if (_textController.text == _difficultyLevel._answer &&
_problemsSolved < _problemCount) {
_problemsSolved += 1;
setState(() {
_difficultyLevel.generateProblem();
_textController.clear();
});
}
if (_problemsSolved >= _problemCount) {
widget.onSolve();
if (_problemsSolved >= _problemCount) {
widget.onSolve();
} else {
setState(() {
_difficultyLevel.generateProblem();
_textController.clear();
});
}
}
});
_difficultyLevel.generateProblem();
initialize();
}

@override
Expand Down
65 changes: 52 additions & 13 deletions lib/alarm/widgets/tasks/retype_task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,51 @@ class _RetypeTaskState extends State<RetypeTask> {
final TextEditingController _textController = TextEditingController();
final Random _random = Random();

late final int characterCount =
widget.settings.getSetting("Number of characters").value.toInt();
late final bool includeNumbers =
widget.settings.getSetting("Include numbers").value;
late final bool includeLowercase =
widget.settings.getSetting("Include lowercase").value;
late final String _chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ${includeLowercase ? "abcdefghijklmnopqrstuvwxyz" : ""}${includeNumbers ? "0123456789" : ""}";
late int characterCount;
late bool includeNumbers;
late bool includeLowercase;
late String _chars;
late double _problemCount;
int _problemsSolved = 0;

late final String string = _generateRandomString(characterCount);
bool _isSolved = false;
late String string;

void initialize() {
characterCount =
widget.settings.getSetting("Number of characters").value.toInt();
includeNumbers = widget.settings.getSetting("Include numbers").value;
includeLowercase = widget.settings.getSetting("Include lowercase").value;
_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ${includeLowercase ? "abcdefghijklmnopqrstuvwxyz" : ""}${includeNumbers ? "0123456789" : ""}";
_problemCount = widget.settings.getSetting("Number of problems").value;
_problemsSolved = 0;
string = _generateRandomString(characterCount);
_textController.clear();
}

@override
void didUpdateWidget(covariant RetypeTask oldWidget) {
super.didUpdateWidget(oldWidget);
initialize();
}

@override
void initState() {
super.initState();
_textController.addListener(() {
if (_textController.text == string && !_isSolved) {
_isSolved = true;
widget.onSolve.call();
if (_textController.text == string && _problemsSolved < _problemCount) {
_problemsSolved += 1;
if (_problemsSolved >= _problemCount) {
widget.onSolve();
} else {
setState(() {
string = _generateRandomString(characterCount);
_textController.clear();
});
}
}
});
initialize();
}

@override
Expand All @@ -68,6 +92,7 @@ class _RetypeTaskState extends State<RetypeTask> {
Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
TextTheme textTheme = theme.textTheme;
ColorScheme colorScheme = theme.colorScheme;
Size textSize =
calcTextSizeFromLength(characterCount + 5, textTheme.displaySmall!);

Expand All @@ -80,6 +105,20 @@ class _RetypeTaskState extends State<RetypeTask> {
style: Theme.of(context).textTheme.headlineMedium,
),
const SizedBox(height: 16.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
for (int i = 0; i < _problemCount; i++)
Padding(
padding: const EdgeInsets.all(4.0),
child: Icon(
_problemsSolved > i ? Icons.circle : Icons.circle_outlined,
color: colorScheme.primary,
),
),
],
),
const SizedBox(height: 16.0),
CardContainer(
child: SizedBox(
width: double.infinity,
Expand Down
23 changes: 1 addition & 22 deletions lib/common/widgets/card_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,7 @@ class CardContainer extends StatelessWidget {
Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
ColorScheme colorScheme = theme.colorScheme;
return
// Card.filled(
// elevation: 1,
// // margin: margin ?? const EdgeInsets.all(4),
// // clipBehavior: Clip.hardEdge,
// // shape: RoundedRectangleBorder(
// // borderRadius: BorderRadius.circular(16),
// // side: showLightBorder
// // ? BorderSide(
// // color: Theme.of(context).colorScheme.onBackground.withOpacity(0.1),
// // width: 1,
// // )
// // : BorderSide.none,
// // ),
// color: color,
// child: InkWell(
// onTap: onTap,
// child: child,
// ),
//
// );
Container(
return Container(
alignment: alignment,
margin: margin ?? const EdgeInsets.all(4),
clipBehavior: Clip.hardEdge,
Expand Down
8 changes: 4 additions & 4 deletions lib/common/widgets/circular_progress_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class _CircularProgressBarState extends State<CircularProgressBar>
final double minSweepAngle = 0.015;

late double circleLength;
late double widgetSize;
// late double widgetSize;

late double startAngle;
late double correctAngle;
Expand All @@ -135,7 +135,7 @@ class _CircularProgressBarState extends State<CircularProgressBar>

void updateState() {
setState(() {
widgetSize = (widget.size <= 0) ? 100.0 : widget.size;
// widgetSize = (widget.size <= 0) ? 100.0 : widget.size;

// Check value notifier
if (widget.valueNotifier != null) {
Expand All @@ -149,7 +149,7 @@ class _CircularProgressBarState extends State<CircularProgressBar>
// Calculate the real starting angle and correction angle.
// Correction angle - the angle to which the main line should be
// shifted in order for the SweepGradient to be displayed correctly.
circleLength = pi * widgetSize;
circleLength = pi * widget.size;
final k = _doublePi / circleLength;

correctAngle = widget.progressStrokeWidth * k;
Expand Down Expand Up @@ -255,7 +255,7 @@ class _CircularProgressBarState extends State<CircularProgressBar>
Transform.rotate(
angle: _degToRad(widget.startAngle - 90),
child: CustomPaint(
size: Size(widgetSize, widgetSize),
size: Size(widget.size, widget.size),
painter: _SimpleCircularProgressBarPainter(
progressStrokeWidth: widget.progressStrokeWidth,
backStrokeWidth: widget.backStrokeWidth,
Expand Down
3 changes: 3 additions & 0 deletions lib/common/widgets/list/custom_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:clock_app/common/logic/get_list_filter_chips.dart';
import 'package:clock_app/common/types/list_controller.dart';
import 'package:clock_app/common/types/list_filter.dart';
import 'package:clock_app/common/types/list_item.dart';
import 'package:clock_app/common/utils/json_serialize.dart';
import 'package:clock_app/common/utils/reorderable_list_decorator.dart';
import 'package:clock_app/common/widgets/list/delete_alert_dialogue.dart';
import 'package:clock_app/common/widgets/list/list_filter_chip.dart';
Expand Down Expand Up @@ -198,6 +199,8 @@ class _CustomListViewState<Item extends ListItem>
[bool callOnModifyList = true]) async {
int index = _getItemIndex(deletedItem);

// print(listToString(widget.items));

setState(() {
widget.items.removeWhere((element) => element.id == deletedItem.id);
updateCurrentList();
Expand Down
2 changes: 1 addition & 1 deletion lib/settings/widgets/list_setting_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class _ListSettingScreenState<Item extends CustomizableListItem>
onPressed: () async {
Item? item = await _openAddBottomSheet();
if (item == null) return;
_listController.addItem(item);
_listController.addItem(item.copy());
},
)
],
Expand Down
Loading

0 comments on commit 3387db9

Please sign in to comment.