2021-12-03 18:31:27 +01:00
|
|
|
import 'package:nc_photos/entity/album.dart';
|
|
|
|
import 'package:nc_photos/entity/face.dart';
|
2022-01-25 11:08:13 +01:00
|
|
|
import 'package:nc_photos/entity/favorite.dart';
|
2021-12-03 18:31:27 +01:00
|
|
|
import 'package:nc_photos/entity/file.dart';
|
2022-05-05 16:06:47 +02:00
|
|
|
import 'package:nc_photos/entity/local_file.dart';
|
2021-12-03 18:31:27 +01:00
|
|
|
import 'package:nc_photos/entity/person.dart';
|
2022-08-06 06:21:11 +02:00
|
|
|
import 'package:nc_photos/entity/search.dart';
|
2021-12-03 18:31:27 +01:00
|
|
|
import 'package:nc_photos/entity/share.dart';
|
|
|
|
import 'package:nc_photos/entity/sharee.dart';
|
2022-07-05 22:20:24 +02:00
|
|
|
import 'package:nc_photos/entity/sqlite_table.dart' as sql;
|
2022-01-28 20:34:38 +01:00
|
|
|
import 'package:nc_photos/entity/tag.dart';
|
2022-01-29 12:31:32 +01:00
|
|
|
import 'package:nc_photos/entity/tagged_file.dart';
|
2021-12-07 19:42:25 +01:00
|
|
|
import 'package:nc_photos/or_null.dart';
|
2021-12-03 18:31:27 +01:00
|
|
|
import 'package:nc_photos/pref.dart';
|
|
|
|
|
|
|
|
enum DiType {
|
|
|
|
albumRepo,
|
2022-07-05 22:20:24 +02:00
|
|
|
albumRepoLocal,
|
2021-12-03 18:31:27 +01:00
|
|
|
faceRepo,
|
|
|
|
fileRepo,
|
2022-07-05 22:20:24 +02:00
|
|
|
fileRepoRemote,
|
|
|
|
fileRepoLocal,
|
2021-12-03 18:31:27 +01:00
|
|
|
personRepo,
|
2022-08-05 11:39:49 +02:00
|
|
|
personRepoRemote,
|
|
|
|
personRepoLocal,
|
2021-12-03 18:31:27 +01:00
|
|
|
shareRepo,
|
|
|
|
shareeRepo,
|
2022-01-25 11:08:13 +01:00
|
|
|
favoriteRepo,
|
2022-01-28 20:34:38 +01:00
|
|
|
tagRepo,
|
2022-08-05 11:28:28 +02:00
|
|
|
tagRepoRemote,
|
|
|
|
tagRepoLocal,
|
2022-01-29 12:31:32 +01:00
|
|
|
taggedFileRepo,
|
2022-05-05 16:06:47 +02:00
|
|
|
localFileRepo,
|
2022-08-06 06:21:11 +02:00
|
|
|
searchRepo,
|
2021-12-03 18:31:27 +01:00
|
|
|
pref,
|
2022-07-05 22:20:24 +02:00
|
|
|
sqliteDb,
|
2021-12-03 18:31:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class DiContainer {
|
2022-07-05 22:20:24 +02:00
|
|
|
DiContainer({
|
2021-12-03 18:31:27 +01:00
|
|
|
AlbumRepo? albumRepo,
|
2022-07-05 22:20:24 +02:00
|
|
|
AlbumRepo? albumRepoLocal,
|
2021-12-03 18:31:27 +01:00
|
|
|
FaceRepo? faceRepo,
|
|
|
|
FileRepo? fileRepo,
|
2022-07-05 22:20:24 +02:00
|
|
|
FileRepo? fileRepoRemote,
|
|
|
|
FileRepo? fileRepoLocal,
|
2021-12-03 18:31:27 +01:00
|
|
|
PersonRepo? personRepo,
|
2022-08-05 11:39:49 +02:00
|
|
|
PersonRepo? personRepoRemote,
|
|
|
|
PersonRepo? personRepoLocal,
|
2021-12-03 18:31:27 +01:00
|
|
|
ShareRepo? shareRepo,
|
|
|
|
ShareeRepo? shareeRepo,
|
2022-01-25 11:08:13 +01:00
|
|
|
FavoriteRepo? favoriteRepo,
|
2022-01-28 20:34:38 +01:00
|
|
|
TagRepo? tagRepo,
|
2022-08-05 11:28:28 +02:00
|
|
|
TagRepo? tagRepoRemote,
|
|
|
|
TagRepo? tagRepoLocal,
|
2022-01-29 12:31:32 +01:00
|
|
|
TaggedFileRepo? taggedFileRepo,
|
2022-05-05 16:06:47 +02:00
|
|
|
LocalFileRepo? localFileRepo,
|
2022-08-06 06:21:11 +02:00
|
|
|
SearchRepo? searchRepo,
|
2021-12-03 18:31:27 +01:00
|
|
|
Pref? pref,
|
2022-07-05 22:20:24 +02:00
|
|
|
sql.SqliteDb? sqliteDb,
|
2021-12-03 18:31:27 +01:00
|
|
|
}) : _albumRepo = albumRepo,
|
2022-07-05 22:20:24 +02:00
|
|
|
_albumRepoLocal = albumRepoLocal,
|
2021-12-03 18:31:27 +01:00
|
|
|
_faceRepo = faceRepo,
|
|
|
|
_fileRepo = fileRepo,
|
2022-07-05 22:20:24 +02:00
|
|
|
_fileRepoRemote = fileRepoRemote,
|
|
|
|
_fileRepoLocal = fileRepoLocal,
|
2021-12-03 18:31:27 +01:00
|
|
|
_personRepo = personRepo,
|
2022-08-05 11:39:49 +02:00
|
|
|
_personRepoRemote = personRepoRemote,
|
|
|
|
_personRepoLocal = personRepoLocal,
|
2021-12-03 18:31:27 +01:00
|
|
|
_shareRepo = shareRepo,
|
|
|
|
_shareeRepo = shareeRepo,
|
2022-01-25 11:08:13 +01:00
|
|
|
_favoriteRepo = favoriteRepo,
|
2022-01-28 20:34:38 +01:00
|
|
|
_tagRepo = tagRepo,
|
2022-08-05 11:28:28 +02:00
|
|
|
_tagRepoRemote = tagRepoRemote,
|
|
|
|
_tagRepoLocal = tagRepoLocal,
|
2022-01-29 12:31:32 +01:00
|
|
|
_taggedFileRepo = taggedFileRepo,
|
2022-05-05 16:06:47 +02:00
|
|
|
_localFileRepo = localFileRepo,
|
2022-08-06 06:21:11 +02:00
|
|
|
_searchRepo = searchRepo,
|
2022-07-05 22:20:24 +02:00
|
|
|
_pref = pref,
|
|
|
|
_sqliteDb = sqliteDb;
|
|
|
|
|
|
|
|
DiContainer.late();
|
2021-12-03 18:31:27 +01:00
|
|
|
|
|
|
|
static bool has(DiContainer contianer, DiType type) {
|
|
|
|
switch (type) {
|
|
|
|
case DiType.albumRepo:
|
|
|
|
return contianer._albumRepo != null;
|
2022-07-05 22:20:24 +02:00
|
|
|
case DiType.albumRepoLocal:
|
|
|
|
return contianer._albumRepoLocal != null;
|
2021-12-03 18:31:27 +01:00
|
|
|
case DiType.faceRepo:
|
|
|
|
return contianer._faceRepo != null;
|
|
|
|
case DiType.fileRepo:
|
|
|
|
return contianer._fileRepo != null;
|
2022-07-05 22:20:24 +02:00
|
|
|
case DiType.fileRepoRemote:
|
|
|
|
return contianer._fileRepoRemote != null;
|
|
|
|
case DiType.fileRepoLocal:
|
|
|
|
return contianer._fileRepoLocal != null;
|
2021-12-03 18:31:27 +01:00
|
|
|
case DiType.personRepo:
|
|
|
|
return contianer._personRepo != null;
|
2022-08-05 11:39:49 +02:00
|
|
|
case DiType.personRepoRemote:
|
|
|
|
return contianer._personRepoRemote != null;
|
|
|
|
case DiType.personRepoLocal:
|
|
|
|
return contianer._personRepoLocal != null;
|
2021-12-03 18:31:27 +01:00
|
|
|
case DiType.shareRepo:
|
|
|
|
return contianer._shareRepo != null;
|
|
|
|
case DiType.shareeRepo:
|
|
|
|
return contianer._shareeRepo != null;
|
2022-01-25 11:08:13 +01:00
|
|
|
case DiType.favoriteRepo:
|
|
|
|
return contianer._favoriteRepo != null;
|
2022-01-28 20:34:38 +01:00
|
|
|
case DiType.tagRepo:
|
|
|
|
return contianer._tagRepo != null;
|
2022-08-05 11:28:28 +02:00
|
|
|
case DiType.tagRepoRemote:
|
|
|
|
return contianer._tagRepoRemote != null;
|
|
|
|
case DiType.tagRepoLocal:
|
|
|
|
return contianer._tagRepoLocal != null;
|
2022-01-29 12:31:32 +01:00
|
|
|
case DiType.taggedFileRepo:
|
|
|
|
return contianer._taggedFileRepo != null;
|
2022-05-05 16:06:47 +02:00
|
|
|
case DiType.localFileRepo:
|
|
|
|
return contianer._localFileRepo != null;
|
2022-08-06 06:21:11 +02:00
|
|
|
case DiType.searchRepo:
|
|
|
|
return contianer._searchRepo != null;
|
2021-12-03 18:31:27 +01:00
|
|
|
case DiType.pref:
|
|
|
|
return contianer._pref != null;
|
2022-07-05 22:20:24 +02:00
|
|
|
case DiType.sqliteDb:
|
|
|
|
return contianer._sqliteDb != null;
|
2021-12-03 18:31:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-07 19:42:25 +01:00
|
|
|
DiContainer copyWith({
|
|
|
|
OrNull<AlbumRepo>? albumRepo,
|
|
|
|
OrNull<FaceRepo>? faceRepo,
|
|
|
|
OrNull<FileRepo>? fileRepo,
|
|
|
|
OrNull<PersonRepo>? personRepo,
|
|
|
|
OrNull<ShareRepo>? shareRepo,
|
|
|
|
OrNull<ShareeRepo>? shareeRepo,
|
2022-01-25 11:08:13 +01:00
|
|
|
OrNull<FavoriteRepo>? favoriteRepo,
|
2022-01-28 20:34:38 +01:00
|
|
|
OrNull<TagRepo>? tagRepo,
|
2022-01-29 12:31:32 +01:00
|
|
|
OrNull<TaggedFileRepo>? taggedFileRepo,
|
2022-05-05 16:06:47 +02:00
|
|
|
OrNull<LocalFileRepo>? localFileRepo,
|
2022-08-06 06:21:11 +02:00
|
|
|
OrNull<SearchRepo>? searchRepo,
|
2021-12-07 19:42:25 +01:00
|
|
|
OrNull<Pref>? pref,
|
2022-07-05 22:20:24 +02:00
|
|
|
OrNull<sql.SqliteDb>? sqliteDb,
|
2021-12-07 19:42:25 +01:00
|
|
|
}) {
|
|
|
|
return DiContainer(
|
2022-01-22 18:00:53 +01:00
|
|
|
albumRepo: albumRepo == null ? _albumRepo : albumRepo.obj,
|
|
|
|
faceRepo: faceRepo == null ? _faceRepo : faceRepo.obj,
|
|
|
|
fileRepo: fileRepo == null ? _fileRepo : fileRepo.obj,
|
|
|
|
personRepo: personRepo == null ? _personRepo : personRepo.obj,
|
|
|
|
shareRepo: shareRepo == null ? _shareRepo : shareRepo.obj,
|
|
|
|
shareeRepo: shareeRepo == null ? _shareeRepo : shareeRepo.obj,
|
2022-01-25 11:08:13 +01:00
|
|
|
favoriteRepo: favoriteRepo == null ? _favoriteRepo : favoriteRepo.obj,
|
2022-01-28 20:34:38 +01:00
|
|
|
tagRepo: tagRepo == null ? _tagRepo : tagRepo.obj,
|
2022-01-29 12:31:32 +01:00
|
|
|
taggedFileRepo:
|
|
|
|
taggedFileRepo == null ? _taggedFileRepo : taggedFileRepo.obj,
|
2022-05-05 16:06:47 +02:00
|
|
|
localFileRepo: localFileRepo == null ? _localFileRepo : localFileRepo.obj,
|
2022-08-06 06:21:11 +02:00
|
|
|
searchRepo: searchRepo == null ? _searchRepo : searchRepo.obj,
|
2022-01-22 18:00:53 +01:00
|
|
|
pref: pref == null ? _pref : pref.obj,
|
2022-07-05 22:20:24 +02:00
|
|
|
sqliteDb: sqliteDb == null ? _sqliteDb : sqliteDb.obj,
|
2021-12-07 19:42:25 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-03 18:31:27 +01:00
|
|
|
AlbumRepo get albumRepo => _albumRepo!;
|
2022-07-05 22:20:24 +02:00
|
|
|
AlbumRepo get albumRepoLocal => _albumRepoLocal!;
|
2021-12-03 18:31:27 +01:00
|
|
|
FaceRepo get faceRepo => _faceRepo!;
|
|
|
|
FileRepo get fileRepo => _fileRepo!;
|
2022-07-05 22:20:24 +02:00
|
|
|
FileRepo get fileRepoRemote => _fileRepoRemote!;
|
|
|
|
FileRepo get fileRepoLocal => _fileRepoLocal!;
|
2021-12-03 18:31:27 +01:00
|
|
|
PersonRepo get personRepo => _personRepo!;
|
2022-08-05 11:39:49 +02:00
|
|
|
PersonRepo get personRepoRemote => _personRepoRemote!;
|
|
|
|
PersonRepo get personRepoLocal => _personRepoLocal!;
|
2021-12-03 18:31:27 +01:00
|
|
|
ShareRepo get shareRepo => _shareRepo!;
|
|
|
|
ShareeRepo get shareeRepo => _shareeRepo!;
|
2022-01-25 11:08:13 +01:00
|
|
|
FavoriteRepo get favoriteRepo => _favoriteRepo!;
|
2022-01-28 20:34:38 +01:00
|
|
|
TagRepo get tagRepo => _tagRepo!;
|
2022-08-05 11:28:28 +02:00
|
|
|
TagRepo get tagRepoRemote => _tagRepoRemote!;
|
|
|
|
TagRepo get tagRepoLocal => _tagRepoLocal!;
|
2022-01-29 12:31:32 +01:00
|
|
|
TaggedFileRepo get taggedFileRepo => _taggedFileRepo!;
|
2022-05-05 16:06:47 +02:00
|
|
|
LocalFileRepo get localFileRepo => _localFileRepo!;
|
2022-08-06 06:21:11 +02:00
|
|
|
SearchRepo get searchRepo => _searchRepo!;
|
2021-12-03 18:31:27 +01:00
|
|
|
|
2022-07-05 22:20:24 +02:00
|
|
|
sql.SqliteDb get sqliteDb => _sqliteDb!;
|
2021-12-03 18:31:27 +01:00
|
|
|
Pref get pref => _pref!;
|
|
|
|
|
2022-07-05 22:20:24 +02:00
|
|
|
set albumRepo(AlbumRepo v) {
|
|
|
|
assert(_albumRepo == null);
|
|
|
|
_albumRepo = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
set albumRepoLocal(AlbumRepo v) {
|
|
|
|
assert(_albumRepoLocal == null);
|
|
|
|
_albumRepoLocal = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
set faceRepo(FaceRepo v) {
|
|
|
|
assert(_faceRepo == null);
|
|
|
|
_faceRepo = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
set fileRepo(FileRepo v) {
|
|
|
|
assert(_fileRepo == null);
|
|
|
|
_fileRepo = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
set fileRepoRemote(FileRepo v) {
|
|
|
|
assert(_fileRepoRemote == null);
|
|
|
|
_fileRepoRemote = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
set fileRepoLocal(FileRepo v) {
|
|
|
|
assert(_fileRepoLocal == null);
|
|
|
|
_fileRepoLocal = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
set personRepo(PersonRepo v) {
|
|
|
|
assert(_personRepo == null);
|
|
|
|
_personRepo = v;
|
|
|
|
}
|
|
|
|
|
2022-08-05 11:39:49 +02:00
|
|
|
set personRepoRemote(PersonRepo v) {
|
|
|
|
assert(_personRepoRemote == null);
|
|
|
|
_personRepoRemote = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
set personRepoLocal(PersonRepo v) {
|
|
|
|
assert(_personRepoLocal == null);
|
|
|
|
_personRepoLocal = v;
|
|
|
|
}
|
|
|
|
|
2022-07-05 22:20:24 +02:00
|
|
|
set shareRepo(ShareRepo v) {
|
|
|
|
assert(_shareRepo == null);
|
|
|
|
_shareRepo = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
set shareeRepo(ShareeRepo v) {
|
|
|
|
assert(_shareeRepo == null);
|
|
|
|
_shareeRepo = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
set favoriteRepo(FavoriteRepo v) {
|
|
|
|
assert(_favoriteRepo == null);
|
|
|
|
_favoriteRepo = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
set tagRepo(TagRepo v) {
|
|
|
|
assert(_tagRepo == null);
|
|
|
|
_tagRepo = v;
|
|
|
|
}
|
|
|
|
|
2022-08-05 11:28:28 +02:00
|
|
|
set tagRepoRemote(TagRepo v) {
|
|
|
|
assert(_tagRepoRemote == null);
|
|
|
|
_tagRepoRemote = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
set tagRepoLocal(TagRepo v) {
|
|
|
|
assert(_tagRepoLocal == null);
|
|
|
|
_tagRepoLocal = v;
|
|
|
|
}
|
|
|
|
|
2022-07-05 22:20:24 +02:00
|
|
|
set taggedFileRepo(TaggedFileRepo v) {
|
|
|
|
assert(_taggedFileRepo == null);
|
|
|
|
_taggedFileRepo = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
set localFileRepo(LocalFileRepo v) {
|
|
|
|
assert(_localFileRepo == null);
|
|
|
|
_localFileRepo = v;
|
|
|
|
}
|
|
|
|
|
2022-08-06 06:21:11 +02:00
|
|
|
set searchRepo(SearchRepo v) {
|
|
|
|
assert(_searchRepo == null);
|
|
|
|
_searchRepo = v;
|
|
|
|
}
|
|
|
|
|
2022-07-05 22:20:24 +02:00
|
|
|
set sqliteDb(sql.SqliteDb v) {
|
|
|
|
assert(_sqliteDb == null);
|
|
|
|
_sqliteDb = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
set pref(Pref v) {
|
|
|
|
assert(_pref == null);
|
|
|
|
_pref = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
AlbumRepo? _albumRepo;
|
|
|
|
// Explicitly request a AlbumRepo backed by local source
|
|
|
|
AlbumRepo? _albumRepoLocal;
|
|
|
|
FaceRepo? _faceRepo;
|
|
|
|
FileRepo? _fileRepo;
|
|
|
|
// Explicitly request a FileRepo backed by remote source
|
|
|
|
FileRepo? _fileRepoRemote;
|
|
|
|
// Explicitly request a FileRepo backed by local source
|
|
|
|
FileRepo? _fileRepoLocal;
|
|
|
|
PersonRepo? _personRepo;
|
2022-08-05 11:39:49 +02:00
|
|
|
PersonRepo? _personRepoRemote;
|
|
|
|
PersonRepo? _personRepoLocal;
|
2022-07-05 22:20:24 +02:00
|
|
|
ShareRepo? _shareRepo;
|
|
|
|
ShareeRepo? _shareeRepo;
|
|
|
|
FavoriteRepo? _favoriteRepo;
|
|
|
|
TagRepo? _tagRepo;
|
2022-08-05 11:28:28 +02:00
|
|
|
TagRepo? _tagRepoRemote;
|
|
|
|
TagRepo? _tagRepoLocal;
|
2022-07-05 22:20:24 +02:00
|
|
|
TaggedFileRepo? _taggedFileRepo;
|
|
|
|
LocalFileRepo? _localFileRepo;
|
2022-08-06 06:21:11 +02:00
|
|
|
SearchRepo? _searchRepo;
|
2022-07-05 22:20:24 +02:00
|
|
|
|
|
|
|
sql.SqliteDb? _sqliteDb;
|
|
|
|
Pref? _pref;
|
2021-12-03 18:31:27 +01:00
|
|
|
}
|
2022-07-22 10:48:16 +02:00
|
|
|
|
|
|
|
extension DiContainerExtension on DiContainer {
|
2022-08-06 06:21:11 +02:00
|
|
|
/// Uses local repo if available
|
|
|
|
///
|
|
|
|
/// Notice that not all repo support this
|
|
|
|
DiContainer withLocalRepo() => copyWith(
|
|
|
|
albumRepo: OrNull(albumRepoLocal),
|
|
|
|
fileRepo: OrNull(fileRepoLocal),
|
|
|
|
personRepo: OrNull(personRepoLocal),
|
|
|
|
tagRepo: OrNull(tagRepoLocal),
|
|
|
|
);
|
|
|
|
|
2022-08-05 11:44:52 +02:00
|
|
|
DiContainer withLocalAlbumRepo() =>
|
|
|
|
copyWith(albumRepo: OrNull(albumRepoLocal));
|
2022-07-22 10:48:16 +02:00
|
|
|
DiContainer withRemoteFileRepo() =>
|
|
|
|
copyWith(fileRepo: OrNull(fileRepoRemote));
|
2022-08-05 11:44:52 +02:00
|
|
|
DiContainer withLocalFileRepo() => copyWith(fileRepo: OrNull(fileRepoLocal));
|
2022-08-05 11:39:49 +02:00
|
|
|
DiContainer withRemotePersonRepo() =>
|
|
|
|
copyWith(personRepo: OrNull(personRepoRemote));
|
|
|
|
DiContainer withLocalPersonRepo() =>
|
|
|
|
copyWith(personRepo: OrNull(personRepoLocal));
|
2022-08-05 11:28:28 +02:00
|
|
|
DiContainer withRemoteTagRepo() => copyWith(tagRepo: OrNull(tagRepoRemote));
|
|
|
|
DiContainer withLocalTagRepo() => copyWith(tagRepo: OrNull(tagRepoLocal));
|
2022-07-22 10:48:16 +02:00
|
|
|
}
|