Skip to content

Commit

Permalink
schedule listening feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ghassenbenzahra123 committed Oct 25, 2024
1 parent 7b8e9a1 commit 1608712
Show file tree
Hide file tree
Showing 15 changed files with 1,623 additions and 23 deletions.
15 changes: 14 additions & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -352,5 +352,18 @@
}
}
},
"surahSelector":"Select Surah"
"surahSelector":"Select Surah",
"scheduleSaved": "Your schedule has been saved.",
"completeAllFields": "Please complete all fields before saving.",
"endTimeAfter": "End time must be later than the start time.",
"scheduleListening": "Scheduled Listening",
"enableScheduling": "Enable Scheduling",
"scheduleDesc": "Activate this feature to automatically play Surah at scheduled times.",
"startTime": "Start Time",
"endTime": "End Time",
"selectReciter": "Choose a Reciter",
"selectMoshaf": "Choose Moshaf",
"randomSurahSelection": "Random Surah Selection",
"selectSurah": "Choose Surah",
"save": "Save"
}
15 changes: 14 additions & 1 deletion lib/l10n/intl_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,19 @@
"example": "604"
}
}
}
},
"scheduleSaved": "Votre planification a été enregistré.",
"completeAllFields": "Veuillez remplir tous les champs avant de sauvegarder.",
"endTimeAfter": "L'heure de fin doit être postérieure à l'heure de début.",
"scheduleListening": "Écoute planifiée",
"enableScheduling": "Activer la planification",
"scheduleDesc": "Activez cette fonctionnalité pour lire automatiquement une Sourate aux heures planifiées.",
"startTime": "Heure de Début",
"endTime": "Heure de Fin",
"selectReciter": "Choisissez un Récitateur",
"selectMoshaf": "Choisissez un Moushaf",
"randomSurahSelection": "Sélection Aléatoire de Sourate",
"selectSurah": "Choisissez une Sourate",
"save": "Sauvegarder"

}
17 changes: 17 additions & 0 deletions lib/src/const/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,20 @@ abstract class SystemFeaturesConstant {
static const String kHdmi = 'android.hardware.hdmi';
static const String kEthernet = 'android.hardware.ethernet';
}
class BackgroundScheduleAudioServiceConstant {
static const String kManualPause = 'manual_pause_enabled';
static const String kPendingSchedule = 'pending_schedule';
static const String kScheduleEnabled = 'schedule_enabled';
static const String kStartTime = 'start_time';
static const String kEndTime = 'end_time';
static const String kRandomEnabled = 'isRandomEnabled';
static const String kRandomUrls = 'random_urls';
static const String kSelectedSurah = 'selected_surah';
static const String kSelectedSurahUrl = 'selected_surah_url';
static const String kSelectedReciter = 'selected_reciter';
static const String kSelectedMoshaf = 'selected_moshaf';
static const String kAudioStateChanged = 'kAudioStateChanged';
static const String kGetPlaybackState = 'kGetPlaybackState';
static const String kStopAudio = 'kStopAudio';
static const String kResumeAudio = 'kResumeAudio';
}
116 changes: 96 additions & 20 deletions lib/src/pages/quran/page/reciter_selection_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import 'package:fluttertoast/fluttertoast.dart';
import 'package:mawaqit/const/resource.dart';
import 'package:mawaqit/src/helpers/RelativeSizes.dart';
import 'package:mawaqit/src/pages/quran/page/quran_reading_screen.dart';
import 'package:mawaqit/src/pages/quran/page/schedule_screen.dart';
import 'package:mawaqit/src/pages/quran/widget/recite_type_grid_view.dart';
import 'package:mawaqit/src/services/theme_manager.dart';
import 'package:mawaqit/src/state_management/quran/quran/quran_notifier.dart';
import 'package:mawaqit/src/state_management/quran/quran/quran_state.dart';
import 'package:mawaqit/src/state_management/quran/recite/recite_notifier.dart';
import 'package:mawaqit/src/state_management/quran/recite/recite_state.dart';
import 'package:mawaqit/src/state_management/quran/schedule_listening/audio_control_notifier.dart';
import 'package:mawaqit/src/state_management/quran/schedule_listening/audio_control_state.dart';
import 'package:shimmer/shimmer.dart';
import 'package:sizer/sizer.dart';
import 'package:mawaqit/i18n/l10n.dart';
Expand Down Expand Up @@ -44,6 +47,7 @@ class _ReciterSelectionScreenState extends ConsumerState<ReciterSelectionScreen>

