functional datastructure. Needs to be able to write to storage as well
Some checks failed
Build and push docker image / Build (pull_request) Failing after 3m5s
Build and release APK / Build APK (pull_request) Successful in 7m24s
Build web / Build Web (pull_request) Successful in 3m36s

This commit is contained in:
2024-06-21 19:30:40 +02:00
parent 9a5ae95d97
commit db41528702
18 changed files with 346 additions and 210 deletions

View File

@@ -1,25 +1,49 @@
// Represents a collection of landmarks that represent a journey
// Different instances of a Trip can be saved and loaded by the user
import 'dart:collection';
import 'dart:convert';
import 'package:fast_network_navigation/structs/landmark.dart';
import 'package:shared_preferences/shared_preferences.dart';
class Trip {
final String uuid;
final String cityName;
final List<Landmark> landmarks;
// TODO: cityName should be inferred from coordinates of the Landmarks
final LinkedList<Landmark> landmarks;
// could be empty as well
Trip({required this.uuid, required this.cityName, required this.landmarks});
Trip({
required this.uuid,
required this.cityName,
required this.landmarks,
});
factory Trip.fromJson(Map<String, dynamic> json) {
List<Landmark> landmarks = [];
for (var landmark in json['landmarks']) {
landmarks.add(Landmark.fromJson(landmark));
}
return Trip(
uuid: json['uuid'],
cityName: json['cityName'],
landmarks: landmarks,
landmarks: LinkedList()
);
}
}
factory Trip.fromPrefs(SharedPreferences prefs, String uuid) {
String? content = prefs.getString('trip_$uuid');
Map<String, dynamic> json = jsonDecode(content!);
Trip trip = Trip.fromJson(json);
String? firstUUID = json['entry_uuid'];
appendLandmarks(trip.landmarks, prefs, firstUUID);
return trip;
}
}
// Helper
appendLandmarks(LinkedList<Landmark> landmarks, SharedPreferences prefs, String? firstUUID) {
while (firstUUID != null) {
var (head, nextUUID) = getLandmarkFromPrefs(prefs, firstUUID);
landmarks.add(head);
firstUUID = nextUUID;
}
}