Handle cases when there are no files left to be deleted
This commit is contained in:
parent
19cde13ab9
commit
edaff6b3ee
2 changed files with 22 additions and 32 deletions
|
@ -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<FreeSpacePage> {
|
||||
Future<BackupStatus> _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<FreeSpacePage> {
|
|||
}
|
||||
|
||||
Widget _getBody() {
|
||||
return FutureBuilder<BackupStatus>(
|
||||
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<FreeSpacePage> {
|
|||
await dialog.show();
|
||||
await deleteLocalFiles(status.localIDs);
|
||||
await dialog.hide();
|
||||
Navigator.of(context).pop(status);
|
||||
Navigator.of(context).pop(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<BackupSectionWidget> {
|
|||
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(
|
||||
|
|
Loading…
Reference in a new issue