2023-03-22 11:38:18 +00:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-02-16 07:01:05 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2021-12-06 18:31:19 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-06-29 09:52:09 +00:00
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
2022-05-17 13:31:34 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
2021-12-06 18:31:19 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/backups/backups_cubit.dart';
|
2023-06-29 09:52:09 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_jobs/server_jobs_cubit.dart';
|
|
|
|
import 'package:selfprivacy/logic/cubit/services/services_cubit.dart';
|
|
|
|
import 'package:selfprivacy/logic/models/backup.dart';
|
|
|
|
import 'package:selfprivacy/logic/models/json/server_job.dart';
|
|
|
|
import 'package:selfprivacy/logic/models/service.dart';
|
2021-12-06 18:31:19 +00:00
|
|
|
import 'package:selfprivacy/logic/models/state_types.dart';
|
2023-03-27 17:02:44 +00:00
|
|
|
import 'package:selfprivacy/ui/components/buttons/brand_button.dart';
|
2023-07-02 15:24:07 +00:00
|
|
|
import 'package:selfprivacy/ui/components/jobs_content/server_job_card.dart';
|
2023-02-23 14:49:14 +00:00
|
|
|
import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart';
|
2021-12-06 18:31:19 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
|
2022-11-09 15:49:37 +00:00
|
|
|
import 'package:selfprivacy/ui/helpers/modals.dart';
|
2023-07-02 15:24:07 +00:00
|
|
|
import 'package:selfprivacy/ui/pages/backups/change_period_modal.dart';
|
2023-07-20 21:35:13 +00:00
|
|
|
import 'package:selfprivacy/ui/pages/backups/copy_encryption_key_modal.dart';
|
2023-07-02 15:24:07 +00:00
|
|
|
import 'package:selfprivacy/ui/pages/backups/create_backups_modal.dart';
|
|
|
|
import 'package:selfprivacy/ui/router/router.dart';
|
|
|
|
import 'package:selfprivacy/utils/extensions/duration.dart';
|
2021-12-06 18:31:19 +00:00
|
|
|
|
2023-03-22 11:38:18 +00:00
|
|
|
@RoutePage()
|
2023-07-03 20:37:23 +00:00
|
|
|
class BackupDetailsPage extends StatelessWidget {
|
2023-02-24 16:45:32 +00:00
|
|
|
const BackupDetailsPage({super.key});
|
2021-12-06 18:31:19 +00:00
|
|
|
|
|
|
|
@override
|
2022-06-05 19:36:32 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final bool isReady = context.watch<ServerInstallationCubit>().state
|
2022-05-17 13:31:34 +00:00
|
|
|
is ServerInstallationFinished;
|
2023-07-03 20:37:23 +00:00
|
|
|
final BackupsState backupsState = context.watch<BackupsCubit>().state;
|
|
|
|
final bool isBackupInitialized = backupsState.isInitialized;
|
2022-06-05 19:36:32 +00:00
|
|
|
final StateType providerState = isReady && isBackupInitialized
|
2023-06-29 09:52:09 +00:00
|
|
|
? StateType.stable
|
2021-12-06 18:31:19 +00:00
|
|
|
: StateType.uninitialized;
|
2023-07-03 20:37:23 +00:00
|
|
|
final bool preventActions = backupsState.preventActions;
|
|
|
|
final List<Backup> backups = backupsState.backups;
|
|
|
|
final bool refreshing = backupsState.refreshing;
|
2023-06-29 09:52:09 +00:00
|
|
|
final List<Service> services =
|
2023-06-29 10:51:38 +00:00
|
|
|
context.watch<ServicesCubit>().state.servicesThatCanBeBackedUp;
|
2023-07-03 20:37:23 +00:00
|
|
|
final Duration? autobackupPeriod = backupsState.autobackupPeriod;
|
2023-07-02 15:24:07 +00:00
|
|
|
final List<ServerJob> backupJobs = context
|
|
|
|
.watch<ServerJobsCubit>()
|
|
|
|
.state
|
|
|
|
.backupJobList
|
|
|
|
.where((final job) => job.status != JobStatusEnum.finished)
|
|
|
|
.toList();
|
2021-12-06 18:31:19 +00:00
|
|
|
|
2023-07-02 15:24:07 +00:00
|
|
|
if (!isReady) {
|
|
|
|
return BrandHeroScreen(
|
|
|
|
heroIcon: BrandIcons.save,
|
|
|
|
heroTitle: 'backup.card_title'.tr(),
|
|
|
|
heroSubtitle: 'not_ready_card.in_menu'.tr(),
|
|
|
|
children: const [],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isBackupInitialized) {
|
|
|
|
return BrandHeroScreen(
|
|
|
|
heroIcon: BrandIcons.save,
|
|
|
|
heroTitle: 'backup.card_title'.tr(),
|
|
|
|
heroSubtitle: 'backup.description'.tr(),
|
|
|
|
children: [
|
2022-02-16 07:01:05 +00:00
|
|
|
BrandButton.rised(
|
|
|
|
onPressed: preventActions
|
|
|
|
? null
|
|
|
|
: () async {
|
2023-06-29 09:52:09 +00:00
|
|
|
await context.read<BackupsCubit>().initializeBackups();
|
2022-02-16 07:01:05 +00:00
|
|
|
},
|
2022-10-03 23:32:35 +00:00
|
|
|
text: 'backup.initialize'.tr(),
|
2022-02-16 07:01:05 +00:00
|
|
|
),
|
2023-07-02 15:24:07 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return BrandHeroScreen(
|
|
|
|
heroIcon: BrandIcons.save,
|
|
|
|
heroTitle: 'backup.card_title'.tr(),
|
|
|
|
heroSubtitle: 'backup.description'.tr(),
|
|
|
|
children: [
|
2023-06-29 09:52:09 +00:00
|
|
|
ListTile(
|
|
|
|
onTap: preventActions
|
|
|
|
? null
|
|
|
|
: () {
|
|
|
|
showModalBottomSheet(
|
|
|
|
useRootNavigator: true,
|
|
|
|
context: context,
|
|
|
|
isScrollControlled: true,
|
|
|
|
builder: (final BuildContext context) =>
|
|
|
|
DraggableScrollableSheet(
|
|
|
|
expand: false,
|
|
|
|
maxChildSize: 0.9,
|
|
|
|
minChildSize: 0.4,
|
|
|
|
initialChildSize: 0.6,
|
2023-06-29 10:51:38 +00:00
|
|
|
builder: (final context, final scrollController) =>
|
2023-06-29 09:52:09 +00:00
|
|
|
CreateBackupsModal(
|
|
|
|
services: services,
|
|
|
|
scrollController: scrollController,
|
2022-06-05 22:40:34 +00:00
|
|
|
),
|
2022-02-16 07:01:05 +00:00
|
|
|
),
|
2023-06-29 09:52:09 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
leading: const Icon(
|
|
|
|
Icons.add_circle_outline_rounded,
|
2022-02-16 07:01:05 +00:00
|
|
|
),
|
2023-06-29 09:52:09 +00:00
|
|
|
title: Text(
|
|
|
|
'backup.create_new'.tr(),
|
|
|
|
),
|
|
|
|
),
|
2023-07-02 15:24:07 +00:00
|
|
|
ListTile(
|
|
|
|
onTap: preventActions
|
|
|
|
? null
|
|
|
|
: () {
|
|
|
|
showModalBottomSheet(
|
|
|
|
useRootNavigator: true,
|
|
|
|
context: context,
|
|
|
|
isScrollControlled: true,
|
|
|
|
builder: (final BuildContext context) =>
|
|
|
|
DraggableScrollableSheet(
|
|
|
|
expand: false,
|
|
|
|
maxChildSize: 0.9,
|
|
|
|
minChildSize: 0.4,
|
|
|
|
initialChildSize: 0.6,
|
|
|
|
builder: (final context, final scrollController) =>
|
|
|
|
ChangeAutobackupsPeriodModal(
|
|
|
|
scrollController: scrollController,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
leading: const Icon(
|
|
|
|
Icons.manage_history_outlined,
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
'backup.autobackup_period_title'.tr(),
|
|
|
|
),
|
|
|
|
subtitle: Text(
|
|
|
|
autobackupPeriod != null
|
|
|
|
? 'backup.autobackup_period_subtitle'.tr(
|
|
|
|
namedArgs: {
|
|
|
|
'period': autobackupPeriod.toPrettyString(context.locale)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
: 'backup.autobackup_period_never'.tr(),
|
|
|
|
),
|
|
|
|
),
|
2023-07-20 21:35:13 +00:00
|
|
|
ListTile(
|
|
|
|
onTap: preventActions
|
|
|
|
? null
|
|
|
|
: () {
|
|
|
|
showModalBottomSheet(
|
|
|
|
useRootNavigator: true,
|
|
|
|
context: context,
|
|
|
|
isScrollControlled: true,
|
|
|
|
builder: (final BuildContext context) =>
|
|
|
|
DraggableScrollableSheet(
|
|
|
|
expand: false,
|
2023-07-25 19:25:08 +00:00
|
|
|
maxChildSize: 0.9,
|
|
|
|
minChildSize: 0.5,
|
|
|
|
initialChildSize: 0.7,
|
2023-07-20 21:35:13 +00:00
|
|
|
builder: (final context, final scrollController) =>
|
|
|
|
CopyEncryptionKeyModal(
|
|
|
|
scrollController: scrollController,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
leading: const Icon(
|
|
|
|
Icons.key_outlined,
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
'backup.backups_encryption_key'.tr(),
|
|
|
|
),
|
2023-07-25 19:25:08 +00:00
|
|
|
subtitle: Text(
|
|
|
|
'backup.backups_encryption_key_subtitle'.tr(),
|
|
|
|
),
|
2023-07-20 21:35:13 +00:00
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 16),
|
2023-07-02 15:24:07 +00:00
|
|
|
if (backupJobs.isNotEmpty)
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
'backup.pending_jobs'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall!.copyWith(
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
for (final job in backupJobs)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
child: ServerJobCard(
|
|
|
|
serverJob: job,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-06-29 09:52:09 +00:00
|
|
|
if (isBackupInitialized)
|
2023-07-02 11:41:31 +00:00
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
2023-07-02 15:24:07 +00:00
|
|
|
'backup.latest_snapshots'.tr(),
|
2023-07-02 11:41:31 +00:00
|
|
|
style: Theme.of(context).textTheme.headlineSmall!.copyWith(
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
subtitle: Text(
|
2023-07-02 15:24:07 +00:00
|
|
|
'backup.latest_snapshots_subtitle'.tr(),
|
2023-07-02 11:41:31 +00:00
|
|
|
style: Theme.of(context).textTheme.labelMedium,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (backups.isEmpty)
|
2022-02-16 07:01:05 +00:00
|
|
|
ListTile(
|
2022-05-24 18:55:39 +00:00
|
|
|
leading: const Icon(
|
2023-07-02 11:41:31 +00:00
|
|
|
Icons.error_outline,
|
2022-02-16 07:01:05 +00:00
|
|
|
),
|
2023-07-02 11:41:31 +00:00
|
|
|
title: Text('backup.no_backups'.tr()),
|
2022-02-16 07:01:05 +00:00
|
|
|
),
|
2023-07-02 11:41:31 +00:00
|
|
|
if (backups.isNotEmpty)
|
|
|
|
Column(
|
2023-07-02 15:24:07 +00:00
|
|
|
children: backups.take(15).map(
|
2023-07-02 11:41:31 +00:00
|
|
|
(final Backup backup) {
|
|
|
|
final service = context
|
|
|
|
.read<ServicesCubit>()
|
|
|
|
.state
|
|
|
|
.getServiceById(backup.serviceId);
|
|
|
|
return ListTile(
|
|
|
|
onTap: preventActions
|
|
|
|
? null
|
|
|
|
: () {
|
|
|
|
showPopUpAlert(
|
|
|
|
alertTitle: 'backup.restoring'.tr(),
|
|
|
|
description: 'backup.restore_alert'.tr(
|
|
|
|
args: [backup.time.toString()],
|
|
|
|
),
|
|
|
|
actionButtonTitle: 'modals.yes'.tr(),
|
|
|
|
actionButtonOnPressed: () => {
|
|
|
|
context
|
|
|
|
.read<BackupsCubit>()
|
|
|
|
.restoreBackup(backup.id)
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
title: Text(
|
|
|
|
'${MaterialLocalizations.of(context).formatShortDate(backup.time)} ${TimeOfDay.fromDateTime(backup.time).format(context)}',
|
|
|
|
),
|
|
|
|
subtitle: Text(
|
|
|
|
service?.displayName ?? backup.fallbackServiceName,
|
|
|
|
),
|
|
|
|
leading: service != null
|
|
|
|
? SvgPicture.string(
|
|
|
|
service.svgIcon,
|
|
|
|
height: 24,
|
|
|
|
width: 24,
|
|
|
|
colorFilter: ColorFilter.mode(
|
|
|
|
Theme.of(context).colorScheme.onBackground,
|
|
|
|
BlendMode.srcIn,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: const Icon(
|
|
|
|
Icons.question_mark_outlined,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
).toList(),
|
2022-02-16 07:01:05 +00:00
|
|
|
),
|
2023-07-02 15:24:07 +00:00
|
|
|
if (backups.isNotEmpty && backups.length > 15)
|
2023-07-02 11:41:31 +00:00
|
|
|
ListTile(
|
|
|
|
title: Text(
|
2023-07-02 15:24:07 +00:00
|
|
|
'backup.show_more'.tr(),
|
2023-07-02 11:41:31 +00:00
|
|
|
style: Theme.of(context).textTheme.labelMedium,
|
2022-02-16 07:01:05 +00:00
|
|
|
),
|
2023-07-02 11:41:31 +00:00
|
|
|
leading: const Icon(
|
|
|
|
Icons.arrow_drop_down,
|
2022-02-16 07:01:05 +00:00
|
|
|
),
|
2023-07-02 15:24:07 +00:00
|
|
|
onTap: () =>
|
|
|
|
context.pushRoute(BackupsListRoute(service: null)),
|
2023-07-02 11:41:31 +00:00
|
|
|
)
|
|
|
|
],
|
2022-02-16 07:01:05 +00:00
|
|
|
),
|
2023-07-02 15:24:07 +00:00
|
|
|
const SizedBox(height: 8),
|
|
|
|
const Divider(),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
'backup.refresh'.tr(),
|
|
|
|
),
|
|
|
|
onTap: refreshing
|
|
|
|
? null
|
|
|
|
: () => {context.read<BackupsCubit>().updateBackups()},
|
|
|
|
enabled: !refreshing,
|
|
|
|
leading: const Icon(
|
|
|
|
Icons.refresh_outlined,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (providerState != StateType.uninitialized)
|
|
|
|
Column(
|
2022-02-16 07:01:05 +00:00
|
|
|
children: [
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
2023-07-02 15:24:07 +00:00
|
|
|
'backup.refetch_backups'.tr(),
|
|
|
|
),
|
|
|
|
subtitle: Text(
|
|
|
|
'backup.refetch_backups_subtitle'.tr(),
|
|
|
|
),
|
|
|
|
leading: const Icon(
|
|
|
|
Icons.cached_outlined,
|
2022-02-16 07:01:05 +00:00
|
|
|
),
|
2023-07-02 15:24:07 +00:00
|
|
|
onTap: preventActions
|
2022-02-16 07:01:05 +00:00
|
|
|
? null
|
2023-07-02 15:24:07 +00:00
|
|
|
: () => {context.read<BackupsCubit>().forceUpdateBackups()},
|
2022-02-16 07:01:05 +00:00
|
|
|
),
|
2023-07-02 15:24:07 +00:00
|
|
|
const SizedBox(height: 8),
|
|
|
|
const Divider(),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
'backup.reupload_key'.tr(),
|
2022-02-16 07:01:05 +00:00
|
|
|
),
|
2023-07-02 15:24:07 +00:00
|
|
|
subtitle: Text(
|
|
|
|
'backup.reupload_key_subtitle'.tr(),
|
|
|
|
),
|
|
|
|
leading: const Icon(
|
|
|
|
Icons.warning_amber_outlined,
|
2023-06-29 09:52:09 +00:00
|
|
|
),
|
2023-07-02 15:24:07 +00:00
|
|
|
onTap: preventActions
|
|
|
|
? null
|
|
|
|
: () => {context.read<BackupsCubit>().reuploadKey()},
|
2023-06-29 09:52:09 +00:00
|
|
|
),
|
2023-07-02 15:24:07 +00:00
|
|
|
],
|
2023-03-27 17:02:44 +00:00
|
|
|
),
|
2022-02-16 07:01:05 +00:00
|
|
|
],
|
2021-12-06 18:31:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|