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 @@ -64,6 +64,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
5 changes: 5 additions & 0 deletions lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@
"description": "Error message when the user hasn't entered a value on a required field"
},
"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 @@ -673,6 +673,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
5 changes: 5 additions & 0 deletions lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
"description": "Label on button to jump back to 'today' in the calendar widget"
},
"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
5 changes: 5 additions & 0 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
"description": "Label on button to jump back to 'today' in the calendar widget"
},
"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
5 changes: 5 additions & 0 deletions lib/l10n/app_it.arb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
"description": "Label on button to jump back to 'today' in the calendar widget"
},
"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
5 changes: 5 additions & 0 deletions lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
"description": "Text to show when entries are being loaded in the background: Loading..."
},
"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
5 changes: 5 additions & 0 deletions lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@
"description": "Text in the about dialog"
},
"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 @@ -22,6 +22,7 @@ import 'dart:convert';
import 'package:collection/collection.dart';
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';
Expand Down Expand Up @@ -63,12 +64,14 @@ class DashboardItem {

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();
_loadDashboardConfig();
}

Expand Down Expand Up @@ -193,6 +196,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
49 changes: 28 additions & 21 deletions lib/widgets/core/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
*/

import 'package:flutter/material.dart';
import 'package:wger/core/wide_screen_wrapper.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/screens/settings_plates_screen.dart';

import './settings/exercise_cache.dart';
import './settings/ingredient_cache.dart';
import './settings/theme.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';

class SettingsPage extends StatelessWidget {
static String routeName = '/SettingsPage';
Expand All @@ -35,23 +36,29 @@ class SettingsPage extends StatelessWidget {

return Scaffold(
appBar: AppBar(title: Text(i18n.settingsTitle)),
body: ListView(
children: [
ListTile(
title: Text(i18n.settingsCacheTitle, style: Theme.of(context).textTheme.headlineSmall),
),
const SettingsExerciseCache(),
const SettingsIngredientCache(),
ListTile(title: Text(i18n.others, style: Theme.of(context).textTheme.headlineSmall)),
const SettingsTheme(),
ListTile(
title: Text(i18n.selectAvailablePlates),
onTap: () {
Navigator.of(context).pushNamed(ConfigurePlatesScreen.routeName);
},
trailing: const Icon(Icons.chevron_right),
),
],
body: WidescreenWrapper(
child: ListView(
children: [
ListTile(
title: Text(
i18n.settingsCacheTitle,
style: Theme.of(context).textTheme.headlineSmall,
),
),
const SettingsExerciseCache(),
const SettingsIngredientCache(),
ListTile(title: Text(i18n.others, style: Theme.of(context).textTheme.headlineSmall)),
const SettingsTheme(),
const SettingsFirstDayOfWeek(),
ListTile(
title: Text(i18n.selectAvailablePlates),
onTap: () {
Navigator.of(context).pushNamed(ConfigurePlatesScreen.routeName);
},
trailing: const Icon(Icons.chevron_right),
),
],
),
),
);
}
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