2021-06-28 05:09:22 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2023-04-06 05:19:52 +00:00
|
|
|
import "package:photos/generated/l10n.dart";
|
2021-06-28 14:30:48 +00:00
|
|
|
import 'package:photos/models/backup_status.dart';
|
2021-09-28 12:51:20 +00:00
|
|
|
import 'package:photos/models/duplicate_files.dart';
|
2021-09-15 19:01:19 +00:00
|
|
|
import 'package:photos/services/deduplication_service.dart';
|
2021-06-28 14:47:06 +00:00
|
|
|
import 'package:photos/services/sync_service.dart';
|
2022-12-07 08:41:52 +00:00
|
|
|
import 'package:photos/services/update_service.dart';
|
2022-10-21 13:37:57 +00:00
|
|
|
import 'package:photos/theme/ente_theme.dart';
|
2023-06-06 09:57:17 +00:00
|
|
|
import "package:photos/ui/components/captioned_text_widget.dart";
|
2022-12-26 11:09:29 +00:00
|
|
|
import 'package:photos/ui/components/dialog_widget.dart';
|
2022-10-05 11:48:56 +00:00
|
|
|
import 'package:photos/ui/components/expandable_menu_item_widget.dart';
|
2023-01-31 12:21:57 +00:00
|
|
|
import 'package:photos/ui/components/menu_item_widget/menu_item_widget.dart';
|
2022-12-29 13:52:04 +00:00
|
|
|
import 'package:photos/ui/components/models/button_type.dart';
|
2023-06-06 09:57:17 +00:00
|
|
|
import 'package:photos/ui/settings/backup/backup_folder_selection_page.dart';
|
|
|
|
import 'package:photos/ui/settings/backup/backup_settings_screen.dart';
|
2022-03-08 19:43:51 +00:00
|
|
|
import 'package:photos/ui/settings/common_settings.dart';
|
2022-07-01 14:39:02 +00:00
|
|
|
import 'package:photos/ui/tools/deduplicate_page.dart';
|
|
|
|
import 'package:photos/ui/tools/free_space_page.dart';
|
2021-06-28 14:30:48 +00:00
|
|
|
import 'package:photos/utils/data_util.dart';
|
|
|
|
import 'package:photos/utils/dialog_util.dart';
|
2021-06-28 10:12:21 +00:00
|
|
|
import 'package:photos/utils/navigation_util.dart';
|
2021-06-28 18:47:48 +00:00
|
|
|
import 'package:photos/utils/toast_util.dart';
|
2021-06-28 05:09:22 +00:00
|
|
|
|
|
|
|
class BackupSectionWidget extends StatefulWidget {
|
2022-12-30 12:10:17 +00:00
|
|
|
const BackupSectionWidget({Key? key}) : super(key: key);
|
2021-06-28 05:09:22 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
BackupSectionWidgetState createState() => BackupSectionWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class BackupSectionWidgetState extends State<BackupSectionWidget> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-10-05 11:48:56 +00:00
|
|
|
return ExpandableMenuItemWidget(
|
2023-04-06 05:19:52 +00:00
|
|
|
title: S.of(context).backup,
|
2022-10-05 11:48:56 +00:00
|
|
|
selectionOptionsWidget: _getSectionOptions(context),
|
|
|
|
leadingIcon: Icons.backup_outlined,
|
2022-03-08 19:43:51 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _getSectionOptions(BuildContext context) {
|
2022-06-19 10:56:22 +00:00
|
|
|
final List<Widget> sectionOptions = [
|
2022-10-05 07:52:48 +00:00
|
|
|
sectionOptionSpacing,
|
2022-10-04 13:15:51 +00:00
|
|
|
MenuItemWidget(
|
2023-04-06 05:19:52 +00:00
|
|
|
captionedTextWidget: CaptionedTextWidget(
|
|
|
|
title: S.of(context).backedUpFolders,
|
2022-10-04 13:15:51 +00:00
|
|
|
),
|
2022-10-21 13:37:57 +00:00
|
|
|
pressedColor: getEnteColorScheme(context).fillFaint,
|
2022-10-04 13:15:51 +00:00
|
|
|
trailingIcon: Icons.chevron_right_outlined,
|
|
|
|
trailingIconIsMuted: true,
|
2023-02-01 01:42:26 +00:00
|
|
|
onTap: () async {
|
2022-06-19 10:56:22 +00:00
|
|
|
routeToPage(
|
|
|
|
context,
|
2023-04-06 05:19:52 +00:00
|
|
|
BackupFolderSelectionPage(
|
|
|
|
buttonText: S.of(context).backup,
|
2022-06-19 10:56:22 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-10-05 07:52:48 +00:00
|
|
|
sectionOptionSpacing,
|
2022-10-28 06:19:49 +00:00
|
|
|
MenuItemWidget(
|
2023-04-06 05:19:52 +00:00
|
|
|
captionedTextWidget: CaptionedTextWidget(
|
|
|
|
title: S.of(context).backupSettings,
|
2022-10-28 06:19:49 +00:00
|
|
|
),
|
|
|
|
pressedColor: getEnteColorScheme(context).fillFaint,
|
|
|
|
trailingIcon: Icons.chevron_right_outlined,
|
|
|
|
trailingIconIsMuted: true,
|
2023-02-01 01:42:26 +00:00
|
|
|
onTap: () async {
|
2022-10-28 06:19:49 +00:00
|
|
|
routeToPage(
|
|
|
|
context,
|
|
|
|
const BackupSettingsScreen(),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
sectionOptionSpacing,
|
2022-06-19 10:56:22 +00:00
|
|
|
];
|
2022-10-28 09:56:51 +00:00
|
|
|
|
2022-06-19 10:56:22 +00:00
|
|
|
sectionOptions.addAll(
|
|
|
|
[
|
2022-10-04 13:15:51 +00:00
|
|
|
MenuItemWidget(
|
2023-04-06 05:19:52 +00:00
|
|
|
captionedTextWidget: CaptionedTextWidget(
|
|
|
|
title: S.of(context).freeUpDeviceSpace,
|
2022-10-04 13:15:51 +00:00
|
|
|
),
|
2022-10-21 13:37:57 +00:00
|
|
|
pressedColor: getEnteColorScheme(context).fillFaint,
|
2022-10-04 13:15:51 +00:00
|
|
|
trailingIcon: Icons.chevron_right_outlined,
|
|
|
|
trailingIconIsMuted: true,
|
2023-02-01 03:44:54 +00:00
|
|
|
showOnlyLoadingState: true,
|
2021-07-28 14:28:12 +00:00
|
|
|
onTap: () async {
|
2022-06-09 11:34:25 +00:00
|
|
|
BackupStatus status;
|
|
|
|
try {
|
|
|
|
status = await SyncService.instance.getBackupStatus();
|
2022-07-03 10:09:01 +00:00
|
|
|
} catch (e) {
|
2022-12-26 11:09:29 +00:00
|
|
|
showGenericErrorDialog(context: context);
|
2022-06-09 11:34:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-28 14:28:12 +00:00
|
|
|
if (status.localIDs.isEmpty) {
|
2022-06-11 08:23:52 +00:00
|
|
|
showErrorDialog(
|
|
|
|
context,
|
2023-04-06 05:19:52 +00:00
|
|
|
S.of(context).allClear,
|
|
|
|
S.of(context).noDeviceThatCanBeDeleted,
|
2022-06-11 08:23:52 +00:00
|
|
|
);
|
2021-07-28 14:28:12 +00:00
|
|
|
} else {
|
2022-12-30 12:10:17 +00:00
|
|
|
final bool? result =
|
2022-10-04 04:16:40 +00:00
|
|
|
await routeToPage(context, FreeSpacePage(status));
|
2021-07-28 14:28:12 +00:00
|
|
|
if (result == true) {
|
|
|
|
_showSpaceFreedDialog(status);
|
2021-07-12 11:54:43 +00:00
|
|
|
}
|
2021-07-28 14:28:12 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2022-10-05 07:52:48 +00:00
|
|
|
sectionOptionSpacing,
|
2022-10-04 13:15:51 +00:00
|
|
|
MenuItemWidget(
|
2023-04-06 05:19:52 +00:00
|
|
|
captionedTextWidget: CaptionedTextWidget(
|
|
|
|
title: S.of(context).removeDuplicates,
|
2022-10-04 13:15:51 +00:00
|
|
|
),
|
2022-10-21 13:37:57 +00:00
|
|
|
pressedColor: getEnteColorScheme(context).fillFaint,
|
2022-10-04 13:15:51 +00:00
|
|
|
trailingIcon: Icons.chevron_right_outlined,
|
|
|
|
trailingIconIsMuted: true,
|
2023-02-01 03:44:54 +00:00
|
|
|
showOnlyLoadingState: true,
|
2021-09-14 19:25:29 +00:00
|
|
|
onTap: () async {
|
2021-09-28 12:51:20 +00:00
|
|
|
List<DuplicateFiles> duplicates;
|
2021-09-28 12:16:15 +00:00
|
|
|
try {
|
2021-09-28 12:51:20 +00:00
|
|
|
duplicates =
|
2021-09-28 12:16:15 +00:00
|
|
|
await DeduplicationService.instance.getDuplicateFiles();
|
|
|
|
} catch (e) {
|
2022-12-26 11:09:29 +00:00
|
|
|
showGenericErrorDialog(context: context);
|
2021-09-28 12:51:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (duplicates.isEmpty) {
|
2022-06-11 08:23:52 +00:00
|
|
|
showErrorDialog(
|
|
|
|
context,
|
2023-04-06 05:19:52 +00:00
|
|
|
S.of(context).noDuplicates,
|
|
|
|
S.of(context).youveNoDuplicateFilesThatCanBeCleared,
|
2022-06-11 08:23:52 +00:00
|
|
|
);
|
2021-09-28 12:51:20 +00:00
|
|
|
} else {
|
2022-12-30 12:10:17 +00:00
|
|
|
final DeduplicationResult? result =
|
2021-09-28 12:51:20 +00:00
|
|
|
await routeToPage(context, DeduplicatePage(duplicates));
|
|
|
|
if (result != null) {
|
|
|
|
_showDuplicateFilesDeletedDialog(result);
|
|
|
|
}
|
2021-09-14 19:25:29 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2022-10-05 07:52:48 +00:00
|
|
|
sectionOptionSpacing,
|
2021-07-28 14:28:12 +00:00
|
|
|
],
|
2021-06-28 05:09:22 +00:00
|
|
|
);
|
2022-06-19 10:56:22 +00:00
|
|
|
return Column(
|
|
|
|
children: sectionOptions,
|
|
|
|
);
|
2021-06-28 05:09:22 +00:00
|
|
|
}
|
2021-06-28 14:30:48 +00:00
|
|
|
|
|
|
|
void _showSpaceFreedDialog(BackupStatus status) {
|
2022-12-29 13:52:04 +00:00
|
|
|
final DialogWidget dialog = choiceDialog(
|
2023-04-06 05:19:52 +00:00
|
|
|
title: S.of(context).success,
|
|
|
|
body: S.of(context).youHaveSuccessfullyFreedUp(formatBytes(status.size)),
|
|
|
|
firstButtonLabel: S.of(context).rateUs,
|
2022-12-29 13:52:04 +00:00
|
|
|
firstButtonOnTap: () async {
|
2023-01-07 10:32:24 +00:00
|
|
|
UpdateService.instance.launchReviewUrl();
|
2022-12-29 13:52:04 +00:00
|
|
|
},
|
|
|
|
firstButtonType: ButtonType.primary,
|
2023-04-06 05:19:52 +00:00
|
|
|
secondButtonLabel: S.of(context).ok,
|
2022-12-29 13:52:04 +00:00
|
|
|
secondButtonOnTap: () async {
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
showToast(
|
|
|
|
context,
|
2023-04-06 05:19:52 +00:00
|
|
|
S.of(context).remindToEmptyDeviceTrash,
|
2022-12-29 13:52:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2021-06-28 14:30:48 +00:00
|
|
|
);
|
|
|
|
}
|
2021-09-14 19:25:29 +00:00
|
|
|
|
2021-09-22 08:26:44 +00:00
|
|
|
void _showDuplicateFilesDeletedDialog(DeduplicationResult result) {
|
2022-12-29 13:52:04 +00:00
|
|
|
final DialogWidget dialog = choiceDialog(
|
2023-04-06 05:19:52 +00:00
|
|
|
title: S.of(context).sparkleSuccess,
|
|
|
|
body: S.of(context).duplicateFileCountWithStorageSaved(
|
|
|
|
result.count,
|
|
|
|
formatBytes(result.size),
|
|
|
|
),
|
|
|
|
firstButtonLabel: S.of(context).rateUs,
|
2022-12-29 13:52:04 +00:00
|
|
|
firstButtonOnTap: () async {
|
2023-01-07 10:32:24 +00:00
|
|
|
UpdateService.instance.launchReviewUrl();
|
2022-12-29 13:52:04 +00:00
|
|
|
},
|
|
|
|
firstButtonType: ButtonType.primary,
|
2023-04-06 05:19:52 +00:00
|
|
|
secondButtonLabel: S.of(context).ok,
|
2022-12-29 13:52:04 +00:00
|
|
|
secondButtonOnTap: () async {
|
|
|
|
showShortToast(
|
|
|
|
context,
|
2023-04-06 05:19:52 +00:00
|
|
|
S.of(context).remindToEmptyEnteTrash,
|
2022-12-29 13:52:04 +00:00
|
|
|
);
|
|
|
|
},
|
2021-09-14 19:25:29 +00:00
|
|
|
);
|
|
|
|
}
|
2021-06-28 05:09:22 +00:00
|
|
|
}
|