small updates

This commit is contained in:
2026-10-27 14:03:31 +01:00
parent 3b50cb0fe9
commit 9d9e0c77f2
8 changed files with 391 additions and 356 deletions
+174 -146
View File
@@ -4,6 +4,7 @@ import '../services/app_settings.dart';
import '../services/target_repository.dart'; import '../services/target_repository.dart';
import '../theme/app_theme.dart'; import '../theme/app_theme.dart';
import '../widgets/bar_tabs.dart'; import '../widgets/bar_tabs.dart';
import '../widgets/help_sheet.dart';
import '../widgets/progress_chart.dart'; import '../widgets/progress_chart.dart';
import '../widgets/section.dart'; import '../widgets/section.dart';
import 'session_screen.dart'; import 'session_screen.dart';
@@ -125,12 +126,15 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
..sort((a, b) => counts[b]!.compareTo(counts[a]!)); ..sort((a, b) => counts[b]!.compareTo(counts[a]!));
} }
Future<void> _openSession(Session session) async { // The full session, not the copy limited to one format
// Open the full session, not the copy limited to one format Session _full(Session session) => _sessions!
final full = _sessions!
.firstWhere((s) => s.name == session.name, orElse: () => session); .firstWhere((s) => s.name == session.name, orElse: () => session);
await Navigator.push(context,
MaterialPageRoute(builder: (_) => SessionScreen(session: full))); Future<void> _openDetails(Session session) async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (_) => SessionScreen(session: _full(session))));
_load(); _load();
} }
@@ -188,7 +192,7 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
); );
} }
// Filters continue the dark app bar, like Koledar/Stiki; sort toggle at the end // Filters continue the dark app bar, like Koledar/Stiki
Widget _buildTabs() { Widget _buildTabs() {
final s = AppSettings.instance; final s = AppSettings.instance;
return BarTabs( return BarTabs(
@@ -201,19 +205,18 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
_filter = _Filter.values[i]; _filter = _Filter.values[i];
_shots = null; _shots = null;
}), }),
trailing: IconButton(
tooltip: _sortByScore ? s.t('Sort by Score') : s.t('Sort by Date'),
icon: Icon(
_sortByScore ? Icons.leaderboard_rounded : Icons.event_rounded,
color: Colors.white),
onPressed: () => setState(() => _sortByScore = !_sortByScore),
),
); );
} }
// Second dark row under the tabs: shots-per-target pills left, year right // Second dark row under the tabs: shots-per-target pills left, year right
// Always 1–5 (the capture limit); older saves above 5 keep their own pill.
// Formats with no targets yet are dimmed and can't be picked.
Widget _buildFilterBar(List<int> formats, int? selected) { Widget _buildFilterBar(List<int> formats, int? selected) {
final sorted = [...formats]..sort(); final sorted = {
for (int n = AppSettings.minBullets; n <= AppSettings.maxBullets; n++) n,
...formats,
}.toList()
..sort();
return Container( return Container(
color: AppTheme.bar, color: AppTheme.bar,
padding: const EdgeInsets.fromLTRB(12, 0, 4, 8), padding: const EdgeInsets.fromLTRB(12, 0, 4, 8),
@@ -224,11 +227,18 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
child: Row( child: Row(
children: [ children: [
Text(AppSettings.instance.t('Shots'),
style:
const TextStyle(fontSize: 12, color: Colors.white60)),
const SizedBox(width: 8),
for (final n in sorted) ...[ for (final n in sorted) ...[
_BarPill( _BarPill(
label: shotCount(n), label: '$n',
selected: n == selected, selected: n == selected,
onTap: () => setState(() => _shots = n)), empty: !formats.contains(n),
onTap: formats.contains(n)
? () => setState(() => _shots = n)
: null),
const SizedBox(width: 6), const SizedBox(width: 6),
], ],
], ],
@@ -286,15 +296,7 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
.toList() .toList()
.reversed .reversed
.toList(); // oldest first .toList(); // oldest first
const divider = VerticalDivider(width: 1, color: Colors.white24);
// Last session's average per shot compared with the overall average
final last =
chartSessions.isNotEmpty ? chartSessions.last.averagePerShot : null;
final delta = (last != null &&
stats.averagePerShot != null &&
chartSessions.length > 1)
? last - stats.averagePerShot!
: null;
return ClipRRect( return ClipRRect(
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
@@ -303,75 +305,54 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Dark header: headline number left, trend right // Dark header: all four numbers in equal columns
Container( Container(
color: AppTheme.bar, color: AppTheme.bar,
padding: const EdgeInsets.fromLTRB(20, 14, 16, 14), padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 14),
child: IntrinsicHeight(
child: Row( child: Row(
children: [ children: [
Expanded( Expanded(
child: Column( child: _MiniStat(
crossAxisAlignment: CrossAxisAlignment.start, label: s.t('Average per shot'),
children: [ value: stats.averagePerShot?.toStringAsFixed(2) ?? '–',
Text(s.t('Average per shot'),
style: const TextStyle(
fontSize: 13, color: Colors.white60)),
Text(
stats.averagePerShot?.toStringAsFixed(2) ?? '–',
style: const TextStyle(
fontSize: 40,
fontWeight: FontWeight.w800,
color: Colors.white,
height: 1.15),
),
],
), ),
), ),
if (delta != null) divider,
_TrendBadge(delta: delta, label: s.t('last training')),
],
),
),
Padding(
padding: const EdgeInsets.fromLTRB(20, 8, 20, 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (chartSessions.length > 1) ...[
const SizedBox(height: 4),
ProgressChart(
points: _chartPoints(chartSessions),
color: s.bulletColor,
textColor: surf.textSecondary,
gridColor: surf.divider,
),
],
const SizedBox(height: 12),
Divider(height: 1, color: surf.divider),
const SizedBox(height: 14),
Row(
children: [
Expanded( Expanded(
child: _MiniStat( child: _MiniStat(
label: s.t('Best target'), label: s.t('Best target'),
value: '${stats.best!.score}', value: '${stats.best!.score}',
), ),
), ),
divider,
Expanded( Expanded(
child: _MiniStat( child: _MiniStat(
label: s.t('Average target'), label: s.t('Average target'),
value: stats.averageTarget!.toStringAsFixed(1), value: stats.averageTarget!.toStringAsFixed(1),
), ),
), ),
divider,
Expanded( Expanded(
child: _MiniStat( child: _MiniStat(
label: s.t('Targets'), label: s.t(_filter == _Filter.tournament
value: '${stats.targets}', ? 'Tournaments'
: 'Trainings'),
value: '${stats.sessions}',
), ),
), ),
], ],
), ),
], ),
),
if (chartSessions.length > 1)
Padding(
padding: const EdgeInsets.fromLTRB(12, 12, 12, 12),
child: ProgressChart(
points: _chartPoints(chartSessions),
color: s.bulletColor,
textColor: surf.textSecondary,
gridColor: surf.divider,
), ),
), ),
], ],
@@ -385,25 +366,29 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
final surf = Surfaces.current; final surf = Surfaces.current;
final widgets = <Widget>[]; final widgets = <Widget>[];
String monthOf(Session x) =>
DateFormat('LLLL yyyy', _locale).format(x.date).toUpperCase();
if (_sortByScore) { if (_sortByScore) {
final ranked = [...sessions] // Average per shot, so sessions with more targets don't win by volume
..sort((a, b) => b.totalScore.compareTo(a.totalScore)); final ranked = [...sessions]..sort(
widgets.add(_monthHeader(s.t('Best results'))); (a, b) => (b.averagePerShot ?? 0).compareTo(a.averagePerShot ?? 0));
widgets.add(_sortBar(s.t('Best results').toUpperCase()));
widgets.addAll(ranked.map(_sessionCard)); widgets.addAll(ranked.map(_sessionCard));
return widgets; return widgets;
} }
String? month; String? month;
for (final session in sessions) { for (final session in sessions) {
final m = final m = monthOf(session);
DateFormat('LLLL yyyy', _locale).format(session.date).toUpperCase();
if (m != month) { if (m != month) {
widgets.add(_monthHeader(m)); // The first month header shares its row with the sort toggle
widgets.add(month == null ? _sortBar(m) : _monthHeader(m));
month = m; month = m;
} }
widgets.add(_sessionCard(session)); widgets.add(_sessionCard(session));
} }
if (widgets.isEmpty) { if (sessions.isEmpty) {
widgets.add(Padding( widgets.add(Padding(
padding: const EdgeInsets.all(24), padding: const EdgeInsets.all(24),
child: Text(s.t('No saved target data found'), child: Text(s.t('No saved target data found'),
@@ -413,6 +398,53 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
return widgets; return widgets;
} }
// Sort choice sits right above the list it sorts
Widget _sortBar(String title) {
final s = AppSettings.instance;
final surf = Surfaces.current;
return Padding(
padding: const EdgeInsets.fromLTRB(4, 16, 0, 4),
child: Row(
children: [
Expanded(
child: Text(
title,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
letterSpacing: 1.4,
color: surf.textSecondary,
),
),
),
SegmentedButton<bool>(
showSelectedIcon: false,
style: SegmentedButton.styleFrom(
visualDensity: VisualDensity.compact,
selectedBackgroundColor: s.bulletColor,
selectedForegroundColor: Colors.white,
foregroundColor: surf.textSecondary,
textStyle:
const TextStyle(fontSize: 12, fontWeight: FontWeight.w600),
),
segments: [
ButtonSegment(
value: false,
icon: const Icon(Icons.event_rounded, size: 16),
label: Text(s.t('Sort by Date'))),
ButtonSegment(
value: true,
icon: const Icon(Icons.leaderboard_rounded, size: 16),
label: Text(s.t('Sort by Score'))),
],
selected: {_sortByScore},
onSelectionChanged: (v) => setState(() => _sortByScore = v.first),
),
],
),
);
}
Widget _monthHeader(String text) { Widget _monthHeader(String text) {
return Padding( return Padding(
padding: const EdgeInsets.fromLTRB(4, 24, 4, 10), padding: const EdgeInsets.fromLTRB(4, 24, 4, 10),
@@ -428,14 +460,12 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
); );
} }
// Same build as the calendar cards: date block on the left, content in the // Date block on the left like the calendar cards. Tap shows this session's
// middle (opens the training), action strip on the right (opens all targets). // targets of the selected format on one target; the menu opens details/edit.
Widget _sessionCard(Session session) { Widget _sessionCard(Session session) {
final s = AppSettings.instance; final s = AppSettings.instance;
final surf = Surfaces.current; final surf = Surfaces.current;
final avg = session.averagePerShot; final avg = session.averagePerShot;
final full = _sessions!
.firstWhere((x) => x.name == session.name, orElse: () => session);
return Padding( return Padding(
padding: const EdgeInsets.only(bottom: 10), padding: const EdgeInsets.only(bottom: 10),
@@ -461,9 +491,10 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
child: Material( child: Material(
color: Colors.transparent, color: Colors.transparent,
child: InkWell( child: InkWell(
onTap: () => _openSession(session), onTap: () => _openTargets(session),
onLongPress: () => _openDetails(session),
child: Padding( child: Padding(
padding: const EdgeInsets.fromLTRB(14, 12, 12, 12), padding: const EdgeInsets.fromLTRB(14, 12, 4, 12),
child: Row( child: Row(
children: [ children: [
Expanded( Expanded(
@@ -516,16 +547,10 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
), ),
), ),
), ),
Material( IconButton(
color: AppTheme.bar, tooltip: s.t('Details'),
child: InkWell( icon: Icon(Icons.more_vert_rounded, color: surf.textSecondary),
onTap: () => _openAllTargets(full), onPressed: () => _openDetails(session),
child: const SizedBox(
width: 56,
child: Icon(Icons.visibility_rounded,
color: Colors.white, size: 22),
),
),
), ),
], ],
), ),
@@ -534,7 +559,7 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
); );
} }
Future<void> _openAllTargets(Session session) async { Future<void> _openTargets(Session session) async {
if (session.targets.isEmpty) return; if (session.targets.isEmpty) return;
await Navigator.push( await Navigator.push(
context, context,
@@ -580,50 +605,39 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
} }
} }
/// ▲/▼ difference with an icon, so the direction never depends on color alone. /// What Knjiga shows and where to tap; opened from the info button in the app bar.
class _TrendBadge extends StatelessWidget { void showBookHelp(BuildContext context) {
final double delta; final s = AppSettings.instance;
final String label; showHelpSheet(context, accent: s.bulletColor, t: s.t, items: const [
(
const _TrendBadge({required this.delta, required this.label}); Icons.emoji_events_rounded,
'Trainings / Tournaments: choose which sessions the statistics count.'
@override
Widget build(BuildContext context) {
final up = delta >= 0;
final color = up ? Colors.green[700]! : Colors.red[700]!;
return Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
decoration: BoxDecoration(
color: color, borderRadius: BorderRadius.circular(12)),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
up
? Icons.arrow_upward_rounded
: Icons.arrow_downward_rounded,
size: 14,
color: Colors.white),
const SizedBox(width: 2),
Text(
delta.abs().toStringAsFixed(2),
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.white),
), ),
], (
Icons.filter_5_rounded,
'Shots 1–5: statistics only compare targets with the same number of shots. Grey numbers have no targets yet.'
), ),
(
Icons.calendar_month_rounded,
'Year (top right): choose which year to show.'
), ),
const SizedBox(height: 2), (
Text(label, Icons.show_chart_rounded,
style: const TextStyle(fontSize: 11, color: Colors.white60)), 'Graph: average per shot over time. Tap or drag on it to see each value.'
], ),
); (
} Icons.leaderboard_rounded,
'By date / By score: sort the list by date or by best average per shot.'
),
(
Icons.touch_app_rounded,
'Tap a session to see all its targets with the selected number of shots on one target.'
),
(
Icons.more_vert_rounded,
'Three dots on the right or long press: session details, single targets, rename and delete.'
),
]);
} }
class _MiniStat extends StatelessWidget { class _MiniStat extends StatelessWidget {
@@ -632,19 +646,27 @@ class _MiniStat extends StatelessWidget {
const _MiniStat({required this.label, required this.value}); const _MiniStat({required this.label, required this.value});
// White on the dark header; labels get two lines since four share the width
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final surf = Surfaces.current; return Padding(
return Column( padding: const EdgeInsets.symmetric(horizontal: 4),
crossAxisAlignment: CrossAxisAlignment.start, child: Column(
children: [ children: [
Text(value, Text(value,
style: TextStyle( style: const TextStyle(
fontSize: 20, fontSize: 24,
fontWeight: FontWeight.w700, fontWeight: FontWeight.w800,
color: surf.textPrimary)), color: Colors.white)),
Text(label, style: TextStyle(fontSize: 12, color: surf.textSecondary)), const SizedBox(height: 2),
Text(label,
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 11, color: Colors.white60, height: 1.2)),
], ],
),
); );
} }
} }
@@ -697,10 +719,14 @@ class _DateBlock extends StatelessWidget {
class _BarPill extends StatelessWidget { class _BarPill extends StatelessWidget {
final String label; final String label;
final bool selected; final bool selected;
final VoidCallback onTap; final bool empty; // no targets with this many shots
final VoidCallback? onTap; // null = not selectable
const _BarPill( const _BarPill(
{required this.label, required this.selected, required this.onTap}); {required this.label,
required this.selected,
this.empty = false,
required this.onTap});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -712,13 +738,15 @@ class _BarPill extends StatelessWidget {
customBorder: const StadiumBorder(), customBorder: const StadiumBorder(),
onTap: onTap, onTap: onTap,
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6), padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 6),
child: Text( child: Text(
label, label,
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: selected ? Colors.black : Colors.white70, color: selected
? Colors.black
: (empty ? Colors.white30 : Colors.white70),
), ),
), ),
), ),
+19 -70
View File
@@ -7,7 +7,9 @@ import 'yolo_detector.dart';
import 'preview_screen.dart'; import 'preview_screen.dart';
import '../utils/translations.dart'; import '../utils/translations.dart';
import '../utils/target_colors.dart'; import '../utils/target_colors.dart';
import '../services/app_settings.dart';
import '../widgets/camera_sheet.dart'; import '../widgets/camera_sheet.dart';
import '../widgets/help_sheet.dart';
class CameraScreen extends StatefulWidget { class CameraScreen extends StatefulWidget {
const CameraScreen({super.key}); const CameraScreen({super.key});
@@ -113,8 +115,9 @@ class _CameraScreenState extends State<CameraScreen> {
Future<void> _loadBulletCount() async { Future<void> _loadBulletCount() async {
final prefs = await SharedPreferences.getInstance(); final prefs = await SharedPreferences.getInstance();
setState(() { setState(() {
_numberOfBullets = prefs.getInt('bulletCount') ?? // Older versions allowed up to 10
5; // Load stored bullet count, default to 5 _numberOfBullets = (prefs.getInt('bulletCount') ?? AppSettings.maxBullets)
.clamp(AppSettings.minBullets, AppSettings.maxBullets);
}); });
} }
@@ -203,11 +206,13 @@ class _CameraScreenState extends State<CameraScreen> {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
CameraSheetHeader( CameraSheetHeader(
title: _t('Select the number of bullets'), subtitle: '1 – 10'), title: _t('Select the number of bullets'),
subtitle:
'${AppSettings.minBullets} – ${AppSettings.maxBullets}'),
SheetStepper( SheetStepper(
value: _numberOfBullets, value: _numberOfBullets,
min: 1, min: AppSettings.minBullets,
max: 10, max: AppSettings.maxBullets,
accent: _bulletColor, accent: _bulletColor,
onChanged: (n) { onChanged: (n) {
_selectBulletCount(n); _selectBulletCount(n);
@@ -222,71 +227,15 @@ class _CameraScreenState extends State<CameraScreen> {
} }
void _showHelpDialog() { void _showHelpDialog() {
showDialog( showHelpSheet(context, accent: _bulletColor, t: _t, items: const [
context: context, (Icons.crop_square, 'Align the target inside the square frame.'),
builder: (BuildContext context) { (
return Dialog( Icons.camera_alt,
backgroundColor: Colors.grey[900], 'Camera button: take a photo. Bullets are detected and you can check and save the result.'
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_t('Help'),
style: const TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.bold),
), ),
const SizedBox(height: 20), (Icons.filter_5_rounded, 'Number bottom left: shots per target (1–5).'),
_buildHelpItem(Icons.camera_alt, (Icons.tune, 'Settings icon: exposure, zoom and flashlight.'),
_t('Tap camera button to capture and detect bullets')), ]);
const SizedBox(height: 12),
_buildHelpItem(Icons.filter_9_plus,
_t('Bottom left number: Set expected bullet count (1-5)')),
const SizedBox(height: 12),
_buildHelpItem(Icons.tune,
_t('Settings icon: exposure, zoom and flashlight')),
const SizedBox(height: 12),
_buildHelpItem(Icons.crop_square,
_t('Align target inside the square frame')),
const SizedBox(height: 20),
Center(
child: ElevatedButton(
onPressed: () => Navigator.of(context).pop(),
style: ElevatedButton.styleFrom(
backgroundColor: _bulletColor,
foregroundColor: Colors.white,
),
child: Text(_t('Got it!')),
),
),
],
),
),
);
},
);
}
Widget _buildHelpItem(IconData icon, String text) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(icon, color: _bulletColor, size: 20),
const SizedBox(width: 12),
Expanded(
child: Text(
text,
style: const TextStyle(color: Colors.white, fontSize: 14),
),
),
],
);
} }
void _showCameraControls() { void _showCameraControls() {
@@ -406,7 +355,7 @@ class _CameraScreenState extends State<CameraScreen> {
centerTitle: true, centerTitle: true,
actions: [ actions: [
IconButton( IconButton(
icon: const Icon(Icons.help_outline, color: Colors.white), icon: const Icon(Icons.info_outline_rounded, color: Colors.white),
onPressed: _showHelpDialog, onPressed: _showHelpDialog,
), ),
const SizedBox(width: 16), const SizedBox(width: 16),
+6
View File
@@ -93,6 +93,12 @@ class _HomeScreenState extends State<HomeScreen> {
automaticallyImplyLeading: false, automaticallyImplyLeading: false,
scrolledUnderElevation: 0, // For Material 3 (Flutter 3.7+) scrolledUnderElevation: 0, // For Material 3 (Flutter 3.7+)
actions: [ actions: [
if (_selected == AppTab.book)
IconButton(
tooltip: settings.t('Help'),
icon: const Icon(Icons.info_outline_rounded, color: Colors.white),
onPressed: () => showBookHelp(context),
),
if (_selected == AppTab.shooting) if (_selected == AppTab.shooting)
IconButton( IconButton(
icon: const Icon(Icons.visibility_rounded, color: Colors.white), icon: const Icon(Icons.visibility_rounded, color: Colors.white),
-3
View File
@@ -31,7 +31,6 @@ class SettingsScreen extends StatelessWidget {
SectionHeader(t('Language')), SectionHeader(t('Language')),
GroupCard(children: [ GroupCard(children: [
SettingsTile( SettingsTile(
leading: Text(language['flag']!, style: const TextStyle(fontSize: 22)),
title: t(language['name']!), title: t(language['name']!),
subtitle: s.followSystemLanguage ? t('Automatic (phone language)') : null, subtitle: s.followSystemLanguage ? t('Automatic (phone language)') : null,
onTap: () => _pickLanguage(context), onTap: () => _pickLanguage(context),
@@ -213,7 +212,6 @@ class SettingsScreen extends StatelessWidget {
children: [ children: [
_SheetTitle(s.t('Select Language')), _SheetTitle(s.t('Select Language')),
SheetOption( SheetOption(
leading: const Text('📱', style: TextStyle(fontSize: 22)),
label: '${s.t('Automatic (phone language)')} · ${s.t(AppSettings.systemLanguage)}', label: '${s.t('Automatic (phone language)')} · ${s.t(AppSettings.systemLanguage)}',
selected: s.followSystemLanguage, selected: s.followSystemLanguage,
selectedColor: s.bulletColor, selectedColor: s.bulletColor,
@@ -224,7 +222,6 @@ class SettingsScreen extends StatelessWidget {
), ),
for (final lang in AppSettings.languages) for (final lang in AppSettings.languages)
SheetOption( SheetOption(
leading: Text(lang['flag']!, style: const TextStyle(fontSize: 22)),
label: s.t(lang['name']!), label: s.t(lang['name']!),
selected: !s.followSystemLanguage && lang['name'] == s.language, selected: !s.followSystemLanguage && lang['name'] == s.language,
selectedColor: s.bulletColor, selectedColor: s.bulletColor,
+28 -70
View File
@@ -12,7 +12,9 @@ import 'yolo_detector.dart';
import 'preview_screen.dart'; import 'preview_screen.dart';
import 'package:wakelock_plus/wakelock_plus.dart'; import 'package:wakelock_plus/wakelock_plus.dart';
import '../utils/translations.dart'; import '../utils/translations.dart';
import '../services/app_settings.dart';
import '../widgets/camera_sheet.dart'; import '../widgets/camera_sheet.dart';
import '../widgets/help_sheet.dart';
import '../widgets/image_settings.dart'; import '../widgets/image_settings.dart';
import '../services/wifi_binding.dart'; import '../services/wifi_binding.dart';
@@ -128,7 +130,9 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
final waitOn = prefs.getBool('timerWaitEnabled') ?? false; final waitOn = prefs.getBool('timerWaitEnabled') ?? false;
setState(() { setState(() {
_selectedLanguage = prefs.getString('language') ?? 'English'; _selectedLanguage = prefs.getString('language') ?? 'English';
_numberOfBullets = prefs.getInt('bulletCount') ?? 5; // Older versions allowed up to 10
_numberOfBullets = (prefs.getInt('bulletCount') ?? AppSettings.maxBullets)
.clamp(AppSettings.minBullets, AppSettings.maxBullets);
_image = image; _image = image;
_bulletColor = _bulletColor =
_getColorFromName(prefs.getString('bulletColor') ?? 'Blue'); _getColorFromName(prefs.getString('bulletColor') ?? 'Blue');
@@ -396,7 +400,8 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
builder: (sheet) => StatefulBuilder( builder: (sheet) => StatefulBuilder(
builder: (context, setSheetState) { builder: (context, setSheetState) {
Future<void> setCount(int count) async { Future<void> setCount(int count) async {
final clamped = count.clamp(1, 10); final clamped =
count.clamp(AppSettings.minBullets, AppSettings.maxBullets);
setState(() => _numberOfBullets = clamped); setState(() => _numberOfBullets = clamped);
setSheetState(() {}); setSheetState(() {});
final prefs = await SharedPreferences.getInstance(); final prefs = await SharedPreferences.getInstance();
@@ -408,12 +413,13 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
children: [ children: [
CameraSheetHeader( CameraSheetHeader(
title: _t('Select the number of bullets'), title: _t('Select the number of bullets'),
subtitle: '1 – 10', subtitle:
'${AppSettings.minBullets} – ${AppSettings.maxBullets}',
), ),
SheetStepper( SheetStepper(
value: _numberOfBullets, value: _numberOfBullets,
min: 1, min: AppSettings.minBullets,
max: 10, max: AppSettings.maxBullets,
accent: _bulletColor, accent: _bulletColor,
onChanged: setCount, onChanged: setCount,
), ),
@@ -426,74 +432,26 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
} }
void _showHelpDialog() { void _showHelpDialog() {
showDialog( showHelpSheet(context, accent: _bulletColor, t: _t, items: const [
context: context, (Icons.pinch, 'Pinch to zoom on the camera stream'),
builder: (BuildContext context) { (Icons.filter_5_rounded, 'Number bottom left: shots per target (1–5).'),
return Dialog( (
backgroundColor: Colors.grey[900], Icons.timer,
shape: 'Timer icon: set shoot, reload and wait times. While the timer runs, tap it to stop.'
RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_t('Help'),
style: const TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.bold),
), ),
const SizedBox(height: 20), (
_buildHelpItem(Icons.timer, Icons.play_arrow,
_t('Timer icon: Configure shoot/wait timer and start session')), 'Play / pause / stop in the middle: control the timer.'
const SizedBox(height: 12),
_buildHelpItem(Icons.filter_9_plus,
_t('Bottom left number: Set expected bullet count (1-5)')),
const SizedBox(height: 12),
_buildHelpItem(Icons.brightness_6,
_t('Sun icon: Adjust brightness and contrast for better visibility')),
const SizedBox(height: 12),
_buildHelpItem(Icons.filter_alt,
_t('Filter icon: Apply color filters (None, Greyscale, Invert)')),
const SizedBox(height: 12),
_buildHelpItem(
Icons.pinch, _t('Pinch to zoom on the camera stream')),
const SizedBox(height: 20),
Center(
child: ElevatedButton(
onPressed: () => Navigator.of(context).pop(),
style: ElevatedButton.styleFrom(
backgroundColor: _bulletColor,
foregroundColor: Colors.white,
), ),
child: Text(_t('Got it!')), (
Icons.circle_outlined,
'Circle icon: shot counter. Tap + after each shot; when the target is full you get a "Change target!" warning.'
), ),
(
Icons.tune,
'Settings icon: brightness, contrast, filters and rotation, saved for each camera.'
), ),
], ]);
),
),
);
},
);
}
Widget _buildHelpItem(IconData icon, String text) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(icon, color: _bulletColor, size: 20),
const SizedBox(width: 12),
Expanded(
child: Text(
text,
style: const TextStyle(color: Colors.white, fontSize: 14),
),
),
],
);
} }
@override @override
@@ -1324,7 +1282,7 @@ class _CameraStreamScreenState extends State<CameraStreamScreen>
), ),
actions: [ actions: [
IconButton( IconButton(
icon: const Icon(Icons.help_outline, color: Colors.white), icon: const Icon(Icons.info_outline_rounded, color: Colors.white),
onPressed: _showHelpDialog, onPressed: _showHelpDialog,
), ),
const SizedBox(width: 16), const SizedBox(width: 16),
+3
View File
@@ -19,6 +19,9 @@ class AppSettings extends ChangeNotifier {
static final AppSettings instance = AppSettings._(); static final AppSettings instance = AppSettings._();
static const String defaultTarget = 'assets/target.png'; static const String defaultTarget = 'assets/target.png';
// Shots per target, same limit for camera and stream capture
static const int minBullets = 1;
static const int maxBullets = 5;
static const List<int> reminderHourOptions = [1, 2, 3, 6, 12, 24, 48]; static const List<int> reminderHourOptions = [1, 2, 3, 6, 12, 24, 48];
static const List<Map<String, String>> languages = [ static const List<Map<String, String>> languages = [
+72 -35
View File
@@ -657,40 +657,49 @@ class AppTranslations {
'English': 'Help', 'English': 'Help',
'Slovenian': 'Pomoč', 'Slovenian': 'Pomoč',
}, },
'Tap camera button to capture and detect bullets': {
'English': 'Tap camera button to capture and detect bullets',
'Slovenian': 'Tapnite gumb kamere za zajem in zaznavanje zadetkov',
},
'Timer icon: Configure shoot/wait timer and start session': {
'English': 'Timer icon: Configure shoot/wait timer and start session',
'Slovenian': 'Ikona časovnika: Nastavi časovnik strela/čakanja in začni serijo',
},
'Bottom left number: Set expected bullet count (1-5)': {
'English': 'Bottom left number: Set expected bullet count (1-5)',
'Slovenian': 'Spodaj levo številka: Nastavite število zadetkov (1-5)',
},
'Sun icon: Adjust brightness and contrast for better visibility': {
'English':
'Sun icon: Adjust brightness and contrast for better visibility',
'Slovenian':
'Ikona sonca: Prilagodite svetlost in kontrast za boljšo vidljivost',
},
'Filter icon: Apply color filters (None, Greyscale, Invert)': {
'English': 'Filter icon: Apply color filters (None, Greyscale, Invert)',
'Slovenian':
'Ikona filtra: Uporabite barvne filtre (Brez, Sivine, Inverzno)',
},
'Pinch to zoom on the camera stream': { 'Pinch to zoom on the camera stream': {
'English': 'Pinch to zoom on the camera stream', 'English': 'Pinch to zoom on the camera stream.',
'Slovenian': 'Povečajte s prstoma na video pretoku', 'Slovenian': 'Z dvema prstoma povečaš sliko kamere.',
}, },
'Align target inside the square frame': { 'Align the target inside the square frame.': {
'English': 'Align target inside the square frame', 'English': 'Align the target inside the square frame.',
'Slovenian': 'Poravnajte tarčo znotraj kvadratnega okvirja', 'Slovenian': 'Poravnaj tarčo znotraj kvadratnega okvirja.',
}, },
'Got it!': { 'Camera button: take a photo. Bullets are detected and you can check and save the result.': {
'English': 'Got it!', 'English':
'Slovenian': 'Razumem!', 'Camera button: take a photo. Bullets are detected and you can check and save the result.',
'Slovenian':
'Gumb kamere: posnemi tarčo. Zadetki se zaznajo, rezultat pa lahko preveriš in shraniš.',
},
'Number bottom left: shots per target (1–5).': {
'English': 'Number bottom left: shots per target (1–5).',
'Slovenian': 'Številka spodaj levo: število strelov na tarčo (1–5).',
},
'Settings icon: exposure, zoom and flashlight.': {
'English': 'Settings icon: exposure, zoom and flashlight.',
'Slovenian': 'Ikona nastavitev: osvetlitev, povečava in svetilka.',
},
'Timer icon: set shoot, reload and wait times. While the timer runs, tap it to stop.': {
'English':
'Timer icon: set shoot, reload and wait times. While the timer runs, tap it to stop.',
'Slovenian':
'Ikona časovnika: nastavi čas streljanja, polnjenja in čakanja. Ko časovnik teče, ga s tapom ustaviš.',
},
'Play / pause / stop in the middle: control the timer.': {
'English': 'Play / pause / stop in the middle: control the timer.',
'Slovenian': 'Predvajaj / premor / ustavi na sredini: upravljanje časovnika.',
},
'Circle icon: shot counter. Tap + after each shot; when the target is full you get a "Change target!" warning.': {
'English':
'Circle icon: shot counter. Tap + after each shot; when the target is full you get a "Change target!" warning.',
'Slovenian':
'Ikona kroga: števec strelov. Po vsakem strelu tapni +; ko je tarča polna, se prikaže opozorilo za menjavo tarče.',
},
'Settings icon: brightness, contrast, filters and rotation, saved for each camera.': {
'English':
'Settings icon: brightness, contrast, filters and rotation, saved for each camera.',
'Slovenian':
'Ikona nastavitev: svetlost, kontrast, filtri in vrtenje, shranjeno za vsako kamero.',
}, },
// Brightness & Contrast dialog translations // Brightness & Contrast dialog translations
@@ -1184,6 +1193,10 @@ class AppTranslations {
'English': 'vs. last training', 'English': 'vs. last training',
'Slovenian': 'zadnji trening', 'Slovenian': 'zadnji trening',
}, },
'Details': {
'English': 'Details',
'Slovenian': 'Podrobnosti',
},
'shot': { 'shot': {
'English': 'shot', 'English': 'shot',
'Slovenian': 'strel', 'Slovenian': 'strel',
@@ -1196,6 +1209,34 @@ class AppTranslations {
'English': 'Saved targets and your statistics will appear here', 'English': 'Saved targets and your statistics will appear here',
'Slovenian': 'Tukaj se bodo prikazale shranjene tarče in tvoja statistika', 'Slovenian': 'Tukaj se bodo prikazale shranjene tarče in tvoja statistika',
}, },
'Trainings / Tournaments: choose which sessions the statistics count.': {
'English': 'Trainings / Tournaments: choose which sessions the statistics count.',
'Slovenian': 'Treningi / Tekmovanja: izberi, katere seje šteje statistika.',
},
'Shots 1–5: statistics only compare targets with the same number of shots. Grey numbers have no targets yet.': {
'English': 'Shots 1–5: statistics only compare targets with the same number of shots. Grey numbers have no targets yet.',
'Slovenian': 'Streli 1–5: statistika primerja le tarče z enakim številom strelov. Sive številke še nimajo tarč.',
},
'Year (top right): choose which year to show.': {
'English': 'Year (top right): choose which year to show.',
'Slovenian': 'Leto (desno zgoraj): izberi, katero leto se prikaže.',
},
'Graph: average per shot over time. Tap or drag on it to see each value.': {
'English': 'Graph: average per shot over time. Tap or drag on it to see each value.',
'Slovenian': 'Graf: povprečje na strel skozi čas. Tapni ali povleci po njem za posamezno vrednost.',
},
'By date / By score: sort the list by date or by best average per shot.': {
'English': 'By date / By score: sort the list by date or by best average per shot.',
'Slovenian': 'Po datumu / Po rezultatu: razvrsti seznam po datumu ali po najboljšem povprečju na strel.',
},
'Tap a session to see all its targets with the selected number of shots on one target.': {
'English': 'Tap a session to see all its targets with the selected number of shots on one target.',
'Slovenian': 'Tapni sejo za prikaz vseh njenih tarč z izbranim številom strelov na eni tarči.',
},
'Three dots on the right or long press: session details, single targets, rename and delete.': {
'English': 'Three dots on the right or long press: session details, single targets, rename and delete.',
'Slovenian': 'Tri pike na desni ali dolg pritisk: podrobnosti seje, posamezne tarče, preimenovanje in brisanje.',
},
'Year': { 'Year': {
'English': 'Year', 'English': 'Year',
'Slovenian': 'Leto', 'Slovenian': 'Leto',
@@ -1268,10 +1309,6 @@ class AppTranslations {
'English': 'Flashlight', 'English': 'Flashlight',
'Slovenian': 'Svetilka', 'Slovenian': 'Svetilka',
}, },
'Settings icon: exposure, zoom and flashlight': {
'English': 'Settings icon: exposure, zoom and flashlight',
'Slovenian': 'Ikona nastavitev: osvetlitev, povečava in svetilka',
},
'Automatic (phone language)': { 'Automatic (phone language)': {
'English': 'Automatic (phone language)', 'English': 'Automatic (phone language)',
'Slovenian': 'Samodejno (jezik telefona)', 'Slovenian': 'Samodejno (jezik telefona)',
+57
View File
@@ -0,0 +1,57 @@
import 'package:flutter/material.dart';
/// Help bottom sheet: one icon + sentence per control, close button at the end.
/// Shared by Knjiga, camera and stream so their info buttons look the same.
void showHelpSheet(
BuildContext context, {
required List<(IconData, String)> items,
required Color accent,
required String Function(String) t,
}) {
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (sheet) => SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.fromLTRB(24, 8, 24, 16),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(t('Help'),
style: const TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
for (final (icon, text) in items)
Padding(
padding: const EdgeInsets.only(bottom: 14),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(icon, color: accent, size: 20),
const SizedBox(width: 12),
Expanded(
child: Text(t(text),
style: const TextStyle(
color: Colors.white, fontSize: 14, height: 1.3)),
),
],
),
),
const SizedBox(height: 4),
SizedBox(
width: double.infinity,
child: FilledButton(
style: FilledButton.styleFrom(backgroundColor: accent),
onPressed: () => Navigator.pop(sheet),
child: Text(t('Close')),
),
),
],
),
),
),
);
}