Fix countdown festival list not sorted after date advancement (#138)

* Initial plan

* Fix: Sort countdown festivals by updated timestamps

Co-authored-by: xkeyC <39891083+xkeyC@users.noreply.github.com>

* fix: Api

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: xkeyC <39891083+xkeyC@users.noreply.github.com>
Co-authored-by: xkeyC <3334969096@qq.com>
This commit is contained in:
Copilot 2025-11-08 15:22:19 +08:00 committed by GitHub
parent 95f1cc6481
commit e212928f57
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 22 deletions

View File

@ -12,17 +12,14 @@ import 'package:starcitizen_doctor/data/sc_localization_data.dart';
class Api {
static Future<AppVersionData> getAppVersion() async {
return AppVersionData.fromJson(
await getRepoJson("sc_doctor", "version.json"));
return AppVersionData.fromJson(await getRepoJson("sc_doctor", "version.json"));
}
static Future<AppPlacardData> getAppPlacard() async {
return AppPlacardData.fromJson(
await getRepoJson("sc_doctor", "placard.json"));
return AppPlacardData.fromJson(await getRepoJson("sc_doctor", "placard.json"));
}
static Future<List<CountdownFestivalItemData>>
getFestivalCountdownList() async {
static Future<List<CountdownFestivalItemData>> getFestivalCountdownList() async {
List<CountdownFestivalItemData> l = [];
final r = json.decode(await getRepoData("sc_doctor", "countdown.json"));
if (r is List) {
@ -30,19 +27,15 @@ class Api {
l.add(CountdownFestivalItemData.fromJson(element));
}
}
l.sort((a, b) => (a.time ?? 0) - (b.time ?? 0));
return l;
}
static Future<Map<String, dynamic>> getAppReleaseDataByVersionName(
String version) async {
final r = await RSHttp.getText(
"${URLConf.gitlabApiPath}repos/SCToolBox/Release/releases/tags/$version");
static Future<Map<String, dynamic>> getAppReleaseDataByVersionName(String version) async {
final r = await RSHttp.getText("${URLConf.gitlabApiPath}repos/SCToolBox/Release/releases/tags/$version");
return json.decode(r);
}
static Future<List<ScLocalizationData>> getScLocalizationData(
String lang) async {
static Future<List<ScLocalizationData>> getScLocalizationData(String lang) async {
final data = json.decode(await getRepoData("localizations", "$lang.json"));
List<ScLocalizationData> l = [];
if (data is List) {
@ -80,28 +73,24 @@ class Api {
}
static Future<List> getScServerStatus() async {
final r = await RSHttp.getText(
"https://status.robertsspaceindustries.com/index.json");
final r = await RSHttp.getText("https://status.robertsspaceindustries.com/index.json");
final map = json.decode(r);
return map["systems"];
}
static Future<Map<String, dynamic>> getRepoJson(
String dir, String name) async {
static Future<Map<String, dynamic>> getRepoJson(String dir, String name) async {
final data = await getRepoData(dir, name);
return json.decode(data);
}
static Future<String> getRepoData(String dir, String name) async {
final r = await RSHttp.getText("${URLConf.apiRepoPath}/$dir/$name",
withCustomDns: await isUseInternalDNS());
final r = await RSHttp.getText("${URLConf.apiRepoPath}/$dir/$name", withCustomDns: await isUseInternalDNS());
return r;
}
static Future<bool> isUseInternalDNS() async {
final userBox = await Hive.openBox("app_conf");
final isUseInternalDNS =
userBox.get("isUseInternalDNS", defaultValue: false);
final isUseInternalDNS = userBox.get("isUseInternalDNS", defaultValue: false);
return isUseInternalDNS;
}
}

View File

@ -251,7 +251,7 @@ class HomeUIModel extends _$HomeUIModel {
List<CountdownFestivalItemData> _fixFestivalCountdownListDateTime(List<CountdownFestivalItemData> list) {
final now = DateTime.now();
return list.map((item) {
final fixedList = list.map((item) {
if (item.time == null) return item;
final itemDateTime = DateTime.fromMillisecondsSinceEpoch(item.time!);
final itemDatePlusSeven = itemDateTime.add(const Duration(days: 7));
@ -270,6 +270,16 @@ class HomeUIModel extends _$HomeUIModel {
return item;
}).toList();
// Sort by time (ascending order - nearest festival first)
fixedList.sort((a, b) {
if (a.time == null && b.time == null) return 0;
if (a.time == null) return 1;
if (b.time == null) return -1;
return a.time!.compareTo(b.time!);
});
return fixedList;
}
Future<void> _updateSCServerStatus() async {