Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/helpers/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const PREFS_INGREDIENTS = 'ingredientData';
const PREFS_WORKOUT_UNITS = 'workoutUnits';
const PREFS_USER = 'userData';
const PREFS_USER_DARK_THEME = 'userDarkMode';
const PREFS_FIRST_DAY_OF_WEEK = 'firstDayOfWeek';
const PREFS_LAST_SERVER = 'lastServer';

const DEFAULT_ANIMATION_DURATION = Duration(milliseconds: 200);
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@
},
"calendar": "Kalender",
"@calendar": {},
"firstDayOfWeek": "Erster Wochentag",
"monday": "Montag",
"sunday": "Sonntag",
"saturday": "Samstag",
"noWeightEntries": "Du hast keine Gewichtseinträge",
"@noWeightEntries": {
"description": "Message shown when the user has no logged weight entries"
Expand Down
7 changes: 7 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,13 @@
"others": "Others",
"calendar": "Calendar",
"@calendar": {},
"firstDayOfWeek": "First day of week",
"@firstDayOfWeek": {
"description": "Setting label for choosing the first day of the week in the calendar"
},
"monday": "Monday",
"sunday": "Sunday",
"saturday": "Saturday",
"goToToday": "Go to today",
"@goToToday": {
"description": "Label on button to jump back to 'today' in the calendar widget"
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
},
"calendar": "Calendario",
"@calendar": {},
"firstDayOfWeek": "Primer día de la semana",
"monday": "Lunes",
"sunday": "Domingo",
"saturday": "Sábado",
"aboutDescription": "¡Gracias por usar wger! wger es un proyecto colaborativo de código abierto, realizado por entusiastas del fitness de todo el planeta.",
"@aboutDescription": {
"description": "Text in the about dialog"
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
},
"calendar": "Calendrier",
"@calendar": {},
"firstDayOfWeek": "Premier jour de la semaine",
"monday": "Lundi",
"sunday": "Dimanche",
"saturday": "Samedi",
"toggleDetails": "Afficher les détails",
"@toggleDetails": {
"description": "Switch to toggle detail / overview"
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_it.arb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
},
"calendar": "Calendario",
"@calendar": {},
"firstDayOfWeek": "Primo giorno della settimana",
"monday": "Lunedì",
"sunday": "Domenica",
"saturday": "Sabato",
"toggleDetails": "Scegli dettagli",
"@toggleDetails": {
"description": "Switch to toggle detail / overview"
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@
},
"calendar": "Kalendarz",
"@calendar": {},
"firstDayOfWeek": "Pierwszy dzień tygodnia",
"monday": "Poniedziałek",
"sunday": "Niedziela",
"saturday": "Sobota",
"selectExercise": "Wybierz ćwiczenie",
"@selectExercise": {
"description": "Error message when the user hasn't selected an exercise in the form"
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@
},
"calendar": "Calendário",
"@calendar": {},
"firstDayOfWeek": "Primeiro dia da semana",
"monday": "Segunda-feira",
"sunday": "Domingo",
"saturday": "Sábado",
"goToToday": "Voltar para hoje",
"@goToToday": {
"description": "Label on button to jump back to 'today' in the calendar widget"
Expand Down
23 changes: 23 additions & 0 deletions lib/providers/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@ import 'dart:async';

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:table_calendar/table_calendar.dart';
import 'package:wger/helpers/consts.dart';
import 'package:wger/helpers/shared_preferences.dart';
import 'package:wger/models/user/profile.dart';
import 'package:wger/providers/base_provider.dart';

class UserProvider with ChangeNotifier {
ThemeMode themeMode = ThemeMode.system;
StartingDayOfWeek firstDayOfWeek = StartingDayOfWeek.monday;
final WgerBaseProvider baseProvider;
late SharedPreferencesAsync prefs;

UserProvider(this.baseProvider, {SharedPreferencesAsync? prefs}) {
this.prefs = prefs ?? PreferenceHelper.asyncPref;
_loadThemeMode();
_loadFirstDayOfWeek();
}

static const PROFILE_URL = 'userprofile';
Expand Down Expand Up @@ -81,6 +84,26 @@ class UserProvider with ChangeNotifier {
notifyListeners();
}

// Load first day of week from SharedPreferences
Future<void> _loadFirstDayOfWeek() async {
final prefsFirstDay = await prefs.getInt(PREFS_FIRST_DAY_OF_WEEK);

if (prefsFirstDay == null) {
firstDayOfWeek = StartingDayOfWeek.monday;
} else {
firstDayOfWeek = StartingDayOfWeek.values[prefsFirstDay];
}

notifyListeners();
}

// Change first day of week
void setFirstDayOfWeek(StartingDayOfWeek day) async {
firstDayOfWeek = day;
await prefs.setInt(PREFS_FIRST_DAY_OF_WEEK, day.index);
notifyListeners();
}

/// Fetch the current user's profile
Future<void> fetchAndSetProfile() async {
final userData = await baseProvider.fetch(baseProvider.makeUrl(PROFILE_URL));
Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/core/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import 'package:wger/core/wide_screen_wrapper.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/screens/configure_plates_screen.dart';
import 'package:wger/widgets/core/settings/exercise_cache.dart';
import 'package:wger/widgets/core/settings/first_day_of_week.dart';
import 'package:wger/widgets/core/settings/ingredient_cache.dart';
import 'package:wger/widgets/core/settings/theme.dart';

Expand Down Expand Up @@ -49,6 +50,7 @@ class SettingsPage extends StatelessWidget {
const SettingsIngredientCache(),
ListTile(title: Text(i18n.others, style: Theme.of(context).textTheme.headlineSmall)),
const SettingsTheme(),
const SettingsFirstDayOfWeek(),
ListTile(
title: Text(i18n.selectAvailablePlates),
onTap: () {
Expand Down
50 changes: 50 additions & 0 deletions lib/widgets/core/settings/first_day_of_week.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:table_calendar/table_calendar.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/providers/user.dart';

class SettingsFirstDayOfWeek extends StatelessWidget {
const SettingsFirstDayOfWeek({super.key});

@override
Widget build(BuildContext context) {
final i18n = AppLocalizations.of(context);
final userProvider = Provider.of<UserProvider>(context);

return ListTile(
title: Text(i18n.firstDayOfWeek),
trailing: DropdownButton<StartingDayOfWeek>(
key: const ValueKey('firstDayOfWeekDropdown'),
value: userProvider.firstDayOfWeek,
onChanged: (StartingDayOfWeek? newValue) {
if (newValue != null) {
userProvider.setFirstDayOfWeek(newValue);
}
},
items:
[
StartingDayOfWeek.monday,
StartingDayOfWeek.sunday,
StartingDayOfWeek.saturday,
].map<DropdownMenuItem<StartingDayOfWeek>>((StartingDayOfWeek value) {
final label = _getDayLabel(value, i18n);
return DropdownMenuItem<StartingDayOfWeek>(value: value, child: Text(label));
}).toList(),
),
);
}

String _getDayLabel(StartingDayOfWeek day, AppLocalizations i18n) {
switch (day) {
case StartingDayOfWeek.monday:
return i18n.monday;
case StartingDayOfWeek.sunday:
return i18n.sunday;
case StartingDayOfWeek.saturday:
return i18n.saturday;
default:
return i18n.monday;
}
}
}
Loading