You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.4 KiB
45 lines
1.4 KiB
import 'package:flutter/material.dart';
|
|
import 'package:timemanage/model/project.dart';
|
|
import 'package:timemanage/model/timer_entry.dart';
|
|
|
|
abstract class DataProvider {
|
|
Future<Project> createProject({required String name, Color? colour});
|
|
Future<List<Project>> listProjects();
|
|
Future<void> editProject(Project project);
|
|
Future<void> deleteProject(Project project);
|
|
Future<TimerEntry> createTimer({
|
|
String? description,
|
|
int? projectID,
|
|
DateTime? startTime,
|
|
DateTime? endTime,
|
|
});
|
|
Future<List<TimerEntry>> listTimers();
|
|
Future<void> editTimer(TimerEntry timer);
|
|
Future<void> deleteTimer(TimerEntry timer);
|
|
|
|
Future<void> import(DataProvider other) async {
|
|
List<TimerEntry> otherEntries = await other.listTimers();
|
|
List<Project> otherProjects = await other.listProjects();
|
|
|
|
List<Project> newOtherProjects = await Stream.fromIterable(otherProjects)
|
|
.asyncMap((event) => createProject(name: event.name))
|
|
.toList();
|
|
|
|
for (TimerEntry otherEntry in otherEntries) {
|
|
int projectOffset = otherProjects
|
|
.indexWhere((element) => element.id == otherEntry.projectID);
|
|
int? projectID;
|
|
if (projectOffset >= 0) {
|
|
projectID = newOtherProjects[projectOffset].id;
|
|
}
|
|
|
|
await createTimer(
|
|
description: otherEntry.description,
|
|
projectID: projectID,
|
|
startTime: otherEntry.startTime,
|
|
endTime: otherEntry.endTime,
|
|
);
|
|
}
|
|
}
|
|
}
|