fetchDataFromServer method
Executa o download completo de dados do servidor
Implementation
Future<void> fetchDataFromServer() async {
final syncConfig = _getSyncConfig();
SyncUtils.debugLog('=== INICIANDO BUSCA DE DADOS DO SERVIDOR ===',
tag: 'SyncDownloadStrategy');
try {
// Mostrar notificação de progresso para busca de dados
if (syncConfig?.enableNotifications == true) {
await SyncNotificationService.instance.showProgressNotification(
title: 'Sincronizando',
progress: 0,
maxProgress: 100,
message: 'Buscando dados atualizados do servidor...',
);
}
// Limpar dados antigos
await _clearOldData();
// Executar todas as estratégias de download
final results = await _executeDownloadStrategies();
// Processar resultados e extrair IDs de medias para pré-cache
final mediaIds = _extractMediaIds(results);
// Fazer pré-cache de imagens e limpeza de órfãs
await _handleImageCaching(mediaIds);
// Cancelar notificações
await _cancelNotifications();
SyncUtils.debugLog('=== BUSCA DE DADOS DO SERVIDOR CONCLUÍDA ===',
tag: 'SyncDownloadStrategy');
} catch (e) {
SyncUtils.debugLog('ERRO GERAL durante busca de dados do servidor: $e',
tag: 'SyncDownloadStrategy');
// Cancelar notificações em caso de erro
await _cancelNotifications();
rethrow;
}
}