Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
waozixyz committed Jan 5, 2024
1 parent 3be33c1 commit 52e2573
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 79 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## [1.2.6] - 2024-01-05
- Fix no breath in after step 3
- fix stop session unwanted screen switch

## [1.2.5] - 2024-01-03
- Optimize metadata for desktop release

Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"language_instruction": "Wählen Sie Ihre bevorzugte Sprache und drücken Sie auf Fortsetzen.",


"guide_welcome_title": "Namaste",
"guide_welcome_title": "Tutorial",
"guide_welcome_description": "Diese einfache, aber wirksame Atemtechnik verspricht tiefen inneren Frieden und bietet einen Zufluchtsort der Ruhe inmitten des hektischen Alltags.",
"safety_instruction": "Um Ihre Sicherheit zu gewährleisten, üben Sie entweder im Liegen oder in einer bequemen Sitzposition.",

Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"language_selection_title": "Language Selection",
"language_instruction": "Select your preferred language and press continue.",

"guide_welcome_title": "Namaste",
"guide_welcome_title": "Tutorial",
"guide_welcome_description": "This easy yet potent breathing technique promises profound inner peace, offering a sanctuary of serenity amidst life's hectic pace.",
"safety_instruction": "To ensure your safety, practice either lying down or sitting in a comfortable position.",

Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"language_selection_title": "Selección de Idioma",
"language_instruction": "Seleccione su idioma preferido y presione continuar.",

"guide_welcome_title": "Namasté",
"guide_welcome_title": "Tutorial",
"guide_welcome_description": "Esta técnica de respiración fácil pero potente promete una profunda paz interior, ofreciendo un santuario de serenidad en medio del ajetreo de la vida.",
"safety_instruction": "Para garantizar tu seguridad, práctica tumbado o sentado en una posición cómoda.",

Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/it_IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"language_selection_title": "Selezione della lingua",
"language_instruction": "Seleziona la lingua preferita e premi Continua.",

"guide_welcome_title": "Ciao",
"guide_welcome_title": "Tutorial",
"guide_welcome_description": "Questa tecnica di respirazione semplice ma potente promette una profonda pace interiore, offrendo un santuario di serenità in mezzo al ritmo frenetico della vita.",
"safety_instruction": "Per garantire la tua sicurezza, esercitati sdraiato o seduto in una posizione comoda.",

