Skip to content

Commit

Permalink
refactor: Update language files and UI for reminders container
Browse files Browse the repository at this point in the history
  • Loading branch information
MoErn878 committed Jun 11, 2024
1 parent 15051aa commit 30a0321
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 52 deletions.
6 changes: 5 additions & 1 deletion assets/lang/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@
"chatWithDoctor": "الدردشة مع الطبيب",
"chatsDescription": "عرض وإدارة الدردشات الخاصة بك.",

"noReminders": "لا توجد تذكيرات"
"noReminders": "لا توجد تذكيرات",

"missed": "فائت",
"today": "اليوم",
"activation": "التفعيل"


}
6 changes: 5 additions & 1 deletion assets/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@
"chatWithDoctor": "Chat with Doctor",
"chatsDescription": "View your chat with a doctor.",

"noReminders": "No Reminders"
"noReminders": "No Reminders",

"missed": "Missed",
"today": "Today",
"activation": "Activation"

}
57 changes: 36 additions & 21 deletions lib/features/main/home/ui/widgets/reminder_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ class _ReminderListTileState extends State<ReminderListTile> {
);
}

Widget _buildTime(BuildContext context) {
Widget _buildTime(
BuildContext context,
{required String date,
String? time,}
) {
return Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
Expand All @@ -97,7 +101,7 @@ class _ReminderListTileState extends State<ReminderListTile> {
color: context.colorScheme.scrim,
),
Text(
'${widget.reminder.date}',
date,
style: AppTextStyle.labelLarge(context).copyWith(
color: context.colorScheme.scrim,
),
Expand All @@ -106,25 +110,27 @@ class _ReminderListTileState extends State<ReminderListTile> {
),
),
const SizedBox(width: 24.0),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
children: [
Icon(
FontAwesomeIcons.solidClock,
size: 22,
color: context.colorScheme.scrim,
),
Text(
'${widget.reminder.getNextDoseTime()?.format('hh:mm a')}',
style: AppTextStyle.labelLarge(context).copyWith(
color: context.colorScheme.scrim,
time != null
? Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
children: [
Icon(
FontAwesomeIcons.solidClock,
size: 22,
color: context.colorScheme.scrim,
),
Text(
time,
style: AppTextStyle.labelLarge(context).copyWith(
color: context.colorScheme.scrim,
),
),
],
),
),
],
),
),
)
: const SizedBox.shrink(),
],
),
);
Expand Down Expand Up @@ -167,7 +173,16 @@ class _ReminderListTileState extends State<ReminderListTile> {
children: [
_buildInfo(context),
const SizedBox(height: 20.0),
_buildTime(context),
widget.reminder.isActivationReminder()
? _buildTime(
context,
date: widget.reminder.activationDate,
)
: _buildTime(
context,
date: widget.reminder.nextDoseDate,
time: widget.reminder.getNextDoseTime()?.format('hh:mm a'),
),
],
),
),
Expand Down
14 changes: 7 additions & 7 deletions lib/features/main/home/ui/widgets/reminders_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ class _RemindersContainerState extends State<RemindersContainer>
controller: tabBarController,
tabs: [
Tab(
text: AppLocalizations.of(context).translate('Missed'),
text: AppLocalizations.of(context).translate('missed'),
),
Tab(
text: AppLocalizations.of(context).translate('Today'),
text: AppLocalizations.of(context).translate('today'),
),
Tab(
text: AppLocalizations.of(context).translate('Coming'),
text: AppLocalizations.of(context).translate('activation'),
),
],
splashBorderRadius: BorderRadius.circular(12),
Expand All @@ -101,7 +101,7 @@ class _RemindersContainerState extends State<RemindersContainer>
tabAlignment: TabAlignment.center,
indicatorSize: TabBarIndicatorSize.label,
enableFeedback: false,
labelPadding: const EdgeInsetsDirectional.fromSTEB(20, 0, 20, 0),
labelPadding: const EdgeInsetsDirectional.fromSTEB(14, 0, 14, 0),
labelStyle: AppTextStyle.titleLarge(context).copyWith(
fontWeight: FontWeight.w900,
),
Expand All @@ -118,11 +118,11 @@ class _RemindersContainerState extends State<RemindersContainer>
controller: tabBarController,
children: [
_buildReminders(context,
bloc.filterReminders(widget.reminders, ReminderTime.previous)),
bloc.filterReminders(widget.reminders, ReminderType.previous)),
_buildReminders(context,
bloc.filterReminders(widget.reminders, ReminderTime.today)),
bloc.filterReminders(widget.reminders, ReminderType.today)),
_buildReminders(context,
bloc.filterReminders(widget.reminders, ReminderTime.coming)),
bloc.filterReminders(widget.reminders, ReminderType.activation)),
],
);
}
Expand Down
36 changes: 28 additions & 8 deletions lib/features/main/reminders/data/models/reminder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,38 @@ class Reminder {
required this.prescriptionId,
});

