new UI + new targets.
This commit is contained in:
+142
-118
@@ -3,7 +3,10 @@ import 'package:intl/intl.dart';
|
||||
import '../services/app_settings.dart';
|
||||
import '../services/target_repository.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import '../utils/format.dart';
|
||||
import '../widgets/section.dart';
|
||||
import '../widgets/target_face.dart';
|
||||
import '../widgets/ui.dart';
|
||||
import 'target_view.dart';
|
||||
|
||||
/// One training or tournament: its stats, its targets, and edit/delete actions.
|
||||
@@ -18,6 +21,20 @@ class SessionScreen extends StatefulWidget {
|
||||
|
||||
class _SessionScreenState extends State<SessionScreen> {
|
||||
late Session _session = widget.session;
|
||||
Map<String, TargetHits> _hits = {}; // file path -> hits, for the thumbnails
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadHits();
|
||||
}
|
||||
|
||||
Future<void> _loadHits() async {
|
||||
final files = _session.files;
|
||||
final all = await TargetRepository.readAllHits(files);
|
||||
if (!mounted) return;
|
||||
setState(() => _hits = {for (int i = 0; i < files.length; i++) files[i].path: all[i]});
|
||||
}
|
||||
|
||||
Future<void> _reload() async {
|
||||
final sessions = await TargetRepository.loadSessions();
|
||||
@@ -27,6 +44,7 @@ class _SessionScreenState extends State<SessionScreen> {
|
||||
Navigator.pop(context); // session no longer exists
|
||||
} else {
|
||||
setState(() => _session = updated.first);
|
||||
_loadHits();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,14 +77,14 @@ class _SessionScreenState extends State<SessionScreen> {
|
||||
|
||||
Future<void> _delete() async {
|
||||
final s = AppSettings.instance;
|
||||
final message = '${s.t('Are you sure you want to delete the folder')} "${_session.name}" ${s.t('and all of its contents?')}';
|
||||
if (await confirmDelete(context, message) != true) return;
|
||||
final message = '${s.t('Are you sure you want to delete the folder')} »${_session.name}« ${s.t('and all of its contents?')}';
|
||||
if (!await confirmDelete(context, message)) return;
|
||||
await TargetRepository.deleteSession(_session);
|
||||
if (mounted) Navigator.pop(context);
|
||||
}
|
||||
|
||||
Future<void> _deleteTarget(TargetRecord target) async {
|
||||
if (await confirmDelete(context, AppSettings.instance.t('Are you sure you want to delete this file?')) != true) return;
|
||||
if (!await confirmDelete(context, AppSettings.instance.t('Are you sure you want to delete this file?'))) return;
|
||||
await TargetRepository.deleteTarget(target);
|
||||
_reload();
|
||||
}
|
||||
@@ -78,71 +96,106 @@ class _SessionScreenState extends State<SessionScreen> {
|
||||
builder: (context, _) {
|
||||
final s = AppSettings.instance;
|
||||
final t = s.t;
|
||||
final surf = Surfaces.current;
|
||||
final c = Palette.current;
|
||||
final session = _session;
|
||||
final stats = ShooterStats.of([session]);
|
||||
final best = session.targets.isEmpty ? null : session.targets.map((x) => x.score).reduce((a, b) => a > b ? a : b);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: s.backgroundColor,
|
||||
appBar: AppBar(
|
||||
title: Text(session.name, style: const TextStyle(color: Colors.white)),
|
||||
backgroundColor: AppTheme.bar,
|
||||
iconTheme: const IconThemeData(color: Colors.white),
|
||||
scrolledUnderElevation: 0,
|
||||
actions: [
|
||||
IconButton(icon: const Icon(Icons.edit), tooltip: t('Edit'), onPressed: _edit),
|
||||
IconButton(icon: const Icon(Icons.delete, color: Colors.red), tooltip: t('Delete'), onPressed: _delete),
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
// Keep the last row clear of the system gesture bar (edge-to-edge)
|
||||
padding: EdgeInsets.fromLTRB(16, 4, 16, 24 + MediaQuery.paddingOf(context).bottom),
|
||||
body: Column(
|
||||
children: [
|
||||
SectionHeader(
|
||||
'${session.isTournament ? t('Tournament') : t('Training')} · ${DateFormat('d. M. yyyy').format(session.date)}',
|
||||
BackHeader(
|
||||
title: session.name,
|
||||
actions: [
|
||||
CircleButton(icon: Icons.edit_outlined, tooltip: t('Edit'), onTap: _edit),
|
||||
CircleButton(
|
||||
icon: Icons.delete_outline_rounded,
|
||||
tooltip: t('Delete'),
|
||||
color: c.red,
|
||||
background: c.redSoft,
|
||||
onTap: _delete,
|
||||
),
|
||||
],
|
||||
),
|
||||
StatGrid(tiles: [
|
||||
StatTile(label: t('Total'), value: '${session.totalScore}', caption: targetCount(session.targets.length)),
|
||||
StatTile(
|
||||
label: t('Average per shot'),
|
||||
value: stats.averagePerShot?.toStringAsFixed(2) ?? '–',
|
||||
caption: shotCount(stats.shots),
|
||||
),
|
||||
]),
|
||||
SectionHeader(t('Targets')),
|
||||
if (session.targets.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text(t('No targets in this folder'), style: TextStyle(color: surf.textSecondary)),
|
||||
)
|
||||
else
|
||||
GroupCard(children: [
|
||||
for (int i = 0; i < session.targets.length; i++)
|
||||
SettingsTile(
|
||||
title: '${t('Target')} ${i + 1}',
|
||||
subtitle: '${DateFormat('HH:mm').format(session.targets[i].shotAt)} · ${shotCount(session.targets[i].shots)}',
|
||||
onTap: () => _openTargets([session.targets[i]]),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'${session.targets[i].score}',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: surf.textPrimary),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete, color: Colors.red, size: 20),
|
||||
onPressed: () => _deleteTarget(session.targets[i]),
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
// Keep the last row clear of the system gesture bar (edge-to-edge)
|
||||
padding: EdgeInsets.fromLTRB(AppTheme.edge, 4, AppTheme.edge, 24 + MediaQuery.paddingOf(context).bottom),
|
||||
children: [
|
||||
Kicker(
|
||||
'${session.isTournament ? t('Tournament') : t('Training')} · ${DateFormat('d. M. yyyy').format(session.date)}',
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
),
|
||||
]),
|
||||
StatGrid(tiles: [
|
||||
StatTile(label: t('Total'), value: '${session.totalScore}', caption: targetCount(session.targets.length)),
|
||||
StatTile(
|
||||
label: t('Average per shot'),
|
||||
value: stats.averagePerShot == null ? '–' : dec(stats.averagePerShot!),
|
||||
caption: shotCount(stats.shots),
|
||||
),
|
||||
]),
|
||||
SectionHeader(t('Targets')),
|
||||
if (session.targets.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text(t('No targets in this folder'), style: TextStyle(color: c.muted)),
|
||||
)
|
||||
else
|
||||
for (int i = 0; i < session.targets.length; i++)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: _targetRow(s, c, i, session.targets[i], session.targets[i].score == best),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _targetRow(AppSettings s, Palette c, int i, TargetRecord target, bool isBest) {
|
||||
return AppCard(
|
||||
padding: const EdgeInsets.fromLTRB(10, 10, 4, 10),
|
||||
onTap: () => _openTargets([target]),
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox.square(
|
||||
dimension: 44,
|
||||
child: TargetFace(
|
||||
style: s.target,
|
||||
hits: _hits[target.file.path]?.bullets ?? const [],
|
||||
hitColor: s.bulletColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('${s.t('Target')} ${i + 1}', style: TextStyle(fontSize: 15, fontWeight: FontWeight.w700, color: c.ink)),
|
||||
const SizedBox(height: 2),
|
||||
Text('${DateFormat('HH:mm').format(target.shotAt)} · ${shotCount(target.shots)}',
|
||||
style: TextStyle(fontSize: 12, color: c.muted)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text('${target.score}',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: isBest ? (c.isDark ? c.gold : c.goldInk) : c.ink,
|
||||
fontFeatures: AppTheme.tnum)),
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete_outline_rounded, color: c.red, size: 20),
|
||||
onPressed: () => _deleteTarget(target),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// "1 target" / "5 targets", with Slovenian dual and plural forms.
|
||||
@@ -165,26 +218,10 @@ String shotCount(int n) {
|
||||
return '$n $word';
|
||||
}
|
||||
|
||||
Future<bool?> confirmDelete(BuildContext context, String message) {
|
||||
/// "Potrdi brisanje" dialog. True when confirmed.
|
||||
Future<bool> confirmDelete(BuildContext context, String message) {
|
||||
final s = AppSettings.instance;
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialog) => AlertDialog(
|
||||
title: Text(s.t('Confirm Deletion')),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialog, false),
|
||||
child: Text(s.t('Cancel'), style: const TextStyle(color: Colors.white70)),
|
||||
),
|
||||
FilledButton(
|
||||
style: FilledButton.styleFrom(backgroundColor: Colors.red[700]),
|
||||
onPressed: () => Navigator.pop(dialog, true),
|
||||
child: Text(s.t('Yes, delete')),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return confirmDialog(context, title: s.t('Confirm Deletion'), message: message, confirm: s.t('Yes, delete'));
|
||||
}
|
||||
|
||||
class SessionEdit {
|
||||
@@ -194,7 +231,7 @@ class SessionEdit {
|
||||
const SessionEdit(this.name, this.isTournament);
|
||||
}
|
||||
|
||||
/// Rename a session and choose training/tournament.
|
||||
/// Rename a session and choose training/tournament ("Nastavitve mape").
|
||||
Future<SessionEdit?> showEditSessionDialog(BuildContext context, Session session) {
|
||||
final s = AppSettings.instance;
|
||||
final controller = TextEditingController(text: session.name);
|
||||
@@ -203,52 +240,39 @@ Future<SessionEdit?> showEditSessionDialog(BuildContext context, Session session
|
||||
return showDialog<SessionEdit>(
|
||||
context: context,
|
||||
builder: (dialog) => StatefulBuilder(
|
||||
builder: (context, setDialogState) => AlertDialog(
|
||||
title: Text(s.t('Folder Settings')),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: controller,
|
||||
style: const TextStyle(color: Colors.white),
|
||||
cursorColor: s.bulletColor,
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: Colors.white10,
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: s.bulletColor),
|
||||
),
|
||||
builder: (context, setDialogState) {
|
||||
final c = Palette.current;
|
||||
return AppDialog(
|
||||
title: s.t('Folder Settings'),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TextField(controller: controller, style: TextStyle(color: c.ink, fontSize: 15)),
|
||||
const SizedBox(height: 12),
|
||||
ToggleRow(
|
||||
icon: Icons.emoji_events_outlined,
|
||||
label: s.t('Tournament'),
|
||||
value: isTournament,
|
||||
onChanged: (v) => setDialogState(() => isTournament = v),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(s.t('Tournament'), style: const TextStyle(color: Colors.white)),
|
||||
secondary: Icon(Icons.emoji_events, color: isTournament ? s.bulletColor : Colors.white54),
|
||||
value: isTournament,
|
||||
activeTrackColor: s.bulletColor,
|
||||
onChanged: (v) => setDialogState(() => isTournament = v),
|
||||
const SizedBox(height: 10),
|
||||
Text(s.t('Rename the session or move it to tournaments.'), style: TextStyle(fontSize: 12, color: c.muted)),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
DialogTextButton(s.t('Cancel'), onTap: () => Navigator.pop(dialog)),
|
||||
PrimaryButton(
|
||||
label: s.t('Save'),
|
||||
height: 46,
|
||||
onTap: () {
|
||||
final name = controller.text.trim();
|
||||
if (name.isEmpty || name.contains('/')) return;
|
||||
Navigator.pop(dialog, SessionEdit(name, isTournament));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialog),
|
||||
child: Text(s.t('Cancel'), style: const TextStyle(color: Colors.white70)),
|
||||
),
|
||||
FilledButton(
|
||||
style: FilledButton.styleFrom(backgroundColor: s.bulletColor),
|
||||
onPressed: () {
|
||||
final name = controller.text.trim();
|
||||
if (name.isEmpty || name.contains('/')) return;
|
||||
Navigator.pop(dialog, SessionEdit(name, isTournament));
|
||||
},
|
||||
child: Text(s.t('Save')),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user