Expand Down
39 changes: 29 additions & 10 deletions lib/screens/exercise/exercise_step1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class _ExerciseStep1State extends State<ExerciseStep1> {
int volume = 80;
int maxBreaths = 30;
int breathsDone = -5;
String animationControl = 'stop';

String? sessionId;
Timer? breathCycleTimer;
Expand Down Expand Up @@ -73,7 +74,10 @@ class _ExerciseStep1State extends State<ExerciseStep1> {
maxBreaths = localMaxBreaths;
tempoDuration = Duration(milliseconds: localTempo);
rounds = localRounds!;
if (rounds > 0) breathsDone = 1;
if (rounds > 0) {
breathsDone = 1;
animationControl = 'repeat';
}

volume = localVolume;
sessionId = localSessionId;
Expand All @@ -94,23 +98,30 @@ class _ExerciseStep1State extends State<ExerciseStep1> {
if (breathsDone < 0) {
breathCycleTimer = Timer.periodic(Duration(seconds: 1), (timer) {
setState(() {
if (animationControl == 'pause') return;
animationControl = 'stop';

breathsDone++;
if (breathsDone == 0) {
breathsDone = 1;
timer.cancel();
animationControl = 'repeat';
startBreathCounting();
}
});
});
} else {
breathCycleTimer = Timer.periodic(tempoDuration, (timer) {
setState(() {
if (animationControl == 'pause') return;

breathsDone = timer.tick ~/ 2 + 1;
});
if (breathsDone == maxBreaths && timer.tick % 2 == 0) {
audioPlayerService.play('assets/sounds/bell.ogg', volume * 0.8, 'bell');
}
if (breathsDone > maxBreaths) {
animationControl = 'stop';
timer.cancel();
_navigateToNextExercise();
}
Expand All @@ -137,17 +148,13 @@ Widget build(BuildContext context) {
tempoDuration: tempoDuration,
volume: volume,
innerText: (breathsDone > maxBreaths ? maxBreaths : breathsDone).toString(),
controlCallback: () {
if (breathsDone > 0 && breathsDone <= maxBreaths) {
return 'repeat';
}
else {
return 'stop';
}
},
controlCallback: () => animationControl,
),
SizedBox(height: 200),
StopSessionButton(),
StopSessionButton(
onPause: pauseBreathCounting,
onResume: resumeBreathCounting,
),
TextButton(
child: Text('skip_button'.i18n()),
onPressed: () {
Expand All @@ -161,7 +168,17 @@ Widget build(BuildContext context) {
),
);
}
void pauseBreathCounting() {
setState(() {
animationControl = 'pause';
});
}

void resumeBreathCounting() {
setState(() {
animationControl = 'resume';
});
}
@override
void dispose() {
audioPlayerService.disposePlayer('bell');
Expand All @@ -177,6 +194,8 @@ Widget build(BuildContext context) {
if (breathsDone < 0) {
setState(() {
breathsDone = 1;
animationControl = 'repeat';

});
startBreathCounting();
} else {
Expand Down
11 changes: 11 additions & 0 deletions lib/screens/exercise/exercise_step2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ class _ExerciseStep2State extends State<ExerciseStep2> {
Duration duration = Duration(seconds: 0);
late Timer timer;
int rounds = 1;
bool isPaused = false;

@override
void initState() {
super.initState();
timer = Timer.periodic(Duration(milliseconds: 10), (Timer t) {
setState(() {
if (isPaused) return;
duration = duration + Duration(milliseconds: 10);
});
});
Expand Down Expand Up @@ -57,6 +59,13 @@ class _ExerciseStep2State extends State<ExerciseStep2> {
}


void pauseTimer() {
isPaused = true;
}

void resumeTimer() {
isPaused = false;
}

void _navigateToNextExercise() async {
WidgetsBinding.instance.addPostFrameCallback((_) {
Expand Down Expand Up @@ -108,6 +117,8 @@ class _ExerciseStep2State extends State<ExerciseStep2> {
SizedBox(height: 20),
StopSessionButton(
onStopSessionPressed: _onStopSessionPressed,
onPause: pauseTimer,
onResume: resumeTimer,
),
],
),
Expand Down
53 changes: 33 additions & 20 deletions lib/screens/exercise/exercise_step3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ class ExerciseStep3 extends StatefulWidget {
}

class _ExerciseStep3State extends State<ExerciseStep3> {
String animationControl = 'forward';
int volume = 80;
int countdown = 30;
int customTicker = 0;
Duration tempoDuration = Duration(seconds: 2);
String innerText= 'in';

Expand Down Expand Up @@ -59,23 +61,29 @@ class _ExerciseStep3State extends State<ExerciseStep3> {
return innerText;
}
}

void startBreathCounting() {
void startBreathCounting() {
breathCycleTimer = Timer.periodic(Duration(seconds: 1), (timer) {
if (animationControl == 'pause') return; // Pause logic

setState(() {
if (timer.tick < 2) {
customTicker++;

if (customTicker < 2) {
innerText = 'in';
} else if ( timer.tick < 17) {
innerText = (17 - timer.tick).toString();
} else if (timer.tick >= 17 && timer.tick <= 18) {
} else if (customTicker < 17) {
innerText = (17 - customTicker).toString();
animationControl = 'stop';
} else if (customTicker >= 17 && customTicker <= 18) {
innerText = 'out';
animationControl = 'reverse';
} else {
_navigateToNextExercise();
}
});
});
});
}


@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -95,22 +103,15 @@ class _ExerciseStep3State extends State<ExerciseStep3> {
volume: volume,
tempoDuration: tempoDuration,
innerText: getDisplayText(),
controlCallback: () {
if (innerText == 'in') {
return 'forward';
}
else if (innerText == 'out') {
return 'reverse';
}
else {
return 'stop';
}
},
controlCallback: () => animationControl,
),
SizedBox(height: 200),
StopSessionButton(),
StopSessionButton(
onPause: pauseBreathCounting,
onResume: resumeBreathCounting,
),
TextButton(
child: Text('skip_button'.i18n()),
child: Text('skip_button'.i18n()),
onPressed: () {
_navigateToNextExercise();
},
Expand All @@ -122,6 +123,18 @@ class _ExerciseStep3State extends State<ExerciseStep3> {
),
);
}
void pauseBreathCounting() {
setState(() {
animationControl = 'pause';
});
}

void resumeBreathCounting() {
setState(() {
animationControl = 'resume';
});
}


@override
void dispose() {
Expand Down
32 changes: 25 additions & 7 deletions lib/utils/audio_player_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,39 @@ class AudioPlayerService {

}


Future<void> play(String assetPath, double volume, String playerId) async {
Future<void> preload(String assetPath, String playerId) async {
try {
await _session.setActive(true);
var player = _players[playerId];
player ??= _players.putIfAbsent(playerId, () => AudioPlayer());
await player.setAsset(assetPath);
await player.seek(Duration(milliseconds: 0));
await player.setVolume(volume / 100);
await player.play();
await player.setVolume(0);
} catch (e) {
print('Error playing audio: $e');
print('Error preloading audio: $e');
}
}

Future<void> play(String assetPath, double volume, String playerId) async {
try {
await _session.setActive(true);
var player = _players[playerId];
if (player == null) {
player = AudioPlayer();
await player.setAsset(assetPath);
_players[playerId] = player;
} else {
var currentAsset = await player.audioSource?.sequence?.first.tag;
if (currentAsset != assetPath) {
await player.setAsset(assetPath);
}
}
await player.seek(Duration.zero);
await player.setVolume(volume / 100);
await player.play();
} catch (e) {
print('Error playing audio: $e');
}
}

Future<void> stop(String playerId) async {
try {
var player = _players[playerId];
Expand Down
18 changes: 16 additions & 2 deletions lib/widgets/animated_circle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AnimatedCircleState extends State<AnimatedCircle>
late AnimationController _controller;
late Animation<double> _radiusAnimation;
AudioPlayerService audioPlayerService = AudioPlayerService();
double? pauseValue;

bool _isInitialized = false;

Expand All @@ -48,8 +49,6 @@ class AnimatedCircleState extends State<AnimatedCircle>
_controller.forward();
_controller.repeat(reverse: true);
}
print(status);
print('aeooaueoau');
if (status == AnimationStatus.forward) {
audioPlayerService.play('assets/sounds/breath-in.ogg', widget.volume.toDouble(), 'in');
} else if (status == AnimationStatus.reverse) {
Expand Down Expand Up @@ -89,6 +88,9 @@ class AnimatedCircleState extends State<AnimatedCircle>
switch (control) {
case 'repeat':
if (_controller.status == AnimationStatus.forward || _controller.status == AnimationStatus.reverse) break;
if (_controller.status == AnimationStatus.dismissed) {
audioPlayerService.play('assets/sounds/breath-in.ogg', widget.volume.toDouble(), 'in');
}
_controller.forward();
_controller.repeat(reverse: true);
break;
Expand All @@ -106,6 +108,18 @@ class AnimatedCircleState extends State<AnimatedCircle>
_controller.forward();
_controller.repeat(reverse: true);
break;
case 'pause':
if (_controller.isAnimating) {
pauseValue = _controller.value; // Save current progress
_controller.stop();
}
break;
case 'resume':
if (pauseValue != null) {
_controller.forward(from: pauseValue); // Resume from saved progress
_controller.repeat(reverse: true);
}
break;
}
}
}
Expand Down
Loading

0 comments on commit 52e2573

Please sign in to comment.