mirror of
https://github.com/StarCitizenToolBox/app.git
synced 2026-01-15 20:50:27 +00:00
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:
parent
95f1cc6481
commit
e212928f57
@ -12,17 +12,14 @@ import 'package:starcitizen_doctor/data/sc_localization_data.dart';
|
|||||||
|
|
||||||
class Api {
|
class Api {
|
||||||
static Future<AppVersionData> getAppVersion() async {
|
static Future<AppVersionData> getAppVersion() async {
|
||||||
return AppVersionData.fromJson(
|
return AppVersionData.fromJson(await getRepoJson("sc_doctor", "version.json"));
|
||||||
await getRepoJson("sc_doctor", "version.json"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<AppPlacardData> getAppPlacard() async {
|
static Future<AppPlacardData> getAppPlacard() async {
|
||||||
return AppPlacardData.fromJson(
|
return AppPlacardData.fromJson(await getRepoJson("sc_doctor", "placard.json"));
|
||||||
await getRepoJson("sc_doctor", "placard.json"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<List<CountdownFestivalItemData>>
|
static Future<List<CountdownFestivalItemData>> getFestivalCountdownList() async {
|
||||||
getFestivalCountdownList() async {
|
|
||||||
List<CountdownFestivalItemData> l = [];
|
List<CountdownFestivalItemData> l = [];
|
||||||
final r = json.decode(await getRepoData("sc_doctor", "countdown.json"));
|
final r = json.decode(await getRepoData("sc_doctor", "countdown.json"));
|
||||||
if (r is List) {
|
if (r is List) {
|
||||||
@ -30,19 +27,15 @@ class Api {
|
|||||||
l.add(CountdownFestivalItemData.fromJson(element));
|
l.add(CountdownFestivalItemData.fromJson(element));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
l.sort((a, b) => (a.time ?? 0) - (b.time ?? 0));
|
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<Map<String, dynamic>> getAppReleaseDataByVersionName(
|
static Future<Map<String, dynamic>> getAppReleaseDataByVersionName(String version) async {
|
||||||
String version) async {
|
final r = await RSHttp.getText("${URLConf.gitlabApiPath}repos/SCToolBox/Release/releases/tags/$version");
|
||||||
final r = await RSHttp.getText(
|
|
||||||
"${URLConf.gitlabApiPath}repos/SCToolBox/Release/releases/tags/$version");
|
|
||||||
return json.decode(r);
|
return json.decode(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<List<ScLocalizationData>> getScLocalizationData(
|
static Future<List<ScLocalizationData>> getScLocalizationData(String lang) async {
|
||||||
String lang) async {
|
|
||||||
final data = json.decode(await getRepoData("localizations", "$lang.json"));
|
final data = json.decode(await getRepoData("localizations", "$lang.json"));
|
||||||
List<ScLocalizationData> l = [];
|
List<ScLocalizationData> l = [];
|
||||||
if (data is List) {
|
if (data is List) {
|
||||||
@ -80,28 +73,24 @@ class Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Future<List> getScServerStatus() async {
|
static Future<List> getScServerStatus() async {
|
||||||
final r = await RSHttp.getText(
|
final r = await RSHttp.getText("https://status.robertsspaceindustries.com/index.json");
|
||||||
"https://status.robertsspaceindustries.com/index.json");
|
|
||||||
final map = json.decode(r);
|
final map = json.decode(r);
|
||||||
return map["systems"];
|
return map["systems"];
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<Map<String, dynamic>> getRepoJson(
|
static Future<Map<String, dynamic>> getRepoJson(String dir, String name) async {
|
||||||
String dir, String name) async {
|
|
||||||
final data = await getRepoData(dir, name);
|
final data = await getRepoData(dir, name);
|
||||||
return json.decode(data);
|
return json.decode(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String> getRepoData(String dir, String name) async {
|
static Future<String> getRepoData(String dir, String name) async {
|
||||||
final r = await RSHttp.getText("${URLConf.apiRepoPath}/$dir/$name",
|
final r = await RSHttp.getText("${URLConf.apiRepoPath}/$dir/$name", withCustomDns: await isUseInternalDNS());
|
||||||
withCustomDns: await isUseInternalDNS());
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<bool> isUseInternalDNS() async {
|
static Future<bool> isUseInternalDNS() async {
|
||||||
final userBox = await Hive.openBox("app_conf");
|
final userBox = await Hive.openBox("app_conf");
|
||||||
final isUseInternalDNS =
|
final isUseInternalDNS = userBox.get("isUseInternalDNS", defaultValue: false);
|
||||||
userBox.get("isUseInternalDNS", defaultValue: false);
|
|
||||||
return isUseInternalDNS;
|
return isUseInternalDNS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -251,7 +251,7 @@ class HomeUIModel extends _$HomeUIModel {
|
|||||||
List<CountdownFestivalItemData> _fixFestivalCountdownListDateTime(List<CountdownFestivalItemData> list) {
|
List<CountdownFestivalItemData> _fixFestivalCountdownListDateTime(List<CountdownFestivalItemData> list) {
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
|
|
||||||
return list.map((item) {
|
final fixedList = list.map((item) {
|
||||||
if (item.time == null) return item;
|
if (item.time == null) return item;
|
||||||
final itemDateTime = DateTime.fromMillisecondsSinceEpoch(item.time!);
|
final itemDateTime = DateTime.fromMillisecondsSinceEpoch(item.time!);
|
||||||
final itemDatePlusSeven = itemDateTime.add(const Duration(days: 7));
|
final itemDatePlusSeven = itemDateTime.add(const Duration(days: 7));
|
||||||
@ -270,6 +270,16 @@ class HomeUIModel extends _$HomeUIModel {
|
|||||||
|
|
||||||
return item;
|
return item;
|
||||||
}).toList();
|
}).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 {
|
Future<void> _updateSCServerStatus() async {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user