Skip to content
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

Fixed meditation session recorded even when done for 0 sec #144

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ String completedAfterDeadline(int daysDiff) =>
String completeTaskWithNoDeadline(String task) => "completed $task";
scoreReducedForTask(String task) => "Score reduced for $task";


//suggestions
final List<String> suggestions = [
'Grocery shopping',
Expand Down Expand Up @@ -120,8 +119,9 @@ String stayFocused(int min) => "Stay focused for $min minutes";
String relax(int min) => "Relax for $min minutes";

//Meditation Completion
String ExtraMeditation(int selectedMinutes, int extraSeconds) =>
String extraMeditation(int selectedMinutes, int extraSeconds) =>
"Great job! You meditated for $selectedMinutes minutes and $extraSeconds extra seconds";
String MeditationComplete(int minutesMeditated, int secondsMeditated) =>
String meditationComplete(int minutesMeditated, int secondsMeditated) =>
"Session ended. You meditated for $minutesMeditated minutes and $secondsMeditated seconds";
String AskDependencyCompletion = "Complete the dependency first!";
String meditationEndedTooSoon() => "Oh no! You stopped meditating too quickly!";
48 changes: 30 additions & 18 deletions lib/screens/meditation_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,40 +54,51 @@ class _MeditationScreenState extends State<MeditationScreen>
if (playaudio) {
audioPlayer.resume();
isAudioPlaying = true;
}
if (playaudio) {
audioPlayer.resume();
isAudioPlaying = true;
}

timer = Timer.periodic(const Duration(seconds: 1), (timer) {
setState(() {
if (remainingSeconds > 0) {
remainingSeconds--;
} else {
extraSeconds++;
}
timer = Timer.periodic(const Duration(seconds: 1), (timer) {
setState(() {
if (remainingSeconds > 0) {
remainingSeconds--;
} else {
extraSeconds++;
}
});
});
});
}
}

void stopTimer() {
setState(() {
int timeDiff;
int totalMeditationTime;
String message;
bool endedTooSoon = false;

if (remainingSeconds == 0) {
// Session went over time
timeDiff = extraSeconds;
totalMeditationTime = selectedMinutes * 60 + extraSeconds;
message = ExtraMeditation(selectedMinutes, extraSeconds);
message = extraMeditation(selectedMinutes, extraSeconds);
MeditationHistoryStorage.addToHistory(selectedMinutes, timeDiff);
} else {
// Session ended early
timeDiff = -remainingSeconds;
totalMeditationTime = (selectedMinutes * 60) - remainingSeconds;
int minutesMeditated = totalMeditationTime ~/ 60;
int secondsMeditated = totalMeditationTime % 60;
message = MeditationComplete(minutesMeditated, secondsMeditated);
}

MeditationHistoryStorage.addToHistory(selectedMinutes, timeDiff);
if (minutesMeditated == 0 && secondsMeditated == 0) {
endedTooSoon = true;
message = meditationEndedTooSoon();
} else {
message = meditationComplete(minutesMeditated, secondsMeditated);
MeditationHistoryStorage.addToHistory(selectedMinutes, timeDiff);
}
}

// Show completion message
ScaffoldMessenger.of(context).showSnackBar(
Expand All @@ -102,11 +113,12 @@ class _MeditationScreenState extends State<MeditationScreen>
style: const TextStyle(fontSize: 16),
textAlign: TextAlign.center,
),
const Text(
'Keep up the great work! 🧘‍♂️',
style: TextStyle(fontSize: 14, fontStyle: FontStyle.italic),
textAlign: TextAlign.center,
),
if (!endedTooSoon)
const Text(
'Keep up the great work! 🧘‍♂️',
style: TextStyle(fontSize: 14, fontStyle: FontStyle.italic),
textAlign: TextAlign.center,
),
],
),
),
Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
#include "generated_plugin_registrant.h"

#include <audioplayers_linux/audioplayers_linux_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) audioplayers_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "AudioplayersLinuxPlugin");
audioplayers_linux_plugin_register_with_registrar(audioplayers_linux_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
}
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
audioplayers_linux
url_launcher_linux
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import audioplayers_darwin
import path_provider_foundation
import shared_preferences_foundation
import speech_to_text
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SpeechToTextPlugin.register(with: registry.registrar(forPlugin: "SpeechToTextPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
64 changes: 64 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,70 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.4.0"
url_launcher:
dependency: "direct main"
description:
name: url_launcher
sha256: "9d06212b1362abc2f0f0d78e6f09f726608c74e3b9462e8368bb03314aa8d603"
url: "https://pub.dev"
source: hosted
version: "6.3.1"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
sha256: "6fc2f56536ee873eeb867ad176ae15f304ccccc357848b351f6f0d8d4a40d193"
url: "https://pub.dev"
source: hosted
version: "6.3.14"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
sha256: "16a513b6c12bb419304e72ea0ae2ab4fed569920d1c7cb850263fe3acc824626"
url: "https://pub.dev"
source: hosted
version: "6.3.2"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
sha256: "4e9ba368772369e3e08f231d2301b4ef72b9ff87c31192ef471b380ef29a4935"
url: "https://pub.dev"
source: hosted
version: "3.2.1"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
sha256: "17ba2000b847f334f16626a574c702b196723af2a289e7a93ffcb79acff855c2"
url: "https://pub.dev"
source: hosted
version: "3.2.2"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: "772638d3b34c779ede05ba3d38af34657a05ac55b06279ea6edd409e323dca8e"
url: "https://pub.dev"
source: hosted
version: "2.3.3"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: "44cf3aabcedde30f2dba119a9dea3b0f2672fbe6fa96e85536251d678216b3c4"
url: "https://pub.dev"
source: hosted
version: "3.1.3"
uuid:
dependency: transitive
description:
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
#include "generated_plugin_registrant.h"

#include <audioplayers_windows/audioplayers_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
AudioplayersWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
audioplayers_windows
url_launcher_windows
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down