v2.40 — Issue #9: Progress-Notification für Download/Upload (flutter_local_notifications)
- flutter_local_notifications ^22.2.0 hinzugefügt - Notification-Channel 'de.baka.melo.downloads' in main() initialisiert - DownloadService._showProgress(): Fortschritts-Notification mit ProgressBar - DownloadService._completeNotification(): Abschluss-Notification (Erfolg/Fehler/Abbruch) - Integration in downloadBatch(): Fortschritt pro Song, Abschluss nach Batch - CloudScreen._upload(): Upload-Fortschritt + Abschluss-Notification
This commit is contained in:
@@ -3,11 +3,13 @@ import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import '../utils/farb_theme.dart';
|
||||
import '../services/cloud_service.dart';
|
||||
import '../services/auth_service.dart';
|
||||
import '../database/db_helper.dart';
|
||||
import '../services/melo_logger.dart';
|
||||
import '../main.dart'; // notificationsPlugin
|
||||
|
||||
/// Melo Cloud Sync Screen v3 — vollständiges Sync-System
|
||||
/// Playlisten, Favoriten, Auto-Sync, Persistent Login, Benutzerdefinierte Namen
|
||||
@@ -398,6 +400,9 @@ class _CloudScreenState extends State<CloudScreen> {
|
||||
|
||||
// ─── Upload / Download ───
|
||||
|
||||
static const String _cloudChannelId = 'de.baka.melo.downloads';
|
||||
static const int _cloudNotifyId = 200;
|
||||
|
||||
Future<void> _upload() async {
|
||||
setState(() => _ladt = true);
|
||||
_setzeStatus('Suche lokale Songs...');
|
||||
@@ -413,12 +418,59 @@ class _CloudScreenState extends State<CloudScreen> {
|
||||
}
|
||||
final files = dir.listSync().whereType<File>().where(
|
||||
(f) => f.path.endsWith('.mp3') || f.path.endsWith('.m4a'));
|
||||
final fileList = files.toList();
|
||||
int count = 0;
|
||||
for (final f in files) {
|
||||
for (int i = 0; i < fileList.length; i++) {
|
||||
final f = fileList[i];
|
||||
_setzeStatus('Upload: ${f.path.split('/').last}...');
|
||||
// Progress-Notification
|
||||
if (Platform.isAndroid) {
|
||||
notificationsPlugin.show(
|
||||
id: _cloudNotifyId,
|
||||
title: 'Melo Cloud Upload',
|
||||
body: '${i + 1} / ${fileList.length}: ${f.path.split('/').last}',
|
||||
notificationDetails: NotificationDetails(
|
||||
android: AndroidNotificationDetails(
|
||||
_cloudChannelId,
|
||||
'Melo Downloads',
|
||||
channelDescription: 'Cloud Upload-Fortschritt',
|
||||
importance: Importance.low,
|
||||
priority: Priority.low,
|
||||
onlyAlertOnce: true,
|
||||
showProgress: true,
|
||||
maxProgress: fileList.length,
|
||||
progress: i,
|
||||
ongoing: true,
|
||||
autoCancel: false,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
final sid = await widget.cloud.upload(f.path, f.path.split('/').last);
|
||||
if (sid != null) count++;
|
||||
}
|
||||
// Abschluss-Notification
|
||||
if (Platform.isAndroid) {
|
||||
notificationsPlugin.cancel(id: _cloudNotifyId);
|
||||
final ok = count > 0;
|
||||
notificationsPlugin.show(
|
||||
id: _cloudNotifyId + 1,
|
||||
title: ok ? 'Cloud Upload fertig' : 'Cloud Upload fehlgeschlagen',
|
||||
body: ok
|
||||
? '$count / ${fileList.length} Songs hochgeladen ✅'
|
||||
: 'Kein Song konnte hochgeladen werden ❌',
|
||||
notificationDetails: NotificationDetails(
|
||||
android: AndroidNotificationDetails(
|
||||
_cloudChannelId,
|
||||
'Melo Downloads',
|
||||
channelDescription: 'Cloud Upload-Abschluss',
|
||||
importance: Importance.defaultImportance,
|
||||
priority: Priority.defaultPriority,
|
||||
autoCancel: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
await _ladeStatus();
|
||||
if (mounted) {
|
||||
setState(() => _ladt = false);
|
||||
@@ -427,6 +479,9 @@ class _CloudScreenState extends State<CloudScreen> {
|
||||
}
|
||||
} catch (e) {
|
||||
MeloLogger().fehler('cloud_upload_path', e);
|
||||
if (Platform.isAndroid) {
|
||||
notificationsPlugin.cancel(id: _cloudNotifyId);
|
||||
}
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_ladt = false;
|
||||
|
||||
Reference in New Issue
Block a user