[mob][photos] Minor fixes for memories and shift date (#5341)

## Description

Small fixes for memories and shift date

## Tests
This commit is contained in:
Neeraj
2025-03-17 17:26:45 +05:30
committed by GitHub
6 changed files with 42 additions and 22 deletions

View File

@@ -152,8 +152,8 @@ class MLService {
if (_mlControllerStatus == true) {
// refresh discover section
magicCacheService.updateCache().ignore();
// refresh memories section
memoriesCacheService.updateCache().ignore();
// refresh memories section (only runs if forced is true)
memoriesCacheService.updateCache(forced: force).ignore();
}
} catch (e, s) {
_logger.severe("runAllML failed", e, s);

View File

@@ -20,6 +20,7 @@ import "package:shared_preferences/shared_preferences.dart";
class MemoriesCacheService {
static const _lastMemoriesCacheUpdateTimeKey = "lastMemoriesCacheUpdateTime";
static const _showAnyMemoryKey = "memories.enabled";
static const _shouldUpdateCacheKey = "memories.shouldUpdateCache";
/// Delay is for cache update to be done not during app init, during which a
/// lot of other things are happening.
@@ -88,8 +89,9 @@ class MemoriesCacheService {
if (!enableSmartMemories) {
return;
}
_shouldUpdate = _prefs.getBool(_shouldUpdateCacheKey) ?? _shouldUpdate;
if (_timeToUpdateCache()) {
_shouldUpdate = true;
queueUpdateCache();
}
}
@@ -125,6 +127,12 @@ class MemoriesCacheService {
void queueUpdateCache() {
_shouldUpdate = true;
unawaited(_prefs.setBool(_shouldUpdateCacheKey, true));
}
void _cacheUpdated() {
_shouldUpdate = false;
unawaited(_prefs.setBool(_shouldUpdateCacheKey, false));
}
Future<void> updateCache({bool forced = false}) async {
@@ -185,7 +193,7 @@ class MemoriesCacheService {
w?.log("cacheWritten");
await _resetLastMemoriesCacheUpdateTime();
w?.logAndReset('done');
_shouldUpdate = false;
_cacheUpdated();
} catch (e, s) {
_logger.info("Error updating memories cache", e, s);
} finally {

View File

@@ -421,7 +421,7 @@ class SmartMemoriesService {
for (final fileID in personFileIDs) {
final bool mePresent = meFileIDs!.contains(fileID);
final personFaces = fileIdToFaces[fileID] ?? [];
if (mePresent || personFaces.length != 2) continue;
if (!mePresent || personFaces.length != 2) continue;
final file = allFileIdsToFile[fileID];
if (file != null) {
youAndThemFiles.add(file);
@@ -1321,7 +1321,7 @@ class SmartMemoriesService {
clipPositiveTextVector: clipPositiveTextVector,
);
final name =
"${DateFormat.MMMd()}, ${currentTime.year - date.year} years ago";
"${DateFormat.MMMd().format(date)}, ${currentTime.year - date.year} years ago";
memoryResult.add(
TimeMemory(
photoSelection,
@@ -1392,8 +1392,7 @@ class SmartMemoriesService {
fileIDToImageEmbedding: fileIDToImageEmbedding,
clipPositiveTextVector: clipPositiveTextVector,
);
final name =
"This week, ${currentTime.year - date.year} years back";
final name = "This week, ${currentTime.year - date.year} years ago";
memoryResult.add(
TimeMemory(
@@ -1451,7 +1450,7 @@ class SmartMemoriesService {
final monthName = DateFormat.MMMM().format(DateTime(year, currentMonth));
final daysLeftInMonth =
DateTime(currentYear, currentMonth + 1, 0).day - currentTime.day + 1;
final name = monthName + ", ${currentTime.year - year} years back";
final name = monthName + ", ${currentTime.year - year} years ago";
memoryResult.add(
TimeMemory(
photoSelection,

View File

@@ -177,4 +177,4 @@ class _DateTimePickerWidgetState extends State<DateTimePickerWidget> {
),
);
}
}
}

View File

@@ -13,8 +13,7 @@ Future<DateTime?> showEditDateSheet(
BuildContext context,
Iterable<EnteFile> enteFiles, {
bool showHeader = true,
}
) async {
}) async {
final newDate = await showModalBottomSheet<DateTime?>(
context: context,
isScrollControlled: true,
@@ -197,7 +196,7 @@ class _EditDateSheetState extends State<EditDateSheet> {
],
),
// Bottom indicator line
const SizedBox(height: 48),
const SizedBox(height: 20),
],
),
),
@@ -266,7 +265,9 @@ class DateAndTimeWidget extends StatelessWidget {
final colorScheme = getEnteColorScheme(context);
final locale = Localizations.localeOf(context);
final String date = DateFormat.yMMMd(locale.languageCode).format(dateTime);
final String time = DateFormat.Hm(locale.languageCode).format(dateTime);
final String time = DateFormat(
MediaQuery.of(context).alwaysUse24HourFormat ? 'HH:mm' : 'h:mm a',
).format(dateTime);
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Column(
@@ -396,7 +397,7 @@ class DateAndTimeWidget extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
_formatDate(dateTime, locale),
_formatDate(dateTime, locale, context),
style: TextStyle(
color: colorScheme.textFaint,
fontSize: 12,
@@ -413,7 +414,7 @@ class DateAndTimeWidget extends StatelessWidget {
),
),
Text(
_formatDate(newRangeEnd!, locale),
_formatDate(newRangeEnd!, locale, context),
style: TextStyle(
color: colorScheme.textFaint,
fontSize: 12,
@@ -578,7 +579,7 @@ class PhotoDateHeaderWidget extends StatelessWidget {
Row(
children: [
Text(
_formatDate(startDate, locale),
_formatDate(startDate, locale, context),
style: TextStyle(
color: colorScheme.textMuted,
fontSize: 12,
@@ -595,7 +596,7 @@ class PhotoDateHeaderWidget extends StatelessWidget {
),
),
Text(
_formatDate(endDate, locale),
_formatDate(endDate, locale, context),
style: TextStyle(
color: colorScheme.textMuted,
fontSize: 12,
@@ -627,7 +628,11 @@ class PhotoDateHeaderWidget extends StatelessWidget {
),
const SizedBox(height: 4),
Text(
"${DateFormat.yMEd(locale.languageCode).format(startDate)} · ${DateFormat.Hm(locale.languageCode).format(startDate)}",
"${DateFormat.yMEd(locale.languageCode).format(startDate)} · ${DateFormat(
MediaQuery.of(context).alwaysUse24HourFormat
? 'HH:mm'
: 'h:mm a',
).format(startDate)}",
style: TextStyle(
color: colorScheme.textMuted,
fontSize: 12,
@@ -642,6 +647,8 @@ class PhotoDateHeaderWidget extends StatelessWidget {
}
}
String _formatDate(DateTime date, Locale locale) {
return "${DateFormat.yMEd(locale.languageCode).format(date)}\n${DateFormat.Hm(locale.languageCode).format(date)}";
String _formatDate(DateTime date, Locale locale, BuildContext context) {
return "${DateFormat.yMEd(locale.languageCode).format(date)}\n${DateFormat(
MediaQuery.of(context).alwaysUse24HourFormat ? 'HH:mm' : 'h:mm a',
).format(date)}";
}

View File

@@ -13,6 +13,8 @@ import "package:photos/ui/components/info_item_widget.dart";
import "package:photos/ui/viewer/file_details/face_widget.dart";
import "package:photos/utils/face/face_box_crop.dart";
final Logger _logger = Logger("FacesItemWidget");
class FacesItemWidget extends StatefulWidget {
final EnteFile file;
const FacesItemWidget(this.file, {super.key});
@@ -135,6 +137,7 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
final _ = await getCachedFaceCrops(file, faces);
final faceCrops = getCachedFaceCrops(file, faces);
final List<String> faceIDs = [];
for (final Face face in faces) {
final String? clusterID = faceIdsToClusterIds[face.faceID];
final PersonEntity? person = clusterIDToPerson[clusterID] != null
@@ -142,6 +145,7 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
: null;
final highlight =
(clusterID == lastViewedClusterID) && (person == null);
faceIDs.add(face.faceID);
faceWidgets.add(
FaceWidget(
file,
@@ -155,9 +159,11 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
);
}
_logger.info('File ${file.uploadedFileID} has FaceIDs: $faceIDs');
return faceWidgets;
} catch (e, s) {
Logger("FacesItemWidget").info(e, s);
_logger.severe('failed to get face widgets in file info', e, s);
return <FaceWidget>[];
}
}