bool isToday() {
bool isNextDoseToday() {
return getNextDoseTime()?.day == DateTime.now().day &&
getNextDoseTime()?.month == DateTime.now().month &&
getNextDoseTime()?.year == DateTime.now().year;
}

bool isBeforeToday() {
bool isNextDoseBeforeToday() {
return getNextDoseTime()
?.isBefore(DateTime.now().subtract(const Duration(days: 1))) ??
false;
}

bool isAfterToday() {
bool isNextDoseAfterToday() {
return getNextDoseTime()?.isAfter(DateTime.now()) ?? false;
}

bool isActivationReminder() {
return startDateActivate != null;
}

DateTime? getNextDoseTime() {
return nextDoseTime != null
? DateTime.parse(nextDoseTime!).toLocal()
: null;
}

DateTime? getActivationTime() {
return startDateActivate != null
? DateTime.parse(startDateActivate!).toLocal()
: null;
}

// ----------------- Drug Name ----------------- //

get drugFirstName => drugName.split(' ').first;
Expand All @@ -75,14 +85,24 @@ class Reminder {

// ----------------- Date ----------------- //

get dayOfDate => getNextDoseTime()?.day;
get monthOfDate => getNextDoseTime()?.month;
get dayOfNextDoseTimeDate => getNextDoseTime()?.day;
get monthOfNextDoseTimeDate => getNextDoseTime()?.month;

get nextDoseDate {
// Return the date in the format of 'dd MMM'
return "${dayOfNextDoseTimeDate.toString().padLeft(2, '0')}"
"/"
"${monthOfNextDoseTimeDate.toString().padLeft(2, '0')}";
}

get dayOfActivationTimeDate => getActivationTime()?.day;
get monthOfActivationTimeDate => getActivationTime()?.month;

get date {
get activationDate {
// Return the date in the format of 'dd MMM'
return "${dayOfDate.toString().padLeft(2, '0')}"
return "${dayOfActivationTimeDate.toString().padLeft(2, '0')}"
"/"
"${monthOfDate.toString().padLeft(2, '0')}";
"${monthOfActivationTimeDate.toString().padLeft(2, '0')}";
}

// ----------------- Time ----------------- //
Expand Down
32 changes: 19 additions & 13 deletions lib/features/main/reminders/data/repo/reminders_repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import '../../../../../core/networking/api/api_result.dart';
import '../../../../../core/networking/api/api_service.dart';
import '../models/reminder.dart';

enum ReminderTime {
enum ReminderType {
all,
previous,
today,
coming,
activation,
}

class RemindersRepo {
Expand All @@ -20,8 +21,7 @@ class RemindersRepo {

Future<ApiResult<List<Reminder>>> getRemindersList() async {
try {
final reminders =
await _apiService.getReminderList();
final reminders = await _apiService.getReminderList();
return ApiResult.success(reminders);
} catch (error) {
getIt<Logger>().e(error);
Expand All @@ -42,20 +42,26 @@ class RemindersRepo {
}

List<Reminder> filterReminders(
List<Reminder> reminders, ReminderTime filter) {
List<Reminder> reminders, ReminderType filter) {
List<Reminder> filteredReminders = [];

if (filter == ReminderTime.all) {
if (filter == ReminderType.all) {
filteredReminders = reminders;
} else if (filter == ReminderTime.previous) {
} else if (filter == ReminderType.previous) {
filteredReminders = reminders
.where((reminder) => reminder.isNextDoseBeforeToday())
.toList();
} else if (filter == ReminderType.today) {
filteredReminders =
reminders.where((reminder) => reminder.isBeforeToday()).toList();
} else if (filter == ReminderTime.today) {
filteredReminders =
reminders.where((reminder) => reminder.isToday()).toList();
} else if (filter == ReminderTime.coming) {
filteredReminders =
reminders.where((reminder) => reminder.isAfterToday()).toList();
reminders.where((reminder) => reminder.isNextDoseToday()).toList();
} else if (filter == ReminderType.coming) {
filteredReminders = reminders
.where((reminder) => reminder.isNextDoseAfterToday())
.toList();
} else if (filter == ReminderType.activation) {
filteredReminders = reminders
.where((reminder) => reminder.isActivationReminder())
.toList();
}

return filteredReminders;
Expand Down
4 changes: 3 additions & 1 deletion lib/features/main/reminders/logic/reminders_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:bloc/bloc.dart';
import 'package:logger/logger.dart';
import '../../../../core/helpers/errors.dart';
import '../data/models/reminder.dart';
import '../data/repo/reminders_repo.dart';
Expand All @@ -15,6 +16,7 @@ class RemindersCubit extends Cubit<RemindersState> {

// Get data
final response = await _remindersRepo.getRemindersList();

response.when(
success: (data) {
emit(RemindersState.remindersSuccess(data));
Expand Down Expand Up @@ -50,7 +52,7 @@ class RemindersCubit extends Cubit<RemindersState> {
}

List<Reminder> filterReminders(
List<Reminder> reminders, ReminderTime filter) {
List<Reminder> reminders, ReminderType filter) {
final filteredReminders = _remindersRepo.filterReminders(reminders, filter);
return filteredReminders;
}
Expand Down

0 comments on commit 30a0321

Please sign in to comment.