From edaff6b3ee4e4ab15bdb5f6cfff054640f1a2e48 Mon Sep 17 00:00:00 2001 From: Vishnu Date: Mon, 28 Jun 2021 20:17:06 +0530 Subject: [PATCH] Handle cases when there are no files left to be deleted --- lib/ui/free_space_page.dart | 38 +++++----------------- lib/ui/settings/backup_section_widget.dart | 16 +++++++-- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/lib/ui/free_space_page.dart b/lib/ui/free_space_page.dart index ca2377d3e..2dffe9c7c 100644 --- a/lib/ui/free_space_page.dart +++ b/lib/ui/free_space_page.dart @@ -3,29 +3,21 @@ import 'package:flutter/widgets.dart'; import 'package:intl/intl.dart'; import 'package:logging/logging.dart'; import 'package:photos/models/backup_status.dart'; -import 'package:photos/services/sync_service.dart'; import 'package:photos/ui/common_elements.dart'; -import 'package:photos/ui/loading_widget.dart'; import 'package:photos/utils/data_util.dart'; import 'package:photos/utils/delete_file_util.dart'; import 'package:photos/utils/dialog_util.dart'; class FreeSpacePage extends StatefulWidget { - FreeSpacePage({Key key}) : super(key: key); + final BackupStatus status; + + FreeSpacePage(this.status, {Key key}) : super(key: key); @override _FreeSpacePageState createState() => _FreeSpacePageState(); } class _FreeSpacePageState extends State { - Future _future; - - @override - void initState() { - super.initState(); - _future = SyncService.instance.getBackupStatus(); - } - @override Widget build(BuildContext context) { return Scaffold( @@ -48,23 +40,11 @@ class _FreeSpacePageState extends State { } Widget _getBody() { - return FutureBuilder( - future: _future, - builder: (_, snapshot) { - if (snapshot.hasData) { - final status = snapshot.data; - Logger("FreeSpacePage").info( - "Number of uploaded files: " + status.localIDs.length.toString()); - Logger("FreeSpacePage") - .info("Space consumed: " + status.size.toString()); - return _getWidget(status); - } else if (snapshot.hasError) { - return Center(child: Text("oops, something went wrong")); - } else { - return loadWidget; - } - }, - ); + Logger("FreeSpacePage").info("Number of uploaded files: " + + widget.status.localIDs.length.toString()); + Logger("FreeSpacePage") + .info("Space consumed: " + widget.status.size.toString()); + return _getWidget(widget.status); } Widget _getWidget(BackupStatus status) { @@ -182,6 +162,6 @@ class _FreeSpacePageState extends State { await dialog.show(); await deleteLocalFiles(status.localIDs); await dialog.hide(); - Navigator.of(context).pop(status); + Navigator.of(context).pop(true); } } diff --git a/lib/ui/settings/backup_section_widget.dart b/lib/ui/settings/backup_section_widget.dart index 098581171..ce8bc8d49 100644 --- a/lib/ui/settings/backup_section_widget.dart +++ b/lib/ui/settings/backup_section_widget.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:photos/core/configuration.dart'; import 'package:photos/models/backup_status.dart'; +import 'package:photos/services/sync_service.dart'; import 'package:photos/ui/backup_folder_selection_widget.dart'; import 'package:photos/ui/free_space_page.dart'; import 'package:photos/ui/settings/settings_section_title.dart'; @@ -81,9 +82,18 @@ class BackupSectionWidgetState extends State { GestureDetector( behavior: HitTestBehavior.translucent, onTap: () async { - BackupStatus status = await routeToPage(context, FreeSpacePage()); - if (status != null) { - _showSpaceFreedDialog(status); + final dialog = createProgressDialog(context, "calculating..."); + await dialog.show(); + final status = await SyncService.instance.getBackupStatus(); + await dialog.hide(); + if (status.localIDs.isEmpty) { + showErrorDialog(context, "✨ all clear", + "you've no files on this device that can be deleted"); + } else { + bool result = await routeToPage(context, FreeSpacePage(status)); + if (result == true) { + _showSpaceFreedDialog(status); + } } }, child: SettingsTextItem(