Add automatic updateAllContacts on app startup and every 8 hours after if not in low bandwidth mode.

codemagic-setup
Hank Grabowski 2023-04-27 22:05:10 -04:00
rodzic d9fc66ba2a
commit 6aecb654a2
3 zmienionych plików z 32 dodań i 4 usunięć

Wyświetl plik

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:logging/logging.dart';
import 'data/interfaces/connections_repo_intf.dart';
@ -71,10 +73,26 @@ Future<void> dependencyInjectionInitialization() async {
getIt.registerSingleton<ActiveProfileSelector<ConnectionsManager>>(
ActiveProfileSelector(
(p) => ConnectionsManager(
getIt<ActiveProfileSelector<IConnectionsRepo>>().getForProfile(p).value,
getIt<ActiveProfileSelector<IGroupsRepo>>().getForProfile(p).value,
),
(p) {
final manager = ConnectionsManager(
getIt<ActiveProfileSelector<IConnectionsRepo>>().getForProfile(p).value,
getIt<ActiveProfileSelector<IGroupsRepo>>().getForProfile(p).value,
);
Future.delayed(Duration.zero, () async {
if (!settingsService.lowBandwidthMode) {
await manager.updateAllContacts();
}
});
Timer.periodic(const Duration(hours: 8), (_) async {
if (!settingsService.lowBandwidthMode) {
await manager.updateAllContacts();
}
});
return manager;
},
));
getIt.registerSingleton<ActiveProfileSelector<GalleryService>>(

Wyświetl plik

@ -128,6 +128,7 @@ class _ContactsScreenState extends State<ContactsScreen> {
)
],
),
Text(manager.lastUpdateStatus),
StandardLinearProgressIndicator(nss.connectionUpdateStatus),
Expanded(child: body),
],

Wyświetl plik

@ -15,11 +15,16 @@ import '../models/exec_error.dart';
import '../models/group_data.dart';
import 'auth_service.dart';
const _notUpdatedYetMesasge = 'Not updated since app started';
class ConnectionsManager extends ChangeNotifier {
static final _logger = Logger('$ConnectionsManager');
late final IConnectionsRepo conRepo;
late final IGroupsRepo groupsRepo;
var groupsNotInitialized = true;
var _lastUpdateStatus = _notUpdatedYetMesasge;
String get lastUpdateStatus => _lastUpdateStatus;
ConnectionsManager(this.conRepo, this.groupsRepo);
@ -27,6 +32,7 @@ class ConnectionsManager extends ChangeNotifier {
conRepo.clear();
groupsRepo.clear();
groupsNotInitialized = true;
_lastUpdateStatus = _notUpdatedYetMesasge;
notifyListeners();
}
@ -148,6 +154,8 @@ class ConnectionsManager extends ChangeNotifier {
Future<void> updateAllContacts() async {
_logger.fine('Updating all contacts');
_lastUpdateStatus = 'Updating';
notifyListeners();
final client = RelationshipsClient(getIt<AccountsService>().currentProfile);
final results = <String, Connection>{};
var moreResults = true;
@ -203,6 +211,7 @@ class ConnectionsManager extends ChangeNotifier {
final myContacts = conRepo.getMyContacts().toList();
myContacts.sort((c1, c2) => c1.name.compareTo(c2.name));
_logger.fine('# Contacts:${myContacts.length}');
_lastUpdateStatus = 'Last updated at: ${DateTime.now()}';
notifyListeners();
}