2021-04-10 06:28:12 +02:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:event_bus/event_bus.dart';
|
|
|
|
import 'package:kiwi/kiwi.dart';
|
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
import 'package:nc_photos/account.dart';
|
|
|
|
import 'package:nc_photos/entity/album.dart';
|
|
|
|
import 'package:nc_photos/entity/file.dart';
|
2021-10-06 22:32:36 +02:00
|
|
|
import 'package:nc_photos/entity/share.dart';
|
2021-08-15 19:06:00 +02:00
|
|
|
import 'package:nc_photos/metadata_task_manager.dart';
|
2021-09-11 14:03:40 +02:00
|
|
|
import 'package:nc_photos/pref.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
|
|
|
|
class AppEventListener<T> {
|
|
|
|
AppEventListener(this._listener);
|
|
|
|
|
|
|
|
void begin() {
|
|
|
|
if (_subscription != null) {
|
|
|
|
_log.warning("[beginListenEvent] Already listening");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_subscription = _stream.listen(_listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
void end() {
|
|
|
|
if (_subscription == null) {
|
|
|
|
_log.warning("[endListenEvent] Already not listening");
|
|
|
|
return;
|
|
|
|
}
|
2021-07-23 22:05:57 +02:00
|
|
|
_subscription?.cancel();
|
2021-04-10 06:28:12 +02:00
|
|
|
_subscription = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
final void Function(T) _listener;
|
|
|
|
final _stream = KiwiContainer().resolve<EventBus>().on<T>();
|
2021-07-23 22:05:57 +02:00
|
|
|
StreamSubscription<T>? _subscription;
|
2021-04-10 06:28:12 +02:00
|
|
|
|
|
|
|
final _log = Logger("event.event.AppEventListener<${T.runtimeType}>");
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:14:24 +01:00
|
|
|
class AccountPrefUpdatedEvent {
|
|
|
|
const AccountPrefUpdatedEvent(this.pref, this.key, this.value);
|
|
|
|
|
|
|
|
final AccountPref pref;
|
|
|
|
final PrefKey key;
|
|
|
|
final dynamic value;
|
|
|
|
}
|
|
|
|
|
2021-04-10 06:28:12 +02:00
|
|
|
class AlbumCreatedEvent {
|
|
|
|
AlbumCreatedEvent(this.account, this.album);
|
|
|
|
|
|
|
|
final Account account;
|
|
|
|
final Album album;
|
|
|
|
}
|
|
|
|
|
|
|
|
class AlbumUpdatedEvent {
|
|
|
|
AlbumUpdatedEvent(this.account, this.album);
|
|
|
|
|
|
|
|
final Account account;
|
|
|
|
final Album album;
|
|
|
|
}
|
|
|
|
|
2021-05-28 19:15:09 +02:00
|
|
|
class FilePropertyUpdatedEvent {
|
|
|
|
FilePropertyUpdatedEvent(this.account, this.file, this.properties);
|
2021-04-10 06:28:12 +02:00
|
|
|
|
|
|
|
final Account account;
|
|
|
|
final File file;
|
2021-05-28 19:15:09 +02:00
|
|
|
final int properties;
|
|
|
|
|
|
|
|
// Bit masks for properties field
|
|
|
|
static const propMetadata = 0x01;
|
2021-05-28 20:45:00 +02:00
|
|
|
static const propIsArchived = 0x02;
|
2021-06-21 12:39:17 +02:00
|
|
|
static const propOverrideDateTime = 0x04;
|
2022-01-25 11:08:13 +01:00
|
|
|
static const propFavorite = 0x08;
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class FileRemovedEvent {
|
|
|
|
FileRemovedEvent(this.account, this.file);
|
|
|
|
|
|
|
|
final Account account;
|
|
|
|
final File file;
|
|
|
|
}
|
2021-04-17 11:04:46 +02:00
|
|
|
|
2021-08-01 22:46:16 +02:00
|
|
|
class FileTrashbinRestoredEvent {
|
|
|
|
FileTrashbinRestoredEvent(this.account, this.file);
|
|
|
|
|
|
|
|
final Account account;
|
|
|
|
final File file;
|
|
|
|
}
|
|
|
|
|
2021-08-13 12:39:17 +02:00
|
|
|
class FileMovedEvent {
|
|
|
|
FileMovedEvent(this.account, this.file, this.destination);
|
|
|
|
|
|
|
|
final Account account;
|
|
|
|
final File file;
|
|
|
|
final String destination;
|
|
|
|
}
|
|
|
|
|
2021-10-17 11:45:56 +02:00
|
|
|
class ShareCreatedEvent {
|
|
|
|
const ShareCreatedEvent(this.account, this.share);
|
|
|
|
|
|
|
|
final Account account;
|
|
|
|
final Share share;
|
|
|
|
}
|
|
|
|
|
2021-10-06 22:32:36 +02:00
|
|
|
class ShareRemovedEvent {
|
|
|
|
const ShareRemovedEvent(this.account, this.share);
|
|
|
|
|
|
|
|
final Account account;
|
|
|
|
final Share share;
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:08:13 +01:00
|
|
|
class FavoriteResyncedEvent {
|
|
|
|
const FavoriteResyncedEvent(
|
|
|
|
this.account, this.newFavorites, this.removedFavorites);
|
|
|
|
|
|
|
|
final Account account;
|
|
|
|
final List<File> newFavorites;
|
|
|
|
final List<File> removedFavorites;
|
|
|
|
}
|
|
|
|
|
2021-04-17 11:04:46 +02:00
|
|
|
class ThemeChangedEvent {}
|
2021-05-28 19:15:09 +02:00
|
|
|
|
2021-06-23 10:15:25 +02:00
|
|
|
class LanguageChangedEvent {}
|
|
|
|
|
2021-08-15 19:06:00 +02:00
|
|
|
class MetadataTaskStateChangedEvent {
|
|
|
|
const MetadataTaskStateChangedEvent(this.state);
|
|
|
|
|
|
|
|
final MetadataTaskState state;
|
|
|
|
}
|
|
|
|
|
2021-09-11 14:03:40 +02:00
|
|
|
class PrefUpdatedEvent {
|
|
|
|
PrefUpdatedEvent(this.key, this.value);
|
|
|
|
|
|
|
|
final PrefKey key;
|
|
|
|
final dynamic value;
|
|
|
|
}
|
|
|
|
|
2021-05-28 19:15:09 +02:00
|
|
|
extension FilePropertyUpdatedEventExtension on FilePropertyUpdatedEvent {
|
|
|
|
bool hasAnyProperties(List<int> properties) =>
|
|
|
|
properties.any((p) => this.properties & p != 0);
|
|
|
|
}
|