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

95 lines
2.4 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';
2023-07-16 13:30:23 +02:00
import 'package:flutter/material.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';
enum PersonProvider {
none,
faceRecognition,
recognize;
static PersonProvider fromValue(int value) => PersonProvider.values[value];
}
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,
);
2023-07-16 13:30:23 +02:00
/// See [PersonContentProvider.getCoverTransform]
Matrix4? getCoverTransform(int viewportSize, int width, int height) =>
contentProvider.getCoverTransform(viewportSize, width, height);
@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,
});
2023-07-16 13:30:23 +02:00
/// Return the transformation matrix to focus the face
///
/// Only viewport in square is supported
Matrix4? getCoverTransform(int viewportSize, int width, int height);
}