Skip to content

Commit

Permalink
Merge branch 'rc-1.5.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
jenspfahl committed Jan 10, 2024
2 parents 1caae5b + 0d2ffec commit 084af96
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 52 deletions.
2 changes: 2 additions & 0 deletions lib/service/PreferenceService.dart
Expand Up @@ -24,6 +24,8 @@ class PreferenceService implements ITranslatePreferences {
static final DATA_WALKTHROUGH_SHOWN = "data/walkThroughShown";
static final DATA_CURRENT_CALENDAR_MODE = "data/currentCalendarMode";
static final DATA_CURRENT_EVENT_TYPE = "data/currentEventType";
static final DATA_CURRENT_STATS_DATA_TYPE = "data/currentStatsDataType";
static final DATA_CURRENT_STATS_GROUP_BY = "data/currentStatsGroupBy";


static final PreferenceService _service = PreferenceService._internal();
Expand Down
3 changes: 3 additions & 0 deletions lib/ui/PersonalTaskLoggerScaffold.dart
Expand Up @@ -216,6 +216,9 @@ class PersonalTaskLoggerScaffoldState extends State<PersonalTaskLoggerScaffold>
// refresh current page
debugPrint("refresh ..");
});
_pages.forEach((page) {
page.getGlobalKey().currentState?.reload();
});
});
});
},
Expand Down
4 changes: 3 additions & 1 deletion lib/ui/pages/SettingsScreen.dart
Expand Up @@ -64,6 +64,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
_getLanguageSelectionAsString(1, localizationDelegate),
_getLanguageSelectionAsString(2, localizationDelegate),
_getLanguageSelectionAsString(3, localizationDelegate),
_getLanguageSelectionAsString(4, localizationDelegate),
],
initialSelected: _languageSelection,
okPressed: () {
Expand All @@ -76,7 +77,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
_preferenceService.getPreferredLocale().then((locale) {
Locale newLocale;
if (locale == null) {
newLocale = currentLocale(context);
newLocale = systemLocale(context);
}
else {
newLocale = locale;
Expand Down Expand Up @@ -329,6 +330,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
case 1: return translate('pages.settings.common.language.dialog.options.english');
case 2: return translate('pages.settings.common.language.dialog.options.german');
case 3: return translate('pages.settings.common.language.dialog.options.french');
case 4: return translate('pages.settings.common.language.dialog.options.russian');
}
final systemLanguage = Platform.localeName
.split("_")
Expand Down
73 changes: 60 additions & 13 deletions lib/ui/pages/TaskEventStats.dart
Expand Up @@ -16,6 +16,7 @@ import 'package:personaltasklogger/util/extensions.dart';

import '../../db/repository/TaskGroupRepository.dart';
import '../../model/Template.dart';
import '../../service/PreferenceService.dart';
import '../../util/units.dart';
import '../PersonalTaskLoggerApp.dart';

Expand All @@ -41,29 +42,44 @@ class _TaskEventStatsState extends State<TaskEventStats> {

int _touchedIndex = -1;

GroupBy? _originGroupBy;
GroupBy _groupBy = GroupBy.TASK_GROUP;
late List<bool> _groupBySelection;

DataType _dataType = DataType.DURATION;
late List<bool> _dataTypeSelection;

bool _groupByChangedByFilter = false;

@override
void initState() {
if (widget.taskEventListState.taskFilterSettings.filterByTaskOrTemplate != null) {
_updateGroupByByFilter(FilterChangeState.TASK_ON);
_initGroupByByFilter(FilterChangeState.TASK_ON);
}
if (widget.taskEventListState.taskFilterSettings.filterByTaskEventIds != null) {
_updateGroupByByFilter(FilterChangeState.SCHEDULED_ON);
_initGroupByByFilter(FilterChangeState.SCHEDULED_ON);
}

_dataTypeSelection = List.generate(DataType.values.length, (index) => index == _dataType.index);
_groupBySelection = List.generate(GroupBy.values.length, (index) => index == _groupBy.index);

// to restore the origin from previous selections if task filter is active (see _initGroupByByFilter())
PreferenceService().getInt(PreferenceService.DATA_CURRENT_STATS_GROUP_BY).then((value) {
if (value != null) {
_originGroupBy = GroupBy.values[value];
}
});

super.initState();
}

@override
Widget build(BuildContext context) {

final fDataType = PreferenceService().getInt(PreferenceService.DATA_CURRENT_STATS_DATA_TYPE);
final fGroupBy = PreferenceService().getInt(PreferenceService.DATA_CURRENT_STATS_GROUP_BY);
final requiredPrefs = Future.wait([fDataType, fGroupBy]);

return Scaffold(
appBar: AppBar(
title: Text(translate('stats.title')),
Expand All @@ -72,14 +88,33 @@ class _TaskEventStatsState extends State<TaskEventStats> {
initialTaskFilterSettings: widget.taskEventListState.taskFilterSettings,
doFilter: (taskFilterSettings, filterChangeState) {
setState(() {
_updateGroupByByFilter(filterChangeState);
_initGroupByByFilter(filterChangeState);
widget.taskEventListState.taskFilterSettings = taskFilterSettings;
widget.taskEventListState.doFilter();
});
}),
],
),
body: _createBody(),
body: FutureBuilder<List<int?>>(
future: requiredPrefs,
builder: (BuildContext context, AsyncSnapshot<List<int?>> snapshot) {
if (snapshot.hasData) {
final dataTypeIndex = snapshot.data![0];
if (dataTypeIndex != null) {
_updateDataType(DataType.values[dataTypeIndex]);
}
if (!_groupByChangedByFilter) {
final groupByIndex = snapshot.data![1];
if (groupByIndex != null) {
_updateGroupBy(GroupBy.values[groupByIndex]);
}
}
return _createBody();
}
else {
return Container();
}
}),
);
}

Expand Down Expand Up @@ -454,14 +489,24 @@ class _TaskEventStatsState extends State<TaskEventStats> {
isSelected: _dataTypeSelection,
onPressed: (int index) {
setState(() {
_dataTypeSelection[_dataType.index] = false;
_dataTypeSelection[index] = true;
_dataType = DataType.values.elementAt(index);
_updateDataType(DataType.values[index]);
});
PreferenceService().setInt(PreferenceService.DATA_CURRENT_STATS_DATA_TYPE, _dataType.index);
},
);
}

void _updateDataType(DataType newDataType) {
_dataTypeSelection[_dataType.index] = false;
_dataTypeSelection[newDataType.index] = true;
_dataType = newDataType;
}

void _updateGroupBy(GroupBy newGroupBy) {
_groupBySelection[_groupBy.index] = false;
_groupBySelection[newGroupBy.index] = true;
_groupBy = newGroupBy;
}

Widget _createGroupByButton() {
return ToggleButtons(
Expand Down Expand Up @@ -498,26 +543,28 @@ class _TaskEventStatsState extends State<TaskEventStats> {
isSelected: _groupBySelection,
onPressed: (int index) {
setState(() {
_groupBySelection[_groupBy.index] = false;
_groupBySelection[index] = true;
_groupBy = GroupBy.values.elementAt(index);
_updateGroupBy(GroupBy.values.elementAt(index));
});
PreferenceService().setInt(PreferenceService.DATA_CURRENT_STATS_GROUP_BY, _groupBy.index);
},
);
}


void _updateGroupByByFilter(FilterChangeState filterChangeState) {
void _initGroupByByFilter(FilterChangeState filterChangeState) {
debugPrint("old: $_groupBy $filterChangeState");

_groupByChangedByFilter = false;
if (filterChangeState == FilterChangeState.TASK_ON
|| filterChangeState == FilterChangeState.SCHEDULED_ON) {
_originGroupBy = _groupBy;
_groupBy = GroupBy.TEMPLATE;
_groupByChangedByFilter = true;
}
else if (filterChangeState == FilterChangeState.TASK_OFF
|| filterChangeState == FilterChangeState.SCHEDULED_OFF
|| filterChangeState == FilterChangeState.ALL_OFF) {
_groupBy = GroupBy.TASK_GROUP;
_groupBy = _originGroupBy??GroupBy.TASK_GROUP;
_groupByChangedByFilter = true;
}
debugPrint("new: $_groupBy");
_groupBySelection = List.generate(GroupBy.values.length, (index) => index == _groupBy.index);
Expand Down
21 changes: 21 additions & 0 deletions lib/util/i18n.dart
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_translate/flutter_translate.dart';
Expand All @@ -11,6 +13,25 @@ Locale currentLocale(BuildContext context) {
return localizationDelegate.currentLocale;
}

Locale systemLocale(BuildContext context) {
final localizationDelegate = LocalizedApp.of(context).delegate;

final systemLanguage = Platform.localeName
.split("_")
.first;
final appLanguages = localizationDelegate.supportedLocales
.map((e) => e.languageCode);
debugPrint("system language: $systemLanguage");
final systemLanguageSupported = appLanguages.contains(systemLanguage);
if (systemLanguageSupported) {
return Locale(systemLanguage);
}
else {
return localizationDelegate.currentLocale;
}

}

bool isI18nKey(String string) =>
string.startsWith(I18N_PREFIX) && string.endsWith(I18N_POSTFIX);

Expand Down
2 changes: 2 additions & 0 deletions metadata/en-US/changelogs/10502.txt
@@ -0,0 +1,2 @@
* Add russian language
* Small bugfixes

0 comments on commit 084af96

Please sign in to comment.