Skip to content

Commit

Permalink
Merge pull request #444 from JisanAR03/sizzle_3_update
Browse files Browse the repository at this point in the history
auto reminder in each 30 min for user
  • Loading branch information
JisanAR03 authored Aug 22, 2024
2 parents 5a9a845 + 45f2a7b commit 28f39af
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 29 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.apps.blt"
minSdkVersion 21
targetSdkVersion 33
targetSdkVersion 34
multiDexEnabled true
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
2 changes: 1 addition & 1 deletion ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
15 changes: 14 additions & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Uncomment this line to define a global platform for your project
platform :ios, '12.0'

Expand Down Expand Up @@ -42,4 +43,16 @@ post_install do |installer|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end

################ Awesome Notifications pod modification 1 ###################
awesome_pod_file = File.expand_path(File.join('plugins', 'awesome_notifications', 'ios', 'Scripts', 'AwesomePodFile'), '.symlinks')
require awesome_pod_file
update_awesome_pod_build_settings(installer)
################ Awesome Notifications pod modification 1 ###################
end

################ Awesome Notifications pod modification 2 ###################
awesome_pod_file = File.expand_path(File.join('plugins', 'awesome_notifications', 'ios', 'Scripts', 'AwesomePodFile'), '.symlinks')
require awesome_pod_file
update_awesome_main_target_settings('Runner', File.dirname(File.realpath(__FILE__)), flutter_root)
################ Awesome Notifications pod modification 2 ###################
32 changes: 28 additions & 4 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
BD4815CBF2E43FB6B6E05F7E /* [CP] Embed Pods Frameworks */,
3D0D20C01154FDD8C26CF626 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -156,7 +157,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -214,6 +215,23 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
};
3D0D20C01154FDD8C26CF626 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
showEnvVarsInLog = 0;
};
769F2DF4327B9A5B0592592B /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -343,7 +361,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand All @@ -356,7 +374,9 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = NO;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
BUILD_LIBRARY_FOR_DISTRIBUTION = NO;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -420,7 +440,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -469,7 +489,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand All @@ -484,7 +504,9 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = NO;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
BUILD_LIBRARY_FOR_DISTRIBUTION = NO;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
ENABLE_BITCODE = NO;
Expand All @@ -506,7 +528,9 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = NO;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
BUILD_LIBRARY_FOR_DISTRIBUTION = NO;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
ENABLE_BITCODE = NO;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import Flutter

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
Expand Down
86 changes: 67 additions & 19 deletions lib/src/pages/sizzle/sizzle_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:blt/src/pages/sizzle/sizzle_state_provider.dart';
import 'package:blt/src/pages/sizzle/sizzle_timer.dart';
import 'dart:async';
import 'package:awesome_notifications/awesome_notifications.dart'; //Added for awesome notifications

class SizzleHome extends ConsumerStatefulWidget {
const SizzleHome({Key? key}) : super(key: key);
Expand All @@ -19,33 +21,65 @@ class _SizzleHomeState extends ConsumerState<SizzleHome>
String? selectedIssueId; // Added to track selected issue's ID
String apiBaseUrl = GeneralEndPoints
.apiBaseUrl; // Updated to use the correct apiBaseUrl variable
Timer? _timer; //Added for managing the timer

@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
if (!isAllowed) {
AwesomeNotifications().requestPermissionToSendNotifications();
}
});

_initializeNotifications(); //Initialize awesome notifications
}

@override
void dispose() async {
print('Dispose called: isTimerRunning = $isTimerRunning');
WidgetsBinding.instance.removeObserver(this);
_cancelTimer(); //Cancel the timer when disposing
if (isTimerRunning) {
await _stopTimer(); // Await the stopTimer to ensure the request completes before disposing
await stopTimer(); // Await the stopTimer to ensure the request completes before disposing
}
super.dispose();
}

