Skip to content

Commit

Permalink
refactor(JumuaWidget): improve handling of multiple jumua times
Browse files Browse the repository at this point in the history
- Add getOrderedJumuaTimes method to collect and order available jumua times
- Refactor jumuaTile to handle cases where jumua1 is null but jumua2/3 exist
- Remove direct dependency on jumua field being non-null
  • Loading branch information
YassinNouh21 committed Oct 31, 2024
1 parent 1d0a695 commit 713f2b9
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions lib/src/pages/times/widgets/jumua_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ import 'package:provider/provider.dart';
class JumuaWidget extends StatelessWidget {
const JumuaWidget({super.key});

List<String> getOrderedJumuaTimes(MosqueManager mosqueManager) {
final times = mosqueManager.times;
List<String> jumuaTimes = [];

if (times?.jumua != null) jumuaTimes.add(times!.jumua!);
if (times?.jumua2 != null) jumuaTimes.add(times!.jumua2!);
if (times?.jumua3 != null) jumuaTimes.add(times!.jumua3!);

return jumuaTimes;
}

@override
Widget build(BuildContext context) {
final mosqueManager = context.watch<MosqueManager>();
final userPrefs = context.watch<UserPreferencesManager>();

/// show eid instead of jumuaa if its eid time and eid is enabled
if (mosqueManager.showEid(userPrefs.hijriAdjustments)) {
return FadeInOutWidget(
first: eidWidget(mosqueManager, context),
Expand All @@ -43,15 +53,27 @@ class JumuaWidget extends StatelessWidget {
}

Widget jumuaTile(MosqueManager mosqueManager, BuildContext context) {
final jumuaTimes = getOrderedJumuaTimes(mosqueManager);

if (jumuaTimes.isEmpty) {
return SalahItemWidget(
withDivider: true,
removeBackground: true,
title: S.of(context).jumua,
time: "",
isIqamaMoreImportant: false,
);
}

return SalahItemWidget(
withDivider: true,
removeBackground: true,
title: S.of(context).jumua,
time: !mosqueManager.isJumuaOrJumua2EmptyOrNull() ? DateFormat.Hm().format(mosqueManager.activeJumuaaDate()) : "",
iqama: mosqueManager.times!.jumua2,
iqama2: mosqueManager.times!.jumua3,
time: jumuaTimes[0],
iqama: jumuaTimes.length > 1 ? jumuaTimes[1] : null,
iqama2: jumuaTimes.length > 2 ? jumuaTimes[2] : null,
isIqamaMoreImportant: false,
active: mosqueManager.nextIqamaIndex() == 1 && AppDateTime.isFriday && mosqueManager.times?.jumua != null,
active: mosqueManager.nextIqamaIndex() == 1 && AppDateTime.isFriday,
);
}
}

0 comments on commit 713f2b9

Please sign in to comment.