mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
Make some entities equatable
This commit is contained in:
parent
49244a3d09
commit
b3f410d8b8
4 changed files with 50 additions and 7 deletions
|
@ -3,6 +3,7 @@ import 'dart:convert';
|
|||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:idb_sqflite/idb_sqflite.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
@ -59,7 +60,7 @@ abstract class AlbumItem {
|
|||
static final _log = Logger("entity.album.AlbumItem");
|
||||
}
|
||||
|
||||
class AlbumFileItem extends AlbumItem {
|
||||
class AlbumFileItem extends AlbumItem with EquatableMixin {
|
||||
AlbumFileItem({this.file});
|
||||
|
||||
factory AlbumFileItem.fromJson(Map<String, dynamic> json) {
|
||||
|
@ -82,13 +83,18 @@ class AlbumFileItem extends AlbumItem {
|
|||
};
|
||||
}
|
||||
|
||||
@override
|
||||
get props => [
|
||||
file,
|
||||
];
|
||||
|
||||
final File file;
|
||||
|
||||
static const _type = "file";
|
||||
}
|
||||
|
||||
/// Immutable object that represents an album
|
||||
class Album {
|
||||
class Album with EquatableMixin {
|
||||
Album({
|
||||
DateTime lastUpdated,
|
||||
@required String name,
|
||||
|
@ -188,6 +194,14 @@ class Album {
|
|||
};
|
||||
}
|
||||
|
||||
@override
|
||||
get props => [
|
||||
lastUpdated,
|
||||
name,
|
||||
items,
|
||||
albumFile,
|
||||
];
|
||||
|
||||
final DateTime lastUpdated;
|
||||
final String name;
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:exifdart/exifdart.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class Exif {
|
||||
class Exif with EquatableMixin {
|
||||
Exif(this.data);
|
||||
|
||||
dynamic operator [](String key) => data[key];
|
||||
|
@ -95,7 +96,12 @@ class Exif {
|
|||
String get gpsLongitudeRef => data["GPSLongitudeRef"];
|
||||
List<Rational> get gpsLongitude => data["GPSLongitude"].cast<Rational>();
|
||||
|
||||
static final dateTimeFormat = DateFormat("yyyy:MM:dd HH:mm:ss");
|
||||
@override
|
||||
get props => [
|
||||
data,
|
||||
];
|
||||
|
||||
final Map<String, dynamic> data;
|
||||
|
||||
static final dateTimeFormat = DateFormat("yyyy:MM:dd HH:mm:ss");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:idb_sqflite/idb_sqflite.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
@ -28,7 +29,7 @@ int compareFileDateTimeDescending(File x, File y) {
|
|||
}
|
||||
|
||||
/// Immutable object that hold metadata of a [File]
|
||||
class Metadata {
|
||||
class Metadata with EquatableMixin {
|
||||
Metadata({
|
||||
DateTime lastUpdated,
|
||||
this.fileEtag,
|
||||
|
@ -106,6 +107,15 @@ class Metadata {
|
|||
return product + "}";
|
||||
}
|
||||
|
||||
@override
|
||||
get props => [
|
||||
lastUpdated,
|
||||
fileEtag,
|
||||
imageWidth,
|
||||
imageHeight,
|
||||
exif,
|
||||
];
|
||||
|
||||
final DateTime lastUpdated;
|
||||
|
||||
/// Etag of the parent file when the metadata is saved
|
||||
|
@ -181,7 +191,7 @@ class MetadataUpgraderV2 implements MetadataUpgrader {
|
|||
static final _log = Logger("entity.file.MetadataUpgraderV2");
|
||||
}
|
||||
|
||||
class File {
|
||||
class File with EquatableMixin {
|
||||
File({
|
||||
@required String path,
|
||||
this.contentLength,
|
||||
|
@ -315,6 +325,19 @@ class File {
|
|||
}
|
||||
}
|
||||
|
||||
@override
|
||||
get props => [
|
||||
path,
|
||||
contentLength,
|
||||
contentType,
|
||||
etag,
|
||||
lastModified,
|
||||
isCollection,
|
||||
usedBytes,
|
||||
hasPreview,
|
||||
metadata,
|
||||
];
|
||||
|
||||
final String path;
|
||||
final int contentLength;
|
||||
final String contentType;
|
||||
|
|
|
@ -258,7 +258,7 @@ class _AlbumViewerState extends State<AlbumViewer>
|
|||
final selectedFiles = _backingFiles.takeIndex(selectedIndexes).toList();
|
||||
final newItems = _album.items.where((element) {
|
||||
if (element is AlbumFileItem) {
|
||||
return !selectedFiles.contains(element.file);
|
||||
return !selectedFiles.any((select) => select.path == element.file.path);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue