nc-photos/app/lib/entity/person.dart

77 lines
1.9 KiB
Dart
Raw Normal View History

2023-07-03 19:23:42 +02:00
import 'package:copy_with/copy_with.dart';
import 'package:equatable/equatable.dart';
2022-12-08 16:39:13 +01:00
import 'package:to_string/to_string.dart';
2022-12-08 16:39:13 +01:00
part 'person.g.dart';
2023-07-03 19:23:42 +02:00
@genCopyWith
2022-12-08 16:39:13 +01:00
@toString
class Person with EquatableMixin {
2022-08-05 11:14:03 +02:00
const Person({
2021-09-10 19:10:26 +02:00
required this.name,
2023-07-03 19:23:42 +02:00
required this.contentProvider,
});
2021-09-10 19:10:26 +02:00
@override
2022-12-08 16:39:13 +01:00
String toString() => _$toString();
2021-09-10 19:10:26 +02:00
2023-07-03 19:23:42 +02:00
bool compareIdentity(Person other) => other.id == id;
int get identityHashCode => id.hashCode;
/// A unique id for each collection. The value is divided into two parts in
/// the format XXXX-YYY...YYY, where XXXX is a four-character code
/// representing the content provider type, and YYY is an implementation
/// detail of each providers
String get id => "${contentProvider.fourCc}-${contentProvider.id}";
/// See [PersonContentProvider.count]
int? get count => contentProvider.count;
/// See [PersonContentProvider.getCoverUrl]
String? getCoverUrl(
int width,
int height, {
bool? isKeepAspectRatio,
}) =>
contentProvider.getCoverUrl(
width,
height,
isKeepAspectRatio: isKeepAspectRatio,
);
@override
2023-07-03 19:23:42 +02:00
List<Object?> get props => [
name,
2023-07-03 19:23:42 +02:00
contentProvider,
];
2021-09-10 19:10:26 +02:00
final String name;
2023-07-03 19:23:42 +02:00
final PersonContentProvider contentProvider;
}
2023-07-03 19:23:42 +02:00
abstract class PersonContentProvider with EquatableMixin {
const PersonContentProvider();
2023-07-03 19:23:42 +02:00
/// Unique FourCC of this provider type
String get fourCc;
2023-07-03 19:23:42 +02:00
/// Return the unique id of this person
String get id;
2023-07-03 19:23:42 +02:00
/// Return the number of items in this person, or null if not supported
int? get count;
/// Return the URL of the cover image if available
///
/// The [width] and [height] are provided as a hint only, implementations are
/// free to ignore them if it's not supported
///
/// [isKeepAspectRatio] is only a hint and implementations may ignore it
String? getCoverUrl(
int width,
int height, {
bool? isKeepAspectRatio,
});
}