late FocusNode favoriteFocusNode;
late FocusNode changeReadingModeFocusNode;
late FocusNode scheduleListeningFocusNode;

late FocusScopeNode reciteTypeFocusScopeNode;
late FocusScopeNode reciteFocusScopeNode;
Expand Down Expand Up @@ -77,7 +81,9 @@ class _ReciterSelectionScreenState extends ConsumerState<ReciterSelectionScreen>
}
}
});

changeReadingModeFocusNode = FocusNode(debugLabel: 'change_reading_mode_focus_node');
scheduleListeningFocusNode = FocusNode(debugLabel: 'scheduleListeningFocusNode');
favoriteFocusNode = FocusNode(debugLabel: 'favorite_focus_node');

reciteTypeFocusScopeNode = FocusScopeNode(debugLabel: 'reciter_type_focus_scope_node');
Expand All @@ -97,6 +103,7 @@ class _ReciterSelectionScreenState extends ConsumerState<ReciterSelectionScreen>

reciteTypeFocusScopeNode.dispose();
reciteFocusScopeNode.dispose();
scheduleListeningFocusNode.dispose();

_tabController.dispose();
_searchController.dispose();
Expand All @@ -110,30 +117,99 @@ class _ReciterSelectionScreenState extends ConsumerState<ReciterSelectionScreen>

@override
Widget build(BuildContext context) {
final audioState = ref.watch(audioControlProvider);

return Scaffold(
key: _scaffoldKey,
floatingActionButton: SizedBox(
width: 40.sp, // Set the desired width
height: 40.sp, // Set the desired height
child: FloatingActionButton(
focusNode: changeReadingModeFocusNode,
focusColor: Theme.of(context).primaryColor,
backgroundColor: Colors.black.withOpacity(.5),
child: Icon(
Icons.menu_book,
color: Colors.white,
size: 15.sp,
floatingActionButton: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
SizedBox(
width: 30.sp, // Set the desired width
height: 30.sp, // Set the desired height
child: Consumer(
builder: (context, ref, child) {
return ref.watch(reciteNotifierProvider).when(
data: (reciter) {
return FloatingActionButton(
backgroundColor: Colors.black.withOpacity(.5),
child: Icon(
Icons.schedule,
color: Colors.white,
size: 15.sp,
),
onPressed: () async {
showDialog(
context: context,
builder: (BuildContext context) {
return ScheduleScreen(reciterList: reciter.reciters);
},
);
},
);
},
loading: () => CircularProgressIndicator(),
error: (error, stackTrace) => Icon(Icons.error, color: Colors.red),
);
},
),
),
onPressed: () async {
ref.read(quranNotifierProvider.notifier).selectModel(QuranMode.reading);
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => QuranReadingScreen(),
SizedBox(
width: 5.sp,
),
SizedBox(
width: 30.sp, // Set the desired width
height: 30.sp, // Set the desired height
child: FloatingActionButton(
focusNode: changeReadingModeFocusNode,
focusColor: Theme.of(context).primaryColor,
backgroundColor: Colors.black.withOpacity(.5),
child: Icon(
Icons.menu_book,
color: Colors.white,
size: 15.sp,
),
);
},
),
onPressed: () async {
ref.read(quranNotifierProvider.notifier).selectModel(QuranMode.reading);
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => QuranReadingScreen(),
),
);
},
),
),
SizedBox(
width: 5.sp,
),
audioState.when(
data: (state) {
if (!state.shouldShowControls) {
return const SizedBox.shrink(); // Hide controls when scheduling is disabled
}

return SizedBox(
width: 30.sp, // Set the desired width
height: 30.sp, // Set the desired height
child: FloatingActionButton(
focusNode: scheduleListeningFocusNode,
focusColor: Theme.of(context).primaryColor,
backgroundColor: state.status == AudioStatus.playing ? Colors.red : Colors.black.withOpacity(.5),
child: Icon(
color: Colors.white,
state.status == AudioStatus.playing ? Icons.pause : Icons.play_arrow,
),
onPressed: () {
ref.read(audioControlProvider.notifier).togglePlayback();
},
),
);
},
loading: () => const CircularProgressIndicator(),
error: (error, stack) => Text('Error: $error'),
)
],
),
appBar: AppBar(
backgroundColor: Color(0xFF28262F),
Expand Down
Loading

0 comments on commit 1608712

Please sign in to comment.