Skip to content

Commit

Permalink
feat(quran): Add moshaf type and version to update notification
Browse files Browse the repository at this point in the history
- Enhanced `UpdateAvailable` state to include `moshafType` (Hafs or Warsh) alongside version information.
- Updated notifier logic to handle `moshafType` when checking and comparing Quran updates.
- Localized new dialog content with placeholders for `moshafName` and `version` in `intl_en.arb`.
- Refactored update dialog to display the moshaf type and version dynamically.
- Streamlined `downloadQuran` functionality to pass the correct moshaf type to the notifier.
  • Loading branch information
YassinNouh21 committed Dec 6, 2024
1 parent dddc417 commit e9816c0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
14 changes: 14 additions & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -395,5 +395,19 @@
"example": "604"
}
}
},
"quranUpdateDialogContent": "A new update for the {moshafName} Quran (version {version}) is available.",
"@quranUpdateDialogContent": {
"description": "Message to display in the update available dialog with Quran name and version.",
"placeholders": {
"moshafName": {
"type": "String",
"example": "Hafs"
},
"version": {
"type": "String",
"example": "2.0"
}
}
}
}
23 changes: 9 additions & 14 deletions lib/src/pages/quran/widget/download_quran_popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class _DownloadQuranDialogState extends ConsumerState<DownloadQuranDialog> {
Extracting() => _buildExtractingDialog(context, state),
Success() => _handleSuccess(context),
CancelDownload() => const SizedBox(),
UpdateAvailable() => _buildUpdateAvailableDialog(context, state),
_ => const SizedBox(),
};
}
Expand Down Expand Up @@ -87,8 +88,14 @@ class _DownloadQuranDialogState extends ConsumerState<DownloadQuranDialog> {
}

Widget _buildUpdateAvailableDialog(BuildContext context, UpdateAvailable state) {
final moshafName = switch (state.moshafType) {
MoshafType.warsh => S.of(context).warsh,
MoshafType.hafs => S.of(context).hafs,
};

return AlertDialog(
title: Text(S.of(context).updateAvailable),
content: Text(S.of(context).quranUpdateDialogContent(moshafName, state.version)),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
Expand All @@ -97,8 +104,8 @@ class _DownloadQuranDialogState extends ConsumerState<DownloadQuranDialog> {
TextButton(
autofocus: true,
onPressed: () {
// final notifier = ref.read(downloadQuranNotifierProvider.notifier);
// notifier.downloadQuran(notifier.selectedMoshafType);
final notifier = ref.read(downloadQuranNotifierProvider.notifier);
notifier.downloadQuran(state.moshafType);
},
child: Text(S.of(context).download),
),
Expand Down Expand Up @@ -171,18 +178,6 @@ class _DownloadQuranDialogState extends ConsumerState<DownloadQuranDialog> {
);
}

Widget _buildNoUpdateDialog(BuildContext context, NoUpdate state) {
return AlertDialog(
title: Text(S.of(context).updatedQuran),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(S.of(context).ok),
),
],
);
}

Widget _buildChooseDownloadMoshaf(BuildContext context) {
return Focus(
focusNode: _dialogFocusNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ class DownloadQuranNotifier extends AutoDisposeAsyncNotifier<DownloadQuranState>
orElse: () async {
final remoteVersion = await downloadQuranRepoImpl.getRemoteQuranVersion(moshafType: moshafType);
return localVersionOption.fold(
() => UpdateAvailable(remoteVersion),
() => UpdateAvailable(
version: remoteVersion,
moshafType: moshafType,
),
(localVersion) => _compareVersions(moshafType, localVersion, remoteVersion),
);
},
Expand All @@ -90,7 +93,10 @@ class DownloadQuranNotifier extends AutoDisposeAsyncNotifier<DownloadQuranState>
final remoteVersion = await downloadQuranRepoImpl.getRemoteQuranVersion(moshafType: moshafType);

return localVersionOption.fold(
() => UpdateAvailable(remoteVersion),
() => UpdateAvailable(
version: remoteVersion,
moshafType: moshafType,
),
(localVersion) => _compareVersions(moshafType, localVersion, remoteVersion),
);
} else {
Expand All @@ -115,7 +121,10 @@ class DownloadQuranNotifier extends AutoDisposeAsyncNotifier<DownloadQuranState>

Future<DownloadQuranState> _compareVersions(MoshafType moshafType, String localVersion, String remoteVersion) async {
if (VersionHelper.isNewer(remoteVersion, localVersion)) {
return UpdateAvailable(remoteVersion);
return UpdateAvailable(
version: remoteVersion,
moshafType: moshafType,
);
} else {
final savePath = await getApplicationSupportDirectory();
final quranPathHelper = QuranPathHelper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,17 @@ class NoUpdate extends DownloadQuranState with EquatableMixin {

class UpdateAvailable extends DownloadQuranState {
final String version;
final MoshafType moshafType;

const UpdateAvailable({
required this.version,
required this.moshafType,
});

const UpdateAvailable(this.version);
@override
String toString() {
return 'UpdateAvailable: $version , $moshafType';
}
}

class CancelDownload extends DownloadQuranState {
Expand Down

0 comments on commit e9816c0

Please sign in to comment.