diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 237a0b3f..aa41e213 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -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" + } + } } } diff --git a/lib/src/pages/quran/widget/download_quran_popup.dart b/lib/src/pages/quran/widget/download_quran_popup.dart index bc6db853..9900c250 100644 --- a/lib/src/pages/quran/widget/download_quran_popup.dart +++ b/lib/src/pages/quran/widget/download_quran_popup.dart @@ -59,6 +59,7 @@ class _DownloadQuranDialogState extends ConsumerState { Extracting() => _buildExtractingDialog(context, state), Success() => _handleSuccess(context), CancelDownload() => const SizedBox(), + UpdateAvailable() => _buildUpdateAvailableDialog(context, state), _ => const SizedBox(), }; } @@ -87,8 +88,14 @@ class _DownloadQuranDialogState extends ConsumerState { } 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), @@ -97,8 +104,8 @@ class _DownloadQuranDialogState extends ConsumerState { 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), ), @@ -171,18 +178,6 @@ class _DownloadQuranDialogState extends ConsumerState { ); } - 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, diff --git a/lib/src/state_management/quran/download_quran/download_quran_notifier.dart b/lib/src/state_management/quran/download_quran/download_quran_notifier.dart index 46e53536..99fbb8cb 100644 --- a/lib/src/state_management/quran/download_quran/download_quran_notifier.dart +++ b/lib/src/state_management/quran/download_quran/download_quran_notifier.dart @@ -81,7 +81,10 @@ class DownloadQuranNotifier extends AutoDisposeAsyncNotifier orElse: () async { final remoteVersion = await downloadQuranRepoImpl.getRemoteQuranVersion(moshafType: moshafType); return localVersionOption.fold( - () => UpdateAvailable(remoteVersion), + () => UpdateAvailable( + version: remoteVersion, + moshafType: moshafType, + ), (localVersion) => _compareVersions(moshafType, localVersion, remoteVersion), ); }, @@ -90,7 +93,10 @@ class DownloadQuranNotifier extends AutoDisposeAsyncNotifier final remoteVersion = await downloadQuranRepoImpl.getRemoteQuranVersion(moshafType: moshafType); return localVersionOption.fold( - () => UpdateAvailable(remoteVersion), + () => UpdateAvailable( + version: remoteVersion, + moshafType: moshafType, + ), (localVersion) => _compareVersions(moshafType, localVersion, remoteVersion), ); } else { @@ -115,7 +121,10 @@ class DownloadQuranNotifier extends AutoDisposeAsyncNotifier Future _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( diff --git a/lib/src/state_management/quran/download_quran/download_quran_state.dart b/lib/src/state_management/quran/download_quran/download_quran_state.dart index 81a52a95..1619bee2 100644 --- a/lib/src/state_management/quran/download_quran/download_quran_state.dart +++ b/lib/src/state_management/quran/download_quran/download_quran_state.dart @@ -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 {