ente/lib/photo_repository.dart

34 lines
851 B
Dart
Raw Normal View History

2020-05-02 16:28:54 +00:00
import 'package:logging/logging.dart';
2020-05-04 20:03:06 +00:00
import 'package:photos/core/event_bus.dart';
import 'package:photos/db/db_helper.dart';
import 'package:photos/events/local_photos_updated_event.dart';
import 'package:photos/models/photo.dart';
2020-03-27 16:07:55 +00:00
2020-05-04 20:44:34 +00:00
class PhotoRepository {
2020-05-02 16:28:54 +00:00
final logger = Logger("PhotoLoader");
2020-03-28 18:18:27 +00:00
final _photos = List<Photo>();
2020-04-13 15:01:27 +00:00
2020-05-04 20:44:34 +00:00
PhotoRepository._privateConstructor();
static final PhotoRepository instance = PhotoRepository._privateConstructor();
2020-03-27 19:54:24 +00:00
2020-04-13 15:01:27 +00:00
List<Photo> get photos {
2020-03-27 16:07:55 +00:00
return _photos;
}
2020-04-13 15:01:27 +00:00
Future<bool> loadPhotos() async {
2020-03-27 16:07:55 +00:00
DatabaseHelper db = DatabaseHelper.instance;
2020-03-28 18:18:27 +00:00
var photos = await db.getAllPhotos();
2020-04-13 15:01:27 +00:00
2020-03-28 18:18:27 +00:00
_photos.clear();
_photos.addAll(photos);
2020-04-13 15:01:27 +00:00
return true;
2020-03-27 16:07:55 +00:00
}
2020-03-27 19:54:24 +00:00
void reloadPhotos() async {
2020-05-02 16:28:54 +00:00
logger.info("Reloading...");
2020-05-04 20:03:06 +00:00
await loadPhotos();
Bus.instance.fire(LocalPhotosUpdatedEvent());
2020-03-27 19:54:24 +00:00
}
2020-04-13 15:01:27 +00:00
}