Skip to content

Commit

Permalink
[mob][photos] Trips memories (internal users only) (#5035)
Browse files Browse the repository at this point in the history
## Description

Added trips memories for internal users in the moments section

## Tests

Tested in debug mode on my pixel phone.
  • Loading branch information
laurenspriem authored Feb 13, 2025
2 parents fb01283 + 74db876 commit 95d218b
Show file tree
Hide file tree
Showing 3 changed files with 507 additions and 0 deletions.
51 changes: 51 additions & 0 deletions mobile/lib/models/base_location.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import "package:photos/models/file/file.dart";
import "package:photos/models/location/location.dart";

class BaseLocation {
final List<EnteFile> files;
int? firstCreationTime;
int? lastCreationTime;
final Location location;
final bool isCurrentBase;

BaseLocation(
this.files,
this.location,
this.isCurrentBase, {
this.firstCreationTime,
this.lastCreationTime,
});

int averageCreationTime() {
if (firstCreationTime != null && lastCreationTime != null) {
return (firstCreationTime! + lastCreationTime!) ~/ 2;
}
final List<int> creationTimes = files
.where((file) => file.creationTime != null)
.map((file) => file.creationTime!)
.toList();
if (creationTimes.length < 2) {
return creationTimes.isEmpty ? 0 : creationTimes.first;
}
creationTimes.sort();
firstCreationTime ??= creationTimes.first;
lastCreationTime ??= creationTimes.last;
return (firstCreationTime! + lastCreationTime!) ~/ 2;
}

BaseLocation copyWith({
List<EnteFile>? files,
int? firstCreationTime,
int? lastCreationTime,
Location? location,
bool? isCurrentBase,
}) {
return BaseLocation(
files ?? this.files,
location ?? this.location,
isCurrentBase ?? this.isCurrentBase,
firstCreationTime: firstCreationTime ?? this.firstCreationTime,
lastCreationTime: lastCreationTime ?? this.lastCreationTime,
);
}
}
32 changes: 32 additions & 0 deletions mobile/lib/models/trip_memory.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import "package:photos/models/file/file.dart";
import "package:photos/models/location/location.dart";

class TripMemory {
final List<EnteFile> files;
final Location location;
final int firstCreationTime;
final int lastCreationTime;

TripMemory(
this.files,
this.location,
this.firstCreationTime,
this.lastCreationTime,
);

int get averageCreationTime => (firstCreationTime + lastCreationTime) ~/ 2;

TripMemory copyWith({
List<EnteFile>? files,
Location? location,
int? firstCreationTime,
int? lastCreationTime,
}) {
return TripMemory(
files ?? this.files,
location ?? this.location,
firstCreationTime ?? this.firstCreationTime,
lastCreationTime ?? this.lastCreationTime,
);
}
}
Loading

0 comments on commit 95d218b

Please sign in to comment.