feat(offline+post): Offline Mode Overhaul & Post Details Screen Redesign (v2.2.0)
This commit is contained in:
@@ -48,4 +48,39 @@ class DownloadedMediaService {
|
||||
Future<Result<void>> clearMissingFiles() => _repository.clearMissingFiles();
|
||||
|
||||
Future<Result<int>> count() => _repository.count();
|
||||
|
||||
static int getFileSizeSync(DownloadedMedia media) {
|
||||
if (media.savedPath.isEmpty) return 0;
|
||||
final file = File(media.savedPath);
|
||||
if (!file.existsSync()) return 0;
|
||||
try {
|
||||
return file.lengthSync();
|
||||
} catch (_) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<int> totalDiskSizeBytes(Iterable<DownloadedMedia> items) async {
|
||||
int total = 0;
|
||||
for (final media in items) {
|
||||
if (media.savedPath.isNotEmpty) {
|
||||
final file = File(media.savedPath);
|
||||
if (await file.exists()) {
|
||||
try {
|
||||
total += await file.length();
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
static String formatBytes(int bytes) {
|
||||
if (bytes < 1024) return '$bytes B';
|
||||
if (bytes < 1024 * 1024) return '${(bytes / 1024).toStringAsFixed(1)} KB';
|
||||
if (bytes < 1024 * 1024 * 1024) {
|
||||
return '${(bytes / (1024 * 1024)).toStringAsFixed(1)} MB';
|
||||
}
|
||||
return '${(bytes / (1024 * 1024 * 1024)).toStringAsFixed(2)} GB';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user