UI fixes and league
This commit is contained in:
@@ -34,20 +34,23 @@ class AppSettings extends ChangeNotifier with WidgetsBindingObserver {
|
||||
|
||||
/// Hit colours, each tuned for the dark and the light theme. The chosen
|
||||
/// one is the accent of the whole interface.
|
||||
// Round the colour wheel, then the neutrals: two rows of 8 in the picker.
|
||||
// No red: a red hit would vanish in the red edge of a selected one.
|
||||
static const Map<String, (Color dark, Color light)> bulletColors = {
|
||||
'Blue': (Color(0xFF4B8EF5), Color(0xFF2D6BD8)),
|
||||
'Green': (Color(0xFF3CC764), Color(0xFF1E9A4C)),
|
||||
'Yellow': (Color(0xFFF2C12E), Color(0xFFC08E00)),
|
||||
'Purple': (Color(0xFFB45EE3), Color(0xFF8E3FBF)),
|
||||
'Cyan': (Color(0xFF22C7E0), Color(0xFF12B4CE)),
|
||||
'Teal': (Color(0xFF17B3A3), Color(0xFF0E9384)),
|
||||
'Indigo': (Color(0xFF6E6CF2), Color(0xFF4F46E5)),
|
||||
'Pink': (Color(0xFFF0457A), Color(0xFFD63366)),
|
||||
'Lime': (Color(0xFFC9DC3C), Color(0xFF85A00E)),
|
||||
'Mint': (Color(0xFF5EE6B0), Color(0xFF1FAE7A)),
|
||||
'Orange': (Color(0xFFFF8A1F), Color(0xFFE06F00)),
|
||||
'Violet': (Color(0xFF8E62F7), Color(0xFF7C3AED)),
|
||||
'Amber': (Color(0xFFFFB020), Color(0xFFD18A00)),
|
||||
'Yellow': (Color(0xFFF2C12E), Color(0xFFC08E00)),
|
||||
'Lime': (Color(0xFFC9DC3C), Color(0xFF85A00E)),
|
||||
'Green': (Color(0xFF3CC764), Color(0xFF1E9A4C)),
|
||||
'Mint': (Color(0xFF5EE6B0), Color(0xFF1FAE7A)),
|
||||
'Teal': (Color(0xFF17B3A3), Color(0xFF0E9384)),
|
||||
'Cyan': (Color(0xFF22C7E0), Color(0xFF12B4CE)),
|
||||
'Blue': (Color(0xFF4B8EF5), Color(0xFF2D6BD8)),
|
||||
'Indigo': (Color(0xFF6E6CF2), Color(0xFF4F46E5)),
|
||||
'Violet': (Color(0xFF8E62F7), Color(0xFF7C3AED)),
|
||||
'Purple': (Color(0xFFB45EE3), Color(0xFF8E3FBF)),
|
||||
'Magenta': (Color(0xFFE04BD8), Color(0xFFB8269F)),
|
||||
'Pink': (Color(0xFFF0457A), Color(0xFFD63366)),
|
||||
'Brown': (Color(0xFFB07A55), Color(0xFF8A5536)),
|
||||
'Grey': (Color(0xFFA3AAB2), Color(0xFF6F757C)),
|
||||
};
|
||||
@@ -93,7 +96,10 @@ class AppSettings extends ChangeNotifier with WidgetsBindingObserver {
|
||||
|
||||
DateTime get today => debugToday ?? DateTime.now();
|
||||
|
||||
HolidayTheme? get holiday => HolidayTheme.on(today);
|
||||
/// Preview only: show the everyday look even on a holiday.
|
||||
bool debugNoHoliday = false;
|
||||
|
||||
HolidayTheme? get holiday => debugNoHoliday ? null : HolidayTheme.on(today);
|
||||
|
||||
/// True while a holiday decides the target.
|
||||
bool get targetLocked => holiday != null;
|
||||
@@ -120,7 +126,16 @@ class AppSettings extends ChangeNotifier with WidgetsBindingObserver {
|
||||
}
|
||||
|
||||
/// The holiday's screen background (the everyday one is painted, see AppBackground).
|
||||
String get background => holiday?.background(isDark) ?? '';
|
||||
/// Screen background of the whole app: the holiday's, else the everyday one.
|
||||
String get background => holiday?.background(isDark) ?? HolidayTheme.everydayBackground(isDark);
|
||||
|
||||
/// Background of the target screens (result, check hits, edit): the shown
|
||||
/// target's own – the holiday target's during a holiday – with the window
|
||||
/// lines the target sits between (target-backgrounds/v3).
|
||||
String get targetBackground {
|
||||
final h = holiday;
|
||||
return (h == null ? _target : TargetStyle.byId(h.targetId)).background(isDark);
|
||||
}
|
||||
|
||||
// A new day may start or end a holiday
|
||||
@override
|
||||
@@ -165,6 +180,9 @@ class AppSettings extends ChangeNotifier with WidgetsBindingObserver {
|
||||
}
|
||||
|
||||
/// The target shown: the holiday's while one is on, otherwise the user's.
|
||||
/// The user's own pick, whatever the holiday.
|
||||
TargetStyle get ownTarget => _target;
|
||||
|
||||
TargetStyle get target {
|
||||
final h = holiday;
|
||||
return h == null ? _target : TargetStyle.byId(h.targetId);
|
||||
@@ -257,9 +275,11 @@ class AppSettings extends ChangeNotifier with WidgetsBindingObserver {
|
||||
await _prefs.setInt('targetStyle', style.id);
|
||||
}
|
||||
|
||||
/// Debug: show the look of [day] (null = today).
|
||||
void previewDay(DateTime? day) {
|
||||
/// Preview: show the look of [day] (null = today); [noHoliday] shows the
|
||||
/// everyday look whatever the day. Not saved: a restart is back to today.
|
||||
void previewDay(DateTime? day, {bool noHoliday = false}) {
|
||||
debugToday = day;
|
||||
debugNoHoliday = noHoliday;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
/// The club's shooting league (liga.bl3kunja.top): the current league, its
|
||||
/// tournaments and the live standings, from the site's public JSON API.
|
||||
///
|
||||
/// `GET /api/lestvica` is the current league (what the site's Lestvica page
|
||||
/// shows). The app reads it only when the Liga tab is opened (or pulled to
|
||||
/// refresh), never in the background.
|
||||
class LeagueService {
|
||||
static const String site = 'https://liga.bl3kunja.top';
|
||||
static const Duration _timeout = Duration(seconds: 10);
|
||||
|
||||
final http.Client _client;
|
||||
LeagueService([http.Client? client]) : _client = client ?? http.Client();
|
||||
|
||||
Future<LeagueStandings> standings() async {
|
||||
final res = await _client.get(Uri.parse('$site/api/lestvica')).timeout(_timeout);
|
||||
if (res.statusCode != 200) throw LeagueException('HTTP ${res.statusCode}');
|
||||
return LeagueStandings.fromJson(jsonDecode(utf8.decode(res.bodyBytes)) as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
void dispose() => _client.close();
|
||||
}
|
||||
|
||||
class LeagueException implements Exception {
|
||||
final String message;
|
||||
const LeagueException(this.message);
|
||||
@override
|
||||
String toString() => message;
|
||||
}
|
||||
|
||||
class LeagueStandings {
|
||||
final League league;
|
||||
final List<LeagueRound> rounds;
|
||||
final List<LeaguePlayer> players; // by rank
|
||||
|
||||
const LeagueStandings({required this.league, required this.rounds, required this.players});
|
||||
|
||||
factory LeagueStandings.fromJson(Map<String, dynamic> j) => LeagueStandings(
|
||||
league: League.fromJson(j['league'] as Map<String, dynamic>),
|
||||
rounds: [for (final r in (j['rounds'] as List? ?? const [])) LeagueRound.fromJson(r as Map<String, dynamic>)]
|
||||
..sort((a, b) => a.number.compareTo(b.number)),
|
||||
players: [for (final p in (j['players'] as List? ?? const [])) LeaguePlayer.fromJson(p as Map<String, dynamic>)]
|
||||
..sort((a, b) => a.rank.compareTo(b.rank)),
|
||||
);
|
||||
|
||||
/// The tournament that is open now, if any.
|
||||
LeagueRound? get openRound => rounds.where((r) => r.isOpen).firstOrNull;
|
||||
|
||||
/// The next one to open, if none is open.
|
||||
LeagueRound? get nextRound => rounds.where((r) => r.isUpcoming).firstOrNull;
|
||||
}
|
||||
|
||||
class League {
|
||||
final int id;
|
||||
final String name; // "Liga 2026-2027"
|
||||
final String status; // "active", …
|
||||
final int counted; // best N tournaments count
|
||||
final int shots; // shots per target
|
||||
final int targets; // targets per tournament
|
||||
|
||||
const League({required this.id, required this.name, required this.status, required this.counted, required this.shots, required this.targets});
|
||||
|
||||
factory League.fromJson(Map<String, dynamic> j) => League(
|
||||
id: (j['id'] as num?)?.toInt() ?? 0,
|
||||
name: j['name'] as String? ?? '',
|
||||
status: j['status'] as String? ?? '',
|
||||
counted: (j['counted'] as num?)?.toInt() ?? 0,
|
||||
shots: (j['shots'] as num?)?.toInt() ?? 0,
|
||||
targets: (j['targets'] as num?)?.toInt() ?? 0,
|
||||
);
|
||||
|
||||
bool get isActive => status == 'active';
|
||||
}
|
||||
|
||||
class LeagueRound {
|
||||
final int number;
|
||||
final DateTime? startsAt;
|
||||
final DateTime? endsAt;
|
||||
final String state; // "open", "upcoming", or done
|
||||
final int submissions; // clubs that have entered their results
|
||||
|
||||
const LeagueRound({required this.number, this.startsAt, this.endsAt, required this.state, required this.submissions});
|
||||
|
||||
factory LeagueRound.fromJson(Map<String, dynamic> j) => LeagueRound(
|
||||
number: (j['number'] as num?)?.toInt() ?? 0,
|
||||
startsAt: DateTime.tryParse(j['starts_at'] as String? ?? ''),
|
||||
endsAt: DateTime.tryParse(j['ends_at'] as String? ?? ''),
|
||||
state: j['state'] as String? ?? '',
|
||||
submissions: (j['submissions'] as num?)?.toInt() ?? 0,
|
||||
);
|
||||
|
||||
bool get isOpen => state == 'open';
|
||||
bool get isUpcoming => state == 'upcoming';
|
||||
bool get isDone => !isOpen && !isUpcoming;
|
||||
}
|
||||
|
||||
class LeaguePlayer {
|
||||
final int rank;
|
||||
final String name;
|
||||
final String club;
|
||||
final List<LeagueCell?> cells; // one per tournament; null = not shot
|
||||
final int total; // all tournaments
|
||||
final int finalScore; // the counted ones: what the ranking uses
|
||||
final int tens; // tie-break
|
||||
final int played;
|
||||
|
||||
const LeaguePlayer({
|
||||
required this.rank,
|
||||
required this.name,
|
||||
required this.club,
|
||||
required this.cells,
|
||||
required this.total,
|
||||
required this.finalScore,
|
||||
required this.tens,
|
||||
required this.played,
|
||||
});
|
||||
|
||||
factory LeaguePlayer.fromJson(Map<String, dynamic> j) => LeaguePlayer(
|
||||
rank: (j['rank'] as num?)?.toInt() ?? 0,
|
||||
name: j['name'] as String? ?? '',
|
||||
club: j['club'] as String? ?? '',
|
||||
cells: [for (final c in (j['cells'] as List? ?? const [])) c == null ? null : LeagueCell.fromJson(c as Map<String, dynamic>)],
|
||||
total: (j['total'] as num?)?.toInt() ?? 0,
|
||||
finalScore: (j['final'] as num?)?.toInt() ?? 0,
|
||||
tens: (j['tens'] as num?)?.toInt() ?? 0,
|
||||
played: (j['played'] as num?)?.toInt() ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
class LeagueCell {
|
||||
final int score;
|
||||
final int tens;
|
||||
final bool counted; // among the best N
|
||||
final bool joker;
|
||||
|
||||
const LeagueCell({required this.score, required this.tens, required this.counted, required this.joker});
|
||||
|
||||
factory LeagueCell.fromJson(Map<String, dynamic> j) => LeagueCell(
|
||||
score: (j['score'] as num?)?.toInt() ?? 0,
|
||||
tens: (j['tens'] as num?)?.toInt() ?? 0,
|
||||
counted: j['counted'] as bool? ?? true,
|
||||
joker: j['joker'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user