[mob][photos] Init locale
This commit is contained in:
@@ -43,6 +43,7 @@ import "package:photos/services/preview_video_store.dart";
|
||||
import 'package:photos/services/push_service.dart';
|
||||
import 'package:photos/services/remote_sync_service.dart';
|
||||
import 'package:photos/services/search_service.dart';
|
||||
import "package:photos/services/smart_memories_service.dart";
|
||||
import "package:photos/services/sync_service.dart";
|
||||
import "package:photos/services/user_service.dart";
|
||||
import 'package:photos/ui/tools/app_lock.dart';
|
||||
@@ -252,6 +253,7 @@ Future<void> _init(bool isBackground, {String via = ''}) async {
|
||||
|
||||
FavoritesService.instance.initFav().ignore();
|
||||
MemoriesService.instance.init(preferences);
|
||||
unawaited(SmartMemoriesService.instance.init());
|
||||
LocalFileUpdateService.instance.init(preferences);
|
||||
SearchService.instance.init();
|
||||
FileDataService.instance.init(preferences);
|
||||
|
||||
@@ -1194,7 +1194,6 @@ class SearchService {
|
||||
BuildContext context,
|
||||
int? limit,
|
||||
) async {
|
||||
SmartMemoriesService.instance.init(context);
|
||||
final memories = await SmartMemoriesService.instance.getMemories(limit);
|
||||
final searchResults = <GenericSearchResult>[];
|
||||
for (final memory in memories) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import "dart:async";
|
||||
import "dart:math" show min, max;
|
||||
|
||||
import "package:flutter/material.dart";
|
||||
@@ -9,6 +10,7 @@ import "package:photos/core/event_bus.dart";
|
||||
import "package:photos/db/memories_db.dart";
|
||||
import "package:photos/db/ml/db.dart";
|
||||
import "package:photos/events/files_updated_event.dart";
|
||||
import "package:photos/l10n/l10n.dart";
|
||||
import "package:photos/models/base_location.dart";
|
||||
import "package:photos/models/file/extensions/file_props.dart";
|
||||
import "package:photos/models/file/file.dart";
|
||||
@@ -31,7 +33,7 @@ class SmartMemoriesService {
|
||||
|
||||
bool _isInit = false;
|
||||
|
||||
late Locale _locale;
|
||||
Locale? _locale;
|
||||
late Map<int, int> _seenTimes;
|
||||
|
||||
List<SmartMemory>? _cachedMemories;
|
||||
@@ -46,14 +48,15 @@ class SmartMemoriesService {
|
||||
static final instance = SmartMemoriesService._privateConstructor();
|
||||
factory SmartMemoriesService() => instance;
|
||||
|
||||
void init(BuildContext context) {
|
||||
Future<void> init() async {
|
||||
if (_isInit) return;
|
||||
_locale = Localizations.localeOf(context);
|
||||
_isInit = true;
|
||||
_locale = await getLocale();
|
||||
|
||||
_memoriesDB.clearMemoriesSeenBeforeTime(
|
||||
DateTime.now().microsecondsSinceEpoch -
|
||||
(_calculationWindowDays * microSecondsInDay),
|
||||
unawaited(
|
||||
_memoriesDB.clearMemoriesSeenBeforeTime(
|
||||
DateTime.now().microsecondsSinceEpoch -
|
||||
(_calculationWindowDays * microSecondsInDay),
|
||||
),
|
||||
);
|
||||
Bus.instance.on<FilesUpdatedEvent>().where((event) {
|
||||
return event.type == EventType.deletedFromEverywhere;
|
||||
@@ -68,6 +71,7 @@ class SmartMemoriesService {
|
||||
.removeWhere((m) => generatedIDs.contains(m.file.generatedID));
|
||||
}
|
||||
});
|
||||
_isInit = true;
|
||||
_logger.info("Smart memories service initialized");
|
||||
}
|
||||
|
||||
@@ -111,6 +115,7 @@ class SmartMemoriesService {
|
||||
// One general method to get all memories, which calls on internal methods for each separate memory type
|
||||
Future<List<SmartMemory>> _calcMemories() async {
|
||||
try {
|
||||
await init();
|
||||
final List<SmartMemory> memories = [];
|
||||
final allFiles = Set<EnteFile>.from(
|
||||
await SearchService.instance.getAllFilesForSearch(),
|
||||
@@ -145,6 +150,7 @@ class SmartMemoriesService {
|
||||
// memories.addAll(fillerMemories);
|
||||
// _logger.finest("All files length: ${allFiles.length}");
|
||||
|
||||
_cachedMemories = memories;
|
||||
return memories;
|
||||
} catch (e, s) {
|
||||
_logger.severe("Error calculating smart memories", e, s);
|
||||
@@ -611,7 +617,7 @@ class SmartMemoriesService {
|
||||
final date = DateTime(year, dayMonth ~/ 100, dayMonth % 100);
|
||||
final files = yearGroups[year]!;
|
||||
final photoSelection = await _bestSelection(files);
|
||||
String name = DateFormat.yMMMd(_locale.languageCode).format(date);
|
||||
String name = DateFormat.yMMMd(_locale?.languageCode).format(date);
|
||||
if (date.day == currentTime.day && date.month == currentTime.month) {
|
||||
name = "This day, ${currentTime.year - date.year} years back";
|
||||
}
|
||||
@@ -726,7 +732,7 @@ class SmartMemoriesService {
|
||||
monthYearFiles,
|
||||
prefferedSize: monthSelectionSize,
|
||||
);
|
||||
final monthName = DateFormat.MMMM(_locale.languageCode)
|
||||
final monthName = DateFormat.MMMM(_locale?.languageCode)
|
||||
.format(DateTime(year, currentMonth));
|
||||
final name = monthName + ", ${currentTime.year - year} years back";
|
||||
memoryResult.add(
|
||||
@@ -744,7 +750,7 @@ class SmartMemoriesService {
|
||||
.toList();
|
||||
final photoSelection =
|
||||
await _bestSelection(allPhotos, prefferedSize: monthSelectionSize);
|
||||
final monthName = DateFormat.MMMM(_locale.languageCode)
|
||||
final monthName = DateFormat.MMMM(_locale?.languageCode)
|
||||
.format(DateTime(currentTime.year, currentMonth));
|
||||
final name = monthName + " through the years";
|
||||
memoryResult.add(
|
||||
|
||||
@@ -59,7 +59,6 @@ class _MemoriesWidgetState extends State<MemoriesWidget> {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
if (flagService.showSmartMemories) {
|
||||
SmartMemoriesService.instance.init(context);
|
||||
return FutureBuilder<List<SmartMemory>>(
|
||||
future: SmartMemoriesService.instance.getMemories(
|
||||
null,
|
||||
|
||||
Reference in New Issue
Block a user