@override
void didChangeAppLifecycleState(AppLifecycleState state) async {
print('AppLifecycleState changed: $state');
void _initializeNotifications() {
AwesomeNotifications().initialize(
null, //Notification icon
[
NotificationChannel(
channelKey: 'sizzle_timer_channel',
channelName: 'Sizzle Timer Notifications',
channelDescription:
'Notifications for Sizzle Timer', //Added channel description
defaultColor: Color(0xFFFD5D00),
importance: NotificationImportance.High,
channelShowBadge: true,
)
],
channelGroups: [
NotificationChannelGroup(
channelGroupKey: 'sizzle_timer_group',
channelGroupName: 'sizzle Timer Group', //Added channel group name
)
],
debug: true,
);
}

if (state == AppLifecycleState.detached) {
// App is detached (e.g., removed from recent apps)
if (isTimerRunning) {
await _stopTimer(); // Await the stopTimer to ensure the request completes
}
}
Future<void> _showNotification() async {
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 14,
channelKey: 'sizzle_timer_channel',
title: 'Timer Stopped',
body: 'The timer has stopped. Are you still working?',
notificationLayout: NotificationLayout.Default,
),
);
}

@override
Expand Down Expand Up @@ -91,7 +125,7 @@ class _SizzleHomeState extends ConsumerState<SizzleHome>
WidgetsBinding.instance.addPostFrameCallback((_) async {
bool isPop = await launchConfirmationDialog(context);
if (isPop) {
await _stopTimer();
await stopTimer();
}
});
}
Expand Down Expand Up @@ -197,8 +231,8 @@ class _SizzleHomeState extends ConsumerState<SizzleHome>
),
floatingActionButton: FloatingActionButton(
onPressed: isTimerRunning
? _stopTimer
: _startTimer, // Added logic to start/stop the timer
? stopTimer
: startTimer, // Added logic to start/stop the timer
child: Icon(isTimerRunning
? Icons.stop
: Icons.play_arrow), // Updated icon based on timer state
Expand All @@ -208,10 +242,11 @@ class _SizzleHomeState extends ConsumerState<SizzleHome>
);
}

Future<void> _startTimer() async {
// Added method to start the timer
Future<void> startTimer() async {
if (selectedIssueUrl == null) return;

selectedIssueId = selectedIssueUrl!.split('/').last;

final response = await http.post(
Uri.parse('$apiBaseUrl' +
'timelogs/start/'), // Updated to use the correct $apiBaseUrl variable
Expand All @@ -232,6 +267,7 @@ class _SizzleHomeState extends ConsumerState<SizzleHome>
timeLogId = data['id']; // Store the returned time log ID
isTimerRunning =
true; // Update the state to indicate the timer is running
_startCountdownTimer(); //Start the countdown for 5 minutes
});
}
} else {
Expand All @@ -244,9 +280,20 @@ class _SizzleHomeState extends ConsumerState<SizzleHome>
}
}

Future<void> _stopTimer() async {
print(timeLogId);
// Added method to stop the timer
void _startCountdownTimer() {
_cancelTimer(); //Cancel any existing timer
_timer = Timer(Duration(minutes: 30), () async {
await stopTimer(); //Automatically stop the timer after 5 minutes
await _showNotification(); //Show a notification to remind the user
});
}

void _cancelTimer() {
_timer?.cancel(); //Cancel the timer
_timer = null;
}

Future<void> stopTimer() async {
if (timeLogId == null) return;

final response = await http.post(
Expand All @@ -266,6 +313,7 @@ class _SizzleHomeState extends ConsumerState<SizzleHome>
false; // Update the state to indicate the timer has stopped
timeLogId = null; // Clear the time log ID
selectedIssueId = null; // Clear the selected issue ID
_cancelTimer(); //Cancel the countdown timer
});
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion lib/src/pages/sizzle/sizzle_state_provider.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:blt/src/components/components_import.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

// Define your providers here
final usernameProvider = StateProvider<String?>((ref) => null);
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies:
lottie: ^3.1.2
webview_flutter: ^3.0.4
permission_handler: ^11.3.1
awesome_notifications: ^0.9.3+1

dev_dependencies:
flutter_launcher_icons: ">=0.9.0 <0.13.0"
Expand Down

0 comments on commit 28f39af

Please sign in to comment.