Skip to content

Commit 815425b

Browse files
Feature/progress bar alternatives (#212)
1 parent 3cf15d7 commit 815425b

File tree

11 files changed

+173
-23
lines changed

11 files changed

+173
-23
lines changed

lib/core/constants/preferences_flags.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ enum PreferencesFlag {
2626
aboutUsCard,
2727
scheduleCard,
2828
progressBarCard,
29-
gradesCard
29+
gradesCard,
30+
progressBarText
3031
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
enum ProgressBarText {
2+
daysElapsedWithTotalDays,
3+
percentage,
4+
remainingDays,
5+
}

lib/core/managers/settings_manager.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class SettingsManager with ChangeNotifier {
209209
Future<bool> getBool(PreferencesFlag flag) async {
210210
// Log the event
211211
_analyticsService.logEvent(
212-
"${tag}_${EnumToString.convertToString(flag)}", 'getString');
212+
"${tag}_${EnumToString.convertToString(flag)}", 'getBool');
213213
return _preferencesService.getBool(flag);
214214
}
215215

lib/core/services/preferences_service.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class PreferencesService {
3232

3333
Future<bool> getBool(PreferencesFlag flag) async {
3434
final SharedPreferences prefs = await SharedPreferences.getInstance();
35-
3635
return prefs.getBool(flag.toString());
3736
}
3837

lib/core/viewmodels/dashboard_viewmodel.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
99
// CONSTANTS
1010
import 'package:notredame/core/constants/preferences_flags.dart';
1111
import 'package:notredame/core/constants/discovery_ids.dart';
12+
import 'package:notredame/core/constants/progress_bar_text_options.dart';
1213

1314
// MANAGER
1415
import 'package:notredame/core/managers/settings_manager.dart';
@@ -68,6 +69,11 @@ class DashboardViewModel extends FutureViewModel<Map<PreferencesFlag, int>> {
6869
/// Get cards to display
6970
List<PreferencesFlag> get cardsToDisplay => _cardsToDisplay;
7071

72+
ProgressBarText _currentProgressBarText =
73+
ProgressBarText.daysElapsedWithTotalDays;
74+
75+
ProgressBarText get currentProgressBarText => _currentProgressBarText;
76+
7177
/// Return session progress based on today's [date]
7278
double getSessionProgress() {
7379
if (_courseRepository.activeSessions.isEmpty) {
@@ -82,6 +88,18 @@ class DashboardViewModel extends FutureViewModel<Map<PreferencesFlag, int>> {
8288
}
8389
}
8490

91+
void changeProgressBarText() {
92+
if (currentProgressBarText.index <= 1) {
93+
_currentProgressBarText =
94+
ProgressBarText.values[currentProgressBarText.index + 1];
95+
} else {
96+
_currentProgressBarText = ProgressBarText.values[0];
97+
}
98+
99+
_settingsManager.setString(
100+
PreferencesFlag.progressBarText, _currentProgressBarText.toString());
101+
}
102+
85103
/// Returns a list containing the number of elapsed days in the active session
86104
/// and the total number of days in the session
87105
List<int> getSessionDays() {
@@ -186,6 +204,14 @@ class DashboardViewModel extends FutureViewModel<Map<PreferencesFlag, int>> {
186204
}
187205

188206
Future<List<Session>> futureToRunSessionProgressBar() async {
207+
String progressBarText =
208+
await _settingsManager.getString(PreferencesFlag.progressBarText);
209+
210+
progressBarText ??= ProgressBarText.daysElapsedWithTotalDays.toString();
211+
212+
_currentProgressBarText = ProgressBarText.values
213+
.firstWhere((e) => e.toString() == progressBarText);
214+
189215
setBusyForObject(progress, true);
190216
return _courseRepository
191217
.getSessions()

lib/l10n/intl_en.arb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,17 @@
241241
"elapsedDays": {},
242242
"totalDays": {}
243243
}
244+
},
245+
"progress_bar_message_percentage": "{percentage} %",
246+
"@progress_bar_message_percentage": {
247+
"placeholders": {
248+
"percentage": {}
249+
}
250+
},
251+
"progress_bar_message_remaining_days": "{remainingDays} remaining days",
252+
"@progress_bar_message_remaining_days": {
253+
"placeholders": {
254+
"remainingDays": {}
255+
}
244256
}
245257
}

lib/l10n/intl_fr.arb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,17 @@
239239
"elapsedDays": {},
240240
"totalDays": {}
241241
}
242+
},
243+
"progress_bar_message_percentage": "{percentage} %",
244+
"@progress_bar_message_percentage": {
245+
"placeholders": {
246+
"percentage": {}
247+
}
248+
},
249+
"progress_bar_message_remaining_days": "{remainingDays} jours restant",
250+
"@progress_bar_message_remaining_days": {
251+
"placeholders": {
252+
"remainingDays": {}
253+
}
242254
}
243255
}

lib/ui/views/dashboard_view.dart

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'package:notredame/core/constants/preferences_flags.dart';
2020
import 'package:notredame/core/constants/urls.dart';
2121
import 'package:notredame/core/models/course_activity.dart';
2222
import 'package:notredame/core/constants/discovery_ids.dart';
23+
import 'package:notredame/core/constants/progress_bar_text_options.dart';
2324

2425
// UTILS
2526
import 'package:notredame/core/utils/utils.dart';
@@ -34,7 +35,10 @@ class DashboardView extends StatefulWidget {
3435
_DashboardViewState createState() => _DashboardViewState();
3536
}
3637

37-
class _DashboardViewState extends State<DashboardView> {
38+
class _DashboardViewState extends State<DashboardView>
39+
with TickerProviderStateMixin {
40+
Text progressBarText;
41+
3842
@override
3943
void initState() {
4044
super.initState();
@@ -95,6 +99,8 @@ class _DashboardViewState extends State<DashboardView> {
9599

96100
default:
97101
}
102+
103+
setText(model);
98104
}
99105

100106
return cards;
@@ -185,22 +191,37 @@ class _DashboardViewState extends State<DashboardView> {
185191
padding: const EdgeInsets.fromLTRB(17, 10, 15, 20),
186192
child: ClipRRect(
187193
borderRadius: const BorderRadius.all(Radius.circular(10)),
188-
child: LinearProgressIndicator(
189-
value: model.progress,
190-
minHeight: 30,
191-
valueColor: const AlwaysStoppedAnimation<Color>(
192-
AppTheme.gradeGoodMax),
193-
backgroundColor: AppTheme.etsDarkGrey,
194+
child: GestureDetector(
195+
onTap: () => setState(
196+
() => setState(() {
197+
model.changeProgressBarText();
198+
setText(model);
199+
}),
200+
),
201+
child: LinearProgressIndicator(
202+
value: model.progress,
203+
minHeight: 30,
204+
valueColor: const AlwaysStoppedAnimation<Color>(
205+
AppTheme.gradeGoodMax),
206+
backgroundColor: AppTheme.etsDarkGrey,
207+
),
194208
),
195209
),
196210
),
197-
Container(
198-
padding: const EdgeInsets.only(top: 16),
199-
child: Center(
200-
child: Text(
201-
AppIntl.of(context).progress_bar_message(
202-
model.sessionDays[0], model.sessionDays[1]),
203-
style: const TextStyle(color: Colors.white),
211+
GestureDetector(
212+
onTap: () => setState(() {
213+
model.changeProgressBarText();
214+
setText(model);
215+
}),
216+
child: Container(
217+
padding: const EdgeInsets.only(top: 16),
218+
child: Center(
219+
child: progressBarText ??
220+
Text(
221+
AppIntl.of(context).progress_bar_message(
222+
model.sessionDays[0], model.sessionDays[1]),
223+
style: const TextStyle(color: Colors.white),
224+
),
204225
),
205226
),
206227
),
@@ -215,6 +236,33 @@ class _DashboardViewState extends State<DashboardView> {
215236
]),
216237
);
217238

239+
void setText(DashboardViewModel model) {
240+
if (model.sessionDays[0] == 0 || model.sessionDays[1] == 0) {
241+
return;
242+
}
243+
244+
if (model.currentProgressBarText ==
245+
ProgressBarText.daysElapsedWithTotalDays) {
246+
progressBarText = Text(
247+
AppIntl.of(context)
248+
.progress_bar_message(model.sessionDays[0], model.sessionDays[1]),
249+
style: const TextStyle(color: Colors.white),
250+
);
251+
} else if (model.currentProgressBarText == ProgressBarText.percentage) {
252+
progressBarText = Text(
253+
AppIntl.of(context).progress_bar_message_percentage(
254+
((model.sessionDays[0] / model.sessionDays[1]) * 100).round()),
255+
style: const TextStyle(color: Colors.white),
256+
);
257+
} else {
258+
progressBarText = Text(
259+
AppIntl.of(context).progress_bar_message_remaining_days(
260+
model.sessionDays[1] - model.sessionDays[0]),
261+
style: const TextStyle(color: Colors.white),
262+
);
263+
}
264+
}
265+
218266
Widget _buildTodayScheduleCard(
219267
DashboardViewModel model, PreferencesFlag flag) {
220268
return DismissibleCard(

pubspec.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ packages:
1414
name: analyzer
1515
url: "https://pub.dartlang.org"
1616
source: hosted
17-
version: "1.7.2"
17+
version: "1.7.1"
1818
archive:
1919
dependency: transitive
2020
description:
@@ -35,7 +35,7 @@ packages:
3535
name: async
3636
url: "https://pub.dartlang.org"
3737
source: hosted
38-
version: "2.8.1"
38+
version: "2.6.1"
3939
boolean_selector:
4040
dependency: transitive
4141
description:
@@ -77,7 +77,7 @@ packages:
7777
name: charcode
7878
url: "https://pub.dartlang.org"
7979
source: hosted
80-
version: "1.3.1"
80+
version: "1.2.0"
8181
cli_util:
8282
dependency: transitive
8383
description:
@@ -496,7 +496,7 @@ packages:
496496
name: meta
497497
url: "https://pub.dartlang.org"
498498
source: hosted
499-
version: "1.7.0"
499+
version: "1.3.0"
500500
mockito:
501501
dependency: "direct dev"
502502
description:
@@ -795,7 +795,7 @@ packages:
795795
name: test_api
796796
url: "https://pub.dartlang.org"
797797
source: hosted
798-
version: "0.4.2"
798+
version: "0.3.0"
799799
typed_data:
800800
dependency: transitive
801801
description:

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
1515
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
1616
# Read more about iOS versioning at
1717
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
18-
version: 4.2.4+1
18+
version: 4.3.0+1
1919

2020
environment:
2121
sdk: ">=2.10.0 <3.0.0"

0 commit comments

Comments
 (0)