diff --git a/lib/api/api.dart b/lib/api/api.dart index 7e6212b..59389a3 100644 --- a/lib/api/api.dart +++ b/lib/api/api.dart @@ -12,17 +12,14 @@ import 'package:starcitizen_doctor/data/sc_localization_data.dart'; class Api { static Future getAppVersion() async { - return AppVersionData.fromJson( - await getRepoJson("sc_doctor", "version.json")); + return AppVersionData.fromJson(await getRepoJson("sc_doctor", "version.json")); } static Future getAppPlacard() async { - return AppPlacardData.fromJson( - await getRepoJson("sc_doctor", "placard.json")); + return AppPlacardData.fromJson(await getRepoJson("sc_doctor", "placard.json")); } - static Future> - getFestivalCountdownList() async { + static Future> getFestivalCountdownList() async { List 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> getAppReleaseDataByVersionName( - String version) async { - final r = await RSHttp.getText( - "${URLConf.gitlabApiPath}repos/SCToolBox/Release/releases/tags/$version"); + static Future> getAppReleaseDataByVersionName(String version) async { + final r = await RSHttp.getText("${URLConf.gitlabApiPath}repos/SCToolBox/Release/releases/tags/$version"); return json.decode(r); } - static Future> getScLocalizationData( - String lang) async { + static Future> getScLocalizationData(String lang) async { final data = json.decode(await getRepoData("localizations", "$lang.json")); List l = []; if (data is List) { @@ -80,28 +73,24 @@ class Api { } static Future 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> getRepoJson( - String dir, String name) async { + static Future> getRepoJson(String dir, String name) async { final data = await getRepoData(dir, name); return json.decode(data); } static Future 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 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; } } diff --git a/lib/ui/home/home_ui_model.dart b/lib/ui/home/home_ui_model.dart index e0a4d83..38e1105 100644 --- a/lib/ui/home/home_ui_model.dart +++ b/lib/ui/home/home_ui_model.dart @@ -251,7 +251,7 @@ class HomeUIModel extends _$HomeUIModel { List _fixFestivalCountdownListDateTime(List 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 _updateSCServerStatus() async {