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

Feat/ Play adhan and show notification when app is on foreground #1310

Open
wants to merge 13 commits into
base: release-1.19
Choose a base branch
from

Conversation

ghassenbenzahra123
Copy link
Contributor

📝 Summary

This PR fixes #719

Description

  • Play adhan and show notification when app is on foreground

Demo

20240910_185152.mp4

Checklist:

  • Coding Standards: I have reviewed my code to ensure it follows the project's coding standards.
  • Testing: I have tested the changes and they work as expected.
  • Merge Conflicts: I have resolved any merge conflicts with the latest main/development branch.
  • Branch Status: The branch is up-to-date with the target branch (main/development).

@ghassenbenzahra123 ghassenbenzahra123 self-assigned this Sep 11, 2024
@ibrahim-zehhaf-mawaqit ibrahim-zehhaf-mawaqit changed the base branch from main to release-1.18.0 November 14, 2024 09:27
ghassenbenzahra123 and others added 10 commits November 20, 2024 16:53
* fix: Improve Quran Download and Navigation Experience (#1452)

* fix: Ensure correct Moshaf type (Hafs) is displayed after download

* fix: display Hafs Quran correctly and remove success dialog

- Set Hafs as default Moshaf type if none is selected.
- Auto-dismiss success dialog on download completion.
- Improved state invalidation for Quran reading updates.
- Added FocusNode for better dialog interaction.
- Optimized resource management with keepAlive and link.close().

* fix: improve Quran Download and Navigation Experience

- Redirect user to Quran reading screen automatically after successful download and extraction of Quran (Hafs).
- Remove the unnecessary "OK" button to confirm Quran download completion, streamlining the user experience.
- Enhance state management for download-related UI in `quran_reading_screen.dart` to handle various download states (needed, downloading, extracting).
- Update `download_quran_popup.dart` to ensure proper navigation based on the user's first-time download experience.
- Improve error handling and loading indicators for a smoother and more intuitive flow.

* fix formating

* Update pubspec.yaml

* fix: Resolve overlapping and focus issues for Back and Switch buttons (#1457)

* fix: Resolve pop-up issue when selecting Listening mode (#1455)

- updated `_handleNavigation` method in `quran_mode_selection_screen.dart` to use `async/await` for ensuring proper completion of Quran mode selection before navigation.
- fixed unexpected pop-ups by adjusting the handling of the `moshafType` state in `download_quran_popup.dart`.
- improved navigation flow for both Reading and Listening modes, ensuring seamless user experience.

Co-authored-by: Ghassen Ben Zahra <ghassen.benzahra@gmail.com>

* Update pubspec.yaml

* fix merger conflict'

* remove just audio package

* format code

---------

Co-authored-by: Yassin Nouh <70436855+YassinNouh21@users.noreply.github.com>
Co-authored-by: Ibrahim ZEHHAF <97339607+ibrahim-zehhaf-mawaqit@users.noreply.github.com>
* fix: Improve Quran Download and Navigation Experience (#1452)

* fix: Ensure correct Moshaf type (Hafs) is displayed after download

* fix: display Hafs Quran correctly and remove success dialog

- Set Hafs as default Moshaf type if none is selected.
- Auto-dismiss success dialog on download completion.
- Improved state invalidation for Quran reading updates.
- Added FocusNode for better dialog interaction.
- Optimized resource management with keepAlive and link.close().

* fix: improve Quran Download and Navigation Experience

- Redirect user to Quran reading screen automatically after successful download and extraction of Quran (Hafs).
- Remove the unnecessary "OK" button to confirm Quran download completion, streamlining the user experience.
- Enhance state management for download-related UI in `quran_reading_screen.dart` to handle various download states (needed, downloading, extracting).
- Update `download_quran_popup.dart` to ensure proper navigation based on the user's first-time download experience.
- Improve error handling and loading indicators for a smoother and more intuitive flow.

* fix formating

* Update pubspec.yaml

* fix: Resolve overlapping and focus issues for Back and Switch buttons (#1457)

* fix: Resolve pop-up issue when selecting Listening mode (#1455)

- updated `_handleNavigation` method in `quran_mode_selection_screen.dart` to use `async/await` for ensuring proper completion of Quran mode selection before navigation.
- fixed unexpected pop-ups by adjusting the handling of the `moshafType` state in `download_quran_popup.dart`.
- improved navigation flow for both Reading and Listening modes, ensuring seamless user experience.

Co-authored-by: Ghassen Ben Zahra <ghassen.benzahra@gmail.com>

* Update pubspec.yaml

* fix merger conflict'

* fix schedule save after device restart

* fix reshedule to clear timers

* add printstatements debug prod

* remove restore on main

* add delay to restore timers

* remove feature from settings

* remove print statements

---------

Co-authored-by: Yassin Nouh <70436855+YassinNouh21@users.noreply.github.com>
Co-authored-by: Ibrahim ZEHHAF <97339607+ibrahim-zehhaf-mawaqit@users.noreply.github.com>
* fix: Improve Quran Download and Navigation Experience (#1452)

* fix: Ensure correct Moshaf type (Hafs) is displayed after download

* fix: display Hafs Quran correctly and remove success dialog

- Set Hafs as default Moshaf type if none is selected.
- Auto-dismiss success dialog on download completion.
- Improved state invalidation for Quran reading updates.
- Added FocusNode for better dialog interaction.
- Optimized resource management with keepAlive and link.close().

* fix: improve Quran Download and Navigation Experience

- Redirect user to Quran reading screen automatically after successful download and extraction of Quran (Hafs).
- Remove the unnecessary "OK" button to confirm Quran download completion, streamlining the user experience.
- Enhance state management for download-related UI in `quran_reading_screen.dart` to handle various download states (needed, downloading, extracting).
- Update `download_quran_popup.dart` to ensure proper navigation based on the user's first-time download experience.
- Improve error handling and loading indicators for a smoother and more intuitive flow.

* fix formating

* Update pubspec.yaml

* fix: Resolve overlapping and focus issues for Back and Switch buttons (#1457)

* fix: Resolve pop-up issue when selecting Listening mode (#1455)

- updated `_handleNavigation` method in `quran_mode_selection_screen.dart` to use `async/await` for ensuring proper completion of Quran mode selection before navigation.
- fixed unexpected pop-ups by adjusting the handling of the `moshafType` state in `download_quran_popup.dart`.
- improved navigation flow for both Reading and Listening modes, ensuring seamless user experience.

Co-authored-by: Ghassen Ben Zahra <ghassen.benzahra@gmail.com>

* Update pubspec.yaml

* fix merger conflict'

* merge main into 1.18

* code format

---------

Co-authored-by: Yassin Nouh <70436855+YassinNouh21@users.noreply.github.com>
Co-authored-by: Ibrahim ZEHHAF <97339607+ibrahim-zehhaf-mawaqit@users.noreply.github.com>
@ibrahim-zehhaf-mawaqit ibrahim-zehhaf-mawaqit changed the base branch from release-1.18.0 to release-1.19 January 23, 2025 09:19
Copy link
Contributor

@YassinNouh21 YassinNouh21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -137,6 +138,13 @@ dependencies:

wakelock_plus: 1.1.4
wakelock_plus_platform_interface: 1.1.0
flutter_background_service: ^5.0.9
audio_service: ^0.18.10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will crach onvo tv

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BackgroundService class is handling too many responsibilities - audio playback, notifications, and prayer scheduling.
Consider splitting it into separate services:
PrayerSchedulerService
AdhanAudioService
PrayerNotificationService

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

services/audio_service
service/adhan_notification_service

import '../models/mosqueConfig.dart';
import '../models/times.dart';

class BackgroundService with WidgetsBindingObserver {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no clean up or dispose for the audioPlayer and notificaiton

 @override
  Future<void> dispose() async {
    _notificationTimer?.cancel();
    await _audioPlayer?.dispose();
    await dismissExistingNotification();
    _scheduledTimes.clear();
    super.dispose();
  }

Comment on lines +197 to +199
if (_scheduledTimes.contains(scheduleTime)) return false;
final delay = scheduleTime.difference(AppDateTime.now());
return !delay.isNegative;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make it more thread safe

static final _lock = Lock(); // The "ticket system"
static final Set<DateTime> _scheduledTimes = {};

static void schedulePrayerTasks(...) async {
  await _lock.synchronized(() async { 
    if (_scheduledTimes.contains(scheduleTime)) return;
    _scheduledTimes.add(scheduleTime); 
    _schedulePrayerTimer(...); 
  }); 
}

what can produce Users get multiple alerts for the same prayer time.

try {
await dismissExistingNotification();
await NotificationOverlay.showNotification(
'$salahName time ($prayerName) notification',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'$salahName time ($prayerName) notification' // Not localized

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Play adhan as notification when the app is killed or in background
3 participants