add android bundle release
All checks were successful
Release / meta (push) Successful in 10s
Release / linux-build (push) Successful in 6m32s
Release / web-build (push) Successful in 5m50s
Release / android-build (push) Successful in 20m43s
Release / release-master (push) Successful in 26s
Release / release-dev (push) Successful in 28s
All checks were successful
Release / meta (push) Successful in 10s
Release / linux-build (push) Successful in 6m32s
Release / web-build (push) Successful in 5m50s
Release / android-build (push) Successful in 20m43s
Release / release-master (push) Successful in 26s
Release / release-dev (push) Successful in 28s
This commit is contained in:
@@ -513,9 +513,9 @@ class _DashboardState extends State<Dashboard> {
|
||||
Widget _buildTripsCard(
|
||||
BuildContext context, DataService data, DistanceUnitService distanceUnits) {
|
||||
final tripsUnsorted = data.trips;
|
||||
List trips = [];
|
||||
List<TripSummary> trips = [];
|
||||
if (tripsUnsorted.isNotEmpty) {
|
||||
trips = [...tripsUnsorted]..sort((a, b) => b.tripId.compareTo(a.tripId));
|
||||
trips = [...tripsUnsorted]..sort(TripSummary.compareByDateDesc);
|
||||
}
|
||||
return _panel(
|
||||
context,
|
||||
|
||||
@@ -42,6 +42,8 @@ class MorePage extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _MoreHome extends StatelessWidget {
|
||||
const _MoreHome({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView(
|
||||
|
||||
@@ -151,7 +151,7 @@ class _NewEntryPageState extends State<NewEntryPage> {
|
||||
|
||||
Widget _buildTripSelector(BuildContext context) {
|
||||
final trips = context.watch<DataService>().tripList;
|
||||
final sorted = [...trips]..sort((a, b) => b.tripId.compareTo(a.tripId));
|
||||
final sorted = [...trips]..sort(TripSummary.compareByDateDesc);
|
||||
final tripIds = sorted.map((t) => t.tripId).toSet();
|
||||
final selectedValue =
|
||||
(_selectedTripId != null && tripIds.contains(_selectedTripId))
|
||||
|
||||
@@ -232,7 +232,7 @@ class _TripsPageState extends State<TripsPage> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Trip',
|
||||
'Trip #${trip.id}',
|
||||
style: Theme.of(context).textTheme.labelMedium,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mileograph_flutter/objects/objects.dart';
|
||||
import 'package:mileograph_flutter/services/api_service.dart';
|
||||
import 'package:mileograph_flutter/services/distance_unit_service.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@@ -210,6 +212,11 @@ Future<void> showTractionDetails(
|
||||
) async {
|
||||
final hasMileageOrTrips = _hasMileageOrTrips(loco);
|
||||
final distanceUnits = context.read<DistanceUnitService>();
|
||||
final api = context.read<ApiService>();
|
||||
final leaderboardId = _leaderboardId(loco);
|
||||
final leaderboardFuture = leaderboardId == null
|
||||
? Future.value(const <LeaderboardEntry>[])
|
||||
: _fetchLocoLeaderboard(api, leaderboardId);
|
||||
await showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
@@ -295,6 +302,63 @@ Future<void> showTractionDetails(
|
||||
_detailRow(context, 'EVN', loco.evn ?? ''),
|
||||
if (loco.notes != null && loco.notes!.isNotEmpty)
|
||||
_detailRow(context, 'Notes', loco.notes!),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Leaderboard',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
FutureBuilder<List<LeaderboardEntry>>(
|
||||
future: leaderboardFuture,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 12.0),
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
height: 24,
|
||||
width: 24,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (snapshot.hasError) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Text(
|
||||
'Failed to load leaderboard',
|
||||
style: Theme.of(context).textTheme.labelMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
final entries = snapshot.data ?? const <LeaderboardEntry>[];
|
||||
if (entries.isEmpty) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Text(
|
||||
'No mileage leaderboard yet.',
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
children: entries.asMap().entries.map((entry) {
|
||||
final rank = entry.key + 1;
|
||||
return _leaderboardRow(
|
||||
context,
|
||||
rank,
|
||||
entry.value,
|
||||
distanceUnits,
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -307,6 +371,105 @@ Future<void> showTractionDetails(
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<LeaderboardEntry>> _fetchLocoLeaderboard(
|
||||
ApiService api,
|
||||
int locoId,
|
||||
) async {
|
||||
try {
|
||||
final json = await api.get('/loco/leaderboard/id/$locoId');
|
||||
Iterable<dynamic>? raw;
|
||||
if (json is List) {
|
||||
raw = json;
|
||||
} else if (json is Map) {
|
||||
for (final key in ['data', 'leaderboard', 'results']) {
|
||||
final value = json[key];
|
||||
if (value is List) {
|
||||
raw = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (raw == null) return const [];
|
||||
return raw.whereType<Map>().map((e) {
|
||||
return LeaderboardEntry.fromJson(
|
||||
e.map((key, value) => MapEntry(key.toString(), value)),
|
||||
);
|
||||
}).toList();
|
||||
} catch (e) {
|
||||
debugPrint('Failed to fetch loco leaderboard for $locoId: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
int? _leaderboardId(LocoSummary loco) {
|
||||
int? parse(dynamic value) {
|
||||
if (value == null) return null;
|
||||
if (value is int) return value == 0 ? null : value;
|
||||
if (value is num) return value.toInt() == 0 ? null : value.toInt();
|
||||
return int.tryParse(value.toString());
|
||||
}
|
||||
|
||||
return parse(loco.extra['loco_id']) ??
|
||||
parse(loco.extra['id']) ??
|
||||
parse(loco.id);
|
||||
}
|
||||
|
||||
Widget _leaderboardRow(
|
||||
BuildContext context,
|
||||
int rank,
|
||||
LeaderboardEntry entry,
|
||||
DistanceUnitService distanceUnits,
|
||||
) {
|
||||
final theme = Theme.of(context);
|
||||
final primaryName =
|
||||
entry.userFullName.isNotEmpty ? entry.userFullName : entry.username;
|
||||
final mileageLabel = distanceUnits.format(entry.mileage, decimals: 1);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.primaryContainer,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
'#$rank',
|
||||
style: theme.textTheme.labelMedium?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: theme.colorScheme.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
primaryName,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
mileageLabel,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _detailRow(BuildContext context, String label, String value) {
|
||||
if (value.isEmpty) return const SizedBox.shrink();
|
||||
return Padding(
|
||||
|
||||
@@ -66,6 +66,29 @@ DateTime _asDateTime(dynamic value, [DateTime? fallback]) {
|
||||
return parsed ?? (fallback ?? DateTime.fromMillisecondsSinceEpoch(0));
|
||||
}
|
||||
|
||||
DateTime? _asNullableDateTime(dynamic value) {
|
||||
if (value == null) return null;
|
||||
if (value is DateTime) return value;
|
||||
return DateTime.tryParse(value.toString());
|
||||
}
|
||||
|
||||
int compareTripsByDateDesc(
|
||||
DateTime? aDate,
|
||||
DateTime? bDate,
|
||||
int aId,
|
||||
int bId,
|
||||
) {
|
||||
if (aDate != null && bDate != null) {
|
||||
final cmp = bDate.compareTo(aDate);
|
||||
if (cmp != 0) return cmp;
|
||||
} else if (aDate != null) {
|
||||
return -1;
|
||||
} else if (bDate != null) {
|
||||
return 1;
|
||||
}
|
||||
return bId.compareTo(aId);
|
||||
}
|
||||
|
||||
class DestinationObject {
|
||||
const DestinationObject(
|
||||
this.label,
|
||||
@@ -443,7 +466,7 @@ class LocoSummary extends Loco {
|
||||
);
|
||||
|
||||
factory LocoSummary.fromJson(Map<String, dynamic> json) => LocoSummary(
|
||||
locoId: json['loco_id'] ?? json['id'] ?? 0,
|
||||
locoId: _asInt(json['loco_id'] ?? json['id']),
|
||||
locoType: json['type'] ?? json['loco_type'] ?? '',
|
||||
locoNumber: json['number'] ?? json['loco_number'] ?? '',
|
||||
locoName: json['name'] ?? json['loco_name'] ?? "",
|
||||
@@ -722,9 +745,12 @@ class TripSummary {
|
||||
final double tripMileage;
|
||||
final int legCount;
|
||||
final List<TripLocoStat> locoStats;
|
||||
final DateTime? startDate;
|
||||
final DateTime? endDate;
|
||||
|
||||
int get locoHadCount => locoStats.length;
|
||||
int get winnersCount => locoStats.where((e) => e.won).length;
|
||||
DateTime? get primaryDate => endDate ?? startDate;
|
||||
|
||||
TripSummary({
|
||||
required this.tripId,
|
||||
@@ -732,20 +758,72 @@ class TripSummary {
|
||||
required this.tripMileage,
|
||||
this.legCount = 0,
|
||||
List<TripLocoStat>? locoStats,
|
||||
this.startDate,
|
||||
this.endDate,
|
||||
}) : locoStats = locoStats ?? const [];
|
||||
|
||||
factory TripSummary.fromJson(Map<String, dynamic> json) => TripSummary(
|
||||
tripId: _asInt(json['trip_id']),
|
||||
tripName: _asString(json['trip_name']),
|
||||
tripMileage: _asDouble(json['trip_mileage']),
|
||||
legCount: _asInt(
|
||||
json['leg_count'],
|
||||
(json['trip_legs'] as List?)?.length ?? 0,
|
||||
),
|
||||
locoStats: TripLocoStat.listFromJson(
|
||||
json['stats'] ?? json['trip_locos'] ?? json['locos'],
|
||||
),
|
||||
);
|
||||
static int compareByDateDesc(TripSummary a, TripSummary b) =>
|
||||
compareTripsByDateDesc(a.primaryDate, b.primaryDate, a.tripId, b.tripId);
|
||||
|
||||
factory TripSummary.fromJson(Map<String, dynamic> json) {
|
||||
DateTime? startDate;
|
||||
DateTime? endDate;
|
||||
|
||||
DateTime? parseDate(dynamic value) => _asNullableDateTime(value);
|
||||
|
||||
for (final key in [
|
||||
'trip_begin_time',
|
||||
'trip_start',
|
||||
'trip_start_time',
|
||||
'trip_date',
|
||||
'start_date',
|
||||
'date',
|
||||
]) {
|
||||
startDate ??= parseDate(json[key]);
|
||||
}
|
||||
|
||||
for (final key in [
|
||||
'trip_end_time',
|
||||
'trip_finish_time',
|
||||
'trip_end',
|
||||
'end_date',
|
||||
]) {
|
||||
endDate ??= parseDate(json[key]);
|
||||
}
|
||||
|
||||
if (json['trip_legs'] is List) {
|
||||
for (final leg in json['trip_legs'] as List) {
|
||||
DateTime? begin;
|
||||
if (leg is TripLeg) {
|
||||
begin = leg.beginTime;
|
||||
} else if (leg is Map) {
|
||||
begin = parseDate(leg['leg_begin_time']);
|
||||
}
|
||||
if (begin == null) continue;
|
||||
if (startDate == null || begin.isBefore(startDate)) {
|
||||
startDate = begin;
|
||||
}
|
||||
if (endDate == null || begin.isAfter(endDate)) {
|
||||
endDate = begin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TripSummary(
|
||||
tripId: _asInt(json['trip_id']),
|
||||
tripName: _asString(json['trip_name']),
|
||||
tripMileage: _asDouble(json['trip_mileage']),
|
||||
legCount: _asInt(
|
||||
json['leg_count'],
|
||||
(json['trip_legs'] as List?)?.length ?? 0,
|
||||
),
|
||||
locoStats: TripLocoStat.listFromJson(
|
||||
json['stats'] ?? json['trip_locos'] ?? json['locos'],
|
||||
),
|
||||
startDate: startDate,
|
||||
endDate: endDate,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Leg {
|
||||
@@ -941,6 +1019,34 @@ class TripDetail {
|
||||
|
||||
int get locoHadCount => locoStats.length;
|
||||
int get winnersCount => locoStats.where((e) => e.won).length;
|
||||
DateTime? get startDate {
|
||||
DateTime? earliest;
|
||||
for (final leg in legs) {
|
||||
final begin = leg.beginTime;
|
||||
if (begin == null) continue;
|
||||
if (earliest == null || begin.isBefore(earliest)) {
|
||||
earliest = begin;
|
||||
}
|
||||
}
|
||||
return earliest;
|
||||
}
|
||||
|
||||
DateTime? get endDate {
|
||||
DateTime? latest;
|
||||
for (final leg in legs) {
|
||||
final begin = leg.beginTime;
|
||||
if (begin == null) continue;
|
||||
if (latest == null || begin.isAfter(latest)) {
|
||||
latest = begin;
|
||||
}
|
||||
}
|
||||
return latest;
|
||||
}
|
||||
|
||||
DateTime? get primaryDate => endDate ?? startDate;
|
||||
|
||||
static int compareByDateDesc(TripDetail a, TripDetail b) =>
|
||||
compareTripsByDateDesc(a.primaryDate, b.primaryDate, a.id, b.id);
|
||||
|
||||
TripDetail({
|
||||
required this.id,
|
||||
|
||||
@@ -151,7 +151,8 @@ class DataService extends ChangeNotifier {
|
||||
try {
|
||||
final json = await api.get('/stats/homepage');
|
||||
_homepageStats = HomepageStats.fromJson(json);
|
||||
_trips = _homepageStats?.trips ?? [];
|
||||
_trips = [...(_homepageStats?.trips ?? const [])]
|
||||
..sort(TripSummary.compareByDateDesc);
|
||||
} catch (e) {
|
||||
debugPrint('Failed to fetch homepage stats: $e');
|
||||
_homepageStats = null;
|
||||
|
||||
@@ -6,7 +6,7 @@ extension DataServiceTrips on DataService {
|
||||
try {
|
||||
final json = await api.get('/trips/info');
|
||||
final tripDetails = _parseTripInfoList(json);
|
||||
_tripDetails = [...tripDetails]..sort((a, b) => b.id.compareTo(a.id));
|
||||
_tripDetails = [...tripDetails]..sort(TripDetail.compareByDateDesc);
|
||||
_tripList = tripDetails
|
||||
.map(
|
||||
(detail) => TripSummary(
|
||||
@@ -15,10 +15,12 @@ extension DataServiceTrips on DataService {
|
||||
tripMileage: detail.mileage,
|
||||
legCount: detail.legCount,
|
||||
locoStats: detail.locoStats,
|
||||
startDate: detail.startDate,
|
||||
endDate: detail.endDate,
|
||||
),
|
||||
)
|
||||
.toList()
|
||||
..sort((a, b) => b.tripId.compareTo(a.tripId));
|
||||
..sort(TripSummary.compareByDateDesc);
|
||||
} catch (e) {
|
||||
debugPrint('Failed to fetch trip_map: $e');
|
||||
_tripDetails = [];
|
||||
@@ -49,7 +51,7 @@ extension DataServiceTrips on DataService {
|
||||
.map((e) => TripSummary.fromJson(e))
|
||||
.toList();
|
||||
|
||||
_tripList = [...tripMap]..sort((a, b) => b.tripId.compareTo(a.tripId));
|
||||
_tripList = [...tripMap]..sort(TripSummary.compareByDateDesc);
|
||||
} else {
|
||||
debugPrint('Unexpected trip list response: $json');
|
||||
_tripList = [];
|
||||
@@ -83,7 +85,7 @@ extension DataServiceTrips on DataService {
|
||||
.map((e) => TripSummary.fromJson(e))
|
||||
.toList();
|
||||
|
||||
_tripList = [...tripMap]..sort((a, b) => b.tripId.compareTo(a.tripId));
|
||||
_tripList = [...tripMap]..sort(TripSummary.compareByDateDesc);
|
||||
} else {
|
||||
debugPrint('Unexpected trip list response: $json');
|
||||
_tripList = [];
|
||||
@@ -105,7 +107,7 @@ extension DataServiceTrips on DataService {
|
||||
} else {
|
||||
_tripList = [trip, ..._tripList];
|
||||
}
|
||||
_tripList.sort((a, b) => b.tripId.compareTo(a.tripId));
|
||||
_tripList.sort(TripSummary.compareByDateDesc);
|
||||
_notifyAsync();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user