calendar fix and update.

This commit is contained in:
2026-10-25 17:46:55 +01:00
parent cd3398df99
commit 9a65ff7ad4
10 changed files with 2596 additions and 1651 deletions
+7 -2
View File
@@ -19,6 +19,7 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
Map<String, List<File>> _groupedFiles = {}; // Files grouped by folder
Map<String, DateTime> _folderCreationDates = {}; // Folder creation dates
Map<String, int> _folderScores = {}; // Folder scores (sum of scores of all target files inside)
Map<String, int> _fileScores = {}; // Per-file score cache to avoid sync reads in build
Color _bulletColor = Colors.blue; // default fallback
Map<String, bool> _folderTypes = {}; // true = tournament, false = training
String _folderFilter = 'all';
@@ -136,6 +137,7 @@ Color _getColorFromName(String colorName) {
Map<String, DateTime> folderDates = {};
Map<String, int> folderScores = {};
Map<String, bool> folderTypes = {};
Map<String, int> fileScores = {};
for (var folder in folders) {
String folderName = folder.path.split('/').last;
@@ -177,7 +179,9 @@ Color _getColorFromName(String colorName) {
for (var file in targetFiles) {
final jsonString = await file.readAsString();
final data = jsonDecode(jsonString);
totalScore += _getScoreFromJson(data);
final score = _getScoreFromJson(data);
fileScores[file.path] = score;
totalScore += score;
}
groupedFiles[folderName] = targetFiles;
@@ -201,6 +205,7 @@ Color _getColorFromName(String colorName) {
_folderTypes = {
for (var name in sortedFolderNames) name: folderTypes[name]!
};
_fileScores = fileScores;
});
} catch (e) {
debugPrint("Error loading target data files: $e");
@@ -782,7 +787,7 @@ Widget _buildTargetsList(String folderName) {
children: targetFiles.asMap().entries.map((entry) {
final index = entry.key;
final file = entry.value;
final score = _getScoreFromJson(jsonDecode(file.readAsStringSync()));
final score = _fileScores[file.path] ?? 0;
final fileName = "${_t('Target')} ${index + 1}";
return Container(
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -133,7 +133,7 @@ class _HomeScreenState extends State<HomeScreen> {
padding: const EdgeInsets.only(right: 16.0),
child: Center(
child: Text(
'V1.1',
'V1.2',
style: TextStyle(
color: Colors.grey[400],
fontSize: 12,
+2 -1
View File
@@ -50,7 +50,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
bool _notifyDezuranje = true;
bool _notifySestanek = true;
bool _notifyTekma = true;
String _selectedLanguage = 'English';
final List<Map<String, String>> _languages = [
{'code': 'en', 'name': 'English', 'flag': '🇬🇧'},
@@ -229,11 +228,13 @@ String _getTargetDisplayName(String targetPath) {
await prefs.setInt('notificationHours_single', hours);
await prefs.setStringList('notificationHours', [hours.toString()]);
setState(() => _notificationHours = hours);
NotificationService().rescheduleFromCalendar();
}
Future<void> _saveNotifyType(String key, bool value) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(key, value);
NotificationService().rescheduleFromCalendar();
}
Future<void> _loadCameraIPs() async {
File diff suppressed because it is too large Load Diff
+17 -20
View File
@@ -29,6 +29,7 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
List<Offset> _bullets = [];
List<Offset> _scaledBullets = []; // Bullets scaled to display target size
int _totalScore = 0;
Map<int, int> _folderChartScores = {};
Offset? _targetCenter;
Uint8List? _targetImageBytes;
img.Image? _targetImageDecoded;
@@ -256,6 +257,21 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
.map((b) => _scoreForBullet(b, _targetCenter!))
.fold(0, (sum, score) => sum + score);
// Pre-compute folder chart scores to avoid sync file reads in build
if (widget.isCombinedView) {
final chartScores = <int, int>{};
for (int i = 0; i < widget.jsonFiles.length; i++) {
final data = jsonDecode(await widget.jsonFiles[i].readAsString());
final bullets = (data['bullets'] as List?) ?? [];
int s = 0;
for (final b in bullets) {
s += _scoreForBullet(Offset(b['x'].toDouble(), b['y'].toDouble()), _targetCenter!);
}
chartScores[i + 1] = s;
}
_folderChartScores = chartScores;
}
setState(() {});
} catch (e) {
print("Error loading JSON or image: $e");
@@ -565,26 +581,7 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
}
Widget _buildFolderChartView() {
// Calculate target scores from all files
// Each file represents one target at position (fileIndex + 1)
final Map<int, int> targetScores = {};
for (int fileIdx = 0; fileIdx < widget.jsonFiles.length; fileIdx++) {
final file = widget.jsonFiles[fileIdx];
final targetPosition = fileIdx + 1; // T1, T2, T3, etc.
final data = jsonDecode(file.readAsStringSync());
final bullets = (data['bullets'] as List?) ?? [];
// Sum scores for this target
int targetScore = 0;
for (int j = 0; j < bullets.length; j++) {
final bullet = Offset(bullets[j]['x'].toDouble(), bullets[j]['y'].toDouble());
final score = _scoreForBullet(bullet, _targetCenter ?? Offset.zero);
targetScore += score;
}
targetScores[targetPosition] = targetScore;
}
final Map<int, int> targetScores = _folderChartScores;
if (targetScores.isEmpty) {
return Center(